00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #ifndef DEPGRAPH_HPP
00012 #define DEPGRAPH_HPP
00013
00014 #include <vector>
00015 #include <set>
00016
00017 #include "CouenneTypes.hpp"
00018 #include "expression.hpp"
00019 #include "exprAux.hpp"
00020 #include "CouenneProblemElem.hpp"
00021
00022
00024 struct compNode {
00025 inline bool operator () (const DepNode *n0, const DepNode *n1) const;
00026 };
00027
00028
00031
00032 class DepNode {
00033
00034 protected:
00035
00037 int index_;
00038
00041 std::set <DepNode *, compNode> *depList_;
00042
00044 int order_;
00045
00046 public:
00047
00050 DepNode (int ind):
00051 index_ (ind),
00052 depList_ (new std::set <DepNode *, compNode>),
00053 order_ (-1) {}
00054
00056 ~DepNode ()
00057 {if (depList_) delete depList_;}
00058
00060 inline int Index () const
00061 {return index_;}
00062
00064 inline int Order () const
00065 {return order_;}
00066
00068 inline std::set <DepNode *, compNode> *DepList () const
00069 {return depList_;}
00070
00072 bool depends (int xi, bool = false,
00073 std::set <DepNode *, compNode> *already_visited = NULL) const;
00074
00076 void createOrder (DepGraph *);
00077
00079 void print (int = 0, bool descend = false) const;
00080
00083 void replaceIndex (DepNode *oldVarNode, DepNode *newVarNode);
00084 };
00085
00086
00088
00089 bool compNode::operator () (const DepNode *n0, const DepNode *n1) const
00090 {return (n0 -> Index () < n1 -> Index ());}
00091
00092
00095
00096 class DepGraph {
00097
00098 protected:
00099
00101 std::set <DepNode *, compNode> vertices_;
00102
00104 int counter_;
00105
00106 public:
00107
00109 DepGraph (): counter_ (0) {}
00110
00112 ~DepGraph () {
00113 for (std::set <DepNode *, compNode>::iterator i = vertices_.begin ();
00114 i != vertices_.end (); ++i)
00115 delete (*i);
00116 }
00117
00119 std::set <DepNode *, compNode> &Vertices ()
00120 {return vertices_;}
00121
00123 inline int &Counter ()
00124 {return counter_;}
00125
00127 void insert (exprVar *);
00128
00130 void insert (exprAux *);
00131
00133 void erase (exprVar *);
00134
00136 bool depends (int, int, bool = false);
00137
00139 void createOrder ();
00140
00142 void print (bool descend = false);
00143
00145 DepNode *lookup (int index);
00146
00148 bool checkCycles ();
00149
00153 void replaceIndex (int oldVar, int newVar);
00154 };
00155
00156 #endif