3 * This file is a part of LEMON, a generic C++ optimization library
5 * Copyright (C) 2003-2008
6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 * (Egervary Research Group on Combinatorial Optimization, EGRES).
9 * Permission to use, modify and distribute this software is granted
10 * provided that this copyright notice appears in all copies. For
11 * precise terms see the accompanying LICENSE file.
13 * This software is provided "AS IS" with no warranty of any kind,
14 * express or implied, and with no claim as to its suitability for any
19 #ifndef LEMON_TEST_GRAPH_TEST_H
20 #define LEMON_TEST_GRAPH_TEST_H
22 //#include <lemon/graph_utils.h>
23 #include "test_tools.h"
27 //! \brief Some utility and test cases to test digraph classes.
30 ///Structure returned by \ref addPetersen().
32 ///Structure returned by \ref addPetersen().
34 template<class Digraph>
37 ///Vector containing the outer nodes.
38 std::vector<typename Digraph::Node> outer;
39 ///Vector containing the inner nodes.
40 std::vector<typename Digraph::Node> inner;
41 ///Vector containing the edges of the inner circle.
42 std::vector<typename Digraph::Arc> incir;
43 ///Vector containing the edges of the outer circle.
44 std::vector<typename Digraph::Arc> outcir;
45 ///Vector containing the chord edges.
46 std::vector<typename Digraph::Arc> chords;
51 ///Adds a Petersen graph to \c G.
53 ///Adds a Petersen graph to \c G.
54 ///\return The nodes and edges of the generated graph.
56 template<typename Digraph>
57 PetStruct<Digraph> addPetersen(Digraph &G,int num = 5)
61 for(int i=0;i<num;i++) {
62 n.outer.push_back(G.addNode());
63 n.inner.push_back(G.addNode());
66 for(int i=0;i<num;i++) {
67 n.chords.push_back(G.addArc(n.outer[i],n.inner[i]));
68 n.outcir.push_back(G.addArc(n.outer[i],n.outer[(i+1) % num]));
69 n.incir.push_back(G.addArc(n.inner[i],n.inner[(i+2) % num]));
74 /// \brief Adds to the digraph the reverse pair of all edges.
76 /// Adds to the digraph the reverse pair of all edges.
78 template<class Digraph>
79 void bidirDigraph(Digraph &G)
81 typedef typename Digraph::Arc Arc;
82 typedef typename Digraph::ArcIt ArcIt;
86 for(ArcIt e(G);e!=INVALID;++e) ee.push_back(e);
88 for(typename std::vector<Arc>::iterator p=ee.begin();p!=ee.end();p++)
89 G.addArc(G.target(*p),G.source(*p));
93 /// \brief Checks the bidirectioned Petersen graph.
95 /// Checks the bidirectioned Petersen graph.
97 template<class Digraph>
98 void checkBidirPetersen(Digraph &G, int num = 5)
100 typedef typename Digraph::Node Node;
102 typedef typename Digraph::ArcIt ArcIt;
103 typedef typename Digraph::NodeIt NodeIt;
105 checkDigraphNodeList(G, 2 * num);
106 checkDigraphArcList(G, 6 * num);
108 for(NodeIt n(G);n!=INVALID;++n) {
109 checkDigraphInArcList(G, n, 3);
110 checkDigraphOutArcList(G, n, 3);
114 template<class Digraph> void checkDigraphNodeList(Digraph &G, int nn)
116 typename Digraph::NodeIt n(G);
117 for(int i=0;i<nn;i++) {
118 check(n!=INVALID,"Wrong Node list linking.");
121 check(n==INVALID,"Wrong Node list linking.");
124 template<class Digraph>
125 void checkDigraphArcList(Digraph &G, int nn)
127 typedef typename Digraph::ArcIt ArcIt;
130 for(int i=0;i<nn;i++) {
131 check(e!=INVALID,"Wrong Arc list linking.");
134 check(e==INVALID,"Wrong Arc list linking.");
137 template<class Digraph>
138 void checkDigraphOutArcList(Digraph &G, typename Digraph::Node n, int nn)
140 typename Digraph::OutArcIt e(G,n);
141 for(int i=0;i<nn;i++) {
142 check(e!=INVALID,"Wrong OutArc list linking.");
143 check(n==G.source(e), "Wrong OutArc list linking.");
146 check(e==INVALID,"Wrong OutArc list linking.");
149 template<class Digraph> void
150 checkDigraphInArcList(Digraph &G, typename Digraph::Node n, int nn)
152 typename Digraph::InArcIt e(G,n);
153 for(int i=0;i<nn;i++) {
154 check(e!=INVALID,"Wrong InArc list linking.");
155 check(n==G.target(e), "Wrong InArc list linking.");
158 check(e==INVALID,"Wrong InArc list linking.");
161 template <class Digraph>
162 void checkDigraph() {
167 checkBidirPetersen(G, num);
170 template <class Digraph>
171 void checkDigraphIterators(const Digraph& digraph) {
172 typedef typename Digraph::Node Node;
173 typedef typename Digraph::NodeIt NodeIt;
174 typedef typename Digraph::Arc Arc;
175 typedef typename Digraph::ArcIt ArcIt;
176 typedef typename Digraph::InArcIt InArcIt;
177 typedef typename Digraph::OutArcIt OutArcIt;
178 // typedef ConArcIt<Digraph> ConArcIt;
182 ///\todo Check target(), source() as well;