C++ main module for gpm Package  1.0
GPM_Graph.h
Go to the documentation of this file.
1 #ifndef GPM_Graph_H
2 #define GPM_Graph_H
3 
4 #include "GPM_Object.h"
5 
6 #include "CORE_Out.h"
7 
8 #include "GPM_Vertex.h"
9 #include "GPM_Node.h"
10 #include "GPM_Edge.h"
11 
12 // boost include
18 
19 class GPM_Graph : public GPM_Object {
20  SP_OBJECT(GPM_Graph);
21 // ATTRIBUTES
22 
23 public:
24  static const tVertexIID NULL_VERTEX;
28 
29 
30 private:
31 
32  int mVertexIdGenerator;
33  int mEdgeIdGenerator;
34  tFlag mGroupId;
35 
36 
37  // ASSOCIATIONS
38 
39 
40 
41 
42  tGraph mGraph;
43 
44 
45 protected:
46  // METHODS
47 
48  // CONSTRUCTORS
49 
51  GPM_Graph(void);
52 
53 
54 
55  // DESTRUCTORS
56 
57 
60  virtual ~GPM_Graph(void);
61 
62 
63 public:
64 
65  // NEW methods
66 
69  static inline SP::GPM_Graph New() {
70  SP::GPM_Graph p(new GPM_Graph(),GPM_Graph::Delete());
71  p->setThis(p);
72  return p;
73  }
74 
75  // SET & GET methods
76 
77  //internal
80  inline const tGraph& getGraphImplement() const {
81  return mGraph;
82  }
83 
87  return mGraph;
88  }
89 
90  // Vertices
91  // --------
92 
93 
94 
95 public:
98  virtual SP::GPM_GraphElement newInstance(const tString& className) const;
99 
102  virtual SP::GPM_Node newNode() const {
103  return GPM_Node::New();
104  }
105 
106 
109  virtual void copy(const GPM_Graph& graph);
110 
115  tVertexIID addVertex(SP::GPM_Vertex vertex);
116 
117 
121  inline tVertexIID addNode() {
122  SP::GPM_Vertex vertex=newNode();
123  vertex->setId(generateVertexId());
124  return addVertex(vertex);
125  }
126 
131  inline tVertexIID addNode(const int& id) {
132  SP::GPM_Vertex vertex=newNode();
133  vertex->setId(id);
134  return addVertex(vertex);
135  }
136 
137 
138 
142  void removeVertex(const tVertexIID& iid);
143 
144 
147  int getVerticesNumber() const;
148 
151  SP::GPM_Vertex getVertex(const tVertexIID& iid) const;
152 
153 
156  int getVertexId(const tVertexIID& iid) const;
157 
160  tVertexIID getVertexIID(const int& id) const;
161 
162 
163 public:
164 
167  void getVertices(vector<tVertexIID>& vertexIIDs) const;
170  void getVertices(SV::GPM_Vertex& vertexIIDs) const;
171 
174  void getConnectedVertices(const tVertexIID& iid,vector<tVertexIID>& vertexIIDs) const;
175 
178  int getDegree(const tVertexIID& id) const;
179 
180 
181  // EDGES
182  // -----
183 private:
188  //tBoolean getEdgeIID(const int& id,tEdgeIID& iid) const;
189 
192  //void updateEdgeIIDs();
193 
194 public:
197  virtual SP::GPM_Edge newEdge() const {
198  return GPM_Edge::New();
199  }
202  virtual SP::GPM_Edge newEdge(const int& id) const {
203  SP::GPM_Edge p=GPM_Edge::New(id);
204  return p;
205  }
208  virtual SP::GPM_Edge newEdge(SP::GPM_Vertex source,SP::GPM_Vertex target) const {
209  SP::GPM_Edge p=GPM_Edge::New(source,target);
210  return p;
211  }
212 
215  inline tBoolean addEdgeFromIds(const int& source,const int& target,tEdgeIID& iid) {
216  tVertexIID sourceIID,targetIID;
217  sourceIID=getVertexIID(source);
218  if (sourceIID==NULL_VERTEX) sourceIID=addNode(source);
219  targetIID=getVertexIID(target);
220  if (targetIID==NULL_VERTEX) targetIID=addNode(target);
221  int id=generateEdgeId();
222  SP::GPM_Edge edge=newEdge();
223  edge->setId(id);
224  return addEdge(sourceIID,targetIID,edge,iid);
225  }
228  inline tBoolean addEdgeFromIds(const int& source,const int& target) {
229  tEdgeIID eiid;
230  return addEdgeFromIds(source,target,eiid);
231  }
234  virtual tBoolean addEdge(const tVertexIID& from,const tVertexIID& to,SP::GPM_Edge edge,tEdgeIID& iid);
235 
238  virtual SP::GPM_Edge addEdge(const tVertexIID& from,const tVertexIID& to) {
239  tEdgeIID eiid;
240  SP::GPM_Edge edge=newEdge();
241  edge->setId(generateEdgeId());
242  if (!addEdge(from,to,edge,eiid)) edge.reset();
243  return edge;
244  }
247  virtual tBoolean addEdge(const tVertexIID& from,const tVertexIID& to,tEdgeIID& eiid) {
248  SP::GPM_Edge edge=newEdge();
249  edge->setId(generateEdgeId());
250  tBoolean succeeds=addEdge(from,to,edge,eiid);
251  if (!succeeds) edge.reset();
252  return succeeds;
253  }
254 protected:
257  tBoolean addEdge_(const tVertexIID& from,const tVertexIID& to,SP::GPM_Edge edge,tEdgeIID& iid);
258 
259 
260 public:
264  tBoolean removeEdge(const tEdgeIID& edgeId);
268  tBoolean removeEdges(const tVertexIID& vertexIID);
269 
273  tBoolean removeEdges(const tVertexIID& form,const tVertexIID& to);
274 
277  int getEdgesNumber() const;
278 
281  void getEdges(vector<tEdgeIID>& ids) const;
282 
285  void getEdges(SV::GPM_Edge& edges) const;
286 
289  void getEdges(const tVertexIID& v,vector<tEdgeIID>& edges) const;
290 
293  tBoolean getEdge(const tVertexIID& e1,const tVertexIID& e2,tEdgeIID& iid) const;
294 
295 
298  inline tBoolean getEdgeFromIds(const int& e1,const int& e2,tEdgeIID& iid) const {
299  return getEdge(getVertexIID(e1),getVertexIID(e2),iid);
300  }
303  inline tBoolean getEdgeFromIds(const int& e1,const int& e2) const {
304  tEdgeIID iid;
305  return getEdge(getVertexIID(e1),getVertexIID(e2),iid);
306  }
307 
308 
311  SP::GPM_Edge getEdge(const tEdgeIID& id);
314  SPC::GPM_Edge getEdge(const tEdgeIID& id) const;
315 
318  const GPM_Edge* getEdge(const tVertexIID& e1,const tVertexIID& e2) const;
321  GPM_Edge* getEdge(const tVertexIID& e1,const tVertexIID& e2);
322 
325  void getEdgeVertices(const tEdgeIID& id,tVertexIID& source,tVertexIID& target) const;
326 
329  int getEdgeId(const tEdgeIID& iid) const;
330 
333  tBoolean getEdgeIID(const int& id,tEdgeIID& iid) const;
334 
335 
336  // COMMON METHODS
337  // ---------------
338 
341  void clear();
342 
345  void close();
346 
351  tBoolean merge(const tVertexIID& from,const tVertexIID& to,CORE_Out& io);
352 
357  void addSubGraph(const GPM_Graph& graph,map<tVertexIID,tVertexIID>& connections);
358 
359 
360  // TRIGGAR Action
361 
362 
366 
367 
368  // IO methods
369  // ----------
370 
373  tBoolean saveToFile(const tString& fileName) const;
376  tBoolean loadFromFile(const tString& fileName,CORE_Out& io);
377 
380  virtual tBoolean exportToCurveFile(const tString& fileName,
381  const tString& title,
382  const tString& XLabel,
383  const tString& YLabel) const;
384 
385 
386 
387  // MORPHISM methods
388  // -----------------
391  void printGroupId(CORE_Out& io) const;
392 
393 
396  void updateGroupId();
397 
398 
399 
402  virtual tBoolean isMappingValid(const SV::GPM_Vertex& smallGraphVertices,
403  const vector<tVertexIID>& mapping,
404  CORE_Out& io) const {
405  return true;
406  }
407 
408 private:
411  void updateGroupIdMap(map<tString,unsigned int>& groupIds) const;
412 
413 public:
419  tBoolean isIsomorph(const GPM_Graph& g,vector<tVertexIID>& verticesMap,CORE_Out& io) const;
425  inline tBoolean isIsomorph(SPC::GPM_Graph g,vector<tVertexIID>& verticesMap,CORE_Out& io) const {
426  if (g.get()==null) return false;
427  return isIsomorph(*g.get(),verticesMap,io);
428 
429  }
434  inline tBoolean isIsomorph(SPC::GPM_Graph g,CORE_Out& io) const {
435  vector<tVertexIID> verticesMap;
436  return isIsomorph(g,verticesMap,io);
437  }
438 
443  inline tBoolean isIsomorph(const GPM_Graph& g,CORE_Out& io) const {
444  vector<tVertexIID> verticesMap;
445  return isIsomorph(g,verticesMap,io);
446  }
447 
451  void getPatterns(const GPM_Graph& pattern,const tBoolean& isUpToAutomorphism,const tFlag& upToAutomorphismType,
452  vector<vector<tVertexIID> >& homomorphisms,CORE_Out& io) const;
453 
457  inline void getPatterns(SPC::GPM_Graph pattern,const tBoolean& isUpToAutomorphism,const tFlag& upToAutomorphismType,
458  vector<vector<tVertexIID> >& homomorphisms,CORE_Out& io) const {
459  if (pattern.get()==null) throw CORE_Exception("gpm/core","GPM_Graph::getPatterns","null graph pattern !");
460  getPatterns(*pattern.get(),isUpToAutomorphism,upToAutomorphismType,homomorphisms,io);
461  }
465  inline void getPatterns(const GPM_Graph& pattern,vector<vector<tVertexIID> >& homomorphisms,CORE_Out& io) const {
466  getPatterns(pattern,false,UP_TO_AUTOMORPHISM_ALL,homomorphisms,io);
467  }
471  inline void getPatterns(SPC::GPM_Graph pattern,vector<vector<tVertexIID> >& homomorphisms,CORE_Out& io) const {
472  getPatterns(pattern,false,UP_TO_AUTOMORPHISM_ALL,homomorphisms,io);
473  }
474 
475 
476 
477 
480  virtual tString toString() const;
481 
482 
483 private:
486  void saveToStream(ofstream& f) const;
489  tBoolean loadFromStream(ifstream& f,CORE_Out& io);
490 
491 public:
494  int generateVertexId();
495 
498  int generateEdgeId();
499 
500 
501 
502 
503 
504 
505 };
506 
507 #endif
tBoolean saveToFile(const tString &fileName) const
save graph to txt file
Definition: GPM_Graph.cpp:793
virtual tBoolean exportToCurveFile(const tString &fileName, const tString &title, const tString &XLabel, const tString &YLabel) const
export to a curve file
Definition: GPM_Graph.cpp:1120
tBoolean removeEdges(const tVertexIID &vertexIID)
remove all edges from vertex with internal id WARNING: the edgeIID of all the edges may changed ! ...
Definition: GPM_Graph.cpp:499
virtual SP::GPM_Node newNode() const
create a node
Definition: GPM_Graph.h:102
tBoolean isIsomorph(const GPM_Graph &g, CORE_Out &io) const
return true if graph is isomorph
Definition: GPM_Graph.h:443
tBoolean isIsomorph(SPC::GPM_Graph g, CORE_Out &io) const
return true if graph is isomorph
Definition: GPM_Graph.h:434
static SP::GPM_Graph New()
create a graphs
Definition: GPM_Graph.h:69
void getConnectedVertices(const tVertexIID &iid, vector< tVertexIID > &vertexIIDs) const
get the internal id vertices connected to vertex with internal iid
Definition: GPM_Graph.cpp:380
virtual void copy(const GPM_Graph &graph)
void copy
Definition: GPM_Graph.cpp:215
const tGraph & getGraphImplement() const
get the graph implementation
Definition: GPM_Graph.h:80
virtual SP::GPM_Edge addEdge(const tVertexIID &from, const tVertexIID &to)
add an edge with name label between vertices from & to
Definition: GPM_Graph.h:238
tGraph::edge_descriptor tEdgeIID
Definition: GPM_Types.h:50
int getVertexId(const tVertexIID &iid) const
get the id of vertex with internal id
Definition: GPM_Graph.cpp:300
void getEdgeVertices(const tEdgeIID &id, tVertexIID &source, tVertexIID &target) const
get vertices of edges
Definition: GPM_Graph.cpp:587
void printGroupId(CORE_Out &io) const
print the group id
Definition: GPM_Graph.cpp:1178
boost::adjacency_list< boost::listS, boost::vecS, boost::undirectedS, VertexProperties, EdgeProperties > tGraph
Definition: GPM_Types.h:36
tVertexIID addNode()
add vertex
Definition: GPM_Graph.h:121
int getEdgeId(const tEdgeIID &iid) const
get id of edge with internal id iid
Definition: GPM_Graph.cpp:546
void clear()
clear the graph
Definition: GPM_Graph.cpp:601
void getEdges(vector< tEdgeIID > &ids) const
get the index of edges of the graph
Definition: GPM_Graph.cpp:528
int getDegree(const tVertexIID &id) const
get the edges number connected to vertex with id
Definition: GPM_Graph.cpp:399
void getPatterns(SPC::GPM_Graph pattern, const tBoolean &isUpToAutomorphism, const tFlag &upToAutomorphismType, vector< vector< tVertexIID > > &homomorphisms, CORE_Out &io) const
get all the patterns in graph this thanks to homomorphism mappings pattern must be smaller ...
Definition: GPM_Graph.h:457
tBoolean getEdgeIID(const int &id, tEdgeIID &iid) const
get the internal id of edge with id (for convenience use)
Definition: GPM_Graph.cpp:552
#define tBoolean
Definition: types.h:35
tBoolean isIsomorph(const GPM_Graph &g, vector< tVertexIID > &verticesMap, CORE_Out &io) const
return true if graph is isomorph
Definition: GPM_Graph.cpp:1222
static SP::GPM_Node New()
create a node
Definition: GPM_Node.h:47
virtual tBoolean isMappingValid(const SV::GPM_Vertex &smallGraphVertices, const vector< tVertexIID > &mapping, CORE_Out &io) const
return true if the mapping is valid
Definition: GPM_Graph.h:402
void getPatterns(const GPM_Graph &pattern, const tBoolean &isUpToAutomorphism, const tFlag &upToAutomorphismType, vector< vector< tVertexIID > > &homomorphisms, CORE_Out &io) const
get all the patterns in graph this thanks to homomorphism mappings pattern must be smaller ...
Definition: GPM_Graph.cpp:1261
tBoolean addEdgeFromIds(const int &source, const int &target, tEdgeIID &iid)
add ad edge from vertex ids (convenience method)
Definition: GPM_Graph.h:215
void getPatterns(const GPM_Graph &pattern, vector< vector< tVertexIID > > &homomorphisms, CORE_Out &io) const
get all the patterns in graph this thanks to homomorphism mappings pattern must be smaller ...
Definition: GPM_Graph.h:465
virtual tBoolean addEdge(const tVertexIID &from, const tVertexIID &to, SP::GPM_Edge edge, tEdgeIID &iid)
add an edge with name label between vertices from & to
Definition: GPM_Graph.cpp:444
#define null
Definition: types.h:13
tBoolean loadFromFile(const tString &fileName, CORE_Out &io)
load graph from txt file
Definition: GPM_Graph.cpp:859
virtual ~GPM_Graph(void)
destroy an object.
Definition: GPM_Graph.cpp:208
tBoolean getEdge(const tVertexIID &e1, const tVertexIID &e2, tEdgeIID &iid) const
get edge between vertices e1 & e2
Definition: GPM_Graph.cpp:409
GPM_Graph(void)
create an object
Definition: GPM_Graph.cpp:199
tBoolean merge(const tVertexIID &from, const tVertexIID &to, CORE_Out &io)
merge two vertex
Definition: GPM_Graph.cpp:608
this class describes the exceptions raised for CORE package
Definition: CORE_Exception.h:15
This class describes a edge.
Definition: GPM_Edge.h:15
tVertexIID addVertex(SP::GPM_Vertex vertex)
add vertex vertex with id
Definition: GPM_Graph.cpp:306
tGraph::vertex_descriptor tVertexIID
Definition: GPM_Types.h:45
virtual tBoolean addEdge(const tVertexIID &from, const tVertexIID &to, tEdgeIID &eiid)
add an edge with name label between vertices from & to
Definition: GPM_Graph.h:247
void getPatterns(SPC::GPM_Graph pattern, vector< vector< tVertexIID > > &homomorphisms, CORE_Out &io) const
get all the patterns in graph this thanks to homomorphism mappings pattern must be smaller ...
Definition: GPM_Graph.h:471
tBoolean isIsomorph(SPC::GPM_Graph g, vector< tVertexIID > &verticesMap, CORE_Out &io) const
return true if graph is isomorph
Definition: GPM_Graph.h:425
SP::GPM_Vertex getVertex(const tVertexIID &iid) const
get vertex with internal id
Definition: GPM_Graph.cpp:330
static SP::GPM_Edge New()
create an edge
Definition: GPM_Edge.h:67
int getEdgesNumber() const
get the edges number
Definition: GPM_Graph.cpp:522
void removeVertex(const tVertexIID &iid)
remove vertex with internal id: iid WARNING: the vertexIID of all the nodes may changed ! ...
Definition: GPM_Graph.cpp:346
static const tFlag UP_TO_AUTOMORPHISM_PORT
Definition: GPM_Graph.h:27
void getVertices(vector< tVertexIID > &vertexIIDs) const
get the internal id of all vertices
Definition: GPM_Graph.cpp:361
static const tFlag UP_TO_AUTOMORPHISM_NODE
Definition: GPM_Graph.h:26
tVertexIID getVertexIID(const int &id) const
get the internal id of vertex with id (for convenience use)
Definition: GPM_Graph.cpp:284
int generateVertexId()
generate a vertex id
Definition: GPM_Graph.cpp:275
#define tString
Definition: types.h:36
virtual SP::GPM_GraphElement newInstance(const tString &className) const
create a new instance of token
Definition: GPM_Graph.cpp:251
tGraph & getGraphImplement()
get the graph implementation
Definition: GPM_Graph.h:86
void close()
close the graph
virtual SP::GPM_Edge newEdge(SP::GPM_Vertex source, SP::GPM_Vertex target) const
create a node
Definition: GPM_Graph.h:208
virtual tString toString() const
set the graph to string
Definition: GPM_Graph.cpp:754
static const tVertexIID NULL_VERTEX
Definition: GPM_Graph.h:24
this class describes the output by default write on standart output
Definition: CORE_Out.h:21
static const tFlag UP_TO_AUTOMORPHISM_ALL
Definition: GPM_Graph.h:25
tBoolean getEdgeFromIds(const int &e1, const int &e2) const
get edge between vertices e1 & e2 (convenience method)
Definition: GPM_Graph.h:303
virtual SP::GPM_Edge newEdge() const
get the edge internal id
Definition: GPM_Graph.h:197
int generateEdgeId()
generate a edge id
Definition: GPM_Graph.cpp:279
tVertexIID addNode(const int &id)
add vertex with id
Definition: GPM_Graph.h:131
tBoolean addEdge_(const tVertexIID &from, const tVertexIID &to, SP::GPM_Edge edge, tEdgeIID &iid)
add edge without verifications if edge or vertices exists
Definition: GPM_Graph.cpp:482
DEFINE_SPTR(GPM_Graph)
int getVerticesNumber() const
the the vertices numbers
Definition: GPM_Graph.cpp:340
This class is the base class of all graph classes.
Definition: GPM_Object.h:17
void addSubGraph(const GPM_Graph &graph, map< tVertexIID, tVertexIID > &connections)
add sub graph
Definition: GPM_Graph.cpp:641
This class describes a graph which is a list of nodes & ports.
Definition: GPM_Graph.h:19
void updateGroupId()
update the group Id of all elements of graph
Definition: GPM_Graph.cpp:1191
tBoolean removeEdge(const tEdgeIID &edgeId)
remove edge with id WARNING: the edgeIID of all the edges may changed !
Definition: GPM_Graph.cpp:491
tBoolean addEdgeFromIds(const int &source, const int &target)
add vertex from vertex ids (convenience method)
Definition: GPM_Graph.h:228
void executeTriggerActions(CORE_Out &io)
execute trigger actions
Definition: GPM_Graph.cpp:697
virtual SP::GPM_Edge newEdge(const int &id) const
create a node
Definition: GPM_Graph.h:202
class Free introduced for deleting a smart pointer
Definition: CORE_Object.h:106
#define tFlag
Definition: types.h:14
tBoolean getEdgeFromIds(const int &e1, const int &e2, tEdgeIID &iid) const
get edge between vertices e1 & e2 (convenience method)
Definition: GPM_Graph.h:298