COIN-OR::LEMON - Graph Library

Changeset 1096:1cfb25ef14d2 in lemon-0.x for src/work


Ignore:
Timestamp:
01/26/05 10:00:40 (19 years ago)
Author:
Akos Ladanyi
Branch:
default
Phase:
public
Convert:
svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@1495
Message:

Various changes.

Location:
src/work/akos
Files:
2 edited

Legend:

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

    r1023 r1096  
    9999    }
    100100    void saveAsBest() {
    101       *best_ent = *curr_ent;
     101      delete(best_ent);
     102      best_ent = new E(*curr_ent);
    102103      best_cost = curr_cost;
    103104    }
     
    130131     */
    131132    SimpleController(long _max_iter = 500000, long _max_no_impr = 20000,
    132     double _temp = 1000, double _ann_fact = 0.9999) : iter(0), last_impr(0),
     133    double _temp = 1000.0, double _ann_fact = 0.9999) : iter(0), last_impr(0),
    133134    max_iter(_max_iter), max_no_impr(_max_no_impr), temp(_temp),
    134135    ann_fact(_ann_fact) {}
     
    150151      double cost_diff = base->getPrevCost() - base->getCurrCost();
    151152      if (cost_diff < 0.0) {
    152         return (drand48() <= exp(cost_diff / temp));
     153        bool ret = drand48() <= exp(cost_diff / temp);
     154        return ret;
    153155      }
    154156      else {
     
    167169    /*! \param time the elapsed time in seconds */
    168170    virtual double threshold(double time) {
    169       // this is the function 1 / log(x) scaled and offset
     171      // 1 / log(x)
     172      /*
    170173      static double xm = 5.0 / end_time;
    171174      static double ym = start_threshold / (1 / log(1.2) - 1 / log(5.0 + 1.2));
    172175      return ym * (1 / log(xm * time + 1.2) - 1 / log(5.0 + 1.2));
     176      */
     177      return (-1.0) * start_threshold / end_time * time + start_threshold;
    173178    }
    174179  public:
     
    185190     */
    186191    AdvancedController(double _end_time, double _alpha = 0.2,
    187     double _beta = 0.9, double _gamma = 1.2) : alpha(_alpha), beta(_beta),
    188     gamma(_gamma), end_time(_end_time), ann_fact(0.9999), warmup(true) {}
     192    double _beta = 0.9, double _gamma = 1.6) : alpha(_alpha), beta(_beta),
     193    gamma(_gamma), end_time(_end_time), ann_fact(0.99999999), warmup(true) {}
    189194    void init() {
    190195      avg_cost = base->getCurrCost();
     
    193198      avg_cost = alpha * base->getCurrCost() + (1.0 - alpha) * avg_cost;
    194199      if (warmup) {
    195         static double max_cost_diff = 0.0;
    196         static int incr_cnt = 0;
    197         double cost_diff = base->getCurrCost() - base->getPrevCost();
    198         if (cost_diff > 0.0) {
    199           incr_cnt++;
    200           if (cost_diff > max_cost_diff) {
    201             max_cost_diff = cost_diff;
    202           }
    203         }
    204         if (incr_cnt >= 100) {
     200        static int cnt = 0;
     201        cnt++;
     202        if (cnt >= 100) {
    205203          // calculate starting threshold and starting temperature
    206           start_threshold = fabs(base->getBestCost() - avg_cost);
    207           temp = max_cost_diff / log(0.5);
     204          start_threshold = 5.0 * fabs(base->getBestCost() - avg_cost);
     205          //temp = max_cost_diff / log(0.5);
     206          temp = 10000.0;
    208207          warmup = false;
    209208          timer.reset();
     
    228227          // increase the temperature
    229228          temp *= gamma;
     229          ann_fact = 0.99999999;
    230230        }
    231231        temp *= ann_fact;
  • src/work/akos/simann_demo.cc

    r1023 r1096  
    1111
    1212int main() {
     13  /*
    1314  SimAnn<MyEntity> simann;
    1415  SimpleController ctrl;
     
    1718  simann.setEntity(ent);
    1819  simann.run();
     20  */
    1921
    2022  SimAnn<MyEntity> simann2;
    21   AdvancedController ctrl2(20.0);
     23  AdvancedController ctrl2(10.0);
    2224  simann2.setController(ctrl2);
    2325  MyEntity ent2;
Note: See TracChangeset for help on using the changeset viewer.