axiom.cpp
Go to the documentation of this file.
00001 #include "helper_functions.h"
00002 #include "axiom.h"
00003 #include "variable.h"
00004 
00005 #include <iostream>
00006 #include <fstream>
00007 #include <cassert>
00008 using namespace std;
00009 
00010 Axiom_relational::Axiom_relational(istream &in,
00011         const vector<Variable *> &variables)
00012 {
00013     check_magic(in, "begin_rule");
00014     int count; // number of conditions
00015     in >> count;
00016     for(int i = 0; i < count; i++) {
00017         int varNo, val;
00018         in >> varNo >> val;
00019         conditions.push_back(Condition(variables[varNo], val));
00020     }
00021     int varNo, oldVal, newVal;
00022     in >> varNo >> oldVal >> newVal;
00023     effect_var = variables[varNo];
00024     old_val = oldVal;
00025     effect_val = newVal;
00026     check_magic(in, "end_rule");
00027 }
00028 
00029 bool Axiom_relational::is_redundant() const
00030 {
00031     return effect_var->get_level() == -1;
00032 }
00033 
00034 void strip_Axiom_relationals(vector<Axiom_relational> &axiom_relationals)
00035 {
00036     int old_count = axiom_relationals.size();
00037     int new_index = 0;
00038     for(int i = 0; i < axiom_relationals.size(); i++)
00039         if(!axiom_relationals[i].is_redundant())
00040             axiom_relationals[new_index++] = axiom_relationals[i];
00041     axiom_relationals.erase(axiom_relationals.begin() + new_index,
00042             axiom_relationals.end());
00043     cout << axiom_relationals.size() << " of " << old_count
00044         << " Axiom_relational rules necessary." << endl;
00045 }
00046 
00047 void strip_Axiom_functionals(vector<Axiom_functional> &axiom_functionals)
00048 {
00049     int old_count = axiom_functionals.size();
00050     int new_index = 0;
00051     for(int i = 0; i < axiom_functionals.size(); i++)
00052         if(!axiom_functionals[i].is_redundant())
00053             axiom_functionals[new_index++] = axiom_functionals[i];
00054     axiom_functionals.erase(axiom_functionals.begin() + new_index,
00055             axiom_functionals.end());
00056     cout << axiom_functionals.size() << " of " << old_count
00057         << " Axiom_functional rules necessary." << endl;
00058 }
00059 
00060 void Axiom_relational::dump() const
00061 {
00062     cout << "relational axiom:" << endl;
00063     cout << "conditions:";
00064     for(int i = 0; i < conditions.size(); i++)
00065         cout << "  " << conditions[i].var->get_name() << " := "
00066             << conditions[i].cond;
00067     cout << endl;
00068     cout << "derived:" << endl;
00069     cout << effect_var->get_name() << " -> " << effect_val << endl;
00070     cout << endl;
00071 }
00072 
00073 void Axiom_relational::generate_cpp_input(ostream &outfile) const
00074 {
00075     assert(effect_var->get_level() != -1);
00076     outfile << "begin_rule" << endl;
00077     outfile << conditions.size() << endl;
00078     for(int i = 0; i < conditions.size(); i++) {
00079         assert(conditions[i].var->get_level() != -1);
00080         outfile << conditions[i].var->get_level() << " " << conditions[i].cond
00081             << endl;
00082     }
00083     outfile << effect_var->get_level() << " " << old_val << " " << effect_val
00084         << endl;
00085     outfile << "end_rule" << endl;
00086 }
00087 
00088 Axiom_functional::Axiom_functional(istream &in,
00089         const vector<Variable *> &variables, bool comparison)
00090 {
00091     this->comparison = false;
00092     int varNo, varNo1, varNo2;
00093     in >> varNo;
00094     if(comparison) {
00095         in >> cop;
00096     } else {
00097         in >> fop;
00098     }
00099     in >> varNo1 >> varNo2;
00100     effect_var = variables[varNo];
00101     if(comparison == true) {
00102         effect_var->set_comparison();
00103         this->set_comparison();
00104     } else {
00105         effect_var->set_subterm();
00106     }
00107     left_var = variables[varNo1];
00108     right_var = variables[varNo2];
00109 }
00110 
00111 bool Axiom_functional::is_redundant() const
00112 {
00113     return effect_var->get_level() == -1;
00114 }
00115 
00116 void Axiom_functional::dump() const
00117 {
00118     cout << "functional ";
00119     if(this->is_comparison()) {
00120         cout << "(comparison) ";
00121     } else {
00122         cout << "(subterm) ";
00123     }
00124     cout << "axiom" << endl;
00125 
00126     cout << effect_var->get_name() << " contains the value of "
00127         << left_var->get_name() << " ";
00128     if(is_comparison()) {
00129         cout << cop;
00130     } else {
00131         cout << fop;
00132     }
00133     cout << " " << right_var->get_name() << endl;
00134     cout << endl;
00135 }
00136 
00137 void Axiom_functional::generate_cpp_input(ostream &outfile) const
00138 {
00139     assert(effect_var->get_level() != -1);
00140     outfile << effect_var->get_level() << " ";
00141     if(is_comparison()) {
00142         outfile << cop;
00143     } else {
00144         outfile << fop;
00145     }
00146     outfile << " " << left_var->get_level() << " " << right_var->get_level() << endl;
00147 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines


tfd_modules
Author(s): Maintained by Christian Dornhege (see AUTHORS file).
autogenerated on Tue Jan 22 2013 12:25:02