src/work/akos/simann.h
changeset 1314 9269c76551cf
parent 1145 99c1aa395a58
equal deleted inserted replaced
9:c80ea62d6665 10:f3a83a88ef26
    33     double prev_cost;
    33     double prev_cost;
    34     /*! \brief Cost of the solution preceding the previous one. */
    34     /*! \brief Cost of the solution preceding the previous one. */
    35     double prev_prev_cost;
    35     double prev_prev_cost;
    36 
    36 
    37     /*! \brief Step to a neighbouring state. */
    37     /*! \brief Step to a neighbouring state. */
    38     virtual void mutate() {}
    38     virtual void mutate() = 0;
    39     /*! \brief Reverts the last mutate(). */
    39     /*! \brief Reverts the last mutate(). */
    40     virtual void revert() {}
    40     virtual void revert() = 0;
    41     /*! \brief Saves the current solution as the best one. */
    41     /*! \brief Saves the current solution as the best one. */
    42     virtual void saveAsBest() {}
    42     virtual void saveAsBest() = 0;
    43   public:
    43   public:
    44     /*! \brief Constructor. */
    44     /*! \brief Constructor. */
    45     SimAnnBase() {
    45     SimAnnBase() {
    46       best_cost = prev_cost = prev_prev_cost = INFTY;
    46       best_cost = prev_cost = prev_prev_cost = INFTY;
    47     }
    47     }
    58     double getBestCost() const { return best_cost; }
    58     double getBestCost() const { return best_cost; }
    59     /*! \brief Starts the annealing process. */
    59     /*! \brief Starts the annealing process. */
    60     void run() {
    60     void run() {
    61       controller->init();
    61       controller->init();
    62       do {
    62       do {
    63         mutate();
    63         curr_cost=mutate();
    64         if (controller->accept()) {
    64         if (controller->accept()) {
    65           controller->acceptEvent();
    65           controller->acceptEvent();
    66           if (curr_cost < best_cost) {
    66           if (curr_cost < best_cost) {
    67             saveAsBest();
    67             saveAsBest();
    68             controller->improveEvent();
    68             controller->improveEvent();