Unify the spelling of LEMON (#103).
1 /* -*- mode: C++; indent-tabs-mode: nil; -*-
3 * This file is a part of LEMON, a generic C++ optimization library.
5 * Copyright (C) 2003-2008
6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 * (Egervary Research Group on Combinatorial Optimization, EGRES).
9 * Permission to use, modify and distribute this software is granted
10 * provided that this copyright notice appears in all copies. For
11 * precise terms see the accompanying LICENSE file.
13 * This software is provided "AS IS" with no warranty of any kind,
14 * express or implied, and with no claim as to its suitability for any
24 #include <lemon/concept_check.h>
25 #include <lemon/concepts/heap.h>
27 #include <lemon/smart_graph.h>
29 #include <lemon/lgf_reader.h>
30 #include <lemon/dijkstra.h>
31 #include <lemon/maps.h>
33 #include <lemon/bin_heap.h>
35 #include "test_tools.h"
37 using namespace lemon;
38 using namespace lemon::concepts;
40 typedef ListDigraph Digraph;
41 DIGRAPH_TYPEDEFS(Digraph);
81 int test_seq[] = { 2, 28, 19, 27, 33, 25, 13, 41, 10, 26, 1, 9, 4, 34};
82 int test_inc[] = {20, 28, 34, 16, 0, 46, 44, 0, 42, 32, 14, 8, 6, 37};
84 int test_len = sizeof(test_seq) / sizeof(test_seq[0]);
86 template <typename Heap>
88 RangeMap<int> map(test_len, -1);
92 std::vector<int> v(test_len);
94 for (int i = 0; i < test_len; ++i) {
98 std::sort(v.begin(), v.end());
99 for (int i = 0; i < test_len; ++i) {
100 check(v[i] == heap.prio() ,"Wrong order in heap sort.");
105 template <typename Heap>
106 void heapIncreaseTest() {
107 RangeMap<int> map(test_len, -1);
111 std::vector<int> v(test_len);
113 for (int i = 0; i < test_len; ++i) {
117 for (int i = 0; i < test_len; ++i) {
119 heap.increase(i, v[i]);
121 std::sort(v.begin(), v.end());
122 for (int i = 0; i < test_len; ++i) {
123 check(v[i] == heap.prio() ,"Wrong order in heap increase test.");
130 template <typename Heap>
131 void dijkstraHeapTest(const Digraph& digraph, const IntArcMap& length,
134 typename Dijkstra<Digraph, IntArcMap>::template DefStandardHeap<Heap>::
135 Create dijkstra(digraph, length);
137 dijkstra.run(source);
139 for(ArcIt a(digraph); a != INVALID; ++a) {
140 Node s = digraph.source(a);
141 Node t = digraph.target(a);
142 if (dijkstra.reached(s)) {
143 check( dijkstra.dist(t) - dijkstra.dist(s) <= length[a],
144 "Error in a shortest path tree!");
148 for(NodeIt n(digraph); n != INVALID; ++n) {
149 if ( dijkstra.reached(n) && dijkstra.predArc(n) != INVALID ) {
150 Arc a = dijkstra.predArc(n);
151 Node s = digraph.source(a);
152 check( dijkstra.dist(n) - dijkstra.dist(s) == length[a],
153 "Error in a shortest path tree!");
163 typedef RangeMap<int> ItemIntMap;
166 IntArcMap length(digraph);
169 std::istringstream input(test_lgf);
170 digraphReader(input, digraph).
171 arcMap("capacity", length).
172 node("source", source).
176 typedef BinHeap<Prio, ItemIntMap> IntHeap;
177 checkConcept<Heap<Prio, ItemIntMap>, IntHeap>();
178 heapSortTest<IntHeap>();
179 heapIncreaseTest<IntHeap>();
181 typedef BinHeap<Prio, IntNodeMap > NodeHeap;
182 checkConcept<Heap<Prio, IntNodeMap >, NodeHeap>();
183 dijkstraHeapTest<NodeHeap>(digraph, length, source);