00001 #ifndef COMPMOD_H
00002 #define COMPMOD_H
00003
00004 #include <vector>
00005 #include <cstdlib>
00006 #include <iterator>
00007 #include <set>
00008 #include <map>
00009 #include <stdexcept>
00010
00011 #include "parser-classes.hpp"
00012 #include "unify.hpp"
00013
00019 class compmod
00020 {
00021 public:
00022
00026 enum strategy { STRATEGY_RANDOM = 1, STRATEGY_FIRST,
00027 STRATEGY_LAST };
00028
00032 class compmod_error: public std::exception {};
00033
00037 class entry
00038 {
00039 public:
00040
00046 friend std::ostream &operator<<(std::ostream &os, const entry &e);
00047
00052 entry(const c_rule *r);
00053
00058 static void init();
00059
00066 bool operator<(const entry &rhs) const;
00067
00071 const c_rule *rule;
00072
00077 mutable std::set<int> possibles;
00078
00079 private:
00080
00085 static std::map<std::string, std::set<int> > all_possibles;
00086 };
00087
00094 friend std::ostream &operator<<(std::ostream &os, const compmod &c);
00095
00102 compmod(c_rule *rule, std::string &random_seed);
00103
00107 void finalise();
00108
00114 static strategy get_strategy(const std::string &name);
00115
00120 void report_answer(const c_term *ans_head) const;
00121
00127 bool extend_set();
00128
00138 void set_pick_strategy(const std::string &s);
00139
00144 void set_ans_a_pick_strategy(const strategy &s);
00145
00150 void set_ans_b_pick_strategy(const strategy &s);
00151
00156 void set_calls_pick_strategy(const strategy &s);
00157
00163 void set_possibles_strategy(const strategy &s);
00164
00168 void set_local_ebc_percentage(size_t p);
00169
00170 private:
00171
00175 void deep_delete();
00176
00182 entry get_next_entry(const std::set<entry> &s, compmod::strategy pick_strategy) const;
00183
00188 entry get_next_call() const;
00189
00194 entry get_next_answer_alternative() const;
00195
00200 entry get_next_answer_bound() const;
00201
00205 void extend_by_call();
00206
00210 void extend_by_answer_alternative();
00211
00215 void extend_by_answer_bound();
00216
00222 std::pair<const c_rule*, unifier*> add_to_set(c_rule *rule);
00223
00235 void extend_by_first_answer(const c_rule *rule, const con_type &answer, const unifier *mgu);
00236
00245 void change_constraint_disjunction_call(const c_rule *original, con_type addition);
00246
00255 void change_constraint_disjunction_answer(const c_rule *original, con_type addition);
00256
00264 void change_constraint_disjunction(const c_rule *original, con_type addition);
00265
00274 void change_constraint_conjunction_call(const c_rule *original, con_type addition);
00275
00284 void change_constraint_conjunction_answer(const c_rule *original, con_type addition);
00285
00293 void change_constraint_conjunction(const c_rule *original, con_type addition);
00294
00308 bool get_answer(const c_term *t, con_type &answer, unifier &mgu) const;
00309
00317 void get_calls(const c_term *t, std::vector<const c_rule*> &calls) const;
00318
00324 void fatal_error() const;
00325
00326 public:
00331 std::set<entry> calls;
00332
00337 std::set<entry> ob_calls;
00338
00343 std::set<entry> ans_a;
00344
00349 std::set<entry> ans_b;
00350
00355 std::set<entry> ob_ans_a;
00356
00361 std::set<entry> ob_ans_b;
00362
00366 strategy calls_pick_strategy;
00367
00372 strategy ans_a_pick_strategy;
00373
00377 strategy ans_b_pick_strategy;
00378
00382 strategy possibles_strategy;
00383
00388 std::string pick_strategy;
00389
00396 size_t percent_local_extensions;
00397
00404 std::map<const c_rule*, std::pair<const c_rule*, unifier*> > answer_extension;
00405
00409 std::set<const c_rule*> used_ebc;
00410
00415 std::vector<c_rule*> all_rules;
00416 };
00417
00418 #endif // COMPMOD_H