- Main Page
- Namespaces
- Classes
- Files
- Related Pages

# /Users/fpy/titan-1-5-MBARI/Mers/Generators/BFIG/BFIGImplicantExpander.cpp

    00001 //==============================================================================
    00002 // Copyright (c) 2001           Model-based Embedded and Robotic Systems Group
    00003 // All Rights Reserved          Massachusetts Institute of Technology
    00004 //
    00005 // This software is provided as is. Model-based Embedded and Robotic Systems
    00006 // (MERS) group does not assume any responsibility.
    00007 //==============================================================================
    00008 //# CHECKED MJP 08-07-2002
    00009
    00010 #include "BFIGImplicantExpander.h"
    00011
    00012 #include <cassert>
    00013 #include "BFIGImplicant.h"
    00014 #include "BFIGVariable.h"
    00015 #include "BFIGAssignment.h"
    00016
    00017 using Mers::Generators::BFIG::BFIGImplicant;
    00018 using Mers::Generators::BFIG::BFIGImplicantExpander;
    00019 using Mers::Generators::BFIG::BFIGAssignment;
    00020 using Mers::Generators::BFIG::BFIGVariable;
    00021 using std::cout;
    00022 using std::endl;
    00023 using std::list;
    00024
    00025
    00026 #ifdef _MSC_VER
    00027 #include "ListManipulator.h"
    00028 using Mers::Generators::BFIG::ListManipulator;
    00029 template  ListManipulator<BFIGVariable *>;
    00030 //template  ListManipulator<BFIGAssignment const *>;
    00031 #else
    00032 typedef bool (*variable_comp_func)(BFIGVariable *, BFIGVariable *);
    00033 //typedef bool (*assignment_comp_func)(BFIGAssignment const *, BFIGAssignment const *);
    00034 #endif
    00035
    00036
    00037 static void
    00038 printAssignmentList(list<BFIGAssignment const *> const & as)
    00039 {
    00040         (void)printAssignmentList;
    00041         cout << "(";
    00042         list<BFIGAssignment const *>::const_iterator aIter;
    00043         bool start = true;
    00044         for (aIter = as.begin(); aIter != as.end(); aIter++)
    00045         {
    00046                 if (start)
    00047                         start = false;
    00048                 else
    00049                         cout << ", ";
    00050                 if (*aIter)
    00051                         cout << *(*aIter);
    00052                 else
    00053                         cout << "NULL";
    00054         }
    00055         cout << ")";
    00056 }
    00057
    00058 static void
    00059 printVariableList(list<BFIGVariable *> const & as)
    00060 {
    00061         (void)printVariableList;
    00062         cout << "(";
    00063         list<BFIGVariable *>::const_iterator aIter;
    00064         bool start = true;
    00065         for (aIter = as.begin(); aIter != as.end(); aIter++)
    00066         {
    00067                 if (start)
    00068                         start = false;
    00069                 else
    00070                         cout << ", ";
    00071                 if (*aIter)
    00072                         cout << *(*aIter);
    00073                 else
    00074                         cout << "NULL";
    00075         }
    00076         cout << ")";
    00077 }
    00078
    00079
    00080 static bool
    00081 variable_name_less(BFIGVariable * v1, BFIGVariable * v2)
    00082 {
    00083         return ( v1->getName() < v2->getName() );
    00084 }
    00085
    00086 /*#
    00087 //static bool
    00088 //assignment_name_less(BFIGAssignment const * a1, BFIGAssignment const * a2)
    00089 //{
    00090 //      return ( a1->getName() < a2->getName() );
    00091 //}
    00092 */
    00093
    00094 BFIGImplicantExpander::BFIGImplicantExpander()
    00095 : variableSet()
    00096 {
    00097         //cout << "warning: default ImplicantExpander constructor called." << endln;
    00098 }
    00099
    00100
    00101 BFIGImplicantExpander::BFIGImplicantExpander(list<BFIGVariable *> const & variables)
    00102 : variableSet(variables)
    00103 {
    00104 #ifdef _MSC_VER
    00105         ListManipulator<BFIGVariable *> lm;
    00106         lm.sort(variableSet, variable_name_less);
    00107 #else
    00108         variableSet.sort<variable_comp_func>(variable_name_less);
    00109 #endif
    00110 /*#
    00111         //cout << endl << endl << "Implicant Expander:" << endl;
    00112         //printVariableList(variableSet);
    00113         //cout << endl;
    00114         //variableSet.sort();
    00115         //printVariableList(variableSet);
    00116         //cout << endl;
    00117         //cout << endl << endl;
    00118 */
    00119 }
    00120
    00121
    00122 Mers::Generators::BFIG::BFIGImplicant *
    00123 BFIGImplicantExpander::expandImplicant(BFIGImplicant const & partialImplicant)  const
    00124 {
    00125         BFIGImplicant * res = new BFIGImplicant(partialImplicant);
    00126         expandImplicant(res);
    00127         return res;
    00128 }
    00129
    00130
    00131 void
    00132 BFIGImplicantExpander::expandImplicant(BFIGImplicant * imp)  const
    00133 {
    00134         // would be a mess otherwise anyway  - but be careful!:
    00135         imp->eliminateSiblings();
    00136
    00137         // loop through all variables we are dealing with
    00138         list<BFIGVariable *>::const_iterator variableIter;
    00139         for (variableIter = variableSet.begin();  //, assignmentIter = oldAssignments.begin();
    00140              variableIter != variableSet.end(); variableIter++)
    00141         {
    00142                 if (!imp->contains((*variableIter)))
    00143                 {
    00144                         BFIGAssignment const * newAssign = (*variableIter)->getBestAssignment();
    00145                         if (newAssign)  // ignore if null??
    00146                         {
    00147                                 imp->addAssignment(newAssign);
    00148                         }
    00149                 }
    00150         }
    00151         // keeps original assignments first in unsorted list of Implicant...
    00152 }
    00153