COIN-OR::LEMON - Graph Library

source: lemon-0.x/src/test/test_tools.h @ 942:75fdd0c6866d

Last change on this file since 942:75fdd0c6866d was 937:d4e911acef3d, checked in by Balazs Dezso, 20 years ago

Revert backport changes -r1230.

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