alpar@415
|
1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*-
|
alpar@415
|
2 |
*
|
alpar@415
|
3 |
* This file is a part of LEMON, a generic C++ optimization library.
|
alpar@415
|
4 |
*
|
alpar@415
|
5 |
* Copyright (C) 2003-2008
|
alpar@415
|
6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
|
alpar@415
|
7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES).
|
alpar@415
|
8 |
*
|
alpar@415
|
9 |
* Permission to use, modify and distribute this software is granted
|
alpar@415
|
10 |
* provided that this copyright notice appears in all copies. For
|
alpar@415
|
11 |
* precise terms see the accompanying LICENSE file.
|
alpar@415
|
12 |
*
|
alpar@415
|
13 |
* This software is provided "AS IS" with no warranty of any kind,
|
alpar@415
|
14 |
* express or implied, and with no claim as to its suitability for any
|
alpar@415
|
15 |
* purpose.
|
alpar@415
|
16 |
*
|
alpar@415
|
17 |
*/
|
alpar@415
|
18 |
|
alpar@415
|
19 |
///\ingroup demos
|
alpar@415
|
20 |
///\file
|
alpar@415
|
21 |
///\brief Demonstrating the usage of LEMON's General Flow algorithm
|
alpar@415
|
22 |
///
|
alpar@415
|
23 |
/// This demo program reads a general network circulation problem from the
|
alpar@415
|
24 |
/// file 'circulation-input.lgf', runs the preflow based algorithm for
|
alpar@415
|
25 |
/// finding a feasible solution and writes the output
|
alpar@415
|
26 |
/// to 'circulation-input.lgf'
|
alpar@415
|
27 |
///
|
alpar@415
|
28 |
/// \include circulation_demo.cc
|
alpar@415
|
29 |
|
alpar@415
|
30 |
#include <iostream>
|
alpar@415
|
31 |
|
alpar@415
|
32 |
#include "test_tools.h"
|
alpar@415
|
33 |
#include <lemon/list_graph.h>
|
alpar@415
|
34 |
#include <lemon/circulation.h>
|
alpar@415
|
35 |
#include <lemon/lgf_reader.h>
|
alpar@415
|
36 |
|
alpar@415
|
37 |
using namespace lemon;
|
alpar@415
|
38 |
|
alpar@415
|
39 |
char test_lgf[] =
|
alpar@415
|
40 |
"@nodes\n"
|
alpar@415
|
41 |
"label delta\n"
|
alpar@415
|
42 |
"0 0\n"
|
alpar@415
|
43 |
"1 13\n"
|
alpar@415
|
44 |
"2 0\n"
|
alpar@415
|
45 |
"3 0\n"
|
alpar@415
|
46 |
"4 0\n"
|
alpar@415
|
47 |
"5 0\n"
|
alpar@415
|
48 |
"6 0\n"
|
alpar@415
|
49 |
"7 0\n"
|
alpar@415
|
50 |
"8 -13\n"
|
alpar@415
|
51 |
"9 0\n"
|
alpar@415
|
52 |
"@edges\n"
|
alpar@415
|
53 |
" label lo_cap up_cap\n"
|
alpar@415
|
54 |
"0 1 0 0 20\n"
|
alpar@415
|
55 |
"0 2 1 0 0\n"
|
alpar@415
|
56 |
"1 1 2 0 3\n"
|
alpar@415
|
57 |
"1 2 3 0 8\n"
|
alpar@415
|
58 |
"1 3 4 0 8\n"
|
alpar@415
|
59 |
"2 5 5 0 5\n"
|
alpar@415
|
60 |
"3 2 6 0 5\n"
|
alpar@415
|
61 |
"3 5 7 0 5\n"
|
alpar@415
|
62 |
"3 6 8 0 5\n"
|
alpar@415
|
63 |
"4 3 9 0 3\n"
|
alpar@415
|
64 |
"5 7 10 0 3\n"
|
alpar@415
|
65 |
"5 6 11 0 10\n"
|
alpar@415
|
66 |
"5 8 12 0 10\n"
|
alpar@415
|
67 |
"6 8 13 0 8\n"
|
alpar@415
|
68 |
"8 9 14 0 20\n"
|
alpar@415
|
69 |
"8 1 15 0 5\n"
|
alpar@415
|
70 |
"9 5 16 0 5\n"
|
alpar@415
|
71 |
"@attributes\n"
|
alpar@415
|
72 |
"source 1\n"
|
alpar@415
|
73 |
"sink 8\n";
|
alpar@415
|
74 |
|
alpar@415
|
75 |
int main (int, char*[])
|
alpar@415
|
76 |
{
|
alpar@415
|
77 |
|
alpar@415
|
78 |
typedef ListDigraph Digraph;
|
alpar@415
|
79 |
typedef Digraph::Node Node;
|
alpar@415
|
80 |
typedef Digraph::NodeIt NodeIt;
|
alpar@415
|
81 |
typedef Digraph::Arc Arc;
|
alpar@415
|
82 |
typedef Digraph::ArcIt ArcIt;
|
alpar@415
|
83 |
typedef Digraph::ArcMap<int> ArcMap;
|
alpar@415
|
84 |
typedef Digraph::NodeMap<int> NodeMap;
|
alpar@415
|
85 |
typedef Digraph::NodeMap<double> DNodeMap;
|
alpar@415
|
86 |
|
alpar@415
|
87 |
Digraph g;
|
alpar@415
|
88 |
ArcMap lo(g);
|
alpar@415
|
89 |
ArcMap up(g);
|
alpar@415
|
90 |
NodeMap delta(g);
|
alpar@415
|
91 |
NodeMap nid(g);
|
alpar@415
|
92 |
ArcMap eid(g);
|
alpar@415
|
93 |
Node source, sink;
|
alpar@415
|
94 |
|
alpar@415
|
95 |
std::istringstream input(test_lgf);
|
alpar@415
|
96 |
DigraphReader<Digraph>(g,input).
|
alpar@415
|
97 |
arcMap("lo_cap", lo).
|
alpar@415
|
98 |
arcMap("up_cap", up).
|
alpar@415
|
99 |
nodeMap("delta", delta).
|
alpar@415
|
100 |
arcMap("label", eid).
|
alpar@415
|
101 |
nodeMap("label", nid).
|
alpar@415
|
102 |
node("source",source).
|
alpar@415
|
103 |
node("sink",sink).
|
alpar@415
|
104 |
run();
|
alpar@415
|
105 |
|
alpar@415
|
106 |
Circulation<Digraph> gen(g,lo,up,delta);
|
alpar@415
|
107 |
bool ret=gen.run();
|
alpar@415
|
108 |
check(ret,"A feasible solution should have been found.");
|
alpar@415
|
109 |
check(gen.checkFlow(), "The found flow is corrupt.");
|
alpar@415
|
110 |
|
alpar@415
|
111 |
delta[source]=14;
|
alpar@415
|
112 |
delta[sink]=-14;
|
alpar@415
|
113 |
|
alpar@415
|
114 |
bool ret2=gen.run();
|
alpar@415
|
115 |
check(!ret2,"A feasible solution should not have been found.");
|
alpar@415
|
116 |
check(gen.checkBarrier(), "The found barrier is corrupt.");
|
alpar@415
|
117 |
|
alpar@415
|
118 |
}
|