# HG changeset patch
# User hegyi
# Date 1089042755 0
# Node ID a0f95e1b17fc970c11a48b31c38fd74342431d93
# Parent  e7cf90de549a25a80a9fa688d8e6861dccdbd8e6


diff -r e7cf90de549a -r a0f95e1b17fc src/work/peter/Makefile
--- a/src/work/peter/Makefile	Wed Jun 30 14:59:46 2004 +0000
+++ b/src/work/peter/Makefile	Mon Jul 05 15:52:35 2004 +0000
@@ -1,5 +1,6 @@
+hier: hierarchygraph.h hierarchygraph_test.cc
+	g++ -Wall -W -I../.. -I../klao -I../../hugo hierarchygraph_test.cc -o test
+
 edge: edgepathgraph_test.cc edgepathgraph.h
-	g++ -I../.. -I../klao -I../../hugo edgepathgraph_test.cc -o test
+	g++ -Wall -W -I../.. -I../klao -I../../hugo edgepathgraph_test.cc -o test
 
-hier: hierarchygraph.h hierarchygraph_test.cc
-	g++ -I../.. -I../klao -I../../hugo hierarchygraph_test.cc -o test
diff -r e7cf90de549a -r a0f95e1b17fc src/work/peter/hierarchygraph.h
--- a/src/work/peter/hierarchygraph.h	Wed Jun 30 14:59:46 2004 +0000
+++ b/src/work/peter/hierarchygraph.h	Mon Jul 05 15:52:35 2004 +0000
@@ -15,7 +15,7 @@
   // @{
 
   /// A graph class in that a simple edge can represent a path.
-  
+
   /// This class provides common features of a graph structure
   /// that represents a network. You can handle with it layers. This
   /// means that a node in one layer can be a complete network in a nother
@@ -31,26 +31,150 @@
     Gact actuallayer;
 
 
-    /// Map of subnetworks that are represented by the nodes of this layer
-    typename Gact::template NodeMap<Gsub> subnetwork;
+    /// Map of the subnetworks in the sublayer
+    /// The appropriate edge nodes are also stored here
 
+    class SubNetwork
+    {
+
+      struct actedgesubnodestruct
+      {
+        typename Gact::Edge actedge;
+        typename Gsub::Node subnode;
+      };
+
+      int edgenumber;
+      bool connectable;
+      Gact * actuallayer;
+      typename Gact::Node * actuallayernode;
+      Gsub * subnetwork;
+      actedgesubnodestruct * assignments;
+
+    public:
+
+      int addAssignment(typename Gact::Edge actedge, typename Gsub::Node subnode)
+      {
+	if(!(actuallayer->valid(actedge)))
+	{
+	  cerr << "The given edge is not in the given network!" << endl;
+	  return -1;
+	}
+	else if(
+	   (actuallayer->id(actuallayer->tail(actedge))!=actuallayer->id(*actuallayernode))
+	   &&
+	   (actuallayer->id(actuallayer->head(actedge))!=actuallayer->id(*actuallayernode))
+	  )
+	{
+	  cerr << "The given edge does not connect to the given node!" << endl;
+	  return -1;
+	}
+
+	if(!(subnetwork->valid(subnode)))
+	{
+	  cerr << "The given node is not in the given network!" << endl;
+	  return -1;
+	}
+
+	int i=0;
+	//while in the array there is valid note that is not equvivalent with the one that would be noted increase i
+	while( (i<edgenumber) && (actuallayer->valid(assignments[i].actedge) ) && (assignments[i].actedge!=actedge) ) i++;
+	if(assignments[i].actedge==actedge)
+	{
+	  cout << "Warning: Redefinement of assigment!!!" << endl;
+	}
+	if(i==edgenumber)
+	{
+	  cout << "This case can't be!!! (because there should be the guven edge in the array already and the cycle had to stop)" << endl;
+	}
+	//if(!(actuallayer->valid(assignments[i].actedge)))   //this condition is necessary if we do not obey redefinition
+	{
+	  assignments[i].actedge=actedge;
+	  assignments[i].subnode=subnode;
+	}
+
+	/// If to all of the edges a subnode is assigned then the subnetwork is connectable (attachable?)
+	/// We do not need to check for further attributes, because to notice an assignment we need
+	/// all of them to be correctly initialised before.
+	if(i==edgenumber-1)connectable=1;
+
+	return 0;
+      }
+
+      int setSubNetwork(Gsub * sn)
+      {
+	subnetwork=sn;
+	return 0;
+      }
+
+      int setActualLayer(Gact * al)
+      {
+	actuallayer=al;
+	return 0;
+      }
+
+      int setActualLayerNode(typename Gact::Node * aln)
+      {
+	typename Gact::InEdgeIt iei;
+	typename Gact::OutEdgeIt oei;
+
+	actuallayernode=aln;
+
+	edgenumber=0;
+
+	if(actuallayer)
+	{
+	  for(iei=actuallayer->first(iei,(*actuallayernode));((actuallayer->valid(iei))&&(actuallayer->head(iei)==(*actuallayernode)));actuallayer->next(iei))
+	  {
+	    cout << actuallayer->id(actuallayer->tail(iei)) << " " << actuallayer->id(actuallayer->head(iei)) << endl;
+	    edgenumber++;
+	  }
+	  //cout << "Number of in-edges: " << edgenumber << endl;
+	  for(oei=actuallayer->first(oei,(*actuallayernode));((actuallayer->valid(oei))&&(actuallayer->tail(oei)==(*actuallayernode)));actuallayer->next(oei))
+	  {
+	    cout << actuallayer->id(actuallayer->tail(oei)) << " " << actuallayer->id(actuallayer->head(oei)) << endl;
+	    edgenumber++;
+	  }
+	  //cout << "Number of in+out-edges: " << edgenumber << endl;
+	  assignments=new actedgesubnodestruct[edgenumber];
+	  for(int i=0;i<edgenumber;i++)
+	  {
+	    assignments[i].actedge=INVALID;
+	    assignments[i].subnode=INVALID;
+	  }
+	}
+	else
+	{
+	  cerr << "There is no actual layer defined yet!" << endl;
+	  return -1;
+	}
+
+	return 0;
+      }
+
+      SubNetwork(): edgenumber(0), connectable(false), actuallayer(NULL), actuallayernode(NULL), subnetwork(NULL), assignments(NULL)
+      {
+      }
+
+    };
+
+    typename Gact::template NodeMap< SubNetwork > subnetworks;
 
 
     /// Defalult constructor.
     /// We don't need any extra lines, because the actuallayer
     /// variable has run its constructor, when we have created this class
     /// So only the two maps has to be initialised here.
-    HierarchyGraph() : subnetwork(actuallayer)
+    HierarchyGraph() : subnetworks(actuallayer)
     {
     }
 
 
     ///Copy consructor.
-    HierarchyGraph(const HierarchyGraph<Gact, Gsub> & HG ) : actuallayer(HG.actuallayer), subnetwork(actuallayer)
+    HierarchyGraph(const HierarchyGraph<Gact, Gsub> & HG ) : actuallayer(HG.actuallayer), subnetworks(actuallayer)
     {
     }
 
- 
+
     /// The base type of the node iterators.
 
     /// This is the base type of each node iterators,
@@ -58,7 +182,7 @@
     /// The Node type of the HierarchyGraph is the Node type of the actual layer.
     typedef typename Gact::Node Node;
 
-    
+
     /// This iterator goes through each node.
 
     /// Its usage is quite simple, for example you can count the number
@@ -69,13 +193,13 @@
     /// \endcode
     /// The NodeIt type of the HierarchyGraph is the NodeIt type of the actual layer.
     typedef typename Gact::NodeIt NodeIt;
-    
-    
+
+
     /// The base type of the edge iterators.
     /// The Edge type of the HierarchyGraph is the Edge type of the actual layer.
     typedef typename  Gact::Edge Edge;
 
-    
+
     /// This iterator goes trough the outgoing edges of a node.
 
     /// This iterator goes trough the \e outgoing edges of a certain node
@@ -160,7 +284,7 @@
     typename Gact::Node head(typename Gact::Edge edge) const { return actuallayer.head(edge); }
     ///Gives back the tail node of an edge.
     typename Gact::Node tail(typename Gact::Edge edge) const { return actuallayer.tail(edge); }
-  
+
     //   Node aNode(InEdgeIt) const {}
     //   Node aNode(OutEdgeIt) const {}
     //   Node aNode(SymEdgeIt) const {}
@@ -193,7 +317,7 @@
 
     //void setInvalid(Node &) const {};
     //void setInvalid(Edge &) const {};
-  
+
     ///Add a new node to the graph.
 
     /// \return the new node.
@@ -205,7 +329,7 @@
     ///and head node \c head.
     ///\return the new edge.
     typename Gact::Edge addEdge(typename Gact::Node node1, typename Gact::Node node2) { return actuallayer.addEdge(node1, node2);}
-    
+
     /// Resets the graph.
 
     /// This function deletes all edges and nodes of the graph.
@@ -271,7 +395,7 @@
 
       EdgeMap(const HierarchyGraph &) {}
       EdgeMap(const HierarchyGraph &, T ) {}
-    
+
       ///\todo It can copy between different types.
       ///
       template<typename TT> EdgeMap(const EdgeMap<TT> &) {}
@@ -280,14 +404,14 @@
       //T get(Edge) const {return *(T*)0;}
       T &operator[](Edge) {return *(T*)0;}
       const T &operator[](Edge) const {return *(T*)0;}
-    
+
       void update() {}
       void update(T a) {}   //FIXME: Is it necessary
     };
   };
 
   /// An empty eraseable graph class.
-  
+
   /// This class provides all the common features of an \e eraseable graph
   /// structure,
   /// however completely without implementations and real data structures
@@ -300,7 +424,7 @@
   ///
   /// It can be used for checking the interface compatibility,
   /// or it can serve as a skeleton of a new graph structure.
-  /// 
+  ///
   /// Also, you will find here the full documentation of a certain graph
   /// feature, the documentation of a real graph imlementation
   /// like @ref ListGraph or
@@ -320,7 +444,7 @@
     EraseableHierarchyGraph(const HierarchyGraph<Gact, Gsub> &EPG) {}
   };
 
-  
+
   // @}
 
 } //namespace hugo
diff -r e7cf90de549a -r a0f95e1b17fc src/work/peter/hierarchygraph_test.cc
--- a/src/work/peter/hierarchygraph_test.cc	Wed Jun 30 14:59:46 2004 +0000
+++ b/src/work/peter/hierarchygraph_test.cc	Mon Jul 05 15:52:35 2004 +0000
@@ -22,4 +22,68 @@
 int main()
 {
   HierarchyGraph<SmartGraph, ListGraph> HGr;
+  ListGraph subnetwork, othernetwork;
+  typedef HierarchyGraph<SmartGraph, ListGraph>::Node Node;
+  typedef HierarchyGraph<SmartGraph, ListGraph>::Edge Edge;
+  typedef HierarchyGraph<SmartGraph, ListGraph>::SubNetwork Sntype;
+
+  Node n0, n1, n2;
+  Edge e0, e1, e2, e3, e4, e5;
+
+  ListGraph::Node sn0, sn1, on0;
+  ListGraph::Edge se0;
+
+  n0=HGr.addNode();
+
+  cout << "Az n0 id-je: " << HGr.actuallayer.id(n0) << endl;
+
+  n1=HGr.addNode();
+  n2=HGr.addNode();
+  
+  e0=HGr.addEdge(n0,n1);
+  e1=HGr.addEdge(n1,n0);
+  e2=HGr.addEdge(n0,n2);
+  e3=HGr.addEdge(n2,n0);
+  e4=HGr.addEdge(n1,n2);
+  e5=HGr.addEdge(n2,n1);
+
+  sn0=subnetwork.addNode();
+  sn1=subnetwork.addNode();
+  se0=subnetwork.addEdge(sn0,sn1);
+
+  Sntype sn;
+  sn.setActualLayer(&(HGr.actuallayer));
+  sn.setActualLayerNode(&(n0));
+  sn.addAssignment(e0, sn0);
+  sn.addAssignment(e1, sn1);
+  sn.addAssignment(e2, sn1);
+  sn.addAssignment(e3, sn0);
+  sn.addAssignment(e1, sn0);
+  sn.addAssignment(e5, sn0);
+  
+
+
+  on0=othernetwork.addNode();
+
+  cout << "ID of a node from a different graph: " << subnetwork.id(on0) << endl;
+  cout << "ID of a node in its graph: " << othernetwork.id(on0) << endl;
+  cout << "ID of a node from a  graph: " << subnetwork.id(sn0) << endl;
+
+  ListGraph::NodeIt snni;
+  //ListGraph::Node snn;
+
+  for(subnetwork.first(snni);subnetwork.valid(snni);subnetwork.next(snni))
+  {
+    if(snni==on0)
+    {
+      cout << "Nem jo, megtalalta az idegen node-ot sajat haloban, pedig azt nem szabad!!!" 
+	   << subnetwork.id(snni) << subnetwork.id(on0) << othernetwork.id(snni) << othernetwork.id(on0) << endl;
+    }
+    else cout << "ID:" << subnetwork.id(snni) << endl;
+      
+  }
+  
+
+  HGr.subnetworks[n0]=sn;
+  
 }
diff -r e7cf90de549a -r a0f95e1b17fc src/work/peter/remarks
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/work/peter/remarks	Mon Jul 05 15:52:35 2004 +0000
@@ -0,0 +1,63 @@
+-hogy lehet elerni, hogy mindig minden fv-t forditson le, ne csak
+ szintaktikailag ellenorizze?
+
+-mennyi adatot taroljunk? taroljunk, vagy szarmaztassunk? pl gondolok
+ itt a ki, illetve a bemeno elek szamara, adott aktualis retegbeli
+ csomopont szamara.
+ -hmm. inkabb megis globalis legyen az edgenumber, mert fontos? hogyan
+ lehet vedeni az utolagos belepiszkalas ellen?
+
+-vedelmet berakni?
+	  -az adatmezo olvashato legyen, de irhato ne
+	  -a beiro fv. csak egyszer legyen hivhato
+
+
+-subnetworkbe kell a perem csomopontokba el? mert szerintem nem. azt
+ ugyis bejeloltuk, hogy az peremcsomopont. csak azt hogy jeloljuk, hogy melyik
+ elhez tartozik?
+-egy subnetworkbeli csomoponthoz tartozhat
+     -tobb be/ki meno el?
+     -egyszerre kimeno is, meg bemeno is?
+-szerintem csak az a megkotes kell, hogy egy elhez egy csp tartozzon
+	   -miert ne lehetne, hogy egy peremcspba tobb el van bekotve?
+
+
+-nem tudom, es nem is kell, hogy hogyan mukodnek az egyes iteratorok
+     -igy ahhoz, hogy ismerjem az egy pontbol, illetve pontba menoket
+     -egyelore
+     -megadom elsot, ami onnan megy, es addig iteralok, ami onnan
+     van???
+
+-van = jel grafoknal?
+	    subnetwork=sn;
+
+-hogyan tudom kiszamitani a NodeMap elemebol, hogy melyik Nodera
+     vonatkozik?
+    -NodeMap-ben osztaly van
+    -kene, hogy melyik Nodehoz tartozik
+    -most parameterben nyomatom at
+    -de valahogyan csak lehet automatizalni, hogy melyik peldany
+     melyik csphoz van hozzarendelve...
+
+-en pointereket hasznalok, nem referenciakat
+
+-mivel osztalybol adodik az osztaly, es nem objektumbol, EZERT kell
+ megadni az actuallayert is, ugye jol gondolom?
+
+-hmmm. nem kene valami vedelem? tul sok minden fugg tul sokmindentol,
+ osztaly erre valo. de hogy lehet megcsinalni, hogy pl. subnetwork
+ olvashato legyen, de csak fv. irhassa, hogy figyelhessen a
+ valtozasra?
+
+-return 0? 1? vagy void?
+
+-hogy tudom leellenorizni, hogy adott el/csp eleme-e egy halonak?
+ valid-dal?
+ -na, azzal tuti nem!!!!! de akkor hogyan?
+ -id 0-t ad!!!!!!! (enyemre nyilvanvaloan), ami rendes szam, tehat id-vel sem!!!
+ -nem adja vissza a nodeiterator? aztan annyi? DE VISSZAADJA!
+      -irtam ciklust, mely vegigmegy a node-okon, es osszehasonlitja a
+ egy masik halo node-javal, es egyszercsak kozolte, hogy egyforma!!!
+
+-most ugy van, hogy feluldefinialhato az el-csp bejegyzes, ha ugyanazt
+ az elet ketszer adjuk meg. jo ez igy, vagy hibauzenet legyen?
\ No newline at end of file