axioms.h
Go to the documentation of this file.
00001 #ifndef AXIOMS_H
00002 #define AXIOMS_H
00003 
00004 #include <cassert>
00005 #include <string>
00006 #include <vector>
00007 
00008 #include "globals.h"
00009 #include "state.h"
00010 #include "operator.h"
00011 
00012 class TimeStampedState;
00013 
00014 struct Prevail;
00015 
00016 class Axiom
00017 {
00018     public:
00019         int affected_variable;
00020 };
00021 
00022 class LogicAxiom : public Axiom
00023 {
00024     public:
00025         std::vector<Prevail> prevail; // var, val
00026         double old_value, new_value;
00027 
00028         LogicAxiom(std::istream &in);
00029 
00030         void dump()
00031         {
00032             for (int i = 0; i < prevail.size(); i++) {
00033                 cout << "[";
00034                 prevail[i].dump();
00035                 cout << "]";
00036             }
00037             cout << "[" << g_variable_name[affected_variable] << ": "
00038                 << old_value << "]";
00039             cout << " => " << g_variable_name[affected_variable] << ": "
00040                 << new_value << endl;
00041         }
00042 
00043         bool is_applicable(const TimeStampedState &state) const
00044         {
00045             for(int i = 0; i < prevail.size(); i++)
00046                 if(!prevail[i].is_applicable(state))
00047                     return false;
00048             return true;
00049         }
00050 };
00051 
00052 class NumericAxiom : public Axiom
00053 {
00054     public:
00055         int var_lhs;
00056         int var_rhs;
00057         binary_op op;
00058 
00059         NumericAxiom(std::istream &in);
00060 
00061         void dump()
00062         {
00063             cout << g_variable_name[affected_variable] << " = ("
00064                 << g_variable_name[var_lhs];
00065             cout << " " << op << " ";
00066             cout << g_variable_name[var_rhs] << ")" << endl;
00067         }
00068 };
00069 
00070 class AxiomEvaluator
00071 {
00072         struct LogicAxiomRule;
00073         struct LogicAxiomLiteral
00074         {
00075             std::vector<LogicAxiomRule *> condition_of;
00076         };
00077         struct LogicAxiomRule
00078         {
00079             int condition_count;
00080             int unsatisfied_conditions;
00081             int effect_var;
00082             int effect_val;
00083             LogicAxiomLiteral *effect_literal;
00084             LogicAxiomRule(int cond_count, int eff_var, int eff_val,
00085                     LogicAxiomLiteral *eff_literal) :
00086                 condition_count(cond_count), unsatisfied_conditions(cond_count),
00087                 effect_var(eff_var), effect_val(eff_val),
00088                 effect_literal(eff_literal)
00089                 {
00090                 }
00091         };
00092         struct NegationByFailureInfo
00093         {
00094             int var_no;
00095             LogicAxiomLiteral *literal;
00096             NegationByFailureInfo(int var, LogicAxiomLiteral *lit) :
00097                 var_no(var), literal(lit)
00098                 {
00099                 }
00100         };
00101 
00102         std::vector<std::vector<LogicAxiomLiteral> > axiom_literals;
00103         std::vector<LogicAxiomRule> rules;
00104         std::vector<std::vector<NegationByFailureInfo> > nbf_info_by_layer;
00105         std::vector<std::vector<Axiom*> > axioms_by_layer;
00106 
00107     private:
00108         void evaluate_arithmetic_axioms(TimeStampedState &state);
00109         void evaluate_comparison_axioms(TimeStampedState &state);
00110         void evaluate_logic_axioms(TimeStampedState &state);
00111 
00112     public:
00113         AxiomEvaluator();
00114         void evaluate(TimeStampedState &state);
00115 };
00116 
00117 #endif


tfd_modules
Author(s): Maintained by Christian Dornhege (see AUTHORS file).
autogenerated on Mon Oct 6 2014 07:52:06