OLD | NEW |
1 #include "weighted_evaluator.h" | 1 #include "weighted_evaluator.h" |
2 | 2 |
3 #include <cstdlib> | 3 #include <cstdlib> |
4 #include <sstream> | 4 #include <sstream> |
5 | 5 |
6 #include "option_parser.h" | 6 #include "option_parser.h" |
7 #include "plugin.h" | 7 #include "plugin.h" |
8 | 8 |
9 WeightedEvaluator::WeightedEvaluator(const Options &opts) | 9 WeightedEvaluator::WeightedEvaluator(const Options &opts) |
10 : evaluator(opts.get_list<ScalarEvaluator *>("evals")[0]), | 10 : evaluator(opts.get_list<ScalarEvaluator *>("evals")[0]), |
11 w(opts.get<int>("weight")) { | 11 w(opts.get<int>("weight")) { |
12 } | 12 } |
13 | 13 |
14 WeightedEvaluator::WeightedEvaluator(ScalarEvaluator *eval, int weight) | 14 WeightedEvaluator::WeightedEvaluator(ScalarEvaluator *eval, int weight) |
15 : evaluator(eval), w(weight) { | 15 : evaluator(eval), w(weight) { |
16 } | 16 } |
17 | 17 |
18 | 18 |
19 WeightedEvaluator::~WeightedEvaluator() { | 19 WeightedEvaluator::~WeightedEvaluator() { |
20 } | 20 } |
21 | 21 |
22 void WeightedEvaluator::evaluate(int g, bool preferred) { | 22 void WeightedEvaluator::evaluate(int g, bool preferred) { |
23 evaluator->evaluate(g, preferred); | 23 evaluator->evaluate(current_evaluation_context, g, preferred); |
24 value = w * evaluator->get_value(); | 24 value = w * evaluator->get_value(current_evaluation_context); |
25 // TODO: catch overflow? | 25 // TODO: catch overflow? |
26 } | 26 } |
27 | 27 |
28 bool WeightedEvaluator::is_dead_end() const { | 28 bool WeightedEvaluator::is_last_evaluated_dead_end() const { |
29 return evaluator->is_dead_end(); | 29 return evaluator->is_dead_end(current_evaluation_context); |
30 } | 30 } |
31 | 31 |
32 bool WeightedEvaluator::dead_end_is_reliable() const { | 32 bool WeightedEvaluator::dead_end_is_reliable() const { |
33 return evaluator->dead_end_is_reliable(); | 33 return evaluator->dead_end_is_reliable(); |
34 } | 34 } |
35 | 35 |
36 int WeightedEvaluator::get_value() const { | 36 int WeightedEvaluator::get_last_evaluated_value() const { |
37 return value; | 37 return value; |
38 } | 38 } |
39 | 39 |
40 void WeightedEvaluator::get_involved_heuristics(std::set<Heuristic *> &hset) { | 40 void WeightedEvaluator::get_involved_heuristics(std::set<Heuristic *> &hset) { |
41 evaluator->get_involved_heuristics(hset); | 41 evaluator->get_involved_heuristics(hset); |
42 } | 42 } |
43 | 43 |
44 static ScalarEvaluator *_parse(OptionParser &parser) { | 44 static ScalarEvaluator *_parse(OptionParser &parser) { |
45 parser.add_list_option<ScalarEvaluator *>("evals"); | 45 parser.add_list_option<ScalarEvaluator *>("evals"); |
46 parser.add_option<int>("weight"); | 46 parser.add_option<int>("weight"); |
47 Options opts = parser.parse(); | 47 Options opts = parser.parse(); |
48 if (parser.dry_run()) | 48 if (parser.dry_run()) |
49 return 0; | 49 return 0; |
50 else | 50 else |
51 return new WeightedEvaluator(opts); | 51 return new WeightedEvaluator(opts); |
52 } | 52 } |
53 | 53 |
54 static Plugin<ScalarEvaluator> _plugin("weight", _parse); | 54 static Plugin<ScalarEvaluator> _plugin("weight", _parse); |
OLD | NEW |