C++ main module for gpm Package  1.0
GPM_PatternFunction.h
Go to the documentation of this file.
1 #ifndef GPM_PatternFunction_H
2 #define GPM_PatternFunction_H
3 
4 #include "GPM_Object.h"
5 
6 #include "CORE_Out.h"
7 
8 #include "GPM_Function.h"
9 #include "GPM_Node.h"
10 #include "GPM_PortGraph.h"
11 
19 
21  SP_OBJECT(GPM_PatternFunction);
22  // ATTRIBUTES
23 
24 private:
25 
26  // the list of vertices to remove from the pattern graph with
27  // id of the pattern vertex -> true or false
28  map<int ,tBoolean> mPVerticesToRemove;
29 
30  // id of pattern vertex to keep
31  map<int ,tBoolean> mPVerticesToKeep;
32 
33  // the list of edge to remove from the pattern graph
34  // id of the pattern edge -> true of false
35  map<int,tBoolean> mPEdgesToRemove;
36 
37  // id of pattern edge to keep
38  map<int ,tBoolean> mPEdgesToKeep;
39 
40  // the list of vertices pair to add between Pattern & Transformer graph
41  // add an edge form Pattern vertex with id to transform index with id
42  SV::GPM_Edge mPTEdgesToAdd;
43 
44 
45  //variable name to build the group id
46  vector<tString> mNodeGroupIds;
47  vector<tString> mPortGroupIds;
48 
49  tBoolean mIsUpToAutomorphism;
50  tFlag mUpToAutomorphismType;
51 
52 
53 
54 
55 protected:
56  // METHODS
57 
58  // CONSTRUCTORS
59 
61  GPM_PatternFunction(void);
62 
63 
64 
65  // DESTRUCTORS
66 
67 
70  virtual ~GPM_PatternFunction(void);
71 
72 
73 public:
74 
75  // NEW methods
76 
77 
78 
79  // SET & GET methods
80 
83  virtual void copy(const GPM_Function& rule);
84 
87  virtual void clear() {
89  mPVerticesToRemove.clear();
90  mPVerticesToKeep.clear();
91  mPEdgesToRemove.clear();
92  mPEdgesToKeep.clear();
93  mPTEdgesToAdd.clear();
94  mNodeGroupIds.clear();
95  mPortGroupIds.clear();
96  mIsUpToAutomorphism=false;
97  mUpToAutomorphismType=0;
98  }
102  mIsUpToAutomorphism=isUpToAutomorphism;
103  }
104  inline void setUpToAutomorphismType( const tFlag& upToAutomorphismType) {
105  mUpToAutomorphismType=upToAutomorphismType;
106  }
107 
108 
111  inline tBoolean isUpToAutomorphism() const {
112  return mIsUpToAutomorphism;
113  }
117  return mUpToAutomorphismType;
118  }
121  inline void addPVertexToRemove(const int& vid) {
122  mPVerticesToRemove[vid]=true;
123  }
126  inline void removePVertexToRemove(const int& vid) {
127  mPVerticesToRemove.erase(vid);
128  }
131  inline void addPVertexToKeep(const int& vid) {
132  mPVerticesToKeep[vid]=true;
133  }
136  inline void removePVertexToKeep(const int& vid) {
137  mPVerticesToKeep.erase(vid);
138  }
139 
142  inline tBoolean isPVertexToRemove(const int& id) const {
143  return (mPVerticesToRemove.find(id)!=mPVerticesToRemove.end());
144  }
147  inline tBoolean isPVertexToKeep(const int& id) const {
148  return (mPVerticesToKeep.find(id)!=mPVerticesToKeep.end());
149  }
152  inline tBoolean isPVertexMustBeKept(const int& id) const {
153  int n=mPTEdgesToAdd.getSize();
154  for (int i=0;i<n;i++) {
155  if (mPTEdgesToAdd[i]->getSource()->getId()==id) return true;
156  }
157  return false;
158  }
159 
162  inline void addPEdgeToRemove(const int& eid) {
163  mPEdgesToRemove[eid]=true;
164  }
167  inline void removePEdgeToRemove(const int& eid) {
168  mPEdgesToRemove.erase(eid);
169  }
172  inline void addPEdgeToKeep(const int& eid) {
173  mPEdgesToKeep[eid]=true;
174  }
177  inline void removePEdgeToKeep(const int& eid) {
178  mPEdgesToKeep.erase(eid);
179  }
180 
183  inline void addPEdgeToKeep(const int& source,const int& target) {
184  tEdgeIID eiid;
185  if (getPatternGraph().getEdgeFromIds(source,target,eiid)) {
186  SPC::GPM_Edge edge=getPatternGraph().getEdge(eiid);
187  if (edge.get()!=null)
188  addPEdgeToKeep(edge->getId());
189  }
190  }
193  inline void addPEdgeToRemove(const int& source,const int& target) {
194  tEdgeIID eiid;
195  if (getPatternGraph().getEdgeFromIds(source,target,eiid)) {
196  SPC::GPM_Edge edge=getPatternGraph().getEdge(eiid);
197  if (edge.get()!=null)
198  addPEdgeToRemove(edge->getId());
199  }
200  }
203  inline const map<int,tBoolean>& getPatternEdgesToRemove() const {
204  return mPEdgesToRemove;
205  }
208  inline const map<int,tBoolean>& getPatternEdgesToKeep() const {
209  return mPEdgesToKeep;
210  }
213  inline const map<int,tBoolean>& getPatternVerticesToRemove() const {
214  return mPVerticesToRemove;
215  }
218  inline const map<int,tBoolean>& getPatternVerticesToKeep() const {
219  return mPVerticesToKeep;
220  }
223  inline tBoolean isPEdgeToRemove(const int& id) {
224  return (mPEdgesToRemove.find(id)!=mPEdgesToRemove.end());
225  }
228  inline tBoolean isPEdgeToKeep(const int& id) const {
229  return (mPEdgesToKeep.find(id)!=mPEdgesToKeep.end());
230  }
233  inline void addPTEdgeToAdd(const int& source,const int& target) {
234  const GPM_PortGraph& patternGraph=getPatternGraph();
235  const GPM_PortGraph& transformerGraph=getTransformerGraph();
236  SP::GPM_Vertex sourceNode=patternGraph.getVertex(patternGraph.getVertexIID(source));
237  SP::GPM_Vertex targetNode=transformerGraph.getVertex(transformerGraph.getVertexIID(target));
238  addPTEdgeToAdd(sourceNode,targetNode);
239  }
240 
243  inline void addPTEdgeToAdd(SP::GPM_Vertex source,SP::GPM_Vertex target) {
244  SP::GPM_Edge edge=getPatternGraph().newEdge(source,target);
245  addPTEdgeToAdd(edge);
246  }
249  inline void addPTEdgeToAdd(SP::GPM_Edge edge) {
250  mPTEdgesToAdd.add(edge);
251  edge->setId(mPTEdgesToAdd.getSize()-1);
252  addPVertexToKeep(edge->getSource()->getId());
253  }
254 
257  inline int getPTEdgesNumber() const {
258  return mPTEdgesToAdd.size();
259  }
267  inline SP::GPM_Edge getPTEdge(const int& index) const {
268  return mPTEdgesToAdd[index];
269  }
270 
273  inline void removeLastPTEdge() {
274  SP::GPM_Edge edge=mPTEdgesToAdd[mPTEdgesToAdd.size()-1];
275  removePTEdgeToAdd(edge);
276  }
281  inline void removePTEdgeToAdd(SP::GPM_Edge edge) {
282  removePTEdgeToAdd(edge->getSource()->getId(),edge->getTarget()->getId());
283  }
284 
289  void removePTEdgeToAdd(const int& source,const int& target);
290 
294  mPTEdgesToAdd.clear();
295  }
299  void removePTEdgeToAddWithSource(const int& sourceId);
300 
304  void removePTEdgeToAddWithTarget(const int& targetId);
305 
306 
310  mNodeGroupIds.push_back(name);
311  }
314  void removeVariableNameToNodeGroupId(const int& index) {
315  mNodeGroupIds.erase(mNodeGroupIds.begin()+index);
316  }
320  mPortGroupIds.push_back(name);
321  }
324  void removeVariableNameToPortGroupId(const int& index) {
325  mPortGroupIds.erase(mPortGroupIds.begin()+index);
326  }
329  void initGroupNames(GPM_PortGraph& graph,CORE_Out& io) const;
330 
331 
332 
335  const vector<tString>& getNodeGroupIds() const {
336  return mNodeGroupIds;
337  }
340  const vector<tString>& getPortGroupIds() const {
341  return mPortGroupIds;
342  }
343 
344 public:
347  void getPatternVerticesToRemove(vector<int>& ids) const {
348  ids.clear();
349  map<int,tBoolean>::const_iterator iter=mPVerticesToRemove.begin();
350  while (iter!=mPVerticesToRemove.end()) {
351  ids.push_back(iter->first);
352  iter++;
353  }
354 
355  }
358  void getPatternVerticesToKeep(vector<int>& ids) const {
359  ids.clear();
360  map<int,tBoolean>::const_iterator iter=mPVerticesToKeep.begin();
361  while (iter!=mPVerticesToKeep.end()) {
362  ids.push_back(iter->first);
363  iter++;
364  }
365 
366  }
367 
368 
371  void getPatternEdgesToRemove( vector<int>& ids) const {
372  ids.clear();
373  map<int,tBoolean>::const_iterator iter=mPEdgesToRemove.begin();
374  while (iter!=mPEdgesToRemove.end()) {
375  ids.push_back(iter->first);
376  iter++;
377  }
378  }
381  void getPatternEdgesToKeep( vector<int>& ids) const {
382  ids.clear();
383  map<int,tBoolean>::const_iterator iter=mPEdgesToKeep.begin();
384  while (iter!=mPEdgesToKeep.end()) {
385  ids.push_back(iter->first);
386  iter++;
387  }
388  }
389 public:
392  const SV::GPM_Edge& getPatternTransformEdgesToAdd() const {
393  return mPTEdgesToAdd;
394  }
398  return mPTEdgesToAdd;
399  }
400 
401 
402 public:
405  virtual tBoolean isMappingValid(const GPM_PortGraph& largeGraph,
406  const SV::GPM_Vertex& smallGraphVertices,
407  const vector<tVertexIID>& mapping,
408  CORE_Out& io) const {
409  return true;
410  }
411 
414  inline tBoolean isVertexCut(const int& id) const {
415  return (mPVerticesToRemove.find(id)!=mPVerticesToRemove.end());
416  }
419  inline tBoolean isVertexKept(const int& id) const {
420  return (mPVerticesToKeep.find(id)!=mPVerticesToKeep.end());
421  }
424  inline tBoolean isEdgeCut(const int& id) const {
425  return (mPEdgesToRemove.find(id)!=mPEdgesToRemove.end());
426  }
429  inline tBoolean isEdgeKept(const int& id) const {
430  return (mPEdgesToKeep.find(id)!=mPEdgesToKeep.end());
431  }
435  tBoolean isValid() const;
436 
441  virtual tBoolean apply(GPM_Graph& largeGraph,
442  const vector<tVertexIID>& mappingP2L,CORE_Out& io) {
444  largeGraph,mappingP2L,
445  io);
446  }
447 public:
450  virtual tBoolean updateTransformerGraphStates(GPM_Graph& largeGraph,
451  const vector<tVertexIID>& mappingP2L,
452  const map<tVertexIID,tVertexIID>& mappingT2L,CORE_Out& io)=0;
455  virtual tBoolean updatePatternGraphStates(GPM_Graph& largeGraph,
456  const vector<tVertexIID>& mappingP2L,CORE_Out& io)=0;
457 
460  virtual tBoolean updatePTEdgesStates(SP::GPM_Edge PTedge,SP::GPM_Edge ledge,
461  GPM_Graph& largeGraph,
462  const vector<tVertexIID>& mappingP2L,
463  const map<tVertexIID,tVertexIID>& mappingT2L,
464  CORE_Out& io)=0;
465 
466 
467 
468 private:
469 
474  tBoolean apply(const GPM_Graph& patternGraph,
475  const GPM_Graph& transformerGraph,
476  GPM_Graph& largeGraph,const vector<tVertexIID>& mapping,
477  CORE_Out& io) ;
478 
479 public:
482  virtual tString toString() const;
483 
484 };
485 
486 #endif
void addPTEdgeToAdd(const int &source, const int &target)
add the edge (source,target) source in pattern graph , target in transformed graph ...
Definition: GPM_PatternFunction.h:233
void addVariableNameToNodeGroupId(const tString &name)
add the state to build the group id of node
Definition: GPM_PatternFunction.h:309
GPM_PatternFunction(void)
create an object
Definition: GPM_PatternFunction.cpp:10
virtual tBoolean updatePTEdgesStates(SP::GPM_Edge PTedge, SP::GPM_Edge ledge, GPM_Graph &largeGraph, const vector< tVertexIID > &mappingP2L, const map< tVertexIID, tVertexIID > &mappingT2L, CORE_Out &io)=0
update the states of edges betwen pattern & transform graph
virtual tString toString() const
return the string representation of the class
Definition: GPM_PatternFunction.cpp:392
const map< int, tBoolean > & getPatternEdgesToKeep() const
get the pattern edges list to keep
Definition: GPM_PatternFunction.h:208
tBoolean isEdgeKept(const int &id) const
return true if the edge is keep
Definition: GPM_PatternFunction.h:429
void removeVariableNameToNodeGroupId(const int &index)
remove the state at index to build the group id of node
Definition: GPM_PatternFunction.h:314
virtual tBoolean updatePatternGraphStates(GPM_Graph &largeGraph, const vector< tVertexIID > &mappingP2L, CORE_Out &io)=0
update the states (coordianates,tags...) of the sub graph of the large graph corresponding to pattern...
tFlag getUpToAutomorphismType() const
return the type of graph element to be up to automorphism
Definition: GPM_PatternFunction.h:116
void removePVertexToKeep(const int &vid)
remove the vertex to keep from pattern graph
Definition: GPM_PatternFunction.h:136
tBoolean isUpToAutomorphism() const
return true if the function is up to automorphism
Definition: GPM_PatternFunction.h:111
tGraph::edge_descriptor tEdgeIID
Definition: GPM_Types.h:50
void removePEdgeToRemove(const int &eid)
remove the edge to remove from pattern graph
Definition: GPM_PatternFunction.h:167
const GPM_PortGraph & getTransformerGraph() const
get the transformer graph for reading
Definition: GPM_Function.h:95
void removePTEdgeToAdd(SP::GPM_Edge edge)
remove the edge (source,target)
Definition: GPM_PatternFunction.h:281
void addVariableNameToPortGroupId(const tString &name)
add the state to build the group id of port
Definition: GPM_PatternFunction.h:319
DEFINE_SPTR(GPM_PatternFunction)
virtual tBoolean isMappingValid(const GPM_PortGraph &largeGraph, const SV::GPM_Vertex &smallGraphVertices, const vector< tVertexIID > &mapping, CORE_Out &io) const
return true if the mapping is valid
Definition: GPM_PatternFunction.h:405
void setIsUpToAutomorphism(const tBoolean &isUpToAutomorphism)
set is up to automorphism
Definition: GPM_PatternFunction.h:101
void getPatternVerticesToKeep(vector< int > &ids) const
get the vertices to keep from associated pattern graph
Definition: GPM_PatternFunction.h:358
tBoolean isPEdgeToKeep(const int &id) const
return true if the edge has already a keep trigger action
Definition: GPM_PatternFunction.h:228
void getPatternVerticesToRemove(vector< int > &ids) const
get the vertices to remove from associated pattern graph
Definition: GPM_PatternFunction.h:347
const SV::GPM_Edge & getPatternTransformEdgesToAdd() const
get the edges to ad dfrom pattern graph to transformed graph
Definition: GPM_PatternFunction.h:392
This class describes a patten function.
Definition: GPM_Function.h:20
void getPatternEdgesToKeep(vector< int > &ids) const
get the edges to keep from associated pattern graph
Definition: GPM_PatternFunction.h:381
#define tBoolean
Definition: types.h:35
tBoolean isPVertexMustBeKept(const int &id) const
return true if the vertex must be kept
Definition: GPM_PatternFunction.h:152
void addPVertexToKeep(const int &vid)
add the vertex to keep from pattern graph
Definition: GPM_PatternFunction.h:131
tBoolean isVertexKept(const int &id) const
return true if the vertex is kept
Definition: GPM_PatternFunction.h:419
void setUpToAutomorphismType(const tFlag &upToAutomorphismType)
Definition: GPM_PatternFunction.h:104
#define null
Definition: types.h:13
const map< int, tBoolean > & getPatternVerticesToRemove() const
get the pattern vertices list to remove
Definition: GPM_PatternFunction.h:213
void removePEdgeToKeep(const int &eid)
remove the edge to keep from pattern graph
Definition: GPM_PatternFunction.h:177
const vector< tString > & getNodeGroupIds() const
get the variables names to define the group name of nodes
Definition: GPM_PatternFunction.h:335
virtual void clear()
clear
Definition: GPM_Function.h:65
void addPTEdgeToAdd(SP::GPM_Edge edge)
add the edge (source,target) source in pattern graph , target in transformed graph ...
Definition: GPM_PatternFunction.h:249
void addPEdgeToKeep(const int &source, const int &target)
add the edge to remove from pattern graph
Definition: GPM_PatternFunction.h:183
const vector< tString > & getPortGroupIds() const
get the variables names to define the group name of ports
Definition: GPM_PatternFunction.h:340
const GPM_PortGraph & getPatternGraph() const
get the pattern graph for reading
Definition: GPM_Function.h:76
tBoolean getEdge(const tVertexIID &e1, const tVertexIID &e2, tEdgeIID &iid) const
get edge between vertices e1 & e2
Definition: GPM_Graph.cpp:409
const map< int, tBoolean > & getPatternVerticesToKeep() const
get the pattern vertices list to keep
Definition: GPM_PatternFunction.h:218
void initGroupNames(GPM_PortGraph &graph, CORE_Out &io) const
init the group name id
Definition: GPM_PatternFunction.cpp:267
void removePTEdgeToAddWithTarget(const int &targetId)
remove the edge for pattern &transform graph with target
Definition: GPM_PatternFunction.cpp:380
void clearPTEdgesToAdd()
Definition: GPM_PatternFunction.h:293
tBoolean isVertexCut(const int &id) const
return true if the vertex is cut
Definition: GPM_PatternFunction.h:414
void removePTEdgeToAddWithSource(const int &sourceId)
remove the edge for pattern &transform graph with source
Definition: GPM_PatternFunction.cpp:363
virtual void copy(const GPM_Function &rule)
copy
Definition: GPM_PatternFunction.cpp:21
void removeLastPTEdge()
remove the last edge (source,target) source in pattern graph , target in transformed graph ...
Definition: GPM_PatternFunction.h:273
SP::GPM_Vertex getVertex(const tVertexIID &iid) const
get vertex with internal id
Definition: GPM_Graph.cpp:330
tBoolean isValid() const
return true if the topological rules transformation will build to a valid graph
Definition: GPM_PatternFunction.cpp:278
virtual tBoolean updateTransformerGraphStates(GPM_Graph &largeGraph, const vector< tVertexIID > &mappingP2L, const map< tVertexIID, tVertexIID > &mappingT2L, CORE_Out &io)=0
update the states (coordianates,tags...) of the transformed graph copied in the large graph ...
int getPTEdgesNumber() const
get the number of edges to add
Definition: GPM_PatternFunction.h:257
virtual tBoolean apply(GPM_Graph &largeGraph, const vector< tVertexIID > &mappingP2L, CORE_Out &io)
apply the trnafsormtaion with pattern
Definition: GPM_PatternFunction.h:441
virtual void clear()
clear all topological modification
Definition: GPM_PatternFunction.h:87
tVertexIID getVertexIID(const int &id) const
get the internal id of vertex with id (for convenience use)
Definition: GPM_Graph.cpp:284
void removeVariableNameToPortGroupId(const int &index)
remove the state at index to build the group id of port
Definition: GPM_PatternFunction.h:324
#define tString
Definition: types.h:36
This class describes a graph which is a list of vertices, ports & edges.
Definition: GPM_PortGraph.h:22
tBoolean isPEdgeToRemove(const int &id)
return true if the edge has already a cut trigger action
Definition: GPM_PatternFunction.h:223
void removePVertexToRemove(const int &vid)
remove the vertex to remove from pattern graph
Definition: GPM_PatternFunction.h:126
void addPEdgeToRemove(const int &eid)
add the edge to remove from pattern graph
Definition: GPM_PatternFunction.h:162
This class describes a patten function.
Definition: GPM_PatternFunction.h:20
this class describes the output by default write on standart output
Definition: CORE_Out.h:21
tBoolean isPVertexToKeep(const int &id) const
return true if the vertex has already a keep trigger action
Definition: GPM_PatternFunction.h:147
virtual SP::GPM_Edge newEdge() const
get the edge internal id
Definition: GPM_Graph.h:197
void getPatternEdgesToRemove(vector< int > &ids) const
get the edges to remove from associated pattern graph
Definition: GPM_PatternFunction.h:371
void addPEdgeToKeep(const int &eid)
add the edge to keep from pattern graph
Definition: GPM_PatternFunction.h:172
void addPVertexToRemove(const int &vid)
add the vertex to remove from pattern graph
Definition: GPM_PatternFunction.h:121
DEFINE_SVPTR(GPM_PatternFunction)
This class describes a graph which is a list of nodes & ports.
Definition: GPM_Graph.h:19
SV::GPM_Edge & getPatternTransformEdgesToAdd()
get the edges to ad dfrom pattern graph to transformed graph
Definition: GPM_PatternFunction.h:397
void addPTEdgeToAdd(SP::GPM_Vertex source, SP::GPM_Vertex target)
add the edge (source,target) source in pattern graph , target in transformed graph ...
Definition: GPM_PatternFunction.h:243
tBoolean isEdgeCut(const int &id) const
return true if the edge is cut
Definition: GPM_PatternFunction.h:424
void addPEdgeToRemove(const int &source, const int &target)
add the edge to remove from pattern graph
Definition: GPM_PatternFunction.h:193
const map< int, tBoolean > & getPatternEdgesToRemove() const
get the pattern edges list to remove
Definition: GPM_PatternFunction.h:203
SP::GPM_Edge getPTEdge(const int &index) const
get the i-th edge to add
Definition: GPM_PatternFunction.h:267
tBoolean isPVertexToRemove(const int &id) const
return true if the vertex has already a cut trigger action
Definition: GPM_PatternFunction.h:142
#define tFlag
Definition: types.h:14
virtual ~GPM_PatternFunction(void)
destroy an object.
Definition: GPM_PatternFunction.cpp:18