Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

test_tools.h

Go to the documentation of this file.
00001 /* -*- C++ -*-
00002  * test/test_tools.h - Part of LEMON, a generic C++ optimization library
00003  *
00004  * Copyright (C) 2005 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
00005  * (Egervary Research Group on Combinatorial Optimization, EGRES).
00006  *
00007  * Permission to use, modify and distribute this software is granted
00008  * provided that this copyright notice appears in all copies. For
00009  * precise terms see the accompanying LICENSE file.
00010  *
00011  * This software is provided "AS IS" with no warranty of any kind,
00012  * express or implied, and with no claim as to its suitability for any
00013  * purpose.
00014  *
00015  */
00016 
00017 #ifndef LEMON_TEST_TEST_TOOLS_H
00018 #define LEMON_TEST_TEST_TOOLS_H
00019 
00020 #include <iostream>
00021 #include <vector>
00022 
00023 #include <lemon/invalid.h>
00024 
00025 using namespace lemon;
00026 
00030 
00031 
00033 
00045 #define check(rc, msg) \
00046   if(!(rc)) { \
00047     std::cerr << __FILE__ ":" << __LINE__ << ": error: " << msg << std::endl; \
00048     exit(1); \
00049   } else { } \
00050 
00051 
00052 
00055 template<class Graph> struct PetStruct
00056 {
00058   std::vector<typename Graph::Node> outer;
00060   std::vector<typename Graph::Node> inner;
00062   std::vector<typename Graph::Edge> incir;
00064   std::vector<typename Graph::Edge> outcir;
00066   std::vector<typename Graph::Edge> chords;
00067 };
00068 
00069 
00070 
00072 
00075 
00076 template<typename Graph>
00077 PetStruct<Graph> addPetersen(Graph &G,int num = 5)
00078 {
00079   PetStruct<Graph> n;
00080 
00081   for(int i=0;i<num;i++) {
00082     n.outer.push_back(G.addNode());
00083     n.inner.push_back(G.addNode());
00084   }
00085 
00086  for(int i=0;i<num;i++) {
00087    n.chords.push_back(G.addEdge(n.outer[i],n.inner[i]));
00088    n.outcir.push_back(G.addEdge(n.outer[i],n.outer[(i+1) % num]));
00089    n.incir.push_back(G.addEdge(n.inner[i],n.inner[(i+2) % num]));
00090   }
00091  return n;
00092 }
00093 
00098 template<class Graph> void bidirGraph(Graph &G)
00099 {
00100   typedef typename Graph::Edge Edge;
00101   typedef typename Graph::EdgeIt EdgeIt;
00102   
00103   std::vector<Edge> ee;
00104   
00105   for(EdgeIt e(G);e!=INVALID;++e) ee.push_back(e);
00106 
00107   for(typename std::vector<Edge>::iterator p=ee.begin();p!=ee.end();p++)
00108     G.addEdge(G.target(*p),G.source(*p));
00109 }
00110 
00111 
00116 template<class Graph> void checkBidirPetersen(Graph &G, int num = 5)
00117 {
00118   typedef typename Graph::Node Node;
00119 
00120   typedef typename Graph::EdgeIt EdgeIt;
00121   typedef typename Graph::NodeIt NodeIt;
00122 
00123   checkGraphNodeList(G, 2 * num);
00124   checkGraphEdgeList(G, 6 * num);
00125 
00126   for(NodeIt n(G);n!=INVALID;++n) {
00127     checkGraphInEdgeList(G, n, 3);
00128     checkGraphOutEdgeList(G, n, 3);
00129   }  
00130 }
00131 
00133 
00136 template<class Graph> struct SymPetStruct
00137 {
00139   std::vector<typename Graph::Node> outer;
00141   std::vector<typename Graph::Node> inner;
00143   std::vector<typename Graph::SymEdge> incir;
00145   std::vector<typename Graph::SymEdge> outcir;
00147   std::vector<typename Graph::SymEdge> chords;
00148 };
00149 
00151 
00154 
00155 template<typename Graph>
00156 SymPetStruct<Graph> addSymPetersen(Graph &G,int num=5)
00157 {
00158   SymPetStruct<Graph> n;
00159 
00160   for(int i=0;i<num;i++) {
00161     n.outer.push_back(G.addNode());
00162     n.inner.push_back(G.addNode());
00163   }
00164 
00165  for(int i=0;i<num;i++) {
00166    n.chords.push_back(G.addEdge(n.outer[i],n.inner[i]));
00167    n.outcir.push_back(G.addEdge(n.outer[i],n.outer[(i+1)%5]));
00168    n.incir.push_back(G.addEdge(n.inner[i],n.inner[(i+2)%5]));
00169   }
00170  return n;
00171 }
00172 
00173 #endif

Generated on Sat Aug 27 14:14:55 2005 for LEMON by  doxygen 1.4.4