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 };
00081
00082
00084
00085 bool compNode::operator () (const DepNode *n0, const DepNode *n1) const
00086 {return (n0 -> Index () < n1 -> Index ());}
00087
00088
00091
00092 class DepGraph {
00093
00094 protected:
00095
00097 std::set <DepNode *, compNode> vertices_;
00098
00100 int counter_;
00101
00102 public:
00103
00105 DepGraph (): counter_ (0) {}
00106
00108 ~DepGraph () {
00109 for (std::set <DepNode *, compNode>::iterator i = vertices_.begin ();
00110 i != vertices_.end (); ++i)
00111 delete (*i);
00112 }
00113
00115 std::set <DepNode *, compNode> &Vertices ()
00116 {return vertices_;}
00117
00119 inline int &Counter ()
00120 {return counter_;}
00121
00123 void insert (exprVar *);
00124
00126 void insert (exprAux *);
00127
00129 void erase (exprVar *);
00130
00132 bool depends (int, int, bool = false);
00133
00135 void createOrder ();
00136
00138 void print (bool descend = false);
00139
00141 DepNode *lookup (int index);
00142
00144 bool checkCycles ();
00145 };
00146
00147 #endif