1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209
|
//=======================================================================
// Boost.Graph library vf2_sub_graph_iso test 2
// Test of return value and behaviour with empty graphs
//
// Copyright (C) 2013 Jakob Lykke Andersen, University of Southern Denmark
// (jlandersen@imada.sdu.dk)
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//=======================================================================
#include <iostream>
#include <boost/core/lightweight_test.hpp>
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/vf2_sub_graph_iso.hpp>
struct test_callback
{
test_callback(bool& got_hit, bool stop) : got_hit(got_hit), stop(stop) {}
template < typename Map1To2, typename Map2To1 >
bool operator()(Map1To2 map1to2, Map2To1 map2to1)
{
got_hit = true;
return stop;
}
bool& got_hit;
bool stop;
};
struct false_predicate
{
template < typename VertexOrEdge1, typename VertexOrEdge2 >
bool operator()(VertexOrEdge1 ve1, VertexOrEdge2 ve2) const
{
return false;
}
};
void test_empty_graph_cases()
{
typedef boost::adjacency_list< boost::vecS, boost::vecS,
boost::bidirectionalS >
Graph;
Graph gEmpty, gLarge;
add_vertex(gLarge);
{ // isomorphism
bool got_hit = false;
test_callback callback(got_hit, true);
bool exists = vf2_graph_iso(gEmpty, gEmpty, callback);
BOOST_TEST(exists);
BOOST_TEST(got_hit); // even empty matches are reported
}
{ // subgraph isomorphism (induced)
{ // empty vs. empty
bool got_hit = false;
test_callback callback(got_hit, true);
bool exists = vf2_subgraph_iso(gEmpty, gEmpty, callback);
BOOST_TEST(exists);
BOOST_TEST(got_hit); // even empty matches are reported
}
{ // empty vs. non-empty
bool got_hit = false;
test_callback callback(got_hit, true);
bool exists = vf2_subgraph_iso(gEmpty, gLarge, callback);
BOOST_TEST(exists);
BOOST_TEST(got_hit); // even empty matches are reported
}
}
{ // subgraph monomorphism (non-induced subgraph isomorphism)
{ // empty vs. empty
bool got_hit = false;
test_callback callback(got_hit, true);
bool exists = vf2_subgraph_mono(gEmpty, gEmpty, callback);
BOOST_TEST(exists);
BOOST_TEST(got_hit); // even empty matches are reported
}
{ // empty vs. non-empty
bool got_hit = false;
test_callback callback(got_hit, true);
bool exists = vf2_subgraph_mono(gEmpty, gLarge, callback);
BOOST_TEST(exists);
BOOST_TEST(got_hit); // even empty matches are reported
}
}
}
void test_return_value()
{
typedef boost::adjacency_list< boost::vecS, boost::vecS,
boost::bidirectionalS >
Graph;
typedef boost::graph_traits< Graph >::vertex_descriptor Vertex;
Graph gSmall, gLarge;
add_vertex(gSmall);
Vertex v1 = add_vertex(gLarge);
Vertex v2 = add_vertex(gLarge);
add_edge(v1, v2, gLarge);
{ // isomorphism
{ // no morphism due to sizes
bool got_hit = false;
test_callback callback(got_hit, true);
bool exists = vf2_graph_iso(gSmall, gLarge, callback);
BOOST_TEST(!exists);
BOOST_TEST(!got_hit);
}
{ // no morphism due to vertex mismatches
bool got_hit = false;
test_callback callback(got_hit, true);
false_predicate pred;
bool exists
= vf2_graph_iso(gLarge, gLarge, callback, vertex_order_by_mult(gLarge),
boost::edges_equivalent(pred).vertices_equivalent(pred));
BOOST_TEST(!exists);
BOOST_TEST(!got_hit);
}
{ // morphism, find all
bool got_hit = false;
test_callback callback(got_hit, false);
bool exists = vf2_graph_iso(gLarge, gLarge, callback);
BOOST_TEST(exists);
BOOST_TEST(got_hit);
}
{ // morphism, stop after first hit
bool got_hit = false;
test_callback callback(got_hit, true);
bool exists = vf2_graph_iso(gLarge, gLarge, callback);
BOOST_TEST(exists);
BOOST_TEST(got_hit);
}
}
{ // subgraph isomorphism (induced)
{ // no morphism due to sizes
bool got_hit = false;
test_callback callback(got_hit, true);
bool exists = vf2_subgraph_iso(gLarge, gSmall, callback);
BOOST_TEST(!exists);
BOOST_TEST(!got_hit);
}
{ // no morphism due to vertex mismatches
bool got_hit = false;
test_callback callback(got_hit, true);
false_predicate pred;
bool exists = vf2_subgraph_iso(gLarge, gLarge, callback,
vertex_order_by_mult(gLarge),
boost::edges_equivalent(pred).vertices_equivalent(pred));
BOOST_TEST(!exists);
BOOST_TEST(!got_hit);
}
{ // morphism, find all
bool got_hit = false;
test_callback callback(got_hit, false);
bool exists = vf2_subgraph_iso(gLarge, gLarge, callback);
BOOST_TEST(exists);
BOOST_TEST(got_hit);
}
{ // morphism, stop after first hit
bool got_hit = false;
test_callback callback(got_hit, true);
bool exists = vf2_subgraph_iso(gLarge, gLarge, callback);
BOOST_TEST(exists);
BOOST_TEST(got_hit);
}
}
{ // subgraph monomorphism (non-induced subgraph isomorphism)
{ // no morphism due to sizes
bool got_hit = false;
test_callback callback(got_hit, true);
bool exists = vf2_subgraph_mono(gLarge, gSmall, callback);
BOOST_TEST(!exists);
BOOST_TEST(!got_hit);
}
{ // no morphism due to vertex mismatches
bool got_hit = false;
test_callback callback(got_hit, true);
false_predicate pred;
bool exists = vf2_subgraph_mono(gLarge, gLarge, callback,
vertex_order_by_mult(gLarge),
boost::edges_equivalent(pred).vertices_equivalent(pred));
BOOST_TEST(!exists);
BOOST_TEST(!got_hit);
}
{ // morphism, find all
bool got_hit = false;
test_callback callback(got_hit, false);
bool exists = vf2_subgraph_mono(gLarge, gLarge, callback);
BOOST_TEST(exists);
BOOST_TEST(got_hit);
}
{ // morphism, stop after first hit
bool got_hit = false;
test_callback callback(got_hit, true);
bool exists = vf2_subgraph_mono(gLarge, gLarge, callback);
BOOST_TEST(exists);
BOOST_TEST(got_hit);
}
}
}
int main(int argc, char* argv[])
{
test_empty_graph_cases();
test_return_value();
return boost::report_errors();
}
|