| 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-2009 |
| 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 <lemon/concepts/digraph.h> |
| 20 | 20 |
#include <lemon/smart_graph.h> |
| 21 | 21 |
#include <lemon/list_graph.h> |
| 22 | 22 |
#include <lemon/lgf_reader.h> |
| 23 | 23 |
#include <lemon/bellman_ford.h> |
| 24 | 24 |
#include <lemon/path.h> |
| 25 | 25 |
|
| 26 | 26 |
#include "graph_test.h" |
| 27 | 27 |
#include "test_tools.h" |
| 28 | 28 |
|
| 29 | 29 |
using namespace lemon; |
| 30 | 30 |
|
| 31 | 31 |
char test_lgf[] = |
| 32 | 32 |
"@nodes\n" |
| 33 | 33 |
"label\n" |
| 34 | 34 |
"0\n" |
| 35 | 35 |
"1\n" |
| 36 | 36 |
"2\n" |
| 37 | 37 |
"3\n" |
| 38 | 38 |
"4\n" |
| 39 | 39 |
"@arcs\n" |
| 40 | 40 |
" length\n" |
| 41 | 41 |
"0 1 3\n" |
| 42 | 42 |
"1 2 -3\n" |
| 43 | 43 |
"1 2 -5\n" |
| 44 | 44 |
"1 3 -2\n" |
| 45 | 45 |
"0 2 -1\n" |
| 46 | 46 |
"1 2 -4\n" |
| 47 | 47 |
"0 3 2\n" |
| 48 | 48 |
"4 2 -5\n" |
| 49 | 49 |
"2 3 1\n" |
| 50 | 50 |
"@attributes\n" |
| 51 | 51 |
"source 0\n" |
| 52 | 52 |
"target 3\n"; |
| 53 | 53 |
|
| 54 | 54 |
|
| 55 | 55 |
void checkBellmanFordCompile() |
| 56 | 56 |
{
|
| 57 | 57 |
typedef int Value; |
| 58 | 58 |
typedef concepts::Digraph Digraph; |
| 59 | 59 |
typedef concepts::ReadMap<Digraph::Arc,Value> LengthMap; |
| 60 | 60 |
typedef BellmanFord<Digraph, LengthMap> BF; |
| 61 | 61 |
typedef Digraph::Node Node; |
| 62 | 62 |
typedef Digraph::Arc Arc; |
| 63 | 63 |
|
| 64 | 64 |
Digraph gr; |
| 65 | 65 |
Node s, t, n; |
| 66 | 66 |
Arc e; |
| 67 | 67 |
Value l; |
| 68 |
int k; |
|
| 68 |
int k=3; |
|
| 69 | 69 |
bool b; |
| 70 | 70 |
BF::DistMap d(gr); |
| 71 | 71 |
BF::PredMap p(gr); |
| 72 | 72 |
LengthMap length; |
| 73 | 73 |
concepts::Path<Digraph> pp; |
| 74 | 74 |
|
| 75 | 75 |
{
|
| 76 | 76 |
BF bf_test(gr,length); |
| 77 | 77 |
const BF& const_bf_test = bf_test; |
| 78 | 78 |
|
| 79 | 79 |
bf_test.run(s); |
| 80 | 80 |
bf_test.run(s,k); |
| 81 | 81 |
|
| 82 | 82 |
bf_test.init(); |
| 83 | 83 |
bf_test.addSource(s); |
| 84 | 84 |
bf_test.addSource(s, 1); |
| 85 | 85 |
b = bf_test.processNextRound(); |
| 86 | 86 |
b = bf_test.processNextWeakRound(); |
| 87 | 87 |
|
| 88 | 88 |
bf_test.start(); |
| 89 | 89 |
bf_test.checkedStart(); |
| 90 | 90 |
bf_test.limitedStart(k); |
| 91 | 91 |
|
| 92 | 92 |
l = const_bf_test.dist(t); |
| 93 | 93 |
e = const_bf_test.predArc(t); |
| 94 | 94 |
s = const_bf_test.predNode(t); |
| 95 | 95 |
b = const_bf_test.reached(t); |
| 96 | 96 |
d = const_bf_test.distMap(); |
| 97 | 97 |
p = const_bf_test.predMap(); |
| 98 | 98 |
pp = const_bf_test.path(t); |
| 99 | 99 |
|
| 100 | 100 |
for (BF::ActiveIt it(const_bf_test); it != INVALID; ++it) {}
|
| 101 | 101 |
} |
| 102 | 102 |
{
|
| 103 | 103 |
BF::SetPredMap<concepts::ReadWriteMap<Node,Arc> > |
| 104 | 104 |
::SetDistMap<concepts::ReadWriteMap<Node,Value> > |
| 105 | 105 |
::SetOperationTraits<BellmanFordDefaultOperationTraits<Value> > |
| 106 | 106 |
::Create bf_test(gr,length); |
| 107 | 107 |
|
| 108 | 108 |
LengthMap length_map; |
| 109 | 109 |
concepts::ReadWriteMap<Node,Arc> pred_map; |
| 110 | 110 |
concepts::ReadWriteMap<Node,Value> dist_map; |
| 111 | 111 |
|
| 112 | 112 |
bf_test |
| 113 | 113 |
.lengthMap(length_map) |
| 114 | 114 |
.predMap(pred_map) |
| 115 | 115 |
.distMap(dist_map); |
| 116 | 116 |
|
| 117 | 117 |
bf_test.run(s); |
| 118 | 118 |
bf_test.run(s,k); |
| 119 | 119 |
|
| 120 | 120 |
bf_test.init(); |
| 121 | 121 |
bf_test.addSource(s); |
| 122 | 122 |
bf_test.addSource(s, 1); |
| 123 | 123 |
b = bf_test.processNextRound(); |
| 124 | 124 |
b = bf_test.processNextWeakRound(); |
| 125 | 125 |
|
| 126 | 126 |
bf_test.start(); |
| 127 | 127 |
bf_test.checkedStart(); |
| 128 | 128 |
bf_test.limitedStart(k); |
| 129 | 129 |
|
| 130 | 130 |
l = bf_test.dist(t); |
| 131 | 131 |
e = bf_test.predArc(t); |
| 132 | 132 |
s = bf_test.predNode(t); |
| 133 | 133 |
b = bf_test.reached(t); |
| 134 | 134 |
pp = bf_test.path(t); |
| 135 | 135 |
} |
| 136 | 136 |
} |
| 137 | 137 |
|
| 138 | 138 |
void checkBellmanFordFunctionCompile() |
| 139 | 139 |
{
|
| 140 | 140 |
typedef int Value; |
| 141 | 141 |
typedef concepts::Digraph Digraph; |
| 142 | 142 |
typedef Digraph::Arc Arc; |
| 143 | 143 |
typedef Digraph::Node Node; |
| 144 | 144 |
typedef concepts::ReadMap<Digraph::Arc,Value> LengthMap; |
| 145 | 145 |
|
| 146 | 146 |
Digraph g; |
| 147 | 147 |
bool b; |
| 148 | 148 |
bellmanFord(g,LengthMap()).run(Node()); |
| 149 | 149 |
b = bellmanFord(g,LengthMap()).run(Node(),Node()); |
| 150 | 150 |
bellmanFord(g,LengthMap()) |
| 151 | 151 |
.predMap(concepts::ReadWriteMap<Node,Arc>()) |
| 152 | 152 |
.distMap(concepts::ReadWriteMap<Node,Value>()) |
| 153 | 153 |
.run(Node()); |
| 154 | 154 |
b=bellmanFord(g,LengthMap()) |
| 155 | 155 |
.predMap(concepts::ReadWriteMap<Node,Arc>()) |
| 156 | 156 |
.distMap(concepts::ReadWriteMap<Node,Value>()) |
| 157 | 157 |
.path(concepts::Path<Digraph>()) |
| 158 | 158 |
.dist(Value()) |
| 159 | 159 |
.run(Node(),Node()); |
| 160 | 160 |
} |
| 161 | 161 |
|
| 162 | 162 |
|
| 163 | 163 |
template <typename Digraph, typename Value> |
| 164 | 164 |
void checkBellmanFord() {
|
0 comments (0 inline)