ListGraph compilation bug fixed.
6 const double INFTY = 1e24;
12 Controller *controller;
18 virtual void mutate() = 0;
19 virtual void revert() = 0;
20 virtual void saveAsBest() = 0;
23 curr_cost = prev_cost = best_cost = INFTY;
25 void setController(Controller &_controller) { controller = &_controller; }
26 double getBestCost() { return best_cost; }
28 while (controller->next()) {
30 if (controller->accept(prev_cost - curr_cost)) {
31 controller->acceptEvent();
32 if (curr_cost < best_cost) {
34 controller->improveEvent();
39 controller->rejectEvent();
46 virtual void acceptEvent() {}
47 virtual void improveEvent() {}
48 virtual void rejectEvent() {}
49 virtual bool next() = 0;
50 virtual bool accept(double cost_diff) = 0;
55 class SimAnn : public SimAnnBase {
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);
67 E getBestEntity() { return *best_ent; }
69 *prev_ent = *curr_ent;
70 prev_cost = curr_cost;
71 curr_cost = curr_ent->mutate();
77 curr_cost = prev_cost;
80 *best_ent = *curr_ent;
81 best_cost = curr_cost;
85 class EntitySkeleton {
87 // returns the new cost
88 double mutate() { return 0.0; }
92 class SimAnn2 : public SimAnnBase {
97 SimAnn2() : SimAnnBase() {}
98 void setEntity(E &Ent) {
99 curr_ent = new E(Ent);
100 best_ent = new E(Ent);
102 E getBestEntity() { return *best_ent; }
110 *best_ent = *curr_ent;
111 best_cost = curr_cost;
115 class EntitySkeleton2 {
117 // returns the new cost
118 double mutate() { return 0.0; }
119 // restores the entity to its previous state i.e. reverts the effects of