COIN-OR::LEMON - Graph Library

Changeset 957:4dd4eaee28e7 in lemon-0.x for src/work/akos


Ignore:
Timestamp:
11/04/04 19:48:58 (20 years ago)
Author:
Akos Ladanyi
Branch:
default
Phase:
public
Convert:
svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@1340
Message:

Now the controller asks SimAnnBase? for the various costs.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/work/akos/simann.h

    r956 r957  
    2323      curr_cost = prev_cost = best_cost = INFTY;
    2424    }
    25     void setController(Controller &_controller) { controller = &_controller; }
     25    void setController(Controller &_controller) {
     26      controller = &_controller;
     27      controller->setBase(this);
     28    }
     29    double getCurrCost() { return curr_cost; }
     30    double getPrevCost() { return prev_cost; }
    2631    double getBestCost() { return best_cost; }
    2732    void run() {
    2833      while (controller->next()) {
    2934        mutate();
    30         if (controller->accept(prev_cost - curr_cost)) {
     35        if (controller->accept()) {
    3136          controller->acceptEvent();
    3237          if (curr_cost < best_cost) {
     
    4449    class Controller {
    4550    public:
     51      SimAnnBase *base;
    4652      virtual void acceptEvent() {}
    4753      virtual void improveEvent() {}
    4854      virtual void rejectEvent() {}
     55      virtual void setBase(SimAnnBase *_base) { base = _base; }
    4956      virtual bool next() = 0;
    50       virtual bool accept(double cost_diff) = 0;
     57      virtual bool accept() = 0;
    5158    };
    5259  };
     
    5865    E *best_ent;
    5966  public:
    60     SimAnn2() : SimAnnBase() {}
    61     void setEntity(E &Ent) {
    62       curr_ent = new E(Ent);
    63       best_ent = new E(Ent);
     67    SimAnn() : SimAnnBase() {}
     68    void setEntity(E &ent) {
     69      curr_ent = new E(ent);
     70      best_ent = new E(ent);
    6471    }
    6572    E getBestEntity() { return *best_ent; }
     
    8996    long iter, last_impr, max_iter, max_no_impr;
    9097    double temp, annealing_factor;
    91     MyController() {
     98    SimpleController() {
    9299      iter = last_impr = 0;
    93100      max_iter = 500000;
     
    110117      return !quit;
    111118    }
    112     bool accept(double cost_diff) {
    113       return (drand48() <= exp(cost_diff / temp));
     119    bool accept() {
     120      return (drand48() <= exp(base->getPrevCost() - base->getCurrCost() / temp));
    114121    }
    115122  };
Note: See TracChangeset for help on using the changeset viewer.