gravatar
kpeter (Peter Kovacs)
kpeter@inf.elte.hu
Fix windows-specific compilation error (#429)
0 1 0
default
1 file changed with 2 insertions and 2 deletions:
↑ Collapse diff ↑
1 1
/* -*- mode: C++; indent-tabs-mode: nil; -*-
2 2
 *
3 3
 * This file is a part of LEMON, a generic C++ optimization library.
4 4
 *
5 5
 * Copyright (C) 2003-2010
6 6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 7
 * (Egervary Research Group on Combinatorial Optimization, EGRES).
8 8
 *
9 9
 * Permission to use, modify and distribute this software is granted
10 10
 * provided that this copyright notice appears in all copies. For
11 11
 * precise terms see the accompanying LICENSE file.
12 12
 *
13 13
 * This software is provided "AS IS" with no warranty of any kind,
14 14
 * express or implied, and with no claim as to its suitability for any
15 15
 * purpose.
16 16
 *
17 17
 */
18 18

	
19 19
#include <iostream>
20 20

	
21 21
#include "test_tools.h"
22 22
#include <lemon/smart_graph.h>
23 23
#include <lemon/max_cardinality_search.h>
24 24
#include <lemon/concepts/digraph.h>
25 25
#include <lemon/concepts/maps.h>
26 26
#include <lemon/concepts/heap.h>
27 27
#include <lemon/lgf_reader.h>
28 28

	
29 29
using namespace lemon;
30 30
using namespace std;
31 31

	
32 32
char test_lgf[] =
33 33
  "@nodes\n"
34 34
  "label\n"
35 35
  "0\n"
36 36
  "1\n"
37 37
  "2\n"
38 38
  "3\n"
39 39
  "@arcs\n"
40 40
  "    label capacity\n"
41 41
  "0 1 0     2\n"
42 42
  "1 0 1     2\n"
43 43
  "2 1 2     1\n"
44 44
  "2 3 3     3\n"
45 45
  "3 2 4     3\n"
46 46
  "3 1 5     5\n"
47 47
  "@attributes\n"
48 48
  "s 0\n"
49 49
  "x 1\n"
50 50
  "y 2\n"
51 51
  "z 3\n";
52 52

	
53 53
void checkMaxCardSearchCompile() {
54 54

	
55 55
  typedef concepts::Digraph Digraph;
56 56
  typedef int Value;
57 57
  typedef Digraph::Node Node;
58 58
  typedef Digraph::Arc Arc;
59 59
  typedef concepts::ReadMap<Arc,Value> CapMap;
60 60
  typedef concepts::ReadWriteMap<Node,Value> CardMap;
61 61
  typedef concepts::ReadWriteMap<Node,bool> ProcMap;
62 62
  typedef Digraph::NodeMap<int> HeapCrossRef;
63 63

	
64 64
  Digraph g;
65 65
  Node n,s;
66 66
  CapMap cap;
67 67
  CardMap card;
68 68
  ProcMap proc;
69 69
  HeapCrossRef crossref(g);
70 70
  
71 71
  typedef MaxCardinalitySearch<Digraph,CapMap>
72 72
    ::SetCapacityMap<CapMap>
73 73
    ::SetCardinalityMap<CardMap>
74 74
    ::SetProcessedMap<ProcMap>
75 75
    ::SetStandardHeap<BinHeap<Value,HeapCrossRef> >
76 76
    ::Create MaxCardType;
77 77

	
78 78
  MaxCardType maxcard(g,cap);
79 79
  const MaxCardType& const_maxcard = maxcard;
80 80

	
81 81
  const MaxCardType::Heap& heap_const = const_maxcard.heap();
82 82
  MaxCardType::Heap& heap = const_cast<MaxCardType::Heap&>(heap_const);
83 83
  maxcard.heap(heap,crossref);
84 84
  
85 85
  maxcard.capacityMap(cap).cardinalityMap(card).processedMap(proc);
86 86

	
87 87
  maxcard.init();
88 88
  maxcard.addSource(s);
89 89
  n = maxcard.nextNode();
90 90
   maxcard.processNextNode();
91 91
   maxcard.start();
92 92
   maxcard.run(s);
93 93
   maxcard.run();
94 94
 }
95 95

	
96 96
 void checkWithIntMap( std::istringstream& input)
97 97
 {
98 98
   typedef SmartDigraph Digraph;
99 99
   typedef Digraph::Node Node;
100 100
   typedef Digraph::ArcMap<int> CapMap;
101 101

	
102 102
   Digraph g;
103 103
   Node s,x,y,z,a;
104 104
   CapMap cap(g);
105 105

	
106 106
   DigraphReader<Digraph>(g,input).
107 107
     arcMap("capacity", cap).
108 108
     node("s",s).
109 109
     node("x",x).
110 110
     node("y",y).
111 111
     node("z",z).
112 112
     run();
113 113

	
114 114
   MaxCardinalitySearch<Digraph,CapMap> maxcard(g,cap);
115 115

	
116 116
   maxcard.init();
117 117
   maxcard.addSource(s);
118 118
   maxcard.start(x);
119 119

	
120
   check(maxcard.processed(s) and !maxcard.processed(x) and
120
   check(maxcard.processed(s) && !maxcard.processed(x) &&
121 121
         !maxcard.processed(y), "Wrong processed()!");
122 122

	
123 123
   a=maxcard.nextNode();
124 124
   check(maxcard.processNextNode()==a,
125 125
         "Wrong nextNode() or processNextNode() return value!");
126 126

	
127 127
   check(maxcard.processed(a), "Wrong processNextNode()!");
128 128

	
129 129
   maxcard.start();
130
   check(maxcard.cardinality(x)==2 and maxcard.cardinality(y)>=4,
130
   check(maxcard.cardinality(x)==2 && maxcard.cardinality(y)>=4,
131 131
         "Wrong cardinalities!");
132 132
 }
133 133

	
134 134
 void checkWithConst1Map(std::istringstream &input) {
135 135
   typedef SmartDigraph Digraph;
136 136
   typedef Digraph::Node Node;
137 137

	
138 138
   Digraph g;
139 139
   Node s,x,y,z;
140 140

	
141 141
  DigraphReader<Digraph>(g,input).
142 142
    node("s",s).
143 143
    node("x",x).
144 144
    node("y",y).
145 145
    node("z",z).
146 146
    run();
147 147

	
148 148
  MaxCardinalitySearch<Digraph> maxcard(g);
149 149
  maxcard.run(s);
150 150
  check(maxcard.cardinality(x)==1 &&
151 151
        maxcard.cardinality(y)+maxcard.cardinality(z)==3,
152 152
        "Wrong cardinalities!");
153 153
}
154 154

	
155 155
int main() {
156 156

	
157 157
  std::istringstream input1(test_lgf);
158 158
  checkWithIntMap(input1);
159 159

	
160 160
  std::istringstream input2(test_lgf);
161 161
  checkWithConst1Map(input2);
162 162
}
0 comments (0 inline)