Changeset 1408:b9fad0f9f8ab in lemon for lemon/vf2.h
- Timestamp:
- 10/07/17 15:45:56 (7 years ago)
- Branch:
- default
- Phase:
- public
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
lemon/vf2.h
r1407 r1408 113 113 #endif 114 114 class Vf2 { 115 //Current depth in the DFS tree. 116 int _depth; 115 //The graph to be embedded 116 const G1 &_g1; 117 118 //The graph into which g1 is to be embedded 119 const G2 &_g2; 117 120 118 121 //Functor with bool operator()(G1::Node,G2::Node), which returns 1 … … 120 123 NEQ _nEq; 121 124 122 // _conn[v2] = number of covered neighbours of v2123 typename G2::template NodeMap<int> _conn;125 //Current depth in the DFS tree. 126 int _depth; 124 127 125 128 //The current mapping. _mapping[v1]=v2 iff v1 has been mapped to v2, … … 127 130 M &_mapping; 128 131 129 //order[i] is the node of g1 for which a pair is searched if depth=i 130 std::vector<typename G1::Node> order; 131 132 //currEdgeIts[i] is the last used edge iterator in the i-th 133 //depth to find a pair for node order[i] 134 std::vector<typename G2::IncEdgeIt> currEdgeIts; 132 //_order[i] is the node of g1 for which a pair is searched if depth=i 133 std::vector<typename G1::Node> _order; 135 134 136 //The graph to be embedded 137 const G1 &_g1; 138 139 //The graph into which g1 is to be embedded 140 const G2 &_g2; 135 //_conn[v2] = number of covered neighbours of v2 136 typename G2::template NodeMap<int> _conn; 137 138 //_currEdgeIts[i] is the last used edge iterator in the i-th 139 //depth to find a pair for node _order[i] 140 std::vector<typename G2::IncEdgeIt> _currEdgeIts; 141 141 142 142 //lookup tables for cutting the searchtree 143 typename G1::template NodeMap<int> rNew1t,rInOut1t;143 typename G1::template NodeMap<int> _rNew1t, _rInOut1t; 144 144 145 145 MappingType _mapping_type; … … 160 160 switch(MT) { 161 161 case INDUCED: 162 return rInOut1t[n1]<=rInOut2&&rNew1t[n1]<=rNew2;162 return _rInOut1t[n1]<=rInOut2&&_rNew1t[n1]<=rNew2; 163 163 case SUBGRAPH: 164 return rInOut1t[n1]<=rInOut2;164 return _rInOut1t[n1]<=rInOut2; 165 165 case ISOMORPH: 166 return rInOut1t[n1]==rInOut2&&rNew1t[n1]==rNew2;166 return _rInOut1t[n1]==rInOut2&&_rNew1t[n1]==rNew2; 167 167 default: 168 168 return false; … … 236 236 // we will find pairs for the nodes of g1 in this order 237 237 238 // bits::vf2::DfsLeaveOrder<G1> v(_g1, order);238 // bits::vf2::DfsLeaveOrder<G1> v(_g1,_order); 239 239 // DfsVisit<G1,bits::vf2::DfsLeaveOrder<G1> >dfs(_g1, v); 240 240 // dfs.run(); 241 241 242 242 //it is more efficient in practice than DFS 243 bits::vf2::BfsLeaveOrder<G1> v(_g1, order);243 bits::vf2::BfsLeaveOrder<G1> v(_g1,_order); 244 244 BfsVisit<G1,bits::vf2::BfsLeaveOrder<G1> >bfs(_g1, v); 245 245 bfs.run(); … … 249 249 bool extMatch() { 250 250 while(_depth>=0) { 251 if(_depth==static_cast<int>( order.size())) {251 if(_depth==static_cast<int>(_order.size())) { 252 252 //all nodes of g1 are mapped to nodes of g2 253 253 --_depth; 254 254 return true; 255 255 } 256 typename G1::Node& nodeOfDepth = order[_depth];256 typename G1::Node& nodeOfDepth = _order[_depth]; 257 257 const typename G2::Node& pairOfNodeOfDepth = _mapping[nodeOfDepth]; 258 typename G2::IncEdgeIt &edgeItOfDepth = currEdgeIts[_depth];258 typename G2::IncEdgeIt &edgeItOfDepth = _currEdgeIts[_depth]; 259 259 //the node of g2 whose neighbours are the candidates for 260 260 //the pair of nodeOfDepth … … 327 327 void setRNew1tRInOut1t() { 328 328 typename G1::template NodeMap<int> tmp(_g1,0); 329 for(unsigned int i=0; i< order.size(); ++i) {330 const typename G1::Node& orderI = order[i];329 for(unsigned int i=0; i<_order.size(); ++i) { 330 const typename G1::Node& orderI = _order[i]; 331 331 tmp[orderI]=-1; 332 332 for(typename G1::IncEdgeIt e1(_g1,orderI); e1!=INVALID; ++e1) { 333 333 const typename G1::Node currNode=_g1.oppositeNode(orderI,e1); 334 334 if(tmp[currNode]>0) 335 ++ rInOut1t[orderI];335 ++_rInOut1t[orderI]; 336 336 else if(tmp[currNode]==0) 337 ++ rNew1t[orderI];337 ++_rNew1t[orderI]; 338 338 } 339 339 for(typename G1::IncEdgeIt e1(_g1,orderI); e1!=INVALID; ++e1) { … … 356 356 ///mappable to another. By default it is an always true operator. 357 357 Vf2(const G1 &g1, const G2 &g2, M &m, const NEQ &neq = NEQ() ) : 358 _nEq(neq), _conn(g2,0), _mapping(m), order(countNodes(g1)), 359 currEdgeIts(countNodes(g1),INVALID), _g1(g1), _g2(g2), rNew1t(g1,0), 360 rInOut1t(g1,0), _mapping_type(SUBGRAPH), _deallocMappingAfterUse(0) 358 _g1(g1), _g2(g2), _nEq(neq), _depth(0), _mapping(m), 359 _order(countNodes(g1)), _conn(g2,0), 360 _currEdgeIts(countNodes(g1),INVALID), _rNew1t(g1,0), _rInOut1t(g1,0), 361 _mapping_type(SUBGRAPH), _deallocMappingAfterUse(0) 361 362 { 362 _depth=0;363 363 setOrder(); 364 364 setRNew1tRInOut1t();
Note: See TracChangeset
for help on using the changeset viewer.