alpar@906
|
1 |
/* -*- C++ -*-
|
alpar@906
|
2 |
* src/test/test_tools.h - Part of HUGOlib, a generic C++ optimization library
|
alpar@906
|
3 |
*
|
alpar@906
|
4 |
* Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
|
alpar@906
|
5 |
* (Egervary Combinatorial Optimization Research Group, EGRES).
|
alpar@906
|
6 |
*
|
alpar@906
|
7 |
* Permission to use, modify and distribute this software is granted
|
alpar@906
|
8 |
* provided that this copyright notice appears in all copies. For
|
alpar@906
|
9 |
* precise terms see the accompanying LICENSE file.
|
alpar@906
|
10 |
*
|
alpar@906
|
11 |
* This software is provided "AS IS" with no warranty of any kind,
|
alpar@906
|
12 |
* express or implied, and with no claim as to its suitability for any
|
alpar@906
|
13 |
* purpose.
|
alpar@906
|
14 |
*
|
alpar@906
|
15 |
*/
|
alpar@906
|
16 |
|
alpar@574
|
17 |
#ifndef HUGO_TEST_TEST_TOOLS_H
|
alpar@574
|
18 |
#define HUGO_TEST_TEST_TOOLS_H
|
alpar@574
|
19 |
|
alpar@574
|
20 |
//! \ingroup misc
|
alpar@574
|
21 |
//! \file
|
alpar@574
|
22 |
//! \brief Some utility to write test programs.
|
alpar@574
|
23 |
|
alpar@574
|
24 |
|
alpar@574
|
25 |
#include<iostream>
|
alpar@574
|
26 |
#include<vector>
|
alpar@574
|
27 |
|
alpar@679
|
28 |
///If \c rc is fail, writes an error message end exit.
|
alpar@574
|
29 |
|
alpar@574
|
30 |
///If \c rc is fail, writes an error message end exit.
|
alpar@574
|
31 |
///The error message contains the file name and the line number of the
|
alpar@679
|
32 |
///source code in a standard from, which makes it possible to go there
|
alpar@574
|
33 |
///using good source browsers like e.g. \c emacs.
|
alpar@574
|
34 |
///
|
alpar@574
|
35 |
///For example
|
alpar@574
|
36 |
///\code check(0==1,"This is obviously false.");\endcode will
|
alpar@574
|
37 |
///print this (and then exits).
|
alpar@574
|
38 |
///\verbatim graph_test.cc:123: error: This is obviously false. \endverbatim
|
alpar@774
|
39 |
///
|
alpar@774
|
40 |
///\todo It should be in \c error.h
|
alpar@574
|
41 |
#define check(rc, msg) \
|
alpar@574
|
42 |
if(!(rc)) { \
|
alpar@574
|
43 |
std::cerr << __FILE__ ":" << __LINE__ << ": error: " << msg << std::endl; \
|
alpar@574
|
44 |
exit(1); \
|
alpar@574
|
45 |
} else { } \
|
alpar@574
|
46 |
|
alpar@574
|
47 |
///Structure returned by \ref addPetersen().
|
alpar@574
|
48 |
|
alpar@574
|
49 |
///Structure returned by \ref addPetersen().
|
alpar@574
|
50 |
///
|
alpar@574
|
51 |
template<class Graph> struct PetStruct
|
alpar@574
|
52 |
{
|
alpar@825
|
53 |
///Vector containing the outer nodes.
|
alpar@825
|
54 |
std::vector<typename Graph::Node> outer;
|
alpar@825
|
55 |
///Vector containing the inner nodes.
|
alpar@825
|
56 |
std::vector<typename Graph::Node> inner;
|
alpar@825
|
57 |
///Vector containing the edges of the inner circle.
|
alpar@825
|
58 |
std::vector<typename Graph::Edge> incir;
|
alpar@825
|
59 |
///Vector containing the edges of the outer circle.
|
alpar@825
|
60 |
std::vector<typename Graph::Edge> outcir;
|
alpar@825
|
61 |
///Vector containing the chord edges.
|
alpar@825
|
62 |
std::vector<typename Graph::Edge> chords;
|
alpar@574
|
63 |
};
|
alpar@574
|
64 |
|
alpar@721
|
65 |
|
alpar@721
|
66 |
|
alpar@574
|
67 |
///Adds a Petersen graph to \c G.
|
alpar@574
|
68 |
|
alpar@574
|
69 |
///Adds a Petersen graph to \c G.
|
deba@909
|
70 |
///\return The nodes and edges of the generated graph.
|
alpar@721
|
71 |
|
alpar@721
|
72 |
template<typename Graph>
|
alpar@721
|
73 |
PetStruct<Graph> addPetersen(Graph &G,int num=5)
|
alpar@574
|
74 |
{
|
alpar@574
|
75 |
PetStruct<Graph> n;
|
alpar@574
|
76 |
|
alpar@574
|
77 |
for(int i=0;i<num;i++) {
|
alpar@574
|
78 |
n.outer.push_back(G.addNode());
|
alpar@574
|
79 |
n.inner.push_back(G.addNode());
|
alpar@574
|
80 |
}
|
alpar@574
|
81 |
|
alpar@574
|
82 |
for(int i=0;i<num;i++) {
|
alpar@574
|
83 |
n.chords.push_back(G.addEdge(n.outer[i],n.inner[i]));
|
alpar@574
|
84 |
n.outcir.push_back(G.addEdge(n.outer[i],n.outer[(i+1)%5]));
|
alpar@574
|
85 |
n.incir.push_back(G.addEdge(n.inner[i],n.inner[(i+2)%5]));
|
alpar@574
|
86 |
}
|
alpar@574
|
87 |
return n;
|
alpar@574
|
88 |
}
|
alpar@574
|
89 |
|
deba@909
|
90 |
///Structure returned by \ref addSymPetersen().
|
alpar@574
|
91 |
|
deba@909
|
92 |
///Structure returned by \ref addSymPetersen().
|
deba@909
|
93 |
///
|
deba@909
|
94 |
template<class Graph> struct SymPetStruct
|
deba@909
|
95 |
{
|
deba@909
|
96 |
///Vector containing the outer nodes.
|
deba@909
|
97 |
std::vector<typename Graph::Node> outer;
|
deba@909
|
98 |
///Vector containing the inner nodes.
|
deba@909
|
99 |
std::vector<typename Graph::Node> inner;
|
deba@909
|
100 |
///Vector containing the edges of the inner circle.
|
deba@909
|
101 |
std::vector<typename Graph::SymEdge> incir;
|
deba@909
|
102 |
///Vector containing the edges of the outer circle.
|
deba@909
|
103 |
std::vector<typename Graph::SymEdge> outcir;
|
deba@909
|
104 |
///Vector containing the chord edges.
|
deba@909
|
105 |
std::vector<typename Graph::SymEdge> chords;
|
deba@909
|
106 |
};
|
deba@909
|
107 |
|
deba@909
|
108 |
///Adds a Petersen graph to the symmetric \c G.
|
deba@909
|
109 |
|
deba@909
|
110 |
///Adds a Petersen graph to the symmetric \c G.
|
deba@909
|
111 |
///\return The nodes and edges of the generated graph.
|
deba@909
|
112 |
|
deba@909
|
113 |
template<typename Graph>
|
deba@909
|
114 |
SymPetStruct<Graph> addSymPetersen(Graph &G,int num=5)
|
deba@909
|
115 |
{
|
deba@909
|
116 |
SymPetStruct<Graph> n;
|
deba@909
|
117 |
|
deba@909
|
118 |
for(int i=0;i<num;i++) {
|
deba@909
|
119 |
n.outer.push_back(G.addNode());
|
deba@909
|
120 |
n.inner.push_back(G.addNode());
|
deba@909
|
121 |
}
|
deba@909
|
122 |
|
deba@909
|
123 |
for(int i=0;i<num;i++) {
|
deba@909
|
124 |
n.chords.push_back(G.addEdge(n.outer[i],n.inner[i]));
|
deba@909
|
125 |
n.outcir.push_back(G.addEdge(n.outer[i],n.outer[(i+1)%5]));
|
deba@909
|
126 |
n.incir.push_back(G.addEdge(n.inner[i],n.inner[(i+2)%5]));
|
deba@909
|
127 |
}
|
deba@909
|
128 |
return n;
|
deba@909
|
129 |
}
|
alpar@574
|
130 |
|
alpar@574
|
131 |
#endif
|