# HG changeset patch # User Alpar Juttner # Date 2009-01-12 14:18:03 # Node ID a1155a9e8e09c336fd9af8f4e0e586c0dbb6003a # Parent 9b082b3fb33fd90819c0ba56df10f59e56dbe3c3 # Parent 4f1431aeef42c7c2bfe998ce6617ee117b00bb0f Merge diff --git a/lemon/adaptors.h b/lemon/adaptors.h --- a/lemon/adaptors.h +++ b/lemon/adaptors.h @@ -2666,10 +2666,10 @@ /// \brief Adaptor class for composing the residual digraph for directed /// flow and circulation problems. /// - /// Residual can be used for composing the \e residual digraph for directed - /// flow and circulation problems. Let \f$ G=(V, A) \f$ be a directed graph - /// and let \f$ F \f$ be a number type. Let \f$ flow, cap: A\to F \f$ be - /// functions on the arcs. + /// ResidualDigraph can be used for composing the \e residual digraph + /// for directed flow and circulation problems. Let \f$ G=(V, A) \f$ + /// be a directed graph and let \f$ F \f$ be a number type. + /// Let \f$ flow, cap: A\to F \f$ be functions on the arcs. /// This adaptor implements a digraph structure with node set \f$ V \f$ /// and arc set \f$ A_{forward}\cup A_{backward} \f$, /// where \f$ A_{forward}=\{uv : uv\in A, flow(uv) - class Residual + class ResidualDigraph #else template, typename FM = CM, typename TL = Tolerance > - class Residual : + class ResidualDigraph : public FilterArcs< Undirector, typename Undirector::template CombinedArcMap< @@ -2730,7 +2730,7 @@ typedef TL Tolerance; typedef typename CapacityMap::Value Value; - typedef Residual Adaptor; + typedef ResidualDigraph Adaptor; protected: @@ -2761,8 +2761,8 @@ /// /// Constructor of the residual digraph adaptor. The parameters are the /// digraph, the capacity map, the flow map, and a tolerance object. - Residual(const Digraph& digraph, const CapacityMap& capacity, - FlowMap& flow, const Tolerance& tolerance = Tolerance()) + ResidualDigraph(const Digraph& digraph, const CapacityMap& capacity, + FlowMap& flow, const Tolerance& tolerance = Tolerance()) : Parent(), _capacity(&capacity), _flow(&flow), _graph(digraph), _forward_filter(capacity, flow, tolerance), _backward_filter(capacity, flow, tolerance), @@ -2869,10 +2869,9 @@ /// \ingroup graph_adaptors /// \relates Residual template - Residual residual(const GR& digraph, - const CM& capacity_map, - FM& flow_map) { - return Residual (digraph, capacity_map, flow_map); + ResidualDigraph + residualDigraph(const GR& digraph, const CM& capacity_map, FM& flow_map) { + return ResidualDigraph (digraph, capacity_map, flow_map); } diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -3,6 +3,7 @@ LINK_DIRECTORIES(${CMAKE_BINARY_DIR}/lemon) SET(TESTS + adaptors_test bfs_test circulation_test counter_test @@ -11,7 +12,6 @@ dijkstra_test dim_test error_test - graph_adaptor_test graph_copy_test graph_test graph_utils_test diff --git a/test/Makefile.am b/test/Makefile.am --- a/test/Makefile.am +++ b/test/Makefile.am @@ -6,6 +6,7 @@ test/test_tools.h check_PROGRAMS += \ + test/adaptors_test \ test/bfs_test \ test/circulation_test \ test/counter_test \ @@ -14,7 +15,6 @@ test/dijkstra_test \ test/dim_test \ test/error_test \ - test/graph_adaptor_test \ test/graph_copy_test \ test/graph_test \ test/graph_utils_test \ @@ -43,6 +43,7 @@ TESTS += $(check_PROGRAMS) XFAIL_TESTS += test/test_tools_fail$(EXEEXT) +test_adaptors_test_SOURCES = test/adaptors_test.cc test_bfs_test_SOURCES = test/bfs_test.cc test_circulation_test_SOURCES = test/circulation_test.cc test_counter_test_SOURCES = test/counter_test.cc @@ -51,7 +52,6 @@ test_dijkstra_test_SOURCES = test/dijkstra_test.cc test_dim_test_SOURCES = test/dim_test.cc test_error_test_SOURCES = test/error_test.cc -test_graph_adaptor_test_SOURCES = test/graph_adaptor_test.cc test_graph_copy_test_SOURCES = test/graph_copy_test.cc test_graph_test_SOURCES = test/graph_test.cc test_graph_utils_test_SOURCES = test/graph_utils_test.cc diff --git a/test/graph_adaptor_test.cc b/test/adaptors_test.cc rename from test/graph_adaptor_test.cc rename to test/adaptors_test.cc --- a/test/graph_adaptor_test.cc +++ b/test/adaptors_test.cc @@ -16,35 +16,48 @@ * */ -#include -#include +#include +#include -#include -#include - -#include -#include - -#include - -#include +#include +#include #include #include -#include"test/test_tools.h" -#include"test/graph_test.h" +#include +#include +#include +#include +#include + +#include + +#include "test/test_tools.h" +#include "test/graph_test.h" using namespace lemon; void checkReverseDigraph() { + // Check concepts checkConcept >(); + checkConcept >(); + checkConcept, + ReverseDigraph >(); + checkConcept, + ReverseDigraph >(); + checkConcept, + ReverseDigraph >(); + checkConcept, + ReverseDigraph >(); + // Create a digraph and an adaptor typedef ListDigraph Digraph; typedef ReverseDigraph Adaptor; Digraph digraph; Adaptor adaptor(digraph); + // Add nodes and arcs to the original digraph Digraph::Node n1 = digraph.addNode(); Digraph::Node n2 = digraph.addNode(); Digraph::Node n3 = digraph.addNode(); @@ -53,6 +66,7 @@ Digraph::Arc a2 = digraph.addArc(n1, n3); Digraph::Arc a3 = digraph.addArc(n2, n3); + // Check the adaptor checkGraphNodeList(adaptor, 3); checkGraphArcList(adaptor, 3); checkGraphConArcList(adaptor, 3); @@ -71,18 +85,87 @@ checkGraphNodeMap(adaptor); checkGraphArcMap(adaptor); + // Check the orientation of the arcs for (Adaptor::ArcIt a(adaptor); a != INVALID; ++a) { check(adaptor.source(a) == digraph.target(a), "Wrong reverse"); check(adaptor.target(a) == digraph.source(a), "Wrong reverse"); } + + // Add and erase nodes and arcs in the digraph through the adaptor + Adaptor::Node n4 = adaptor.addNode(); + + Adaptor::Arc a4 = adaptor.addArc(n4, n3); + Adaptor::Arc a5 = adaptor.addArc(n2, n4); + Adaptor::Arc a6 = adaptor.addArc(n2, n4); + Adaptor::Arc a7 = adaptor.addArc(n1, n4); + Adaptor::Arc a8 = adaptor.addArc(n1, n2); + + adaptor.erase(a1); + adaptor.erase(n3); + + // Check the adaptor + checkGraphNodeList(adaptor, 3); + checkGraphArcList(adaptor, 4); + checkGraphConArcList(adaptor, 4); + + checkGraphOutArcList(adaptor, n1, 2); + checkGraphOutArcList(adaptor, n2, 2); + checkGraphOutArcList(adaptor, n4, 0); + + checkGraphInArcList(adaptor, n1, 0); + checkGraphInArcList(adaptor, n2, 1); + checkGraphInArcList(adaptor, n4, 3); + + checkNodeIds(adaptor); + checkArcIds(adaptor); + + checkGraphNodeMap(adaptor); + checkGraphArcMap(adaptor); + + // Check the digraph + checkGraphNodeList(digraph, 3); + checkGraphArcList(digraph, 4); + checkGraphConArcList(digraph, 4); + + checkGraphOutArcList(digraph, n1, 0); + checkGraphOutArcList(digraph, n2, 1); + checkGraphOutArcList(digraph, n4, 3); + + checkGraphInArcList(digraph, n1, 2); + checkGraphInArcList(digraph, n2, 2); + checkGraphInArcList(digraph, n4, 0); + + checkNodeIds(digraph); + checkArcIds(digraph); + + checkGraphNodeMap(digraph); + checkGraphArcMap(digraph); + + // Check the conversion of nodes and arcs + Digraph::Node nd = n4; + nd = n4; + Adaptor::Node na = n1; + na = n2; + Digraph::Arc ad = a4; + ad = a5; + Adaptor::Arc aa = a1; + aa = a2; } void checkSubDigraph() { - checkConcept, - concepts::Digraph::ArcMap > >(); + // Check concepts + checkConcept >(); + checkConcept >(); + checkConcept, + SubDigraph >(); + checkConcept, + SubDigraph >(); + checkConcept, + SubDigraph >(); + checkConcept, + SubDigraph >(); + // Create a digraph and an adaptor typedef ListDigraph Digraph; typedef Digraph::NodeMap NodeFilter; typedef Digraph::ArcMap ArcFilter; @@ -93,179 +176,16 @@ ArcFilter arc_filter(digraph); Adaptor adaptor(digraph, node_filter, arc_filter); + // Add nodes and arcs to the original digraph and the adaptor Digraph::Node n1 = digraph.addNode(); Digraph::Node n2 = digraph.addNode(); - Digraph::Node n3 = digraph.addNode(); + Adaptor::Node n3 = adaptor.addNode(); + + node_filter[n1] = node_filter[n2] = node_filter[n3] = true; Digraph::Arc a1 = digraph.addArc(n1, n2); Digraph::Arc a2 = digraph.addArc(n1, n3); - Digraph::Arc a3 = digraph.addArc(n2, n3); - - node_filter[n1] = node_filter[n2] = node_filter[n3] = true; - arc_filter[a1] = arc_filter[a2] = arc_filter[a3] = true; - - checkGraphNodeList(adaptor, 3); - checkGraphArcList(adaptor, 3); - checkGraphConArcList(adaptor, 3); - - checkGraphOutArcList(adaptor, n1, 2); - checkGraphOutArcList(adaptor, n2, 1); - checkGraphOutArcList(adaptor, n3, 0); - - checkGraphInArcList(adaptor, n1, 0); - checkGraphInArcList(adaptor, n2, 1); - checkGraphInArcList(adaptor, n3, 2); - - checkNodeIds(adaptor); - checkArcIds(adaptor); - - checkGraphNodeMap(adaptor); - checkGraphArcMap(adaptor); - - arc_filter[a2] = false; - - checkGraphNodeList(adaptor, 3); - checkGraphArcList(adaptor, 2); - checkGraphConArcList(adaptor, 2); - - checkGraphOutArcList(adaptor, n1, 1); - checkGraphOutArcList(adaptor, n2, 1); - checkGraphOutArcList(adaptor, n3, 0); - - checkGraphInArcList(adaptor, n1, 0); - checkGraphInArcList(adaptor, n2, 1); - checkGraphInArcList(adaptor, n3, 1); - - checkNodeIds(adaptor); - checkArcIds(adaptor); - - checkGraphNodeMap(adaptor); - checkGraphArcMap(adaptor); - - node_filter[n1] = false; - - checkGraphNodeList(adaptor, 2); - checkGraphArcList(adaptor, 1); - checkGraphConArcList(adaptor, 1); - - checkGraphOutArcList(adaptor, n2, 1); - checkGraphOutArcList(adaptor, n3, 0); - - checkGraphInArcList(adaptor, n2, 0); - checkGraphInArcList(adaptor, n3, 1); - - checkNodeIds(adaptor); - checkArcIds(adaptor); - - checkGraphNodeMap(adaptor); - checkGraphArcMap(adaptor); - - node_filter[n1] = node_filter[n2] = node_filter[n3] = false; - arc_filter[a1] = arc_filter[a2] = arc_filter[a3] = false; - - checkGraphNodeList(adaptor, 0); - checkGraphArcList(adaptor, 0); - checkGraphConArcList(adaptor, 0); - - checkNodeIds(adaptor); - checkArcIds(adaptor); - - checkGraphNodeMap(adaptor); - checkGraphArcMap(adaptor); -} - -void checkFilterNodes1() { - checkConcept > >(); - - typedef ListDigraph Digraph; - typedef Digraph::NodeMap NodeFilter; - typedef FilterNodes Adaptor; - - Digraph digraph; - NodeFilter node_filter(digraph); - Adaptor adaptor(digraph, node_filter); - - Digraph::Node n1 = digraph.addNode(); - Digraph::Node n2 = digraph.addNode(); - Digraph::Node n3 = digraph.addNode(); - - Digraph::Arc a1 = digraph.addArc(n1, n2); - Digraph::Arc a2 = digraph.addArc(n1, n3); - Digraph::Arc a3 = digraph.addArc(n2, n3); - - node_filter[n1] = node_filter[n2] = node_filter[n3] = true; - - checkGraphNodeList(adaptor, 3); - checkGraphArcList(adaptor, 3); - checkGraphConArcList(adaptor, 3); - - checkGraphOutArcList(adaptor, n1, 2); - checkGraphOutArcList(adaptor, n2, 1); - checkGraphOutArcList(adaptor, n3, 0); - - checkGraphInArcList(adaptor, n1, 0); - checkGraphInArcList(adaptor, n2, 1); - checkGraphInArcList(adaptor, n3, 2); - - checkNodeIds(adaptor); - checkArcIds(adaptor); - - checkGraphNodeMap(adaptor); - checkGraphArcMap(adaptor); - - node_filter[n1] = false; - - checkGraphNodeList(adaptor, 2); - checkGraphArcList(adaptor, 1); - checkGraphConArcList(adaptor, 1); - - checkGraphOutArcList(adaptor, n2, 1); - checkGraphOutArcList(adaptor, n3, 0); - - checkGraphInArcList(adaptor, n2, 0); - checkGraphInArcList(adaptor, n3, 1); - - checkNodeIds(adaptor); - checkArcIds(adaptor); - - checkGraphNodeMap(adaptor); - checkGraphArcMap(adaptor); - - node_filter[n1] = node_filter[n2] = node_filter[n3] = false; - - checkGraphNodeList(adaptor, 0); - checkGraphArcList(adaptor, 0); - checkGraphConArcList(adaptor, 0); - - checkNodeIds(adaptor); - checkArcIds(adaptor); - - checkGraphNodeMap(adaptor); - checkGraphArcMap(adaptor); -} - -void checkFilterArcs() { - checkConcept > >(); - - typedef ListDigraph Digraph; - typedef Digraph::ArcMap ArcFilter; - typedef FilterArcs Adaptor; - - Digraph digraph; - ArcFilter arc_filter(digraph); - Adaptor adaptor(digraph, arc_filter); - - Digraph::Node n1 = digraph.addNode(); - Digraph::Node n2 = digraph.addNode(); - Digraph::Node n3 = digraph.addNode(); - - Digraph::Arc a1 = digraph.addArc(n1, n2); - Digraph::Arc a2 = digraph.addArc(n1, n3); - Digraph::Arc a3 = digraph.addArc(n2, n3); + Adaptor::Arc a3 = adaptor.addArc(n2, n3); arc_filter[a1] = arc_filter[a2] = arc_filter[a3] = true; @@ -287,7 +207,10 @@ checkGraphNodeMap(adaptor); checkGraphArcMap(adaptor); - arc_filter[a2] = false; + // Hide an arc + adaptor.status(a2, false); + adaptor.disable(a3); + if (!adaptor.status(a3)) adaptor.enable(a3); checkGraphNodeList(adaptor, 3); checkGraphArcList(adaptor, 2); @@ -307,6 +230,223 @@ checkGraphNodeMap(adaptor); checkGraphArcMap(adaptor); + // Hide a node + adaptor.status(n1, false); + adaptor.disable(n3); + if (!adaptor.status(n3)) adaptor.enable(n3); + + checkGraphNodeList(adaptor, 2); + checkGraphArcList(adaptor, 1); + checkGraphConArcList(adaptor, 1); + + checkGraphOutArcList(adaptor, n2, 1); + checkGraphOutArcList(adaptor, n3, 0); + + checkGraphInArcList(adaptor, n2, 0); + checkGraphInArcList(adaptor, n3, 1); + + checkNodeIds(adaptor); + checkArcIds(adaptor); + + checkGraphNodeMap(adaptor); + checkGraphArcMap(adaptor); + + // Hide all nodes and arcs + node_filter[n1] = node_filter[n2] = node_filter[n3] = false; + arc_filter[a1] = arc_filter[a2] = arc_filter[a3] = false; + + checkGraphNodeList(adaptor, 0); + checkGraphArcList(adaptor, 0); + checkGraphConArcList(adaptor, 0); + + checkNodeIds(adaptor); + checkArcIds(adaptor); + + checkGraphNodeMap(adaptor); + checkGraphArcMap(adaptor); + + // Check the conversion of nodes and arcs + Digraph::Node nd = n3; + nd = n3; + Adaptor::Node na = n1; + na = n2; + Digraph::Arc ad = a3; + ad = a3; + Adaptor::Arc aa = a1; + aa = a2; +} + +void checkFilterNodes1() { + // Check concepts + checkConcept >(); + checkConcept >(); + checkConcept, + FilterNodes >(); + checkConcept, + FilterNodes >(); + checkConcept, + FilterNodes >(); + checkConcept, + FilterNodes >(); + + // Create a digraph and an adaptor + typedef ListDigraph Digraph; + typedef Digraph::NodeMap NodeFilter; + typedef FilterNodes Adaptor; + + Digraph digraph; + NodeFilter node_filter(digraph); + Adaptor adaptor(digraph, node_filter); + + // Add nodes and arcs to the original digraph and the adaptor + Digraph::Node n1 = digraph.addNode(); + Digraph::Node n2 = digraph.addNode(); + Adaptor::Node n3 = adaptor.addNode(); + + node_filter[n1] = node_filter[n2] = node_filter[n3] = true; + + Digraph::Arc a1 = digraph.addArc(n1, n2); + Digraph::Arc a2 = digraph.addArc(n1, n3); + Adaptor::Arc a3 = adaptor.addArc(n2, n3); + + checkGraphNodeList(adaptor, 3); + checkGraphArcList(adaptor, 3); + checkGraphConArcList(adaptor, 3); + + checkGraphOutArcList(adaptor, n1, 2); + checkGraphOutArcList(adaptor, n2, 1); + checkGraphOutArcList(adaptor, n3, 0); + + checkGraphInArcList(adaptor, n1, 0); + checkGraphInArcList(adaptor, n2, 1); + checkGraphInArcList(adaptor, n3, 2); + + checkNodeIds(adaptor); + checkArcIds(adaptor); + + checkGraphNodeMap(adaptor); + checkGraphArcMap(adaptor); + + // Hide a node + adaptor.status(n1, false); + adaptor.disable(n3); + if (!adaptor.status(n3)) adaptor.enable(n3); + + checkGraphNodeList(adaptor, 2); + checkGraphArcList(adaptor, 1); + checkGraphConArcList(adaptor, 1); + + checkGraphOutArcList(adaptor, n2, 1); + checkGraphOutArcList(adaptor, n3, 0); + + checkGraphInArcList(adaptor, n2, 0); + checkGraphInArcList(adaptor, n3, 1); + + checkNodeIds(adaptor); + checkArcIds(adaptor); + + checkGraphNodeMap(adaptor); + checkGraphArcMap(adaptor); + + // Hide all nodes + node_filter[n1] = node_filter[n2] = node_filter[n3] = false; + + checkGraphNodeList(adaptor, 0); + checkGraphArcList(adaptor, 0); + checkGraphConArcList(adaptor, 0); + + checkNodeIds(adaptor); + checkArcIds(adaptor); + + checkGraphNodeMap(adaptor); + checkGraphArcMap(adaptor); + + // Check the conversion of nodes and arcs + Digraph::Node nd = n3; + nd = n3; + Adaptor::Node na = n1; + na = n2; + Digraph::Arc ad = a3; + ad = a3; + Adaptor::Arc aa = a1; + aa = a2; +} + +void checkFilterArcs() { + // Check concepts + checkConcept >(); + checkConcept >(); + checkConcept, + FilterArcs >(); + checkConcept, + FilterArcs >(); + checkConcept, + FilterArcs >(); + checkConcept, + FilterArcs >(); + + // Create a digraph and an adaptor + typedef ListDigraph Digraph; + typedef Digraph::ArcMap ArcFilter; + typedef FilterArcs Adaptor; + + Digraph digraph; + ArcFilter arc_filter(digraph); + Adaptor adaptor(digraph, arc_filter); + + // Add nodes and arcs to the original digraph and the adaptor + Digraph::Node n1 = digraph.addNode(); + Digraph::Node n2 = digraph.addNode(); + Adaptor::Node n3 = adaptor.addNode(); + + Digraph::Arc a1 = digraph.addArc(n1, n2); + Digraph::Arc a2 = digraph.addArc(n1, n3); + Adaptor::Arc a3 = adaptor.addArc(n2, n3); + + arc_filter[a1] = arc_filter[a2] = arc_filter[a3] = true; + + checkGraphNodeList(adaptor, 3); + checkGraphArcList(adaptor, 3); + checkGraphConArcList(adaptor, 3); + + checkGraphOutArcList(adaptor, n1, 2); + checkGraphOutArcList(adaptor, n2, 1); + checkGraphOutArcList(adaptor, n3, 0); + + checkGraphInArcList(adaptor, n1, 0); + checkGraphInArcList(adaptor, n2, 1); + checkGraphInArcList(adaptor, n3, 2); + + checkNodeIds(adaptor); + checkArcIds(adaptor); + + checkGraphNodeMap(adaptor); + checkGraphArcMap(adaptor); + + // Hide an arc + adaptor.status(a2, false); + adaptor.disable(a3); + if (!adaptor.status(a3)) adaptor.enable(a3); + + checkGraphNodeList(adaptor, 3); + checkGraphArcList(adaptor, 2); + checkGraphConArcList(adaptor, 2); + + checkGraphOutArcList(adaptor, n1, 1); + checkGraphOutArcList(adaptor, n2, 1); + checkGraphOutArcList(adaptor, n3, 0); + + checkGraphInArcList(adaptor, n1, 0); + checkGraphInArcList(adaptor, n2, 1); + checkGraphInArcList(adaptor, n3, 1); + + checkNodeIds(adaptor); + checkArcIds(adaptor); + + checkGraphNodeMap(adaptor); + checkGraphArcMap(adaptor); + + // Hide all arcs arc_filter[a1] = arc_filter[a2] = arc_filter[a3] = false; checkGraphNodeList(adaptor, 3); @@ -318,42 +458,77 @@ checkGraphNodeMap(adaptor); checkGraphArcMap(adaptor); + + // Check the conversion of nodes and arcs + Digraph::Node nd = n3; + nd = n3; + Adaptor::Node na = n1; + na = n2; + Digraph::Arc ad = a3; + ad = a3; + Adaptor::Arc aa = a1; + aa = a2; } void checkUndirector() { + // Check concepts checkConcept >(); + checkConcept >(); + checkConcept, + Undirector >(); + checkConcept, + Undirector >(); + checkConcept, + Undirector >(); + checkConcept, + Undirector >(); + + // Create a digraph and an adaptor typedef ListDigraph Digraph; typedef Undirector Adaptor; Digraph digraph; Adaptor adaptor(digraph); + // Add nodes and arcs/edges to the original digraph and the adaptor Digraph::Node n1 = digraph.addNode(); Digraph::Node n2 = digraph.addNode(); - Digraph::Node n3 = digraph.addNode(); + Adaptor::Node n3 = adaptor.addNode(); Digraph::Arc a1 = digraph.addArc(n1, n2); Digraph::Arc a2 = digraph.addArc(n1, n3); - Digraph::Arc a3 = digraph.addArc(n2, n3); + Adaptor::Edge e3 = adaptor.addEdge(n2, n3); + // Check the original digraph + checkGraphNodeList(digraph, 3); + checkGraphArcList(digraph, 3); + checkGraphConArcList(digraph, 3); + + checkGraphOutArcList(digraph, n1, 2); + checkGraphOutArcList(digraph, n2, 1); + checkGraphOutArcList(digraph, n3, 0); + + checkGraphInArcList(digraph, n1, 0); + checkGraphInArcList(digraph, n2, 1); + checkGraphInArcList(digraph, n3, 2); + + checkNodeIds(digraph); + checkArcIds(digraph); + + checkGraphNodeMap(digraph); + checkGraphArcMap(digraph); + + // Check the adaptor checkGraphNodeList(adaptor, 3); checkGraphArcList(adaptor, 6); checkGraphEdgeList(adaptor, 3); checkGraphConArcList(adaptor, 6); checkGraphConEdgeList(adaptor, 3); - checkGraphOutArcList(adaptor, n1, 2); - checkGraphOutArcList(adaptor, n2, 2); - checkGraphOutArcList(adaptor, n3, 2); - - checkGraphInArcList(adaptor, n1, 2); - checkGraphInArcList(adaptor, n2, 2); - checkGraphInArcList(adaptor, n3, 2); - - checkGraphIncEdgeList(adaptor, n1, 2); - checkGraphIncEdgeList(adaptor, n2, 2); - checkGraphIncEdgeList(adaptor, n3, 2); + checkGraphIncEdgeArcLists(adaptor, n1, 2); + checkGraphIncEdgeArcLists(adaptor, n2, 2); + checkGraphIncEdgeArcLists(adaptor, n3, 2); checkNodeIds(adaptor); checkArcIds(adaptor); @@ -363,22 +538,58 @@ checkGraphArcMap(adaptor); checkGraphEdgeMap(adaptor); + // Check the edges of the adaptor for (Adaptor::EdgeIt e(adaptor); e != INVALID; ++e) { check(adaptor.u(e) == digraph.source(e), "Wrong undir"); check(adaptor.v(e) == digraph.target(e), "Wrong undir"); } + // Check CombinedArcMap + typedef Adaptor::CombinedArcMap + , Digraph::ArcMap > IntCombinedMap; + typedef Adaptor::CombinedArcMap + , Digraph::ArcMap > BoolCombinedMap; + checkConcept, + IntCombinedMap>(); + checkConcept, + BoolCombinedMap>(); + + Digraph::ArcMap fw_map(digraph), bk_map(digraph); + for (Digraph::ArcIt a(digraph); a != INVALID; ++a) { + fw_map[a] = digraph.id(a); + bk_map[a] = -digraph.id(a); + } + + Adaptor::CombinedArcMap, Digraph::ArcMap > + comb_map(fw_map, bk_map); + for (Adaptor::ArcIt a(adaptor); a != INVALID; ++a) { + if (adaptor.source(a) == digraph.source(a)) { + check(comb_map[a] == fw_map[a], "Wrong combined map"); + } else { + check(comb_map[a] == bk_map[a], "Wrong combined map"); + } + } + + // Check the conversion of nodes and arcs/edges + Digraph::Node nd = n3; + nd = n3; + Adaptor::Node na = n1; + na = n2; + Digraph::Arc ad = e3; + ad = e3; + Adaptor::Edge ea = a1; + ea = a2; } -void checkResidual() { - checkConcept, - concepts::Digraph::ArcMap > >(); +void checkResidualDigraph() { + // Check concepts + checkConcept >(); + checkConcept >(); + // Create a digraph and an adaptor typedef ListDigraph Digraph; typedef Digraph::ArcMap IntArcMap; - typedef Residual Adaptor; + typedef ResidualDigraph Adaptor; Digraph digraph; IntArcMap capacity(digraph), flow(digraph); @@ -403,7 +614,8 @@ capacity[a5] = 6; capacity[a6] = 10; - for (Adaptor::ArcIt a(adaptor); a != INVALID; ++a) { + // Check the adaptor with various flow values + for (Digraph::ArcIt a(digraph); a != INVALID; ++a) { flow[a] = 0; } @@ -421,7 +633,7 @@ checkGraphInArcList(adaptor, n3, 2); checkGraphInArcList(adaptor, n4, 3); - for (Adaptor::ArcIt a(adaptor); a != INVALID; ++a) { + for (Digraph::ArcIt a(digraph); a != INVALID; ++a) { flow[a] = capacity[a] / 2; } @@ -445,7 +657,7 @@ checkGraphNodeMap(adaptor); checkGraphArcMap(adaptor); - for (Adaptor::ArcIt a(adaptor); a != INVALID; ++a) { + for (Digraph::ArcIt a(digraph); a != INVALID; ++a) { flow[a] = capacity[a]; } @@ -463,11 +675,30 @@ checkGraphInArcList(adaptor, n3, 1); checkGraphInArcList(adaptor, n4, 0); + // Saturate all backward arcs + // (set the flow to zero on all forward arcs) for (Adaptor::ArcIt a(adaptor); a != INVALID; ++a) { - flow[a] = 0; + if (adaptor.backward(a)) + adaptor.augment(a, adaptor.residualCapacity(a)); } + checkGraphNodeList(adaptor, 4); + checkGraphArcList(adaptor, 6); + checkGraphConArcList(adaptor, 6); + + checkGraphOutArcList(adaptor, n1, 3); + checkGraphOutArcList(adaptor, n2, 2); + checkGraphOutArcList(adaptor, n3, 1); + checkGraphOutArcList(adaptor, n4, 0); + + checkGraphInArcList(adaptor, n1, 0); + checkGraphInArcList(adaptor, n2, 1); + checkGraphInArcList(adaptor, n3, 2); + checkGraphInArcList(adaptor, n4, 3); + + // Find maximum flow by augmenting along shortest paths int flow_value = 0; + Adaptor::ResidualCapacity res_cap(adaptor); while (true) { Bfs bfs(adaptor); @@ -479,8 +710,7 @@ int min = std::numeric_limits::max(); for (Path::ArcIt a(p); a != INVALID; ++a) { - if (adaptor.residualCapacity(a) < min) - min = adaptor.residualCapacity(a); + if (res_cap[a] < min) min = res_cap[a]; } for (Path::ArcIt a(p); a != INVALID; ++a) { @@ -491,11 +721,30 @@ check(flow_value == 18, "Wrong flow with res graph adaptor"); + // Check forward() and backward() + for (Adaptor::ArcIt a(adaptor); a != INVALID; ++a) { + check(adaptor.forward(a) != adaptor.backward(a), + "Wrong forward() or backward()"); + check((adaptor.forward(a) && adaptor.forward(Digraph::Arc(a)) == a) || + (adaptor.backward(a) && adaptor.backward(Digraph::Arc(a)) == a), + "Wrong forward() or backward()"); + } + + // Check the conversion of nodes and arcs + Digraph::Node nd = Adaptor::NodeIt(adaptor); + nd = ++Adaptor::NodeIt(adaptor); + Adaptor::Node na = n1; + na = n2; + Digraph::Arc ad = Adaptor::ArcIt(adaptor); + ad = ++Adaptor::ArcIt(adaptor); } void checkSplitNodes() { + // Check concepts checkConcept >(); + checkConcept >(); + // Create a digraph and an adaptor typedef ListDigraph Digraph; typedef SplitNodes Adaptor; @@ -534,6 +783,7 @@ checkGraphNodeMap(adaptor); checkGraphArcMap(adaptor); + // Check split for (Adaptor::ArcIt a(adaptor); a != INVALID; ++a) { if (adaptor.origArc(a)) { Digraph::Arc oa = a; @@ -547,14 +797,82 @@ check(adaptor.target(a) == adaptor.outNode(on), "Wrong split"); } } + + // Check combined node map + typedef Adaptor::CombinedNodeMap + , Digraph::NodeMap > IntCombinedNodeMap; + typedef Adaptor::CombinedNodeMap + , Digraph::NodeMap > BoolCombinedNodeMap; + checkConcept, + IntCombinedNodeMap>(); +//checkConcept, +// BoolCombinedNodeMap>(); + checkConcept, + BoolCombinedNodeMap>(); + + Digraph::NodeMap in_map(digraph), out_map(digraph); + for (Digraph::NodeIt n(digraph); n != INVALID; ++n) { + in_map[n] = digraph.id(n); + out_map[n] = -digraph.id(n); + } + + Adaptor::CombinedNodeMap, Digraph::NodeMap > + node_map(in_map, out_map); + for (Adaptor::NodeIt n(adaptor); n != INVALID; ++n) { + if (adaptor.inNode(n)) { + check(node_map[n] == in_map[n], "Wrong combined node map"); + } else { + check(node_map[n] == out_map[n], "Wrong combined node map"); + } + } + + // Check combined arc map + typedef Adaptor::CombinedArcMap + , Digraph::NodeMap > IntCombinedArcMap; + typedef Adaptor::CombinedArcMap + , Digraph::NodeMap > BoolCombinedArcMap; + checkConcept, + IntCombinedArcMap>(); +//checkConcept, +// BoolCombinedArcMap>(); + checkConcept, + BoolCombinedArcMap>(); + + Digraph::ArcMap a_map(digraph); + for (Digraph::ArcIt a(digraph); a != INVALID; ++a) { + a_map[a] = digraph.id(a); + } + + Adaptor::CombinedArcMap, Digraph::NodeMap > + arc_map(a_map, out_map); + for (Digraph::ArcIt a(digraph); a != INVALID; ++a) { + check(arc_map[adaptor.arc(a)] == a_map[a], "Wrong combined arc map"); + } + for (Digraph::NodeIt n(digraph); n != INVALID; ++n) { + check(arc_map[adaptor.arc(n)] == out_map[n], "Wrong combined arc map"); + } + + // Check the conversion of nodes + Digraph::Node nd = adaptor.inNode(n1); + check (nd == n1, "Wrong node conversion"); + nd = adaptor.outNode(n2); + check (nd == n2, "Wrong node conversion"); } void checkSubGraph() { - checkConcept, - concepts::Graph::EdgeMap > >(); + // Check concepts + checkConcept >(); + checkConcept >(); + checkConcept, + SubGraph >(); + checkConcept, + SubGraph >(); + checkConcept, + SubGraph >(); + checkConcept, + SubGraph >(); + // Create a graph and an adaptor typedef ListGraph Graph; typedef Graph::NodeMap NodeFilter; typedef Graph::EdgeMap EdgeFilter; @@ -565,17 +883,19 @@ EdgeFilter edge_filter(graph); Adaptor adaptor(graph, node_filter, edge_filter); + // Add nodes and edges to the original graph and the adaptor Graph::Node n1 = graph.addNode(); Graph::Node n2 = graph.addNode(); - Graph::Node n3 = graph.addNode(); - Graph::Node n4 = graph.addNode(); + Adaptor::Node n3 = adaptor.addNode(); + Adaptor::Node n4 = adaptor.addNode(); + + node_filter[n1] = node_filter[n2] = node_filter[n3] = node_filter[n4] = true; Graph::Edge e1 = graph.addEdge(n1, n2); Graph::Edge e2 = graph.addEdge(n1, n3); - Graph::Edge e3 = graph.addEdge(n2, n3); - Graph::Edge e4 = graph.addEdge(n3, n4); + Adaptor::Edge e3 = adaptor.addEdge(n2, n3); + Adaptor::Edge e4 = adaptor.addEdge(n3, n4); - node_filter[n1] = node_filter[n2] = node_filter[n3] = node_filter[n4] = true; edge_filter[e1] = edge_filter[e2] = edge_filter[e3] = edge_filter[e4] = true; checkGraphNodeList(adaptor, 4); @@ -584,20 +904,10 @@ checkGraphConArcList(adaptor, 8); checkGraphConEdgeList(adaptor, 4); - checkGraphOutArcList(adaptor, n1, 2); - checkGraphOutArcList(adaptor, n2, 2); - checkGraphOutArcList(adaptor, n3, 3); - checkGraphOutArcList(adaptor, n4, 1); - - checkGraphInArcList(adaptor, n1, 2); - checkGraphInArcList(adaptor, n2, 2); - checkGraphInArcList(adaptor, n3, 3); - checkGraphInArcList(adaptor, n4, 1); - - checkGraphIncEdgeList(adaptor, n1, 2); - checkGraphIncEdgeList(adaptor, n2, 2); - checkGraphIncEdgeList(adaptor, n3, 3); - checkGraphIncEdgeList(adaptor, n4, 1); + checkGraphIncEdgeArcLists(adaptor, n1, 2); + checkGraphIncEdgeArcLists(adaptor, n2, 2); + checkGraphIncEdgeArcLists(adaptor, n3, 3); + checkGraphIncEdgeArcLists(adaptor, n4, 1); checkNodeIds(adaptor); checkArcIds(adaptor); @@ -607,7 +917,10 @@ checkGraphArcMap(adaptor); checkGraphEdgeMap(adaptor); - edge_filter[e2] = false; + // Hide an edge + adaptor.status(e2, false); + adaptor.disable(e3); + if (!adaptor.status(e3)) adaptor.enable(e3); checkGraphNodeList(adaptor, 4); checkGraphArcList(adaptor, 6); @@ -615,20 +928,10 @@ checkGraphConArcList(adaptor, 6); checkGraphConEdgeList(adaptor, 3); - checkGraphOutArcList(adaptor, n1, 1); - checkGraphOutArcList(adaptor, n2, 2); - checkGraphOutArcList(adaptor, n3, 2); - checkGraphOutArcList(adaptor, n4, 1); - - checkGraphInArcList(adaptor, n1, 1); - checkGraphInArcList(adaptor, n2, 2); - checkGraphInArcList(adaptor, n3, 2); - checkGraphInArcList(adaptor, n4, 1); - - checkGraphIncEdgeList(adaptor, n1, 1); - checkGraphIncEdgeList(adaptor, n2, 2); - checkGraphIncEdgeList(adaptor, n3, 2); - checkGraphIncEdgeList(adaptor, n4, 1); + checkGraphIncEdgeArcLists(adaptor, n1, 1); + checkGraphIncEdgeArcLists(adaptor, n2, 2); + checkGraphIncEdgeArcLists(adaptor, n3, 2); + checkGraphIncEdgeArcLists(adaptor, n4, 1); checkNodeIds(adaptor); checkArcIds(adaptor); @@ -638,7 +941,10 @@ checkGraphArcMap(adaptor); checkGraphEdgeMap(adaptor); - node_filter[n1] = false; + // Hide a node + adaptor.status(n1, false); + adaptor.disable(n3); + if (!adaptor.status(n3)) adaptor.enable(n3); checkGraphNodeList(adaptor, 3); checkGraphArcList(adaptor, 4); @@ -646,17 +952,9 @@ checkGraphConArcList(adaptor, 4); checkGraphConEdgeList(adaptor, 2); - checkGraphOutArcList(adaptor, n2, 1); - checkGraphOutArcList(adaptor, n3, 2); - checkGraphOutArcList(adaptor, n4, 1); - - checkGraphInArcList(adaptor, n2, 1); - checkGraphInArcList(adaptor, n3, 2); - checkGraphInArcList(adaptor, n4, 1); - - checkGraphIncEdgeList(adaptor, n2, 1); - checkGraphIncEdgeList(adaptor, n3, 2); - checkGraphIncEdgeList(adaptor, n4, 1); + checkGraphIncEdgeArcLists(adaptor, n2, 1); + checkGraphIncEdgeArcLists(adaptor, n3, 2); + checkGraphIncEdgeArcLists(adaptor, n4, 1); checkNodeIds(adaptor); checkArcIds(adaptor); @@ -666,6 +964,7 @@ checkGraphArcMap(adaptor); checkGraphEdgeMap(adaptor); + // Hide all nodes and edges node_filter[n1] = node_filter[n2] = node_filter[n3] = node_filter[n4] = false; edge_filter[e1] = edge_filter[e2] = edge_filter[e3] = edge_filter[e4] = false; @@ -682,32 +981,52 @@ checkGraphNodeMap(adaptor); checkGraphArcMap(adaptor); checkGraphEdgeMap(adaptor); + + // Check the conversion of nodes and edges + Graph::Node ng = n3; + ng = n4; + Adaptor::Node na = n1; + na = n2; + Graph::Edge eg = e3; + eg = e4; + Adaptor::Edge ea = e1; + ea = e2; } void checkFilterNodes2() { - checkConcept > >(); + // Check concepts + checkConcept >(); + checkConcept >(); + checkConcept, + FilterNodes >(); + checkConcept, + FilterNodes >(); + checkConcept, + FilterNodes >(); + checkConcept, + FilterNodes >(); + // Create a graph and an adaptor typedef ListGraph Graph; typedef Graph::NodeMap NodeFilter; typedef FilterNodes Adaptor; + // Add nodes and edges to the original graph and the adaptor Graph graph; NodeFilter node_filter(graph); Adaptor adaptor(graph, node_filter); Graph::Node n1 = graph.addNode(); Graph::Node n2 = graph.addNode(); - Graph::Node n3 = graph.addNode(); - Graph::Node n4 = graph.addNode(); + Adaptor::Node n3 = adaptor.addNode(); + Adaptor::Node n4 = adaptor.addNode(); + + node_filter[n1] = node_filter[n2] = node_filter[n3] = node_filter[n4] = true; Graph::Edge e1 = graph.addEdge(n1, n2); Graph::Edge e2 = graph.addEdge(n1, n3); - Graph::Edge e3 = graph.addEdge(n2, n3); - Graph::Edge e4 = graph.addEdge(n3, n4); - - node_filter[n1] = node_filter[n2] = node_filter[n3] = node_filter[n4] = true; + Adaptor::Edge e3 = adaptor.addEdge(n2, n3); + Adaptor::Edge e4 = adaptor.addEdge(n3, n4); checkGraphNodeList(adaptor, 4); checkGraphArcList(adaptor, 8); @@ -715,20 +1034,10 @@ checkGraphConArcList(adaptor, 8); checkGraphConEdgeList(adaptor, 4); - checkGraphOutArcList(adaptor, n1, 2); - checkGraphOutArcList(adaptor, n2, 2); - checkGraphOutArcList(adaptor, n3, 3); - checkGraphOutArcList(adaptor, n4, 1); - - checkGraphInArcList(adaptor, n1, 2); - checkGraphInArcList(adaptor, n2, 2); - checkGraphInArcList(adaptor, n3, 3); - checkGraphInArcList(adaptor, n4, 1); - - checkGraphIncEdgeList(adaptor, n1, 2); - checkGraphIncEdgeList(adaptor, n2, 2); - checkGraphIncEdgeList(adaptor, n3, 3); - checkGraphIncEdgeList(adaptor, n4, 1); + checkGraphIncEdgeArcLists(adaptor, n1, 2); + checkGraphIncEdgeArcLists(adaptor, n2, 2); + checkGraphIncEdgeArcLists(adaptor, n3, 3); + checkGraphIncEdgeArcLists(adaptor, n4, 1); checkNodeIds(adaptor); checkArcIds(adaptor); @@ -738,7 +1047,10 @@ checkGraphArcMap(adaptor); checkGraphEdgeMap(adaptor); - node_filter[n1] = false; + // Hide a node + adaptor.status(n1, false); + adaptor.disable(n3); + if (!adaptor.status(n3)) adaptor.enable(n3); checkGraphNodeList(adaptor, 3); checkGraphArcList(adaptor, 4); @@ -746,17 +1058,9 @@ checkGraphConArcList(adaptor, 4); checkGraphConEdgeList(adaptor, 2); - checkGraphOutArcList(adaptor, n2, 1); - checkGraphOutArcList(adaptor, n3, 2); - checkGraphOutArcList(adaptor, n4, 1); - - checkGraphInArcList(adaptor, n2, 1); - checkGraphInArcList(adaptor, n3, 2); - checkGraphInArcList(adaptor, n4, 1); - - checkGraphIncEdgeList(adaptor, n2, 1); - checkGraphIncEdgeList(adaptor, n3, 2); - checkGraphIncEdgeList(adaptor, n4, 1); + checkGraphIncEdgeArcLists(adaptor, n2, 1); + checkGraphIncEdgeArcLists(adaptor, n3, 2); + checkGraphIncEdgeArcLists(adaptor, n4, 1); checkNodeIds(adaptor); checkArcIds(adaptor); @@ -766,6 +1070,7 @@ checkGraphArcMap(adaptor); checkGraphEdgeMap(adaptor); + // Hide all nodes node_filter[n1] = node_filter[n2] = node_filter[n3] = node_filter[n4] = false; checkGraphNodeList(adaptor, 0); @@ -781,13 +1086,32 @@ checkGraphNodeMap(adaptor); checkGraphArcMap(adaptor); checkGraphEdgeMap(adaptor); + + // Check the conversion of nodes and edges + Graph::Node ng = n3; + ng = n4; + Adaptor::Node na = n1; + na = n2; + Graph::Edge eg = e3; + eg = e4; + Adaptor::Edge ea = e1; + ea = e2; } void checkFilterEdges() { - checkConcept > >(); + // Check concepts + checkConcept >(); + checkConcept >(); + checkConcept, + FilterEdges >(); + checkConcept, + FilterEdges >(); + checkConcept, + FilterEdges >(); + checkConcept, + FilterEdges >(); + // Create a graph and an adaptor typedef ListGraph Graph; typedef Graph::EdgeMap EdgeFilter; typedef FilterEdges Adaptor; @@ -796,15 +1120,16 @@ EdgeFilter edge_filter(graph); Adaptor adaptor(graph, edge_filter); + // Add nodes and edges to the original graph and the adaptor Graph::Node n1 = graph.addNode(); Graph::Node n2 = graph.addNode(); - Graph::Node n3 = graph.addNode(); - Graph::Node n4 = graph.addNode(); + Adaptor::Node n3 = adaptor.addNode(); + Adaptor::Node n4 = adaptor.addNode(); Graph::Edge e1 = graph.addEdge(n1, n2); Graph::Edge e2 = graph.addEdge(n1, n3); - Graph::Edge e3 = graph.addEdge(n2, n3); - Graph::Edge e4 = graph.addEdge(n3, n4); + Adaptor::Edge e3 = adaptor.addEdge(n2, n3); + Adaptor::Edge e4 = adaptor.addEdge(n3, n4); edge_filter[e1] = edge_filter[e2] = edge_filter[e3] = edge_filter[e4] = true; @@ -814,20 +1139,10 @@ checkGraphConArcList(adaptor, 8); checkGraphConEdgeList(adaptor, 4); - checkGraphOutArcList(adaptor, n1, 2); - checkGraphOutArcList(adaptor, n2, 2); - checkGraphOutArcList(adaptor, n3, 3); - checkGraphOutArcList(adaptor, n4, 1); - - checkGraphInArcList(adaptor, n1, 2); - checkGraphInArcList(adaptor, n2, 2); - checkGraphInArcList(adaptor, n3, 3); - checkGraphInArcList(adaptor, n4, 1); - - checkGraphIncEdgeList(adaptor, n1, 2); - checkGraphIncEdgeList(adaptor, n2, 2); - checkGraphIncEdgeList(adaptor, n3, 3); - checkGraphIncEdgeList(adaptor, n4, 1); + checkGraphIncEdgeArcLists(adaptor, n1, 2); + checkGraphIncEdgeArcLists(adaptor, n2, 2); + checkGraphIncEdgeArcLists(adaptor, n3, 3); + checkGraphIncEdgeArcLists(adaptor, n4, 1); checkNodeIds(adaptor); checkArcIds(adaptor); @@ -837,7 +1152,10 @@ checkGraphArcMap(adaptor); checkGraphEdgeMap(adaptor); - edge_filter[e2] = false; + // Hide an edge + adaptor.status(e2, false); + adaptor.disable(e3); + if (!adaptor.status(e3)) adaptor.enable(e3); checkGraphNodeList(adaptor, 4); checkGraphArcList(adaptor, 6); @@ -845,20 +1163,10 @@ checkGraphConArcList(adaptor, 6); checkGraphConEdgeList(adaptor, 3); - checkGraphOutArcList(adaptor, n1, 1); - checkGraphOutArcList(adaptor, n2, 2); - checkGraphOutArcList(adaptor, n3, 2); - checkGraphOutArcList(adaptor, n4, 1); - - checkGraphInArcList(adaptor, n1, 1); - checkGraphInArcList(adaptor, n2, 2); - checkGraphInArcList(adaptor, n3, 2); - checkGraphInArcList(adaptor, n4, 1); - - checkGraphIncEdgeList(adaptor, n1, 1); - checkGraphIncEdgeList(adaptor, n2, 2); - checkGraphIncEdgeList(adaptor, n3, 2); - checkGraphIncEdgeList(adaptor, n4, 1); + checkGraphIncEdgeArcLists(adaptor, n1, 1); + checkGraphIncEdgeArcLists(adaptor, n2, 2); + checkGraphIncEdgeArcLists(adaptor, n3, 2); + checkGraphIncEdgeArcLists(adaptor, n4, 1); checkNodeIds(adaptor); checkArcIds(adaptor); @@ -868,6 +1176,7 @@ checkGraphArcMap(adaptor); checkGraphEdgeMap(adaptor); + // Hide all edges edge_filter[e1] = edge_filter[e2] = edge_filter[e3] = edge_filter[e4] = false; checkGraphNodeList(adaptor, 4); @@ -883,32 +1192,90 @@ checkGraphNodeMap(adaptor); checkGraphArcMap(adaptor); checkGraphEdgeMap(adaptor); + + // Check the conversion of nodes and edges + Graph::Node ng = n3; + ng = n4; + Adaptor::Node na = n1; + na = n2; + Graph::Edge eg = e3; + eg = e4; + Adaptor::Edge ea = e1; + ea = e2; } void checkOrienter() { - checkConcept > >(); + // Check concepts + checkConcept >(); + checkConcept >(); + checkConcept, + Orienter >(); + checkConcept, + Orienter >(); + checkConcept, + Orienter >(); + checkConcept, + Orienter >(); + // Create a graph and an adaptor typedef ListGraph Graph; typedef ListGraph::EdgeMap DirMap; typedef Orienter Adaptor; Graph graph; - DirMap dir(graph, true); + DirMap dir(graph); Adaptor adaptor(graph, dir); + // Add nodes and edges to the original graph and the adaptor Graph::Node n1 = graph.addNode(); Graph::Node n2 = graph.addNode(); - Graph::Node n3 = graph.addNode(); + Adaptor::Node n3 = adaptor.addNode(); Graph::Edge e1 = graph.addEdge(n1, n2); Graph::Edge e2 = graph.addEdge(n1, n3); - Graph::Edge e3 = graph.addEdge(n2, n3); + Adaptor::Arc e3 = adaptor.addArc(n2, n3); + dir[e1] = dir[e2] = dir[e3] = true; + + // Check the original graph + checkGraphNodeList(graph, 3); + checkGraphArcList(graph, 6); + checkGraphConArcList(graph, 6); + checkGraphEdgeList(graph, 3); + checkGraphConEdgeList(graph, 3); + + checkGraphIncEdgeArcLists(graph, n1, 2); + checkGraphIncEdgeArcLists(graph, n2, 2); + checkGraphIncEdgeArcLists(graph, n3, 2); + + checkNodeIds(graph); + checkArcIds(graph); + checkEdgeIds(graph); + + checkGraphNodeMap(graph); + checkGraphArcMap(graph); + checkGraphEdgeMap(graph); + + // Check the adaptor checkGraphNodeList(adaptor, 3); checkGraphArcList(adaptor, 3); checkGraphConArcList(adaptor, 3); + checkGraphOutArcList(adaptor, n1, 2); + checkGraphOutArcList(adaptor, n2, 1); + checkGraphOutArcList(adaptor, n3, 0); + + checkGraphInArcList(adaptor, n1, 0); + checkGraphInArcList(adaptor, n2, 1); + checkGraphInArcList(adaptor, n3, 2); + + checkNodeIds(adaptor); + checkArcIds(adaptor); + + checkGraphNodeMap(adaptor); + checkGraphArcMap(adaptor); + + // Check direction changing { dir[e1] = true; Adaptor::Node u = adaptor.source(e1); @@ -948,6 +1315,11 @@ dir[e3] = n2 == u; } + // Check the adaptor again + checkGraphNodeList(adaptor, 3); + checkGraphArcList(adaptor, 3); + checkGraphConArcList(adaptor, 3); + checkGraphOutArcList(adaptor, n1, 1); checkGraphOutArcList(adaptor, n2, 1); checkGraphOutArcList(adaptor, n3, 1); @@ -962,23 +1334,153 @@ checkGraphNodeMap(adaptor); checkGraphArcMap(adaptor); + // Check reverseArc() + adaptor.reverseArc(e2); + adaptor.reverseArc(e3); + adaptor.reverseArc(e2); + + checkGraphNodeList(adaptor, 3); + checkGraphArcList(adaptor, 3); + checkGraphConArcList(adaptor, 3); + + checkGraphOutArcList(adaptor, n1, 1); + checkGraphOutArcList(adaptor, n2, 0); + checkGraphOutArcList(adaptor, n3, 2); + + checkGraphInArcList(adaptor, n1, 1); + checkGraphInArcList(adaptor, n2, 2); + checkGraphInArcList(adaptor, n3, 0); + + // Check the conversion of nodes and arcs/edges + Graph::Node ng = n3; + ng = n3; + Adaptor::Node na = n1; + na = n2; + Graph::Edge eg = e3; + eg = e3; + Adaptor::Arc aa = e1; + aa = e2; } +void checkCombiningAdaptors() { + // Create a grid graph + GridGraph graph(2,2); + GridGraph::Node n1 = graph(0,0); + GridGraph::Node n2 = graph(0,1); + GridGraph::Node n3 = graph(1,0); + GridGraph::Node n4 = graph(1,1); + + GridGraph::EdgeMap dir_map(graph); + dir_map[graph.right(n1)] = graph.u(graph.right(n1)) == n1; + dir_map[graph.up(n1)] = graph.u(graph.up(n1)) != n1; + dir_map[graph.left(n4)] = graph.u(graph.left(n4)) != n4; + dir_map[graph.down(n4)] = graph.u(graph.down(n4)) != n4; + + // Apply several adaptors on the grid graph + typedef SplitNodes< ReverseDigraph< const Orienter< + const GridGraph, GridGraph::EdgeMap > > > + RevSplitGridGraph; + typedef ReverseDigraph SplitGridGraph; + typedef Undirector USplitGridGraph; + typedef Undirector UUSplitGridGraph; + checkConcept(); + checkConcept(); + checkConcept(); + checkConcept(); + + RevSplitGridGraph rev_adaptor = + splitNodes(reverseDigraph(orienter(graph, dir_map))); + SplitGridGraph adaptor = reverseDigraph(rev_adaptor); + USplitGridGraph uadaptor = undirector(adaptor); + UUSplitGridGraph uuadaptor = undirector(uadaptor); + + // Check adaptor + checkGraphNodeList(adaptor, 8); + checkGraphArcList(adaptor, 8); + checkGraphConArcList(adaptor, 8); + + checkGraphOutArcList(adaptor, rev_adaptor.inNode(n1), 1); + checkGraphOutArcList(adaptor, rev_adaptor.outNode(n1), 1); + checkGraphOutArcList(adaptor, rev_adaptor.inNode(n2), 2); + checkGraphOutArcList(adaptor, rev_adaptor.outNode(n2), 1); + checkGraphOutArcList(adaptor, rev_adaptor.inNode(n3), 1); + checkGraphOutArcList(adaptor, rev_adaptor.outNode(n3), 1); + checkGraphOutArcList(adaptor, rev_adaptor.inNode(n4), 0); + checkGraphOutArcList(adaptor, rev_adaptor.outNode(n4), 1); + + checkGraphInArcList(adaptor, rev_adaptor.inNode(n1), 1); + checkGraphInArcList(adaptor, rev_adaptor.outNode(n1), 1); + checkGraphInArcList(adaptor, rev_adaptor.inNode(n2), 1); + checkGraphInArcList(adaptor, rev_adaptor.outNode(n2), 0); + checkGraphInArcList(adaptor, rev_adaptor.inNode(n3), 1); + checkGraphInArcList(adaptor, rev_adaptor.outNode(n3), 1); + checkGraphInArcList(adaptor, rev_adaptor.inNode(n4), 1); + checkGraphInArcList(adaptor, rev_adaptor.outNode(n4), 2); + + checkNodeIds(adaptor); + checkArcIds(adaptor); + + checkGraphNodeMap(adaptor); + checkGraphArcMap(adaptor); + + // Check uadaptor + checkGraphNodeList(uadaptor, 8); + checkGraphEdgeList(uadaptor, 8); + checkGraphArcList(uadaptor, 16); + checkGraphConEdgeList(uadaptor, 8); + checkGraphConArcList(uadaptor, 16); + + checkNodeIds(uadaptor); + checkEdgeIds(uadaptor); + checkArcIds(uadaptor); + + checkGraphNodeMap(uadaptor); + checkGraphEdgeMap(uadaptor); + checkGraphArcMap(uadaptor); + + checkGraphIncEdgeArcLists(uadaptor, rev_adaptor.inNode(n1), 2); + checkGraphIncEdgeArcLists(uadaptor, rev_adaptor.outNode(n1), 2); + checkGraphIncEdgeArcLists(uadaptor, rev_adaptor.inNode(n2), 3); + checkGraphIncEdgeArcLists(uadaptor, rev_adaptor.outNode(n2), 1); + checkGraphIncEdgeArcLists(uadaptor, rev_adaptor.inNode(n3), 2); + checkGraphIncEdgeArcLists(uadaptor, rev_adaptor.outNode(n3), 2); + checkGraphIncEdgeArcLists(uadaptor, rev_adaptor.inNode(n4), 1); + checkGraphIncEdgeArcLists(uadaptor, rev_adaptor.outNode(n4), 3); + + // Check uuadaptor + checkGraphNodeList(uuadaptor, 8); + checkGraphEdgeList(uuadaptor, 16); + checkGraphArcList(uuadaptor, 32); + checkGraphConEdgeList(uuadaptor, 16); + checkGraphConArcList(uuadaptor, 32); + + checkNodeIds(uuadaptor); + checkEdgeIds(uuadaptor); + checkArcIds(uuadaptor); + + checkGraphNodeMap(uuadaptor); + checkGraphEdgeMap(uuadaptor); + checkGraphArcMap(uuadaptor); +} int main(int, const char **) { - + // Check the digraph adaptors (using ListDigraph) checkReverseDigraph(); checkSubDigraph(); checkFilterNodes1(); checkFilterArcs(); checkUndirector(); - checkResidual(); + checkResidualDigraph(); checkSplitNodes(); + // Check the graph adaptors (using ListGraph) checkSubGraph(); checkFilterNodes2(); checkFilterEdges(); checkOrienter(); + // Combine adaptors (using GridGraph) + checkCombiningAdaptors(); + return 0; } diff --git a/tools/lemon-0.x-to-1.x.sh b/tools/lemon-0.x-to-1.x.sh --- a/tools/lemon-0.x-to-1.x.sh +++ b/tools/lemon-0.x-to-1.x.sh @@ -92,6 +92,30 @@ -e "s/\/loggerBoolMap/g"\ -e "s/\/Box/g"\ -e "s/\/readNautyGraph/g"\ + -e "s/\/ReverseDigraph/g"\ + -e "s/\/reverseDigraph/g"\ + -e "s/\/SubDigraph/g"\ + -e "s/\/subDigraph/g"\ + -e "s/\/SubGraph/g"\ + -e "s/\/subGraph/g"\ + -e "s/\/FilterNodes/g"\ + -e "s/\/filterNodes/g"\ + -e "s/\/FilterArcs/g"\ + -e "s/\/filterArcs/g"\ + -e "s/\/Undirector/g"\ + -e "s/\/undirector/g"\ + -e "s/\/ResidualDigraph/g"\ + -e "s/\/residualDigraph/g"\ + -e "s/\/SplitNodes/g"\ + -e "s/\/splitNodes/g"\ + -e "s/\/SubGraph/g"\ + -e "s/\/subGraph/g"\ + -e "s/\/FilterNodes/g"\ + -e "s/\/filterNodes/g"\ + -e "s/\/FilterEdges/g"\ + -e "s/\/filterEdges/g"\ + -e "s/\/Orienter/g"\ + -e "s/\/orienter/g"\ <$i > $TMP mv $TMP $i done