[Lemon-commits] Peter Kovacs: Merge tests of VF2 and VF2++ (#597)

Lemon HG hg at lemon.cs.elte.hu
Wed Oct 17 23:21:03 CEST 2018


details:   http://lemon.cs.elte.hu/hg/lemon/rev/120b9031eada
changeset: 1406:120b9031eada
user:      Peter Kovacs <kpeter [at] inf.elte.hu>
date:      Sat Oct 07 00:14:05 2017 +0200
description:
	Merge tests of VF2 and VF2++ (#597)

diffstat:

 test/CMakeLists.txt |    1 -
 test/vf2_test.cc    |  279 ++++++++++++++++++++++++------------
 test/vf2pp_test.cc  |  392 ----------------------------------------------------
 3 files changed, 187 insertions(+), 485 deletions(-)

diffs (truncated from 786 to 300 lines):

diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
--- a/test/CMakeLists.txt
+++ b/test/CMakeLists.txt
@@ -55,7 +55,6 @@
   tsp_test
   unionfind_test
   vf2_test
-  vf2pp_test
 )
 
 IF(LEMON_HAVE_LP)
diff --git a/test/vf2_test.cc b/test/vf2_test.cc
--- a/test/vf2_test.cc
+++ b/test/vf2_test.cc
@@ -16,6 +16,7 @@
  */
 
 #include <lemon/vf2.h>
+#include <lemon/vf2pp.h>
 #include <lemon/concepts/digraph.h>
 #include <lemon/smart_graph.h>
 #include <lemon/lgf_reader.h>
@@ -152,31 +153,31 @@
 void make_graphs() {
   std::stringstream ss(petersen_lgf);
   graphReader(petersen, ss)
-    .nodeMap("col1",petersen_col1)
-    .nodeMap("col2",petersen_col2)
+    .nodeMap("col1", petersen_col1)
+    .nodeMap("col2", petersen_col2)
     .run();
 
   ss.clear();
   ss.str("");
-  ss<<c5_lgf;
+  ss << c5_lgf;
   //std::stringstream ss2(c5_lgf);
   graphReader(c5, ss)
-    .nodeMap("col",c5_col)
+    .nodeMap("col", c5_col)
     .run();
 
   ss.clear();
   ss.str("");
-  ss<<c7_lgf;
+  ss << c7_lgf;
   graphReader(c7, ss).run();
 
   ss.clear();
   ss.str("");
-  ss<<c10_lgf;
+  ss << c10_lgf;
   graphReader(c10, ss).run();
 
   ss.clear();
   ss.str("");
-  ss<<p10_lgf;
+  ss << p10_lgf;
   graphReader(p10, ss).run();
 
 }
@@ -196,6 +197,20 @@
   }
 };
 
+class IntConvertible1 {
+public:
+  operator int() {
+    return 0;
+  }
+};
+
+class IntConvertible2 {
+public:
+  operator int() {
+    return 0;
+  }
+};
+
 template<class G1,class G2>
 void checkVf2Compile() {
   G1 g;
@@ -224,141 +239,221 @@
     .mapping(r).run();
 }
 
-void justCompile() {
+void vf2Compile() {
   checkVf2Compile<concepts::Graph,concepts::Graph>();
   checkVf2Compile<concepts::Graph,SmartGraph>();
   checkVf2Compile<SmartGraph,concepts::Graph>();
 }
 
-template<class G1, class G2, class I>
-void checkSub(const G1 &g1, const G2 &g2, const I &i) {
-  {
-    std::set<typename G2::Node> image;
-    for(typename G1::NodeIt n(g1);n!=INVALID;++n){
-      check(i[n]!=INVALID, "Wrong isomorphism: incomplete mapping.");
-      check(image.count(i[n])==0,"Wrong isomorphism: not injective.");
-      image.insert(i[n]);
-    }
-  }
-  for(typename G1::EdgeIt e(g1);e!=INVALID;++e)
-    check(findEdge(g2,i[g1.u(e)],i[g1.v(e)])!=INVALID,
-          "Wrong isomorphism: missing edge(checkSub).");
+template<class G1,class G2>
+void checkVf2ppCompile() {
+  G1 g;
+  G2 h;
+  concepts::ReadWriteMap<typename G1::Node, typename G2::Node> r;
+  bool succ;
+  ::lemon::ignore_unused_variable_warning(succ);
+
+  succ = vf2pp(g,h).run();
+  succ = vf2pp(g,h).induced().run();
+  succ = vf2pp(g,h).iso().run();
+  succ = vf2pp(g,h).mapping(r).run();
+  succ = vf2pp(g,h).induced().mapping(r).run();
+  succ = vf2pp(g,h).iso().mapping(r).run();
+
+  concepts::ReadMap<typename G1::Node, int> c1;
+  concepts::ReadMap<typename G2::Node, int> c2;
+  Vf2pp<G1,G2,concepts::ReadWriteMap<typename G1::Node, typename G2::Node>,
+        concepts::ReadMap<typename G1::Node, int>,
+        concepts::ReadMap<typename G2::Node, int> >
+    myVf2pp(g,h,r,c1,c2);
+  myVf2pp.find();
+
+  succ = vf2pp(g,h).nodeLabels(c1,c2).mapping(r).run();
+  succ = vf2pp(g,h).nodeLabels(c1,c2).mapping(r).run();
+
+  concepts::ReadMap<typename G1::Node, char> c1_c;
+  concepts::ReadMap<typename G2::Node, char> c2_c;
+  Vf2pp<G1,G2,concepts::ReadWriteMap<typename G1::Node, typename G2::Node>,
+        concepts::ReadMap<typename G1::Node, char>,
+        concepts::ReadMap<typename G2::Node, char> >
+    myVf2pp_c(g,h,r,c1_c,c2_c);
+  myVf2pp_c.find();
+
+  succ = vf2pp(g,h).nodeLabels(c1_c,c2_c).mapping(r).run();
+  succ = vf2pp(g,h).nodeLabels(c1_c,c2_c).mapping(r).run();
+
+  concepts::ReadMap<typename G1::Node, IntConvertible1> c1_IntConv;
+  concepts::ReadMap<typename G2::Node, IntConvertible2> c2_IntConv;
+  Vf2pp<G1,G2,concepts::ReadWriteMap<typename G1::Node, typename G2::Node>,
+        concepts::ReadMap<typename G1::Node, IntConvertible1>,
+        concepts::ReadMap<typename G2::Node, IntConvertible2> >
+    myVf2pp_IntConv(g,h,r,c1_IntConv,c2_IntConv);
+  myVf2pp_IntConv.find();
+
+  succ = vf2pp(g,h).nodeLabels(c1_IntConv,c2_IntConv).mapping(r).run();
+  succ = vf2pp(g,h).nodeLabels(c1_IntConv,c2_IntConv).mapping(r).run();
+}
+
+void vf2ppCompile() {
+  checkVf2ppCompile<concepts::Graph,concepts::Graph>();
+  checkVf2ppCompile<concepts::Graph,SmartGraph>();
+  checkVf2ppCompile<SmartGraph,concepts::Graph>();
 }
 
 template<class G1, class G2, class I>
-void checkInd(const G1 &g1, const G2 &g2, const I &i) {
+void checkSubIso(const G1 &g1, const G2 &g2, const I &i) {
   std::set<typename G2::Node> image;
-  for(typename G1::NodeIt n(g1);n!=INVALID;++n) {
+  for (typename G1::NodeIt n(g1);n!=INVALID;++n){
     check(i[n]!=INVALID, "Wrong isomorphism: incomplete mapping.");
     check(image.count(i[n])==0,"Wrong isomorphism: not injective.");
     image.insert(i[n]);
   }
-  for(typename G1::NodeIt n(g1); n!=INVALID; ++n)
-    for(typename G1::NodeIt m(g1); m!=INVALID; ++m)
+  for (typename G1::EdgeIt e(g1);e!=INVALID;++e) {
+    check(findEdge(g2,i[g1.u(e)],i[g1.v(e)])!=INVALID,
+          "Wrong isomorphism: missing edge(checkSub).");
+  }
+}
+
+template<class G1, class G2, class I>
+void checkIndIso(const G1 &g1, const G2 &g2, const I &i) {
+  std::set<typename G2::Node> image;
+  for (typename G1::NodeIt n(g1);n!=INVALID;++n) {
+    check(i[n]!=INVALID, "Wrong isomorphism: incomplete mapping.");
+    check(image.count(i[n])==0,"Wrong isomorphism: not injective.");
+    image.insert(i[n]);
+  }
+  for (typename G1::NodeIt n(g1); n!=INVALID; ++n) {
+    for (typename G1::NodeIt m(g1); m!=INVALID; ++m) {
       if((findEdge(g1,n,m)==INVALID) != (findEdge(g2,i[n],i[m])==INVALID)) {
         std::cout << "Wrong isomorphism: edge mismatch";
         exit(1);
       }
+    }
+  }
 }
 
-template<class G1,class G2>
-int checkSub(const G1 &g1, const G2 &g2) {
+template<class G1,class G2,class T>
+bool checkSub(const G1 &g1, const G2 &g2, const T &vf2) {
   typename G1:: template NodeMap<typename G2::Node> iso(g1,INVALID);
-  if(vf2(g1,g2).mapping(iso).run()) {
-    checkSub(g1,g2,iso);
+  if (const_cast<T&>(vf2).mapping(iso).run()) {
+    checkSubIso(g1,g2,iso);
     return true;
   }
-  else
-    return false;
+  return false;
 }
 
-template<class G1,class G2>
-int checkInd(const G1 &g1, const G2 &g2) {
+template<class G1,class G2,class T>
+bool checkInd(const G1 &g1, const G2 &g2, const T &vf2) {
   typename G1:: template NodeMap<typename G2::Node> iso(g1,INVALID);
-  if(vf2(g1,g2).induced().mapping(iso).run()) {
-    checkInd(g1,g2,iso);
+  if (const_cast<T&>(vf2).induced().mapping(iso).run()) {
+    checkIndIso(g1,g2,iso);
     return true;
   }
-  else
-    return false;
+  return false;
 }
 
-template<class G1,class G2>
-int checkIso(const G1 &g1, const G2 &g2) {
+template<class G1,class G2,class T>
+bool checkIso(const G1 &g1, const G2 &g2, const T &vf2) {
   typename G1:: template NodeMap<typename G2::Node> iso(g1,INVALID);
-  if(vf2(g1,g2).iso().mapping(iso).run()) {
+  if (const_cast<T&>(vf2).iso().mapping(iso).run()) {
     check(countNodes(g1)==countNodes(g2),
           "Wrong iso alg.: they are not isomophic.");
-    checkInd(g1,g2,iso);
+    checkIndIso(g1,g2,iso);
     return true;
   }
-  else
-    return false;
+  return false;
 }
 
 template<class G1, class G2, class L1, class L2, class I>
 void checkLabel(const G1 &g1, const G2 &,
-                const L1 &l1, const L2 &l2,const I &i) {
-  for(typename G1::NodeIt n(g1);n!=INVALID;++n)
+                const L1 &l1, const L2 &l2, const I &i) {
+  for (typename G1::NodeIt n(g1);n!=INVALID;++n) {
     check(l1[n]==l2[i[n]],"Wrong isomorphism: label mismatch.");
+  }
+}
+
+template<class G1,class G2,class L1,class L2,class T>
+bool checkSub(const G1 &g1, const G2 &g2, const L1 &l1, const L2 &l2, const T &vf2) {
+  typename G1:: template NodeMap<typename G2::Node> iso(g1,INVALID);
+  if (const_cast<T&>(vf2).nodeLabels(l1,l2).mapping(iso).run()){
+    checkSubIso(g1,g2,iso);
+    checkLabel(g1,g2,l1,l2,iso);
+    return true;
+  }
+  return false;
+}
+
+template<class G1,class G2>
+void checkSub(const G1 &g1, const G2 &g2, bool expected, const char* msg) {
+  check(checkSub(g1,g2,vf2(g1,g2)) == expected, msg);
+  check(checkSub(g1,g2,vf2pp(g1,g2)) == expected, msg);
+}
+
+template<class G1,class G2>
+void checkInd(const G1 &g1, const G2 &g2, bool expected, const char* msg) {
+  check(checkInd(g1,g2,vf2(g1,g2)) == expected, msg);
+  check(checkInd(g1,g2,vf2pp(g1,g2)) == expected, msg);
+}
+
+template<class G1,class G2>
+void checkIso(const G1 &g1, const G2 &g2, bool expected, const char* msg) {
+  check(checkIso(g1,g2,vf2(g1,g2)) == expected, msg);
+  check(checkIso(g1,g2,vf2pp(g1,g2)) == expected, msg);
 }
 
 template<class G1,class G2,class L1,class L2>
-int checkSub(const G1 &g1, const G2 &g2, const L1 &l1, const L2 &l2) {
-  typename G1:: template NodeMap<typename G2::Node> iso(g1,INVALID);
-  if(vf2(g1,g2).nodeLabels(l1,l2).mapping(iso).run()){
-    checkSub(g1,g2,iso);
-    checkLabel(g1,g2,l1,l2,iso);
-    return true;
-  }
-  else
-    return false;
+void checkSub(const G1 &g1, const G2 &g2, const L1 &l1, const L2 &l2, bool expected, const char* msg) {
+  check(checkSub(g1,g2,l1,l2,vf2(g1,g2)) == expected, msg);
+  check(checkSub(g1,g2,l1,l2,vf2pp(g1,g2)) == expected, msg);
 }


More information about the Lemon-commits mailing list