COIN-OR::LEMON - Graph Library

Changeset 956:0ff924405d21 in lemon-0.x


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

Added the SimpleController? class, and removed the first version of SimAnn? in favour of the second.

File:
1 edited

Legend:

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

    r942 r956  
    5656  private:
    5757    E *curr_ent;
    58     E *prev_ent;
    59     E *best_ent;
    60   public:
    61     SimAnn() : SimAnnBase() {}
    62     void setEntity(E &Ent) {
    63       curr_ent = new E(Ent);
    64       prev_ent = new E(Ent);
    65       best_ent = new E(Ent);
    66     }
    67     E getBestEntity() { return *best_ent; }
    68     void mutate() {
    69       *prev_ent = *curr_ent;
    70       prev_cost = curr_cost;
    71       curr_cost = curr_ent->mutate();
    72     }
    73     void revert() {
    74       E *tmp = curr_ent;
    75       curr_ent = prev_ent;
    76       prev_ent = tmp;
    77       curr_cost = prev_cost;
    78     }
    79     void saveAsBest() {
    80       *best_ent = *curr_ent;
    81       best_cost = curr_cost;
    82     }
    83   };
    84 
    85   class EntitySkeleton {
    86   public:
    87     // returns the new cost
    88     double mutate() { return 0.0; }
    89   };
    90 
    91   template <typename E>
    92   class SimAnn2 : public SimAnnBase {
    93   private:
    94     E *curr_ent;
    9558    E *best_ent;
    9659  public:
     
    11376  };
    11477
    115   class EntitySkeleton2 {
     78  class EntitySkeleton {
    11679  public:
    11780    // returns the new cost
     
    12285  };
    12386
     87  class SimpleController : public SimAnnBase::Controller {
     88  public:
     89    long iter, last_impr, max_iter, max_no_impr;
     90    double temp, annealing_factor;
     91    MyController() {
     92      iter = last_impr = 0;
     93      max_iter = 500000;
     94      max_no_impr = 20000;
     95      annealing_factor = 0.9999;
     96      temp = 1000;
     97    }
     98    void acceptEvent() {
     99      iter++;
     100    }
     101    void improveEvent() {
     102      last_impr = iter;
     103    }
     104    void rejectEvent() {
     105      iter++;
     106    }
     107    bool next() {
     108      temp *= annealing_factor;
     109      bool quit = (iter > max_iter) || (iter - last_impr > max_no_impr);
     110      return !quit;
     111    }
     112    bool accept(double cost_diff) {
     113      return (drand48() <= exp(cost_diff / temp));
     114    }
     115  };
     116
    124117}
    125118
Note: See TracChangeset for help on using the changeset viewer.