Go to the documentation of this file.00001 #include "tfd_modules/module_api/pddlModuleTypes.h"
00002 #include "printTypes.h"
00003 #include <iomanip>
00004 #include <iostream>
00005
00006 #include <deque>
00007 using std::deque;
00008 namespace modules {
00009
00010 std::ostream & operator<<(std::ostream & os, const Parameter & p)
00011 {
00012 if(p.value.empty()) {
00013 os << "?" << p.name << " - " << p.type;
00014 } else {
00015 os << "?" << p.name << " - " << p.type << " : " << p.value;
00016 }
00017 return os;
00018 }
00019
00020 std::ostream & operator<<(std::ostream & os, const ParameterList & pl)
00021 {
00022 bool first = true;
00023 for(ParameterList::const_iterator it = pl.begin(); it != pl.end(); it++) {
00024 if(first) {
00025 os << *it;
00026 first = false;
00027 } else {
00028 os << ", " << *it;
00029 }
00030 }
00031 return os;
00032 }
00033
00034 std::ostream & operator<<(std::ostream & os, const Predicate & p)
00035 {
00036 os << p.name << "(";
00037 os << p.parameters;
00038 os << ") : ";
00039 os << p.value;
00040 return os;
00041 }
00042
00043 int pcomp(const Predicate & n1, const Predicate & n2)
00044 {
00045 bool res = false;
00046 if(n1.parameters.size() != n2.parameters.size())
00047 return n1.parameters.size() > n2.parameters.size();
00048 if(n1.parameters.size() == 1 && n2.parameters.size() == 1) {
00049 if(n1.parameters.front().value.compare(n2.parameters.front().value) != 0) {
00050 res = n1.parameters.front().value < n2.parameters.front().value;
00051 return res;
00052 }
00053 }
00054 if(n1.name.length() != n2.name.length())
00055 return n1.name.length() < n2.name.length();
00056 res = n1.name < n2.name;
00057 return res;
00058 }
00059
00060 std::ostream & operator<<(std::ostream & os, const PredicateList & nl_)
00061 {
00062 deque<Predicate> dn;
00063 for(PredicateList::const_iterator it = nl_.begin(); it != nl_.end(); it++) {
00064 dn.push_back(*it);
00065 }
00066 sort(dn.begin(), dn.end(), pcomp);
00067 PredicateList pl;
00068 for(deque<Predicate>::iterator it = dn.begin(); it != dn.end(); it++) {
00069 pl.push_back(*it);
00070 }
00071
00072 bool first = true;
00073 for(PredicateList::const_iterator it = pl.begin(); it != pl.end(); it++) {
00074 if(PredicateList_OStreamMode::s_Condensed) {
00075 if(!it->value)
00076 continue;
00077 os << it->name << "(";
00078 bool pfirst = true;
00079 for(ParameterList::const_iterator itp = it->parameters.begin(); itp != it->parameters.end(); itp++) {
00080 if(!pfirst)
00081 os << ", " << itp->value;
00082 else {
00083 os << itp->value;
00084 pfirst = false;
00085 }
00086 }
00087 os << ") ";
00088 } else {
00089 os << *it;
00090 first = false;
00091 os << std::endl;
00092 }
00093 }
00094 return os;
00095 }
00096
00097 std::ostream & operator<<(std::ostream & os, const NumericalFluent & n)
00098 {
00099 os << n.name << "(";
00100 os << n.parameters;
00101 os << ") : ";
00102 os << n.value;
00103 return os;
00104 }
00105
00106 int nfcomp(const NumericalFluent & n1, const NumericalFluent & n2)
00107 {
00108 bool res = false;
00109 if(n1.parameters.size() != n2.parameters.size())
00110 return n1.parameters.size() > n2.parameters.size();
00111 if(n1.parameters.size() == 1 && n2.parameters.size() == 1) {
00112 if(n1.parameters.front().value.compare(n2.parameters.front().value) != 0) {
00113 res = n1.parameters.front().value < n2.parameters.front().value;
00114 return res;
00115 }
00116 }
00117 if(n1.name.length() != n2.name.length())
00118 return n1.name.length() < n2.name.length();
00119 res = n1.name < n2.name;
00120 return res;
00121 }
00122
00123 std::ostream & operator<<(std::ostream & os, const NumericalFluentList & nl_)
00124 {
00125 deque<NumericalFluent> dn;
00126 for(NumericalFluentList::const_iterator it = nl_.begin(); it != nl_.end(); it++) {
00127 dn.push_back(*it);
00128 }
00129 sort(dn.begin(), dn.end(), nfcomp);
00130 NumericalFluentList nl;
00131 for(deque<NumericalFluent>::iterator it = dn.begin(); it != dn.end(); it++) {
00132 nl.push_back(*it);
00133 }
00134 bool first = true;
00135 int count = 0;
00136 for(NumericalFluentList::const_iterator it = nl.begin(); it != nl.end(); it++) {
00137 if(NumericalFluentList_OStreamMode::s_Condensed) {
00138 std::ios_base::fmtflags flagsBak = os.flags();
00139 os << std::fixed << std::setprecision(2);
00140 os << it->name << "(";
00141 bool pfirst = true;
00142 for(ParameterList::const_iterator itp = it->parameters.begin(); itp != it->parameters.end(); itp++) {
00143 if(!pfirst)
00144 os << ", " << itp->value;
00145 else {
00146 os << itp->value;
00147 pfirst = false;
00148 }
00149 }
00150 os << ") = " << it->value << " ";
00151 count++;
00152 if(count >= 4) {
00153 count = 0;
00154 os << std::endl;
00155 }
00156 os.setf(flagsBak);
00157 } else {
00158 if(first) {
00159 os << *it;
00160 first = false;
00161 } else {
00162 os << ", " << *it;
00163 }
00164 os<<std::endl;
00165 }
00166 }
00167 return os;
00168 }
00169
00170 bool PredicateList_OStreamMode::s_Condensed = false;
00171 bool NumericalFluentList_OStreamMode::s_Condensed = false;
00172
00173 }
00174