↑ Collapse diff ↑
Ignore white space 6 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
 * Copyright (C) 2003-2009
5
 * Copyright (C) 2003-2011
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,
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
 * Copyright (C) 2003-2009
5
 * Copyright (C) 2003-2011
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,
Ignore white space 6 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
 * Copyright (C) 2003-2009
5
 * Copyright (C) 2003-2011
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,
Ignore white space 6 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
 * Copyright (C) 2003-2010
5
 * Copyright (C) 2003-2011
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,
Ignore white space 6 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
 * Copyright (C) 2003-2010
5
 * Copyright (C) 2003-2011
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,
Ignore white space 6 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
 * Copyright (C) 2003-2010
5
 * Copyright (C) 2003-2011
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,
Ignore white space 16 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
 * Copyright (C) 2003-2010
5
 * Copyright (C) 2003-2011
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,
... ...
@@ -549,20 +549,20 @@
549 549
        Value rem = (*_flow)[e];
550 550
        if (_tolerance.positive(rem)) {
551 551
          Node v = _graph.source(e);
552 552
          if ((*_level)[v] == _level->maxLevel()) continue;
553 553
          _flow->set(e, 0);
554 554
          (*_excess)[v] += rem;
555 555
        }
556 556
      }
557
      for (NodeIt n(_graph); n != INVALID; ++n) 
557
      for (NodeIt n(_graph); n != INVALID; ++n)
558 558
        if(n!=_source && n!=_target && _tolerance.positive((*_excess)[n]))
559 559
          _level->activate(n);
560
          
560

	
561 561
      return true;
562 562
    }
563 563

	
564 564
    /// \brief Starts the first phase of the preflow algorithm.
565 565
    ///
566 566
    /// The preflow algorithm consists of two phases, this method runs
567 567
    /// the first phase. After the first phase the maximum flow value
568 568
    /// and a minimum value cut can already be computed, although a
... ...
@@ -580,17 +580,17 @@
580 580
        Node n = INVALID;
581 581
        int level = -1;
582 582

	
583 583
        while (num > 0) {
584 584
          n = _level->highestActive();
585 585
          if (n == INVALID) goto first_phase_done;
586 586
          level = _level->highestActiveLevel();
587 587
          --num;
588
          
588

	
589 589
          Value excess = (*_excess)[n];
590 590
          int new_level = _level->maxLevel();
591 591

	
592 592
          for (OutArcIt e(_graph, n); e != INVALID; ++e) {
593 593
            Value rem = (*_capacity)[e] - (*_flow)[e];
594 594
            if (!_tolerance.positive(rem)) continue;
595 595
            Node v = _graph.target(e);
596 596
            if ((*_level)[v] < level) {
Ignore white space 6 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
 * Copyright (C) 2003-2010
5
 * Copyright (C) 2003-2011
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,
... ...
@@ -214,17 +214,17 @@
214 214
      }
215 215
    }
216 216
  }
217 217

	
218 218
  {
219 219
  Dfs<Digraph> dfs(G);
220 220
  check(dfs.run(s1,t1) && dfs.reached(t1),"Node 3 is reachable from Node 6.");
221 221
  }
222
  
222

	
223 223
  {
224 224
    NullMap<Node,Arc> myPredMap;
225 225
    dfs(G).predMap(myPredMap).run(s);
226 226
  }
227 227
}
228 228

	
229 229
int main()
230 230
{
Ignore white space 6 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
 * Copyright (C) 2003-2009
5
 * Copyright (C) 2003-2011
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,
... ...
@@ -65,17 +65,17 @@
65 65
  ListDigraph::NodeMap<SmartDigraph::Node> ncr(to);
66 66
  ListDigraph::ArcMap<SmartDigraph::Arc> ecr(to);
67 67

	
68 68
  digraphCopy(from, to).
69 69
    nodeMap(fnm, tnm).arcMap(fam, tam).
70 70
    nodeRef(nr).arcRef(er).
71 71
    nodeCrossRef(ncr).arcCrossRef(ecr).
72 72
    node(fn, tn).arc(fa, ta).run();
73
  
73

	
74 74
  check(countNodes(from) == countNodes(to), "Wrong copy.");
75 75
  check(countArcs(from) == countArcs(to), "Wrong copy.");
76 76

	
77 77
  for (SmartDigraph::NodeIt it(from); it != INVALID; ++it) {
78 78
    check(ncr[nr[it]] == it, "Wrong copy.");
79 79
    check(fnm[it] == tnm[nr[it]], "Wrong copy.");
80 80
  }
81 81

	
... ...
@@ -93,17 +93,17 @@
93 93
  for (ListDigraph::ArcIt it(to); it != INVALID; ++it) {
94 94
    check(er[ecr[it]] == it, "Wrong copy.");
95 95
  }
96 96
  check(tn == nr[fn], "Wrong copy.");
97 97
  check(ta == er[fa], "Wrong copy.");
98 98

	
99 99
  // Test repeated copy
100 100
  digraphCopy(from, to).run();
101
  
101

	
102 102
  check(countNodes(from) == countNodes(to), "Wrong copy.");
103 103
  check(countArcs(from) == countArcs(to), "Wrong copy.");
104 104
}
105 105

	
106 106
void graph_copy_test() {
107 107
  const int nn = 10;
108 108

	
109 109
  // Build a graph
... ...
@@ -195,17 +195,17 @@
195 195
    check(er[ecr[it]] == it, "Wrong copy.");
196 196
  }
197 197
  check(tn == nr[fn], "Wrong copy.");
198 198
  check(ta == ar[fa], "Wrong copy.");
199 199
  check(te == er[fe], "Wrong copy.");
200 200

	
201 201
  // Test repeated copy
202 202
  graphCopy(from, to).run();
203
  
203

	
204 204
  check(countNodes(from) == countNodes(to), "Wrong copy.");
205 205
  check(countEdges(from) == countEdges(to), "Wrong copy.");
206 206
  check(countArcs(from) == countArcs(to), "Wrong copy.");
207 207
}
208 208

	
209 209

	
210 210
int main() {
211 211
  digraph_copy_test();
Ignore white space 6 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
 * Copyright (C) 2003-2009
5
 * Copyright (C) 2003-2011
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,
Ignore white space 6 line context
... ...
@@ -58,20 +58,20 @@
58 58
  "label\n"
59 59
  "0\n"
60 60
  "1\n"
61 61
  "@arcs\n"
62 62
  "     label -\n"
63 63
  "0 1\n";
64 64

	
65 65

	
66
int main() 
66
int main()
67 67
{
68 68
  {
69
    ListDigraph d; 
69
    ListDigraph d;
70 70
    ListDigraph::Node s,t;
71 71
    ListDigraph::ArcMap<int> label(d);
72 72
    std::istringstream input(test_lgf);
73 73
    digraphReader(d, input).
74 74
      node("source", s).
75 75
      node("target", t).
76 76
      arcMap("label", label).
77 77
      run();
... ...
@@ -88,41 +88,41 @@
88 88
      node("target", t).
89 89
      edgeMap("label", label).
90 90
      run();
91 91
    check(countNodes(g) == 2,"There should be 2 nodes");
92 92
    check(countEdges(g) == 2,"There should be 2 arcs");
93 93
  }
94 94

	
95 95
  {
96
    ListDigraph d; 
96
    ListDigraph d;
97 97
    std::istringstream input(test_lgf_nomap);
98 98
    digraphReader(d, input).
99 99
      run();
100 100
    check(countNodes(d) == 2,"There should be 2 nodes");
101 101
    check(countArcs(d) == 1,"There should be 1 arc");
102 102
  }
103 103
  {
104 104
    ListGraph g;
105 105
    std::istringstream input(test_lgf_nomap);
106 106
    graphReader(g, input).
107 107
      run();
108 108
    check(countNodes(g) == 2,"There should be 2 nodes");
109 109
    check(countEdges(g) == 1,"There should be 1 edge");
110 110
  }
111 111

	
112 112
  {
113
    ListDigraph d; 
113
    ListDigraph d;
114 114
    std::istringstream input(test_lgf_bad1);
115 115
    bool ok=false;
116 116
    try {
117 117
      digraphReader(d, input).
118 118
        run();
119 119
    }
120
    catch (FormatError& error) 
120
    catch (FormatError& error)
121 121
      {
122 122
        ok = true;
123 123
      }
124 124
    check(ok,"FormatError exception should have occured");
125 125
  }
126 126
  {
127 127
    ListGraph g;
128 128
    std::istringstream input(test_lgf_bad1);
... ...
@@ -134,17 +134,17 @@
134 134
    catch (FormatError& error)
135 135
      {
136 136
        ok = true;
137 137
      }
138 138
    check(ok,"FormatError exception should have occured");
139 139
  }
140 140

	
141 141
  {
142
    ListDigraph d; 
142
    ListDigraph d;
143 143
    std::istringstream input(test_lgf_bad2);
144 144
    bool ok=false;
145 145
    try {
146 146
      digraphReader(d, input).
147 147
        run();
148 148
    }
149 149
    catch (FormatError& error)
150 150
      {
Ignore white space 6 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
 * Copyright (C) 2003-2010
5
 * Copyright (C) 2003-2011
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,
Ignore white space 6 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
 * Copyright (C) 2003-2010
5
 * Copyright (C) 2003-2011
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,
... ...
@@ -154,17 +154,17 @@
154 154
    if (sum != 0) return false;
155 155
  }
156 156
  return true;
157 157
}
158 158

	
159 159
void initFlowTest()
160 160
{
161 161
  DIGRAPH_TYPEDEFS(SmartDigraph);
162
  
162

	
163 163
  SmartDigraph g;
164 164
  SmartDigraph::ArcMap<int> cap(g),iflow(g);
165 165
  Node s=g.addNode(); Node t=g.addNode();
166 166
  Node n1=g.addNode(); Node n2=g.addNode();
167 167
  Arc a;
168 168
  a=g.addArc(s,n1); cap[a]=20; iflow[a]=20;
169 169
  a=g.addArc(n1,n2); cap[a]=10; iflow[a]=0;
170 170
  a=g.addArc(n2,t); cap[a]=20; iflow[a]=0;
... ...
@@ -266,11 +266,11 @@
266 266
  preflow_test.minCutMap(min_cut3);
267 267
  min_cut_value=cutValue(g,min_cut3,cap);
268 268

	
269 269

	
270 270
  check(preflow_test.flowValue() == min_cut_value,
271 271
        "The max flow value or the three min cut values are incorrect.");
272 272

	
273 273
  initFlowTest();
274
  
274

	
275 275
  return 0;
276 276
}
0 comments (0 inline)