COIN-OR::LEMON - Graph Library

Ticket #682: vf2Fix.patch

File vf2Fix.patch, 7.5 KB (added by Peter Madarasi, 6 months ago)
  • lemon/vf2.h

    # HG changeset patch
    # User Peter Madarasi <madarasi@cs.elte.hu>
    # Date 1715881419 -7200
    #      Thu May 16 19:43:39 2024 +0200
    # Node ID 7929660eaed36cd926a6b0a43266d2f375250569
    # Parent  a278d16bd2d082aa3c52ff4a9b0e2224ddc0549a
    Bugfix in Vf2 and Vf2++; extend tests
    
    diff -r a278d16bd2d0 -r 7929660eaed3 lemon/vf2.h
    a b  
    9898           class NEQ = bits::vf2::AlwaysEq >
    9999#endif
    100100  class Vf2 {
     101    template<class T>
     102    friend class Vf2Wizard;
     103
    101104    //The graph to be embedded
    102105    const G1 &_g1;
    103106
  • lemon/vf2pp.h

    diff -r a278d16bd2d0 -r 7929660eaed3 lemon/vf2pp.h
    a b  
    6666           class M2 = typename G2::template NodeMap<int> >
    6767#endif
    6868  class Vf2pp {
     69    template<class T>
     70    friend class Vf2ppWizard;
     71
    6972    //The graph to be embedded
    7073    const G1 &_g1;
    7174
     
    119122    //indicates whether the mapping or the labels must be deleted in the destructor
    120123    bool _deallocMappingAfterUse,_deallocLabelsAfterUse;
    121124
    122 
    123125    //improved cutting function
    124126    template<MappingType MT>
    125127    bool cutByLabels(const typename G1::Node n1,const typename G2::Node n2) {
     
    776778      if(Base::_local_mapping)
    777779        ptr->_deallocMappingAfterUse=true;
    778780      if(Base::_local_nodeLabels)
    779         ptr->_deallocLabelMapsAfterUse=true;
     781        ptr->_deallocLabelsAfterUse=true;
    780782
    781783      return ptr;
    782784    }
  • test/vf2_test.cc

    diff -r a278d16bd2d0 -r 7929660eaed3 test/vf2_test.cc
    a b  
    292292
    293293  succ = vf2pp(g,h).nodeLabels(c1_IntConv,c2_IntConv).mapping(r).run();
    294294  succ = vf2pp(g,h).nodeLabels(c1_IntConv,c2_IntConv).mapping(r).run();
     295
     296  auto* vf2ppPtr = vf2pp(g, h).mapping(r).nodeLabels(c1, c2).induced()
     297    .getPtrToVf2ppObject();
    295298}
    296299
    297300void vf2ppCompile() {
     
    373376}
    374377
    375378template<class G1,class G2,class L1,class L2,class T>
    376 bool checkSub(const G1 &g1, const G2 &g2, const L1 &l1, const L2 &l2, const T &vf2) {
     379bool checkSub(const G1 &g1, const G2 &g2, const L1 &l1, const L2 &l2,
     380              const T &vf2) {
    377381  typename G1:: template NodeMap<typename G2::Node> iso(g1,INVALID);
    378382  if (const_cast<T&>(vf2).nodeLabels(l1,l2).mapping(iso).run()){
    379383    checkSubIso(g1,g2,iso);
     
    402406}
    403407
    404408template<class G1,class G2,class L1,class L2>
    405 void checkSub(const G1 &g1, const G2 &g2, const L1 &l1, const L2 &l2, bool expected, const char* msg) {
     409void checkSub(const G1 &g1, const G2 &g2, const L1 &l1, const L2 &l2,
     410              bool expected, const char* msg) {
    406411  check(checkSub(g1,g2,l1,l2,vf2(g1,g2)) == expected, msg);
    407412  check(checkSub(g1,g2,l1,l2,vf2pp(g1,g2)) == expected, msg);
    408413}
    409414
     415
     416template<class G1,class G2>
     417void checkSubCount(const G1 &g1, const G2 &g2, int expected, const char* msg) {
     418  check(vf2(g1,g2).count() == expected, msg);
     419  check(vf2pp(g1,g2).count() == expected, msg);
     420  {
     421    auto* vf2ppPtr = vf2pp(g1, g2).getPtrToVf2ppObject();
     422    int cnt = 0;
     423    while(vf2ppPtr->find())
     424      ++cnt;
     425    check(cnt == expected, msg);
     426  }
     427  {
     428    auto* vf2Ptr = vf2(g1, g2).getPtrToVf2Object();
     429    int cnt = 0;
     430    while(vf2Ptr->find())
     431      ++cnt;
     432    check(cnt == expected, msg);
     433  }
     434}
     435
     436template<class G1,class G2>
     437void checkIndCount(const G1 &g1, const G2 &g2, int expected, const char* msg) {
     438  check(vf2(g1,g2).induced().count() == expected, msg);
     439  check(vf2pp(g1,g2).induced().count() == expected, msg);
     440  {
     441    typename G1::NodeMap<char> l1(g1,0);
     442    typename G2::NodeMap<char> l2(g2,0);
     443    typename G1::NodeMap<typename G1::Node> m(g1);
     444    auto* vf2ppPtr = vf2pp(g1, g2).induced().mapping(m).nodeLabels(l1,l2)
     445      .getPtrToVf2ppObject();
     446    int cnt = 0;
     447    while(vf2ppPtr->find())
     448      ++cnt;
     449    check(cnt == expected, msg);
     450  }
     451  {
     452    typename G1::NodeMap<char> l1(g1,0);
     453    typename G2::NodeMap<char> l2(g2,0);
     454    typename G1::NodeMap<typename G1::Node> m(g1);
     455    auto* vf2Ptr = vf2(g1, g2).induced().mapping(m).nodeLabels(l1,l2)
     456      .getPtrToVf2Object();
     457    int cnt = 0;
     458    while(vf2Ptr->find())
     459      ++cnt;
     460    check(cnt == expected, msg);
     461  }
     462}
     463
     464template<class G1,class G2>
     465void checkIsoCount(const G1 &g1, const G2 &g2, int expected, const char* msg) {
     466  check(vf2(g1,g2).iso().count() == expected, msg);
     467  check(vf2pp(g1,g2).iso().count() == expected, msg);
     468  {
     469    auto* vf2ppPtr = vf2pp(g1, g2).iso().getPtrToVf2ppObject();
     470    int cnt = 0;
     471    while(vf2ppPtr->find())
     472      ++cnt;
     473    check(cnt == expected, msg);
     474  }
     475  {
     476    auto* vf2Ptr = vf2(g1, g2).iso().getPtrToVf2Object();
     477    int cnt = 0;
     478    while(vf2Ptr->find())
     479      ++cnt;
     480    check(cnt == expected, msg);
     481  }
     482}
     483
    410484int main() {
    411485  make_graphs();
    412486
    413487  checkSub(c5,petersen,true,
    414488      "There should exist a C5->Petersen mapping.");
     489  checkSubCount(c5,petersen,120,
     490      "There should exist 120 Petersen->Petersen mappings.");
    415491  checkSub(c7,petersen,false,
    416492      "There should not exist a C7->Petersen mapping.");
    417493  checkSub(p10,petersen,true,
    418494      "There should exist a P10->Petersen mapping.");
     495  checkSubCount(p10,petersen,240,
     496      "There should exist 240 Petersen->Petersen mappings.");
    419497  checkSub(c10,petersen,false,
    420498      "There should not exist a C10->Petersen mapping.");
    421499  checkSub(petersen,petersen,true,
    422500      "There should exist a Petersen->Petersen mapping.");
     501  checkSubCount(petersen,petersen,120,
     502      "There should exist 120 Petersen->Petersen mappings.");
    423503
    424504  checkInd(c5,petersen,true,
    425       "There should exist a C5->Petersen spanned mapping.");
     505      "There should exist a C5->Petersen induced mapping.");
     506  checkIndCount(c5,petersen,120,
     507      "There should exist 120 C5->Petersen induced mappings.");
    426508  checkInd(c7,petersen,false,
    427       "There should exist a C7->Petersen spanned mapping.");
     509      "There should exist a C7->Petersen induced mapping.");
    428510  checkInd(p10,petersen,false,
    429       "There should not exist a P10->Petersen spanned mapping.");
     511      "There should not exist a P10->Petersen induced mapping.");
    430512  checkInd(c10,petersen,false,
    431       "There should not exist a C10->Petersen spanned mapping.");
     513      "There should not exist a C10->Petersen induced mapping.");
    432514  checkInd(petersen,petersen,true,
    433         "There should exist a Petersen->Petersen spanned mapping.");
     515        "There should exist a Petersen->Petersen induced mapping.");
     516  checkIndCount(petersen,petersen,120,
     517        "There should exist 120 Petersen->Petersen induced mappings.");
    434518
    435519  checkSub(petersen,c10,false,
    436520      "There should not exist a Petersen->C10 mapping.");
    437521  checkSub(p10,c10,true,
    438522      "There should exist a P10->C10 mapping.");
     523  checkSubCount(p10,c10,20,
     524      "There should exist 20 P10->C10 mappings.");
    439525  checkInd(p10,c10,false,
    440       "There should not exist a P10->C10 spanned mapping.");
     526      "There should not exist a P10->C10 induced mapping.");
    441527  checkSub(c10,p10,false,
    442528      "There should not exist a C10->P10 mapping.");
    443529
     
    446532  checkIso(c10,c10,true,
    447533      "C10 and C10 are isomorphic.");
    448534
     535  checkSubCount(c10,c10,20,
     536      "There should exists 20 C10 -> C10 mappings.");
     537  checkIndCount(c10,c10,20,
     538      "There should exists 20 C10 -> C10 induced mappings.");
     539  checkIsoCount(c10,c10,20,
     540      "There should exists 20 C10 -> C10 iso mappings.");
     541
    449542  checkSub(c5,petersen,c5_col,petersen_col1,false,
    450543      "There should exist a C5->Petersen mapping.");
    451544  checkSub(c5,petersen,c5_col,petersen_col2,true,