1.1 --- a/src/work/peter/hierarchygraph.h Mon Jul 05 15:52:35 2004 +0000
1.2 +++ b/src/work/peter/hierarchygraph.h Mon Jul 05 16:44:18 2004 +0000
1.3 @@ -9,7 +9,8 @@
1.4 #include <hugo/maps.h>
1.5
1.6 /// The namespace of HugoLib
1.7 -namespace hugo {
1.8 +namespace hugo
1.9 +{
1.10
1.11 // @defgroup empty_graph The HierarchyGraph class
1.12 // @{
1.13 @@ -21,8 +22,7 @@
1.14 /// means that a node in one layer can be a complete network in a nother
1.15 /// layer.
1.16
1.17 - template <class Gact, class Gsub>
1.18 - class HierarchyGraph
1.19 + template < class Gact, class Gsub > class HierarchyGraph
1.20 {
1.21
1.22 public:
1.23 @@ -39,138 +39,159 @@
1.24
1.25 struct actedgesubnodestruct
1.26 {
1.27 - typename Gact::Edge actedge;
1.28 - typename Gsub::Node subnode;
1.29 + typename Gact::Edge actedge;
1.30 + typename Gsub::Node subnode;
1.31 };
1.32
1.33 int edgenumber;
1.34 bool connectable;
1.35 - Gact * actuallayer;
1.36 + Gact *actuallayer;
1.37 typename Gact::Node * actuallayernode;
1.38 - Gsub * subnetwork;
1.39 - actedgesubnodestruct * assignments;
1.40 + Gsub *subnetwork;
1.41 + actedgesubnodestruct *assignments;
1.42
1.43 public:
1.44
1.45 - int addAssignment(typename Gact::Edge actedge, typename Gsub::Node subnode)
1.46 + int addAssignment (typename Gact::Edge actedge,
1.47 + typename Gsub::Node subnode)
1.48 {
1.49 - if(!(actuallayer->valid(actedge)))
1.50 - {
1.51 - cerr << "The given edge is not in the given network!" << endl;
1.52 - return -1;
1.53 - }
1.54 - else if(
1.55 - (actuallayer->id(actuallayer->tail(actedge))!=actuallayer->id(*actuallayernode))
1.56 - &&
1.57 - (actuallayer->id(actuallayer->head(actedge))!=actuallayer->id(*actuallayernode))
1.58 - )
1.59 - {
1.60 - cerr << "The given edge does not connect to the given node!" << endl;
1.61 - return -1;
1.62 - }
1.63 + if (!(actuallayer->valid (actedge)))
1.64 + {
1.65 + cerr << "The given edge is not in the given network!" << endl;
1.66 + return -1;
1.67 + }
1.68 + else if ((actuallayer->id (actuallayer->tail (actedge)) !=
1.69 + actuallayer->id (*actuallayernode))
1.70 + && (actuallayer->id (actuallayer->head (actedge)) !=
1.71 + actuallayer->id (*actuallayernode)))
1.72 + {
1.73 + cerr << "The given edge does not connect to the given node!" <<
1.74 + endl;
1.75 + return -1;
1.76 + }
1.77
1.78 - if(!(subnetwork->valid(subnode)))
1.79 - {
1.80 - cerr << "The given node is not in the given network!" << endl;
1.81 - return -1;
1.82 - }
1.83 + if (!(subnetwork->valid (subnode)))
1.84 + {
1.85 + cerr << "The given node is not in the given network!" << endl;
1.86 + return -1;
1.87 + }
1.88
1.89 - int i=0;
1.90 + int i = 0;
1.91 //while in the array there is valid note that is not equvivalent with the one that would be noted increase i
1.92 - while( (i<edgenumber) && (actuallayer->valid(assignments[i].actedge) ) && (assignments[i].actedge!=actedge) ) i++;
1.93 - if(assignments[i].actedge==actedge)
1.94 - {
1.95 - cout << "Warning: Redefinement of assigment!!!" << endl;
1.96 - }
1.97 - if(i==edgenumber)
1.98 - {
1.99 - cout << "This case can't be!!! (because there should be the guven edge in the array already and the cycle had to stop)" << endl;
1.100 - }
1.101 + while ((i < edgenumber)
1.102 + && (actuallayer->valid (assignments[i].actedge))
1.103 + && (assignments[i].actedge != actedge))
1.104 + i++;
1.105 + if (assignments[i].actedge == actedge)
1.106 + {
1.107 + cout << "Warning: Redefinement of assigment!!!" << endl;
1.108 + }
1.109 + if (i == edgenumber)
1.110 + {
1.111 + cout <<
1.112 + "This case can't be!!! (because there should be the guven edge in the array already and the cycle had to stop)"
1.113 + << endl;
1.114 + }
1.115 //if(!(actuallayer->valid(assignments[i].actedge))) //this condition is necessary if we do not obey redefinition
1.116 {
1.117 - assignments[i].actedge=actedge;
1.118 - assignments[i].subnode=subnode;
1.119 + assignments[i].actedge = actedge;
1.120 + assignments[i].subnode = subnode;
1.121 }
1.122
1.123 /// If to all of the edges a subnode is assigned then the subnetwork is connectable (attachable?)
1.124 /// We do not need to check for further attributes, because to notice an assignment we need
1.125 /// all of them to be correctly initialised before.
1.126 - if(i==edgenumber-1)connectable=1;
1.127 + if (i == edgenumber - 1)
1.128 + connectable = 1;
1.129
1.130 return 0;
1.131 }
1.132
1.133 - int setSubNetwork(Gsub * sn)
1.134 + int setSubNetwork (Gsub * sn)
1.135 {
1.136 - subnetwork=sn;
1.137 + subnetwork = sn;
1.138 return 0;
1.139 }
1.140
1.141 - int setActualLayer(Gact * al)
1.142 + int setActualLayer (Gact * al)
1.143 {
1.144 - actuallayer=al;
1.145 + actuallayer = al;
1.146 return 0;
1.147 }
1.148
1.149 - int setActualLayerNode(typename Gact::Node * aln)
1.150 + int setActualLayerNode (typename Gact::Node * aln)
1.151 {
1.152 typename Gact::InEdgeIt iei;
1.153 typename Gact::OutEdgeIt oei;
1.154
1.155 - actuallayernode=aln;
1.156 + actuallayernode = aln;
1.157
1.158 - edgenumber=0;
1.159 + edgenumber = 0;
1.160
1.161 - if(actuallayer)
1.162 - {
1.163 - for(iei=actuallayer->first(iei,(*actuallayernode));((actuallayer->valid(iei))&&(actuallayer->head(iei)==(*actuallayernode)));actuallayer->next(iei))
1.164 + if (actuallayer)
1.165 {
1.166 - cout << actuallayer->id(actuallayer->tail(iei)) << " " << actuallayer->id(actuallayer->head(iei)) << endl;
1.167 - edgenumber++;
1.168 + for (iei = actuallayer->first (iei, (*actuallayernode));
1.169 + ((actuallayer->valid (iei))
1.170 + && (actuallayer->head (iei) == (*actuallayernode)));
1.171 + actuallayer->next (iei))
1.172 + {
1.173 + cout << actuallayer->id (actuallayer->
1.174 + tail (iei)) << " " << actuallayer->
1.175 + id (actuallayer->head (iei)) << endl;
1.176 + edgenumber++;
1.177 + }
1.178 + //cout << "Number of in-edges: " << edgenumber << endl;
1.179 + for (oei = actuallayer->first (oei, (*actuallayernode));
1.180 + ((actuallayer->valid (oei))
1.181 + && (actuallayer->tail (oei) == (*actuallayernode)));
1.182 + actuallayer->next (oei))
1.183 + {
1.184 + cout << actuallayer->id (actuallayer->
1.185 + tail (oei)) << " " << actuallayer->
1.186 + id (actuallayer->head (oei)) << endl;
1.187 + edgenumber++;
1.188 + }
1.189 + //cout << "Number of in+out-edges: " << edgenumber << endl;
1.190 + assignments = new actedgesubnodestruct[edgenumber];
1.191 + for (int i = 0; i < edgenumber; i++)
1.192 + {
1.193 + assignments[i].actedge = INVALID;
1.194 + assignments[i].subnode = INVALID;
1.195 + }
1.196 }
1.197 - //cout << "Number of in-edges: " << edgenumber << endl;
1.198 - for(oei=actuallayer->first(oei,(*actuallayernode));((actuallayer->valid(oei))&&(actuallayer->tail(oei)==(*actuallayernode)));actuallayer->next(oei))
1.199 + else
1.200 {
1.201 - cout << actuallayer->id(actuallayer->tail(oei)) << " " << actuallayer->id(actuallayer->head(oei)) << endl;
1.202 - edgenumber++;
1.203 + cerr << "There is no actual layer defined yet!" << endl;
1.204 + return -1;
1.205 }
1.206 - //cout << "Number of in+out-edges: " << edgenumber << endl;
1.207 - assignments=new actedgesubnodestruct[edgenumber];
1.208 - for(int i=0;i<edgenumber;i++)
1.209 - {
1.210 - assignments[i].actedge=INVALID;
1.211 - assignments[i].subnode=INVALID;
1.212 - }
1.213 - }
1.214 - else
1.215 - {
1.216 - cerr << "There is no actual layer defined yet!" << endl;
1.217 - return -1;
1.218 - }
1.219
1.220 return 0;
1.221 }
1.222
1.223 - SubNetwork(): edgenumber(0), connectable(false), actuallayer(NULL), actuallayernode(NULL), subnetwork(NULL), assignments(NULL)
1.224 + SubNetwork ():edgenumber (0), connectable (false), actuallayer (NULL),
1.225 + actuallayernode (NULL), subnetwork (NULL),
1.226 + assignments (NULL)
1.227 {
1.228 }
1.229
1.230 };
1.231
1.232 - typename Gact::template NodeMap< SubNetwork > subnetworks;
1.233 + typename Gact::template NodeMap < SubNetwork > subnetworks;
1.234
1.235
1.236 /// Defalult constructor.
1.237 /// We don't need any extra lines, because the actuallayer
1.238 /// variable has run its constructor, when we have created this class
1.239 /// So only the two maps has to be initialised here.
1.240 - HierarchyGraph() : subnetworks(actuallayer)
1.241 + HierarchyGraph ():subnetworks (actuallayer)
1.242 {
1.243 }
1.244
1.245
1.246 ///Copy consructor.
1.247 - HierarchyGraph(const HierarchyGraph<Gact, Gsub> & HG ) : actuallayer(HG.actuallayer), subnetworks(actuallayer)
1.248 + HierarchyGraph (const HierarchyGraph < Gact, Gsub > &HG):actuallayer (HG.actuallayer),
1.249 + subnetworks
1.250 + (actuallayer)
1.251 {
1.252 }
1.253
1.254 @@ -197,7 +218,7 @@
1.255
1.256 /// The base type of the edge iterators.
1.257 /// The Edge type of the HierarchyGraph is the Edge type of the actual layer.
1.258 - typedef typename Gact::Edge Edge;
1.259 + typedef typename Gact::Edge Edge;
1.260
1.261
1.262 /// This iterator goes trough the outgoing edges of a node.
1.263 @@ -247,20 +268,34 @@
1.264
1.265 /// \retval i the first node.
1.266 /// \return the first node.
1.267 - typename Gact::NodeIt &first(typename Gact::NodeIt &i) const { return actuallayer.first(i);}
1.268 + typename Gact::NodeIt & first (typename Gact::NodeIt & i) const
1.269 + {
1.270 + return actuallayer.first (i);
1.271 + }
1.272
1.273
1.274 /// The first incoming edge.
1.275 - typename Gact::InEdgeIt &first(typename Gact::InEdgeIt &i, typename Gact::Node) const { return actuallayer.first(i);}
1.276 + typename Gact::InEdgeIt & first (typename Gact::InEdgeIt & i,
1.277 + typename Gact::Node) const
1.278 + {
1.279 + return actuallayer.first (i);
1.280 + }
1.281
1.282
1.283 /// The first outgoing edge.
1.284 - typename Gact::OutEdgeIt &first(typename Gact::OutEdgeIt &i, typename Gact::Node) const { return actuallayer.first(i);}
1.285 + typename Gact::OutEdgeIt & first (typename Gact::OutEdgeIt & i,
1.286 + typename Gact::Node) const
1.287 + {
1.288 + return actuallayer.first (i);
1.289 + }
1.290
1.291
1.292 // SymEdgeIt &first(SymEdgeIt &, Node) const { return i;}
1.293 /// The first edge of the Graph.
1.294 - typename Gact::EdgeIt &first(typename Gact::EdgeIt &i) const { return actuallayer.first(i);}
1.295 + typename Gact::EdgeIt & first (typename Gact::EdgeIt & i) const
1.296 + {
1.297 + return actuallayer.first (i);
1.298 + }
1.299
1.300
1.301 // Node getNext(Node) const {}
1.302 @@ -271,19 +306,37 @@
1.303
1.304
1.305 /// Go to the next node.
1.306 - typename Gact::NodeIt &next(typename Gact::NodeIt &i) const { return actuallayer.next(i);}
1.307 + typename Gact::NodeIt & next (typename Gact::NodeIt & i) const
1.308 + {
1.309 + return actuallayer.next (i);
1.310 + }
1.311 /// Go to the next incoming edge.
1.312 - typename Gact::InEdgeIt &next(typename Gact::InEdgeIt &i) const { return actuallayer.next(i);}
1.313 + typename Gact::InEdgeIt & next (typename Gact::InEdgeIt & i) const
1.314 + {
1.315 + return actuallayer.next (i);
1.316 + }
1.317 /// Go to the next outgoing edge.
1.318 - typename Gact::OutEdgeIt &next(typename Gact::OutEdgeIt &i) const { return actuallayer.next(i);}
1.319 + typename Gact::OutEdgeIt & next (typename Gact::OutEdgeIt & i) const
1.320 + {
1.321 + return actuallayer.next (i);
1.322 + }
1.323 //SymEdgeIt &next(SymEdgeIt &) const {}
1.324 /// Go to the next edge.
1.325 - typename Gact::EdgeIt &next(typename Gact::EdgeIt &i) const { return actuallayer.next(i);}
1.326 + typename Gact::EdgeIt & next (typename Gact::EdgeIt & i) const
1.327 + {
1.328 + return actuallayer.next (i);
1.329 + }
1.330
1.331 ///Gives back the head node of an edge.
1.332 - typename Gact::Node head(typename Gact::Edge edge) const { return actuallayer.head(edge); }
1.333 + typename Gact::Node head (typename Gact::Edge edge) const
1.334 + {
1.335 + return actuallayer.head (edge);
1.336 + }
1.337 ///Gives back the tail node of an edge.
1.338 - typename Gact::Node tail(typename Gact::Edge edge) const { return actuallayer.tail(edge); }
1.339 + typename Gact::Node tail (typename Gact::Edge edge) const
1.340 + {
1.341 + return actuallayer.tail (edge);
1.342 + }
1.343
1.344 // Node aNode(InEdgeIt) const {}
1.345 // Node aNode(OutEdgeIt) const {}
1.346 @@ -297,23 +350,35 @@
1.347
1.348 ///\todo Maybe, it would be better if iterator converted to
1.349 ///bool directly, as Jacint prefers.
1.350 - bool valid(const typename Gact::Node& node) const { return actuallayer.valid(node);}
1.351 + bool valid (const typename Gact::Node & node) const
1.352 + {
1.353 + return actuallayer.valid (node);
1.354 + }
1.355 /// Checks if an edge iterator is valid
1.356
1.357 ///\todo Maybe, it would be better if iterator converted to
1.358 ///bool directly, as Jacint prefers.
1.359 - bool valid(const typename Gact::Edge& edge) const { return actuallayer.valid(edge);}
1.360 + bool valid (const typename Gact::Edge & edge) const
1.361 + {
1.362 + return actuallayer.valid (edge);
1.363 + }
1.364
1.365 ///Gives back the \e id of a node.
1.366
1.367 ///\warning Not all graph structures provide this feature.
1.368 ///
1.369 - int id(const typename Gact::Node & node) const { return actuallayer.id(node);}
1.370 + int id (const typename Gact::Node & node) const
1.371 + {
1.372 + return actuallayer.id (node);
1.373 + }
1.374 ///Gives back the \e id of an edge.
1.375
1.376 ///\warning Not all graph structures provide this feature.
1.377 ///
1.378 - int id(const typename Gact::Edge & edge) const { return actuallayer.id(edge);}
1.379 + int id (const typename Gact::Edge & edge) const
1.380 + {
1.381 + return actuallayer.id (edge);
1.382 + }
1.383
1.384 //void setInvalid(Node &) const {};
1.385 //void setInvalid(Edge &) const {};
1.386 @@ -322,22 +387,38 @@
1.387
1.388 /// \return the new node.
1.389 ///
1.390 - typename Gact::Node addNode() { return actuallayer.addNode();}
1.391 + typename Gact::Node addNode ()
1.392 + {
1.393 + return actuallayer.addNode ();
1.394 + }
1.395 ///Add a new edge to the graph.
1.396
1.397 ///Add a new edge to the graph with tail node \c tail
1.398 ///and head node \c head.
1.399 ///\return the new edge.
1.400 - typename Gact::Edge addEdge(typename Gact::Node node1, typename Gact::Node node2) { return actuallayer.addEdge(node1, node2);}
1.401 + typename Gact::Edge addEdge (typename Gact::Node node1,
1.402 + typename Gact::Node node2)
1.403 + {
1.404 + return actuallayer.addEdge (node1, node2);
1.405 + }
1.406
1.407 /// Resets the graph.
1.408
1.409 /// This function deletes all edges and nodes of the graph.
1.410 /// It also frees the memory allocated to store them.
1.411 - void clear() {actuallayer.clear();}
1.412 + void clear ()
1.413 + {
1.414 + actuallayer.clear ();
1.415 + }
1.416
1.417 - int nodeNum() const { return actuallayer.nodeNum();}
1.418 - int edgeNum() const { return actuallayer.edgeNum();}
1.419 + int nodeNum () const
1.420 + {
1.421 + return actuallayer.nodeNum ();
1.422 + }
1.423 + int edgeNum () const
1.424 + {
1.425 + return actuallayer.edgeNum ();
1.426 + }
1.427
1.428 ///Read/write/reference map of the nodes to type \c T.
1.429
1.430 @@ -349,33 +430,51 @@
1.431 /// \warning Making maps that can handle bool type (NodeMap<bool>)
1.432 /// needs extra attention!
1.433
1.434 - template<class T> class NodeMap
1.435 + template < class T > class NodeMap
1.436 {
1.437 public:
1.438 typedef T ValueType;
1.439 typedef Node KeyType;
1.440
1.441 - NodeMap(const HierarchyGraph &) {}
1.442 - NodeMap(const HierarchyGraph &, T) {}
1.443 + NodeMap (const HierarchyGraph &)
1.444 + {
1.445 + }
1.446 + NodeMap (const HierarchyGraph &, T)
1.447 + {
1.448 + }
1.449
1.450 - template<typename TT> NodeMap(const NodeMap<TT> &) {}
1.451 + template < typename TT > NodeMap (const NodeMap < TT > &)
1.452 + {
1.453 + }
1.454
1.455 /// Sets the value of a node.
1.456
1.457 /// Sets the value associated with node \c i to the value \c t.
1.458 ///
1.459 - void set(Node, T) {}
1.460 + void set (Node, T)
1.461 + {
1.462 + }
1.463 // Gets the value of a node.
1.464 //T get(Node i) const {return *(T*)0;} //FIXME: Is it necessary?
1.465 - T &operator[](Node) {return *(T*)0;}
1.466 - const T &operator[](Node) const {return *(T*)0;}
1.467 + T & operator[](Node)
1.468 + {
1.469 + return *(T *) 0;
1.470 + }
1.471 + const T & operator[] (Node) const
1.472 + {
1.473 + return *(T *) 0;
1.474 + }
1.475
1.476 /// Updates the map if the graph has been changed
1.477
1.478 /// \todo Do we need this?
1.479 ///
1.480 - void update() {}
1.481 - void update(T a) {} //FIXME: Is it necessary
1.482 + void update ()
1.483 + {
1.484 + }
1.485 + void update (T a)
1.486 + {
1.487 + } //FIXME: Is it necessary
1.488 };
1.489
1.490 ///Read/write/reference map of the edges to type \c T.
1.491 @@ -387,26 +486,44 @@
1.492 /// \todo We may need copy constructor
1.493 /// \todo We may need conversion from other edgetype
1.494 /// \todo We may need operator=
1.495 - template<class T> class EdgeMap
1.496 + template < class T > class EdgeMap
1.497 {
1.498 public:
1.499 typedef T ValueType;
1.500 typedef Edge KeyType;
1.501
1.502 - EdgeMap(const HierarchyGraph &) {}
1.503 - EdgeMap(const HierarchyGraph &, T ) {}
1.504 + EdgeMap (const HierarchyGraph &)
1.505 + {
1.506 + }
1.507 + EdgeMap (const HierarchyGraph &, T)
1.508 + {
1.509 + }
1.510
1.511 ///\todo It can copy between different types.
1.512 ///
1.513 - template<typename TT> EdgeMap(const EdgeMap<TT> &) {}
1.514 + template < typename TT > EdgeMap (const EdgeMap < TT > &)
1.515 + {
1.516 + }
1.517
1.518 - void set(Edge, T) {}
1.519 + void set (Edge, T)
1.520 + {
1.521 + }
1.522 //T get(Edge) const {return *(T*)0;}
1.523 - T &operator[](Edge) {return *(T*)0;}
1.524 - const T &operator[](Edge) const {return *(T*)0;}
1.525 + T & operator[](Edge)
1.526 + {
1.527 + return *(T *) 0;
1.528 + }
1.529 + const T & operator[] (Edge) const
1.530 + {
1.531 + return *(T *) 0;
1.532 + }
1.533
1.534 - void update() {}
1.535 - void update(T a) {} //FIXME: Is it necessary
1.536 + void update ()
1.537 + {
1.538 + }
1.539 + void update (T a)
1.540 + {
1.541 + } //FIXME: Is it necessary
1.542 };
1.543 };
1.544
1.545 @@ -429,25 +546,36 @@
1.546 /// feature, the documentation of a real graph imlementation
1.547 /// like @ref ListGraph or
1.548 /// @ref SmartGraph will just refer to this structure.
1.549 - template <typename Gact, typename Gsub>
1.550 - class EraseableHierarchyGraph : public HierarchyGraph<Gact, Gsub>
1.551 +template < typename Gact, typename Gsub > class EraseableHierarchyGraph:public HierarchyGraph < Gact,
1.552 + Gsub
1.553 + >
1.554 {
1.555 public:
1.556 /// Deletes a node.
1.557 - void erase(typename Gact::Node n) {actuallayer.erase(n);}
1.558 + void erase (typename Gact::Node n)
1.559 + {
1.560 + actuallayer.erase (n);
1.561 + }
1.562 /// Deletes an edge.
1.563 - void erase(typename Gact::Edge e) {actuallayer.erase(e);}
1.564 + void erase (typename Gact::Edge e)
1.565 + {
1.566 + actuallayer.erase (e);
1.567 + }
1.568
1.569 /// Defalult constructor.
1.570 - EraseableHierarchyGraph() {}
1.571 + EraseableHierarchyGraph ()
1.572 + {
1.573 + }
1.574 ///Copy consructor.
1.575 - EraseableHierarchyGraph(const HierarchyGraph<Gact, Gsub> &EPG) {}
1.576 + EraseableHierarchyGraph (const HierarchyGraph < Gact, Gsub > &EPG)
1.577 + {
1.578 + }
1.579 };
1.580
1.581
1.582 // @}
1.583
1.584 -} //namespace hugo
1.585 +} //namespace hugo
1.586
1.587
1.588 #endif // HUGO_SKELETON_GRAPH_H