00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00013
00014 #include "BFIGImplicantNoMPI.h"
00015
00016 #ifdef _MSC_VER
00017 #pragma warning( disable : 4786 )
00018 #endif
00019
00020 #include <cassert>
00021 #include "BFIGAssignment.h"
00022 #include "BFIGVariable.h"
00023 #include "BFIGConstraint.h"
00024 #include "BFIGObjectiveFunction.h"
00025 #include "ListManipulator.h"
00026
00027 using namespace std;
00028 using Mers::Generators::BFIG::BFIGImplicant;
00029 using Mers::Generators::BFIG::BFIGImplicantNoMPI;
00030 using Mers::Generators::BFIG::BFIGVariable;
00031 using Mers::Generators::BFIG::BFIGAssignment;
00032 using Mers::Generators::BFIG::BFIGConstraint;
00033 using Mers::Generators::BFIG::ListManipulator;
00034 using Mers::Generators::BFIG::BFIGObjectiveFunction;
00035
00037
00039
00040 BFIGImplicantNoMPI::BFIGImplicantNoMPI(vector<BFIGConstraint const *> const & unentailedConflictsList,
00041 BFIGObjectiveFunction const * of)
00042 : BFIGImplicant(unentailedConflictsList, of)
00043 {
00044 if(objectiveFunction != NULL)
00045 bestCost = objectiveFunction->getCost(assignments);
00046 }
00047
00049
00050 BFIGImplicantNoMPI::BFIGImplicantNoMPI(const BFIGImplicant & i)
00051 : BFIGImplicant(i)
00052 {
00053 if(objectiveFunction != NULL)
00054 bestCost = objectiveFunction->getCost(assignments);
00055 }
00056
00058
00059 BFIGImplicantNoMPI::~BFIGImplicantNoMPI()
00060 {
00061 }
00062
00064
00065
00066
00067 BFIGImplicantNoMPI::BFIGImplicantNoMPI(BFIGImplicant const * parent,
00068 BFIGAssignment const * extraAssign)
00069 : BFIGImplicant(parent, extraAssign)
00070 {
00071 LOG4CPLUS_DEBUG(mLogger, "Created BFIGImplicantNoMPI");
00072
00073 if(objectiveFunction != NULL)
00074 bestCost = objectiveFunction->getCost(assignments);
00075 }
00076
00078
00079 BFIGImplicantNoMPI::BFIGImplicantNoMPI(BFIGImplicant * parent,
00080 BFIGAssignment const * extraAssign,
00081 vector<BFIGAssignment const *> siblingAssigns)
00082 : BFIGImplicant(parent, extraAssign, siblingAssigns)
00083 {
00084 LOG4CPLUS_DEBUG(mLogger, "Created BFIGImplicantNoMPI");
00085
00086 if(objectiveFunction != NULL)
00087 bestCost = objectiveFunction->getCost(assignments);
00088 }
00089
00091
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00126
00127 double
00128 BFIGImplicantNoMPI::getBestCost() const
00129 {
00130 return bestCost;
00131 }
00132
00134
00135 double
00136 BFIGImplicantNoMPI::getTrueCost() const
00137 {
00138 return bestCost;
00139 }
00140
00142
00143 void
00144 BFIGImplicantNoMPI::updateBestCost()
00145 {
00146 cerr << "<BFIGImplicantNoMPI> ERROR: Should be updating costs through Objective Function!" << endl;
00147 }
00148
00150
00151 vector<BFIGImplicant *>
00152 BFIGImplicantNoMPI::generateChildren(vector<BFIGVariable *> const * varSet)
00153 {
00154 vector<BFIGImplicant *> ext;
00155
00156
00157 delete siblingParent;
00158 siblingParent = NULL;
00159
00160
00161 list<BFIGAssignment const *> supports;
00162 if (entailsAllConflictsCheck())
00163 {
00164
00165 if (varSet)
00166 {
00167
00168 vector<BFIGVariable *>::const_iterator vIter;
00169 for (vIter = varSet->begin(); vIter != varSet->end(); vIter++)
00170 {
00171 if(*vIter == NULL)
00172 continue;
00173 if (!contains(*vIter))
00174 {
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185 vector<BFIGAssignment const *> vSupports = (*vIter)->getAssignments();
00186 for(unsigned int v = 0; v < vSupports.size(); v++){
00187 supports.push_back(vSupports[v]);
00188 }
00189 break;
00190
00191 }
00192 }
00193 } else
00194 {
00195
00196 }
00197 } else
00198 {
00199
00200 BFIGConstraint const * firstConflict = unentailedConflicts.front();
00201 supports = firstConflict->getPrimeImplicants();
00202
00203 }
00204
00205
00206 BFIGAssignment const * bestExtension = NULL;
00207 list<BFIGAssignment const *>::iterator sIter = supports.begin();
00208 while(sIter != supports.end())
00209 {
00210 bestExtension = *sIter;
00211 sIter = supports.erase(sIter);
00212 if (bestExtension->compatible(assignments))
00213 {
00214 if(ext.empty())
00215 ext.push_back(new BFIGImplicantNoMPI(this, bestExtension));
00216 else
00217 {
00218 BFIGImplicant * newParent = new BFIGImplicantNoMPI(*this);
00219 ext.push_back(new BFIGImplicantNoMPI(newParent, bestExtension));
00220 }
00221 }
00222 }
00223
00224 return ext;
00225 }
00226
00228
00229 BFIGImplicant * BFIGImplicantNoMPI::generateSibling()
00230 {
00231 BFIGImplicant * sibimp = NULL;
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276 return sibimp;
00277 }
00278
00280
00281 namespace Mers {
00282 namespace Generators {
00283 namespace BFIG {
00284 ostream&
00285 operator<<(ostream& os, BFIGImplicantNoMPI const & in)
00286 {
00287 os << "NonMPI[" ;
00288 if (!in.terse)
00289 os << in.getBestCost() << ": " ;
00290
00291 vector<BFIGAssignment const *> assigns = in.assignments;
00292 bool first = true;
00293 vector<BFIGAssignment const *>::const_iterator assignmentIter;
00294 for (assignmentIter = assigns.begin();
00295 assignmentIter != assigns.end(); assignmentIter++)
00296 {
00297 if (first)
00298 first = false;
00299 else
00300 if (in.terse)
00301 os << " ";
00302 else
00303 os << ", ";
00304 os << *(*assignmentIter) ;
00305 }
00306 if (in.essentialConflict)
00307 os << " X";
00308 if(!in.terse) {
00309 if(!in.entailsAllConflicts())
00310 os << " C";
00311 }
00312 os << "]";
00313 return os;
00314 }
00315 }
00316 }
00317 }
00318
00320