gravatar
alpar (Alpar Juttner)
alpar@cs.elte.hu
Def -> Set renaming in Preflow
0 2 0
default
2 files changed with 13 insertions and 13 deletions:
↑ Collapse diff ↑
Ignore white space 96 line context
... ...
@@ -148,157 +148,157 @@
148 148
    Elevator* _level;
149 149
    bool _local_level;
150 150

	
151 151
    typedef typename Digraph::template NodeMap<Value> ExcessMap;
152 152
    ExcessMap* _excess;
153 153

	
154 154
    Tolerance _tolerance;
155 155

	
156 156
    bool _phase;
157 157

	
158 158

	
159 159
    void createStructures() {
160 160
      _node_num = countNodes(_graph);
161 161

	
162 162
      if (!_flow) {
163 163
        _flow = Traits::createFlowMap(_graph);
164 164
        _local_flow = true;
165 165
      }
166 166
      if (!_level) {
167 167
        _level = Traits::createElevator(_graph, _node_num);
168 168
        _local_level = true;
169 169
      }
170 170
      if (!_excess) {
171 171
        _excess = new ExcessMap(_graph);
172 172
      }
173 173
    }
174 174

	
175 175
    void destroyStructures() {
176 176
      if (_local_flow) {
177 177
        delete _flow;
178 178
      }
179 179
      if (_local_level) {
180 180
        delete _level;
181 181
      }
182 182
      if (_excess) {
183 183
        delete _excess;
184 184
      }
185 185
    }
186 186

	
187 187
  public:
188 188

	
189 189
    typedef Preflow Create;
190 190

	
191 191
    ///\name Named template parameters
192 192

	
193 193
    ///@{
194 194

	
195 195
    template <typename _FlowMap>
196
    struct DefFlowMapTraits : public Traits {
196
    struct SetFlowMapTraits : public Traits {
197 197
      typedef _FlowMap FlowMap;
198 198
      static FlowMap *createFlowMap(const Digraph&) {
199 199
        LEMON_ASSERT(false, "FlowMap is not initialized");
200 200
        return 0; // ignore warnings
201 201
      }
202 202
    };
203 203

	
204 204
    /// \brief \ref named-templ-param "Named parameter" for setting
205 205
    /// FlowMap type
206 206
    ///
207 207
    /// \ref named-templ-param "Named parameter" for setting FlowMap
208 208
    /// type
209 209
    template <typename _FlowMap>
210
    struct DefFlowMap
211
      : public Preflow<Digraph, CapacityMap, DefFlowMapTraits<_FlowMap> > {
210
    struct SetFlowMap
211
      : public Preflow<Digraph, CapacityMap, SetFlowMapTraits<_FlowMap> > {
212 212
      typedef Preflow<Digraph, CapacityMap,
213
                      DefFlowMapTraits<_FlowMap> > Create;
213
                      SetFlowMapTraits<_FlowMap> > Create;
214 214
    };
215 215

	
216 216
    template <typename _Elevator>
217
    struct DefElevatorTraits : public Traits {
217
    struct SetElevatorTraits : public Traits {
218 218
      typedef _Elevator Elevator;
219 219
      static Elevator *createElevator(const Digraph&, int) {
220 220
        LEMON_ASSERT(false, "Elevator is not initialized");
221 221
        return 0; // ignore warnings
222 222
      }
223 223
    };
224 224

	
225 225
    /// \brief \ref named-templ-param "Named parameter" for setting
226 226
    /// Elevator type
227 227
    ///
228 228
    /// \ref named-templ-param "Named parameter" for setting Elevator
229 229
    /// type
230 230
    template <typename _Elevator>
231
    struct DefElevator
232
      : public Preflow<Digraph, CapacityMap, DefElevatorTraits<_Elevator> > {
231
    struct SetElevator
232
      : public Preflow<Digraph, CapacityMap, SetElevatorTraits<_Elevator> > {
233 233
      typedef Preflow<Digraph, CapacityMap,
234
                      DefElevatorTraits<_Elevator> > Create;
234
                      SetElevatorTraits<_Elevator> > Create;
235 235
    };
236 236

	
237 237
    template <typename _Elevator>
238
    struct DefStandardElevatorTraits : public Traits {
238
    struct SetStandardElevatorTraits : public Traits {
239 239
      typedef _Elevator Elevator;
240 240
      static Elevator *createElevator(const Digraph& digraph, int max_level) {
241 241
        return new Elevator(digraph, max_level);
242 242
      }
243 243
    };
244 244

	
245 245
    /// \brief \ref named-templ-param "Named parameter" for setting
246 246
    /// Elevator type
247 247
    ///
248 248
    /// \ref named-templ-param "Named parameter" for setting Elevator
249 249
    /// type. The Elevator should be standard constructor interface, ie.
250 250
    /// the digraph and the maximum level should be passed to it.
251 251
    template <typename _Elevator>
252
    struct DefStandardElevator
252
    struct SetStandardElevator
253 253
      : public Preflow<Digraph, CapacityMap,
254
                       DefStandardElevatorTraits<_Elevator> > {
254
                       SetStandardElevatorTraits<_Elevator> > {
255 255
      typedef Preflow<Digraph, CapacityMap,
256
                      DefStandardElevatorTraits<_Elevator> > Create;
256
                      SetStandardElevatorTraits<_Elevator> > Create;
257 257
    };
258 258

	
259 259
    /// @}
260 260

	
261 261
  protected:
262 262

	
263 263
    Preflow() {}
264 264

	
265 265
  public:
266 266

	
267 267

	
268 268
    /// \brief The constructor of the class.
269 269
    ///
270 270
    /// The constructor of the class.
271 271
    /// \param digraph The digraph the algorithm runs on.
272 272
    /// \param capacity The capacity of the arcs.
273 273
    /// \param source The source node.
274 274
    /// \param target The target node.
275 275
    Preflow(const Digraph& digraph, const CapacityMap& capacity,
276 276
               Node source, Node target)
277 277
      : _graph(digraph), _capacity(&capacity),
278 278
        _node_num(0), _source(source), _target(target),
279 279
        _flow(0), _local_flow(false),
280 280
        _level(0), _local_level(false),
281 281
        _excess(0), _tolerance(), _phase() {}
282 282

	
283 283
    /// \brief Destrcutor.
284 284
    ///
285 285
    /// Destructor.
286 286
    ~Preflow() {
287 287
      destroyStructures();
288 288
    }
289 289

	
290 290
    /// \brief Sets the capacity map.
291 291
    ///
292 292
    /// Sets the capacity map.
293 293
    /// \return \c (*this)
294 294
    Preflow& capacityMap(const CapacityMap& map) {
295 295
      _capacity = &map;
296 296
      return *this;
297 297
    }
298 298

	
299 299
    /// \brief Sets the flow map.
300 300
    ///
301 301
    /// Sets the flow map.
302 302
    /// \return \c (*this)
303 303
    Preflow& flowMap(FlowMap& map) {
304 304
      if (_local_flow) {
Ignore white space 96 line context
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-2008
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 <fstream>
20 20
#include <string>
21 21

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

	
29 29
using namespace lemon;
30 30

	
31 31
void checkPreflow()
32 32
{
33 33
  typedef int VType;
34 34
  typedef concepts::Digraph Digraph;
35 35

	
36 36
  typedef Digraph::Node Node;
37 37
  typedef Digraph::Arc Arc;
38 38
  typedef concepts::ReadMap<Arc,VType> CapMap;
39 39
  typedef concepts::ReadWriteMap<Arc,VType> FlowMap;
40 40
  typedef concepts::WriteMap<Node,bool> CutMap;
41 41

	
42 42
  Digraph g;
43 43
  Node n;
44 44
  Arc e;
45 45
  CapMap cap;
46 46
  FlowMap flow;
47 47
  CutMap cut;
48 48

	
49
  Preflow<Digraph, CapMap>::DefFlowMap<FlowMap>::Create preflow_test(g,cap,n,n);
49
  Preflow<Digraph, CapMap>::SetFlowMap<FlowMap>::Create preflow_test(g,cap,n,n);
50 50

	
51 51
  preflow_test.capacityMap(cap);
52 52
  flow = preflow_test.flowMap();
53 53
  preflow_test.flowMap(flow);
54 54
  preflow_test.source(n);
55 55
  preflow_test.target(n);
56 56

	
57 57
  preflow_test.init();
58 58
  preflow_test.flowInit(cap);
59 59
  preflow_test.startFirstPhase();
60 60
  preflow_test.startSecondPhase();
61 61
  preflow_test.run();
62 62
  preflow_test.runMinCut();
63 63

	
64 64
  preflow_test.flowValue();
65 65
  preflow_test.minCut(n);
66 66
  preflow_test.minCutMap(cut);
67 67
  preflow_test.flow(e);
68 68

	
69 69
}
70 70

	
71 71
int cutValue (const SmartDigraph& g,
72 72
              const SmartDigraph::NodeMap<bool>& cut,
73 73
              const SmartDigraph::ArcMap<int>& cap) {
74 74

	
75 75
  int c=0;
76 76
  for(SmartDigraph::ArcIt e(g); e!=INVALID; ++e) {
77 77
    if (cut[g.source(e)] && !cut[g.target(e)]) c+=cap[e];
78 78
  }
79 79
  return c;
80 80
}
81 81

	
82 82
bool checkFlow(const SmartDigraph& g,
83 83
               const SmartDigraph::ArcMap<int>& flow,
84 84
               const SmartDigraph::ArcMap<int>& cap,
85 85
               SmartDigraph::Node s, SmartDigraph::Node t) {
86 86

	
87 87
  for (SmartDigraph::ArcIt e(g); e != INVALID; ++e) {
88 88
    if (flow[e] < 0 || flow[e] > cap[e]) return false;
89 89
  }
90 90

	
91 91
  for (SmartDigraph::NodeIt n(g); n != INVALID; ++n) {
92 92
    if (n == s || n == t) continue;
93 93
    int sum = 0;
94 94
    for (SmartDigraph::OutArcIt e(g, n); e != INVALID; ++e) {
95 95
      sum += flow[e];
96 96
    }
97 97
    for (SmartDigraph::InArcIt e(g, n); e != INVALID; ++e) {
0 comments (0 inline)