!
!
!
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
1 |
/* -*- C++ -*- |
|
1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
|
2 | 2 |
* |
3 |
* This file is a part of LEMON, a generic C++ optimization library |
|
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 |
///\ingroup demos |
20 | 20 |
///\file |
21 | 21 |
///\brief Argument parser demo |
22 | 22 |
/// |
23 | 23 |
/// This example shows how the argument parser can be used. |
24 | 24 |
/// |
25 | 25 |
/// \include arg_parser_demo.cc |
26 | 26 |
|
27 | 27 |
#include <lemon/arg_parser.h> |
28 | 28 |
|
29 | 29 |
using namespace lemon; |
30 | 30 |
int main(int argc, const char **argv) |
31 | 31 |
{ |
32 | 32 |
// Initialize the argument parser |
33 | 33 |
ArgParser ap(argc, argv); |
34 | 34 |
int i; |
35 | 35 |
std::string s; |
36 | 36 |
double d = 1.0; |
37 | 37 |
bool b, nh; |
38 | 38 |
bool g1, g2, g3; |
39 | 39 |
|
40 | 40 |
// Add a mandatory integer option with storage reference |
41 | 41 |
ap.refOption("n", "An integer input.", i, true); |
42 | 42 |
// Add a double option with storage reference (the default value is 1.0) |
43 | 43 |
ap.refOption("val", "A double input.", d); |
44 | 44 |
// Add a double option without storage reference (the default value is 3.14) |
45 | 45 |
ap.doubleOption("val2", "A double input.", 3.14); |
46 | 46 |
// Set synonym for -val option |
47 | 47 |
ap.synonym("vals", "val"); |
48 | 48 |
// Add a string option |
49 | 49 |
ap.refOption("name", "A string input.", s); |
50 | 50 |
// Add bool options |
51 | 51 |
ap.refOption("f", "A switch.", b) |
52 | 52 |
.refOption("nohelp", "", nh) |
53 | 53 |
.refOption("gra", "Choice A", g1) |
54 | 54 |
.refOption("grb", "Choice B", g2) |
55 | 55 |
.refOption("grc", "Choice C", g3); |
56 | 56 |
// Bundle -gr* options into a group |
57 | 57 |
ap.optionGroup("gr", "gra") |
58 | 58 |
.optionGroup("gr", "grb") |
59 | 59 |
.optionGroup("gr", "grc"); |
60 | 60 |
// Set the group mandatory |
61 | 61 |
ap.mandatoryGroup("gr"); |
62 | 62 |
// Set the options of the group exclusive (only one option can be given) |
63 | 63 |
ap.onlyOneGroup("gr"); |
64 | 64 |
// Add non-parsed arguments (e.g. input files) |
65 | 65 |
ap.other("infile", "The input file.") |
66 | 66 |
.other("..."); |
67 | 67 |
|
68 | 68 |
// Perform the parsing process |
69 | 69 |
// (in case of any error it terminates the program) |
70 | 70 |
ap.parse(); |
71 | 71 |
|
72 | 72 |
// Check each option if it has been given and print its value |
73 | 73 |
std::cout << "Parameters of '" << ap.commandName() << "':\n"; |
74 | 74 |
|
75 | 75 |
std::cout << " Value of -n: " << i << std::endl; |
76 | 76 |
if(ap.given("val")) std::cout << " Value of -val: " << d << std::endl; |
77 | 77 |
if(ap.given("val2")) { |
78 | 78 |
d = ap["val2"]; |
79 | 79 |
std::cout << " Value of -val2: " << d << std::endl; |
80 | 80 |
} |
81 | 81 |
if(ap.given("name")) std::cout << " Value of -name: " << s << std::endl; |
82 | 82 |
if(ap.given("f")) std::cout << " -f is given\n"; |
83 | 83 |
if(ap.given("nohelp")) std::cout << " Value of -nohelp: " << nh << std::endl; |
84 | 84 |
if(ap.given("gra")) std::cout << " -gra is given\n"; |
85 | 85 |
if(ap.given("grb")) std::cout << " -grb is given\n"; |
86 | 86 |
if(ap.given("grc")) std::cout << " -grc is given\n"; |
87 | 87 |
|
88 | 88 |
switch(ap.files().size()) { |
89 | 89 |
case 0: |
90 | 90 |
std::cout << " No file argument was given.\n"; |
91 | 91 |
break; |
92 | 92 |
case 1: |
93 | 93 |
std::cout << " 1 file argument was given. It is:\n"; |
94 | 94 |
break; |
95 | 95 |
default: |
96 | 96 |
std::cout << " " |
97 | 97 |
<< ap.files().size() << " file arguments were given. They are:\n"; |
98 | 98 |
} |
99 | 99 |
for(unsigned int i=0;i<ap.files().size();++i) |
1 |
/* -*- C++ -*- |
|
1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
|
2 | 2 |
* |
3 |
* This file is a part of LEMON, a generic C++ optimization library |
|
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 |
/// \ingroup demos |
20 | 20 |
/// \file |
21 | 21 |
/// \brief Demo of the graph drawing function \ref graphToEps() |
22 | 22 |
/// |
23 | 23 |
/// This demo program shows examples how to use the function \ref |
24 | 24 |
/// graphToEps(). It takes no input but simply creates six |
25 | 25 |
/// <tt>.eps</tt> files demonstrating the capability of \ref |
26 | 26 |
/// graphToEps(), and showing how to draw directed graphs, |
27 | 27 |
/// how to handle parallel egdes, how to change the properties (like |
28 | 28 |
/// color, shape, size, title etc.) of nodes and arcs individually |
29 | 29 |
/// using appropriate \ref maps-page "graph maps". |
30 | 30 |
/// |
31 | 31 |
/// \include graph_to_eps_demo.cc |
32 | 32 |
|
33 | 33 |
#include<lemon/list_graph.h> |
34 | 34 |
#include<lemon/graph_utils.h> |
35 | 35 |
#include<lemon/graph_to_eps.h> |
36 | 36 |
#include<lemon/math.h> |
37 | 37 |
|
38 | 38 |
using namespace std; |
39 | 39 |
using namespace lemon; |
40 | 40 |
|
41 | 41 |
int main() |
42 | 42 |
{ |
43 | 43 |
Palette palette; |
44 | 44 |
Palette paletteW(true); |
45 | 45 |
|
46 | 46 |
// Create a small digraph |
47 | 47 |
ListDigraph g; |
48 | 48 |
typedef ListDigraph::Node Node; |
49 | 49 |
typedef ListDigraph::NodeIt NodeIt; |
50 | 50 |
typedef ListDigraph::Arc Arc; |
51 | 51 |
typedef dim2::Point<int> Point; |
52 | 52 |
|
53 | 53 |
Node n1=g.addNode(); |
54 | 54 |
Node n2=g.addNode(); |
55 | 55 |
Node n3=g.addNode(); |
56 | 56 |
Node n4=g.addNode(); |
57 | 57 |
Node n5=g.addNode(); |
58 | 58 |
|
59 | 59 |
ListDigraph::NodeMap<Point> coords(g); |
60 | 60 |
ListDigraph::NodeMap<double> sizes(g); |
61 | 61 |
ListDigraph::NodeMap<int> colors(g); |
62 | 62 |
ListDigraph::NodeMap<int> shapes(g); |
63 | 63 |
ListDigraph::ArcMap<int> acolors(g); |
64 | 64 |
ListDigraph::ArcMap<int> widths(g); |
65 | 65 |
|
66 | 66 |
coords[n1]=Point(50,50); sizes[n1]=1; colors[n1]=1; shapes[n1]=0; |
67 | 67 |
coords[n2]=Point(50,70); sizes[n2]=2; colors[n2]=2; shapes[n2]=2; |
68 | 68 |
coords[n3]=Point(70,70); sizes[n3]=1; colors[n3]=3; shapes[n3]=0; |
69 | 69 |
coords[n4]=Point(70,50); sizes[n4]=2; colors[n4]=4; shapes[n4]=1; |
70 | 70 |
coords[n5]=Point(85,60); sizes[n5]=3; colors[n5]=5; shapes[n5]=2; |
71 | 71 |
|
72 | 72 |
Arc a; |
73 | 73 |
|
74 | 74 |
a=g.addArc(n1,n2); acolors[a]=0; widths[a]=1; |
75 | 75 |
a=g.addArc(n2,n3); acolors[a]=0; widths[a]=1; |
76 | 76 |
a=g.addArc(n3,n5); acolors[a]=0; widths[a]=3; |
77 | 77 |
a=g.addArc(n5,n4); acolors[a]=0; widths[a]=1; |
78 | 78 |
a=g.addArc(n4,n1); acolors[a]=0; widths[a]=1; |
79 | 79 |
a=g.addArc(n2,n4); acolors[a]=1; widths[a]=2; |
80 | 80 |
a=g.addArc(n3,n4); acolors[a]=2; widths[a]=1; |
81 | 81 |
|
82 | 82 |
IdMap<ListDigraph,Node> id(g); |
83 | 83 |
|
84 | 84 |
// Create five .eps files showing the digraph with different options |
85 | 85 |
cout << "Create 'graph_to_eps_demo_out_1_pure.eps'" << endl; |
86 | 86 |
graphToEps(g,"graph_to_eps_demo_out_1_pure.eps"). |
87 | 87 |
coords(coords). |
88 | 88 |
title("Sample .eps figure"). |
89 | 89 |
copyright("(C) 2003-2008 LEMON Project"). |
90 | 90 |
run(); |
91 | 91 |
|
92 | 92 |
cout << "Create 'graph_to_eps_demo_out_2.eps'" << endl; |
93 | 93 |
graphToEps(g,"graph_to_eps_demo_out_2.eps"). |
94 | 94 |
coords(coords). |
95 | 95 |
title("Sample .eps figure"). |
96 | 96 |
copyright("(C) 2003-2008 LEMON Project"). |
97 | 97 |
absoluteNodeSizes().absoluteArcWidths(). |
98 | 98 |
nodeScale(2).nodeSizes(sizes). |
99 | 99 |
nodeShapes(shapes). |
1 |
/* -*- C++ -*- |
|
1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
|
2 | 2 |
* |
3 |
* This file is a part of LEMON, a generic C++ optimization library |
|
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 |
///\ingroup demos |
20 | 20 |
///\file |
21 | 21 |
///\brief Demonstrating graph input and output |
22 | 22 |
/// |
23 | 23 |
/// This program gives an example of how to read and write a digraph |
24 | 24 |
/// and additional maps from/to a stream or a file using the |
25 | 25 |
/// \ref lgf-format "LGF" format. |
26 | 26 |
/// |
27 | 27 |
/// The \c "digraph.lgf" file: |
28 | 28 |
/// \include digraph.lgf |
29 | 29 |
/// |
30 | 30 |
/// And the program which reads it and prints the digraph to the |
31 | 31 |
/// standard output: |
32 | 32 |
/// \include lgf_demo.cc |
33 | 33 |
|
34 | 34 |
#include <iostream> |
35 | 35 |
#include <lemon/smart_graph.h> |
36 | 36 |
#include <lemon/lgf_reader.h> |
37 | 37 |
#include <lemon/lgf_writer.h> |
38 | 38 |
|
39 | 39 |
using namespace lemon; |
40 | 40 |
|
41 | 41 |
int main() { |
42 | 42 |
SmartDigraph g; |
43 | 43 |
SmartDigraph::ArcMap<int> cap(g); |
44 | 44 |
SmartDigraph::Node s, t; |
45 | 45 |
|
46 | 46 |
try { |
47 | 47 |
digraphReader("digraph.lgf", g). // read the directed graph into g |
48 | 48 |
arcMap("capacity", cap). // read the 'capacity' arc map into cap |
49 | 49 |
node("source", s). // read 'source' node to s |
50 | 50 |
node("target", t). // read 'target' node to t |
51 | 51 |
run(); |
52 | 52 |
} catch (DataFormatError& error) { // check if there was any error |
53 | 53 |
std::cerr << "Error: " << error.what() << std::endl; |
54 | 54 |
return -1; |
55 | 55 |
} |
56 | 56 |
|
57 | 57 |
std::cout << "A digraph is read from 'digraph.lgf'." << std::endl; |
58 | 58 |
std::cout << "Number of nodes: " << countNodes(g) << std::endl; |
59 | 59 |
std::cout << "Number of arcs: " << countArcs(g) << std::endl; |
60 | 60 |
|
61 | 61 |
std::cout << "We can write it to the standard output:" << std::endl; |
62 | 62 |
|
63 | 63 |
digraphWriter(std::cout, g). // write g to the standard output |
64 | 64 |
arcMap("capacity", cap). // write cap into 'capacity' |
65 | 65 |
node("source", s). // write s to 'source' |
66 | 66 |
node("target", t). // write t to 'target' |
67 | 67 |
run(); |
68 | 68 |
|
69 | 69 |
return 0; |
70 | 70 |
} |
1 |
/* -*- C++ -*- |
|
1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
|
2 | 2 |
* |
3 |
* This file is a part of LEMON, a generic C++ optimization library |
|
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 |
/*! |
20 | 20 |
|
21 | 21 |
\page coding_style LEMON Coding Style |
22 | 22 |
|
23 | 23 |
\section naming_conv Naming Conventions |
24 | 24 |
|
25 | 25 |
In order to make development easier we have made some conventions |
26 | 26 |
according to coding style. These include names of types, classes, |
27 | 27 |
functions, variables, constants and exceptions. If these conventions |
28 | 28 |
are met in one's code then it is easier to read and maintain |
29 | 29 |
it. Please comply with these conventions if you want to contribute |
30 | 30 |
developing LEMON library. |
31 | 31 |
|
32 | 32 |
\note When the coding style requires the capitalization of an abbreviation, |
33 | 33 |
only the first letter should be upper case. |
34 | 34 |
|
35 | 35 |
\code |
36 | 36 |
XmlReader |
37 | 37 |
\endcode |
38 | 38 |
|
39 | 39 |
|
40 | 40 |
\warning In some cases we diverge from these rules. |
41 | 41 |
This is primary done because STL uses different naming convention and |
42 | 42 |
in certain cases |
43 | 43 |
it is beneficial to provide STL compatible interface. |
44 | 44 |
|
45 | 45 |
\subsection cs-files File Names |
46 | 46 |
|
47 | 47 |
The header file names should look like the following. |
48 | 48 |
|
49 | 49 |
\code |
50 | 50 |
header_file.h |
51 | 51 |
\endcode |
52 | 52 |
|
53 | 53 |
Note that all standard LEMON headers are located in the \c lemon subdirectory, |
54 | 54 |
so you should include them from C++ source like this: |
55 | 55 |
|
56 | 56 |
\code |
57 | 57 |
#include <lemon/header_file.h> |
58 | 58 |
\endcode |
59 | 59 |
|
60 | 60 |
The source code files use the same style and they have '.cc' extension. |
61 | 61 |
|
62 | 62 |
\code |
63 | 63 |
source_code.cc |
64 | 64 |
\endcode |
65 | 65 |
|
66 | 66 |
\subsection cs-class Classes and other types |
67 | 67 |
|
68 | 68 |
The name of a class or any type should look like the following. |
69 | 69 |
|
70 | 70 |
\code |
71 | 71 |
AllWordsCapitalizedWithoutUnderscores |
72 | 72 |
\endcode |
73 | 73 |
|
74 | 74 |
\subsection cs-func Methods and other functions |
75 | 75 |
|
76 | 76 |
The name of a function should look like the following. |
77 | 77 |
|
78 | 78 |
\code |
79 | 79 |
firstWordLowerCaseRestCapitalizedWithoutUnderscores |
80 | 80 |
\endcode |
81 | 81 |
|
82 | 82 |
\subsection cs-funcs Constants, Macros |
83 | 83 |
|
84 | 84 |
The names of constants and macros should look like the following. |
85 | 85 |
|
86 | 86 |
\code |
87 | 87 |
ALL_UPPER_CASE_WITH_UNDERSCORES |
88 | 88 |
\endcode |
89 | 89 |
|
90 | 90 |
\subsection cs-loc-var Class and instance member variables, auto variables |
91 | 91 |
|
92 | 92 |
The names of class and instance member variables and auto variables (=variables used locally in methods) should look like the following. |
93 | 93 |
|
94 | 94 |
\code |
95 | 95 |
all_lower_case_with_underscores |
96 | 96 |
\endcode |
97 | 97 |
|
98 | 98 |
\subsection pri-loc-var Private member variables |
99 | 99 |
1 |
/* -*- C++ -*- |
|
1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
|
2 | 2 |
* |
3 |
* This file is a part of LEMON, a generic C++ optimization library |
|
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 |
/** |
20 | 20 |
\dir demo |
21 | 21 |
\brief A collection of demo application. |
22 | 22 |
|
23 | 23 |
This directory contains several simple demo application, mainly |
24 | 24 |
for educational purposes. |
25 | 25 |
*/ |
26 | 26 |
|
27 | 27 |
/** |
28 | 28 |
\dir doc |
29 | 29 |
\brief Auxiliary (and the whole generated) documentation. |
30 | 30 |
|
31 | 31 |
Auxiliary (and the whole generated) documentation. |
32 | 32 |
*/ |
33 | 33 |
|
34 | 34 |
/** |
35 | 35 |
\dir test |
36 | 36 |
\brief Test programs. |
37 | 37 |
|
38 | 38 |
This directory contains several test programs that check the consistency |
39 | 39 |
of the code. |
40 | 40 |
*/ |
41 | 41 |
|
42 | 42 |
/** |
43 | 43 |
\dir tools |
44 | 44 |
\brief Some useful executables |
45 | 45 |
|
46 | 46 |
This directory contains the sources of some useful complete executables. |
47 | 47 |
|
48 | 48 |
*/ |
49 | 49 |
|
50 | 50 |
|
51 | 51 |
|
52 | 52 |
/** |
53 | 53 |
\dir lemon |
54 | 54 |
\brief Base include directory of LEMON |
55 | 55 |
|
56 | 56 |
This is the base directory of lemon includes, so each include file must be |
57 | 57 |
prefixed with this, e.g. |
58 | 58 |
\code |
59 | 59 |
#include<lemon/list_graph.h> |
60 | 60 |
#include<lemon/dijkstra.h> |
61 | 61 |
\endcode |
62 | 62 |
*/ |
63 | 63 |
|
64 | 64 |
/** |
65 | 65 |
\dir concepts |
66 | 66 |
\brief Concept descriptors and checking classes |
67 | 67 |
|
68 | 68 |
This directory contains the concept descriptors and concept checkers. As a user |
69 | 69 |
you typically don't have to deal with these files. |
70 | 70 |
*/ |
71 | 71 |
|
72 | 72 |
/** |
73 | 73 |
\dir bits |
74 | 74 |
\brief Implementation helper files |
75 | 75 |
|
76 | 76 |
This directory contains some helper classes to implement graphs, maps and |
77 | 77 |
some other classes. As a user you typically don't have to deal with these |
78 | 78 |
files. |
79 | 79 |
*/ |
1 |
/* -*- C++ -*- |
|
1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
|
2 | 2 |
* |
3 |
* This file is a part of LEMON, a generic C++ optimization library |
|
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 |
/** |
20 | 20 |
@defgroup datas Data Structures |
21 | 21 |
This group describes the several data structures implemented in LEMON. |
22 | 22 |
*/ |
23 | 23 |
|
24 | 24 |
/** |
25 | 25 |
@defgroup graphs Graph Structures |
26 | 26 |
@ingroup datas |
27 | 27 |
\brief Graph structures implemented in LEMON. |
28 | 28 |
|
29 | 29 |
The implementation of combinatorial algorithms heavily relies on |
30 | 30 |
efficient graph implementations. LEMON offers data structures which are |
31 | 31 |
planned to be easily used in an experimental phase of implementation studies, |
32 | 32 |
and thereafter the program code can be made efficient by small modifications. |
33 | 33 |
|
34 | 34 |
The most efficient implementation of diverse applications require the |
35 | 35 |
usage of different physical graph implementations. These differences |
36 | 36 |
appear in the size of graph we require to handle, memory or time usage |
37 | 37 |
limitations or in the set of operations through which the graph can be |
38 | 38 |
accessed. LEMON provides several physical graph structures to meet |
39 | 39 |
the diverging requirements of the possible users. In order to save on |
40 | 40 |
running time or on memory usage, some structures may fail to provide |
41 | 41 |
some graph features like arc/edge or node deletion. |
42 | 42 |
|
43 | 43 |
Alteration of standard containers need a very limited number of |
44 | 44 |
operations, these together satisfy the everyday requirements. |
45 | 45 |
In the case of graph structures, different operations are needed which do |
46 | 46 |
not alter the physical graph, but gives another view. If some nodes or |
47 | 47 |
arcs have to be hidden or the reverse oriented graph have to be used, then |
48 | 48 |
this is the case. It also may happen that in a flow implementation |
49 | 49 |
the residual graph can be accessed by another algorithm, or a node-set |
50 | 50 |
is to be shrunk for another algorithm. |
51 | 51 |
LEMON also provides a variety of graphs for these requirements called |
52 | 52 |
\ref graph_adaptors "graph adaptors". Adaptors cannot be used alone but only |
53 | 53 |
in conjunction with other graph representations. |
54 | 54 |
|
55 | 55 |
You are free to use the graph structure that fit your requirements |
56 | 56 |
the best, most graph algorithms and auxiliary data structures can be used |
57 | 57 |
with any graph structures. |
58 | 58 |
*/ |
59 | 59 |
|
60 | 60 |
/** |
61 | 61 |
@defgroup semi_adaptors Semi-Adaptor Classes for Graphs |
62 | 62 |
@ingroup graphs |
63 | 63 |
\brief Graph types between real graphs and graph adaptors. |
64 | 64 |
|
65 | 65 |
This group describes some graph types between real graphs and graph adaptors. |
66 | 66 |
These classes wrap graphs to give new functionality as the adaptors do it. |
67 | 67 |
On the other hand they are not light-weight structures as the adaptors. |
68 | 68 |
*/ |
69 | 69 |
|
70 | 70 |
/** |
71 | 71 |
@defgroup maps Maps |
72 | 72 |
@ingroup datas |
73 | 73 |
\brief Map structures implemented in LEMON. |
74 | 74 |
|
75 | 75 |
This group describes the map structures implemented in LEMON. |
76 | 76 |
|
77 | 77 |
LEMON provides several special purpose maps that e.g. combine |
78 | 78 |
new maps from existing ones. |
79 | 79 |
*/ |
80 | 80 |
|
81 | 81 |
/** |
82 | 82 |
@defgroup graph_maps Graph Maps |
83 | 83 |
@ingroup maps |
84 | 84 |
\brief Special graph-related maps. |
85 | 85 |
|
86 | 86 |
This group describes maps that are specifically designed to assign |
87 | 87 |
values to the nodes and arcs of graphs. |
88 | 88 |
*/ |
89 | 89 |
|
90 | 90 |
|
91 | 91 |
/** |
92 | 92 |
\defgroup map_adaptors Map Adaptors |
93 | 93 |
\ingroup maps |
94 | 94 |
\brief Tools to create new maps from existing ones |
95 | 95 |
|
96 | 96 |
This group describes map adaptors that are used to create "implicit" |
97 | 97 |
maps from other maps. |
98 | 98 |
|
99 | 99 |
Most of them are \ref lemon::concepts::ReadMap "read-only maps". |
1 |
/* -*- C++ -*- |
|
1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
|
2 | 2 |
* |
3 |
* This file is a part of LEMON, a generic C++ optimization library |
|
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 |
namespace lemon { |
20 | 20 |
/*! |
21 | 21 |
|
22 | 22 |
|
23 | 23 |
|
24 | 24 |
\page lgf-format Lemon Graph Format (LGF) |
25 | 25 |
|
26 | 26 |
The \e LGF is a <em>column oriented</em> |
27 | 27 |
file format for storing graphs and associated data like |
28 | 28 |
node and edge maps. |
29 | 29 |
|
30 | 30 |
Each line with \c '#' first non-whitespace |
31 | 31 |
character is considered as a comment line. |
32 | 32 |
|
33 | 33 |
Otherwise the file consists of sections starting with |
34 | 34 |
a header line. The header lines starts with an \c '@' character followed by the |
35 | 35 |
type of section. The standard section types are \c \@nodes, \c |
36 | 36 |
\@arcs and \c \@edges |
37 | 37 |
and \@attributes. Each header line may also have an optional |
38 | 38 |
\e name, which can be use to distinguish the sections of the same |
39 | 39 |
type. |
40 | 40 |
|
41 | 41 |
The standard sections are column oriented, each line consists of |
42 | 42 |
<em>token</em>s separated by whitespaces. A token can be \e plain or |
43 | 43 |
\e quoted. A plain token is just a sequence of non-whitespace characters, |
44 | 44 |
while a quoted token is a |
45 | 45 |
character sequence surrounded by double quotes, and it can also |
46 | 46 |
contain whitespaces and escape sequences. |
47 | 47 |
|
48 | 48 |
The \c \@nodes section describes a set of nodes and associated |
49 | 49 |
maps. The first is a header line, its columns are the names of the |
50 | 50 |
maps appearing in the following lines. |
51 | 51 |
One of the maps must be called \c |
52 | 52 |
"label", which plays special role in the file. |
53 | 53 |
The following |
54 | 54 |
non-empty lines until the next section describes nodes of the |
55 | 55 |
graph. Each line contains the values of the node maps |
56 | 56 |
associated to the current node. |
57 | 57 |
|
58 | 58 |
\code |
59 | 59 |
@nodes |
60 | 60 |
label coordinates size title |
61 | 61 |
1 (10,20) 10 "First node" |
62 | 62 |
2 (80,80) 8 "Second node" |
63 | 63 |
3 (40,10) 10 "Third node" |
64 | 64 |
\endcode |
65 | 65 |
|
66 | 66 |
The \c \@arcs section is very similar to the \c \@nodes section, |
67 | 67 |
it again starts with a header line describing the names of the maps, |
68 | 68 |
but the \c "label" map is not obligatory here. The following lines |
69 | 69 |
describe the arcs. The first two tokens of each line are |
70 | 70 |
the source and the target node of the arc, respectively, then come the map |
71 | 71 |
values. The source and target tokens must be node labels. |
72 | 72 |
|
73 | 73 |
\code |
74 | 74 |
@arcs |
75 | 75 |
capacity |
76 | 76 |
1 2 16 |
77 | 77 |
1 3 12 |
78 | 78 |
2 3 18 |
79 | 79 |
\endcode |
80 | 80 |
|
81 | 81 |
The \c \@edges is just a synonym of \c \@arcs. The @arcs section can |
82 | 82 |
also store the edge set of an undirected graph. In such case there is |
83 | 83 |
a conventional method for store arc maps in the file, if two columns |
84 | 84 |
has the same caption with \c '+' and \c '-' prefix, then these columns |
85 | 85 |
can be regarded as the values of an arc map. |
86 | 86 |
|
87 | 87 |
The \c \@attributes section contains key-value pairs, each line |
88 | 88 |
consists of two tokens, an attribute name, and then an attribute |
89 | 89 |
value. The value of the attribute could be also a label value of a |
90 | 90 |
node or an edge, or even an edge label prefixed with \c '+' or \c '-', |
91 | 91 |
which regards to the forward or backward directed arc of the |
92 | 92 |
corresponding edge. |
93 | 93 |
|
94 | 94 |
\code |
95 | 95 |
@attributes |
96 | 96 |
source 1 |
97 | 97 |
target 3 |
98 | 98 |
caption "LEMON test digraph" |
99 | 99 |
\endcode |
1 |
/* -*- C++ -*- |
|
1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
|
2 | 2 |
* |
3 |
* This file is a part of LEMON, a generic C++ optimization library |
|
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 |
/** |
20 | 20 |
|
21 | 21 |
\page license License Terms |
22 | 22 |
|
23 | 23 |
\verbinclude LICENSE |
24 | 24 |
|
25 | 25 |
*/ |
1 |
/* -*- C++ -*- |
|
1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
|
2 | 2 |
* |
3 |
* This file is a part of LEMON, a generic C++ optimization library |
|
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 |
/** |
20 | 20 |
\mainpage LEMON Documentation |
21 | 21 |
|
22 | 22 |
\section intro Introduction |
23 | 23 |
|
24 | 24 |
\subsection whatis What is LEMON |
25 | 25 |
|
26 | 26 |
LEMON stands for |
27 | 27 |
<b>L</b>ibrary of <b>E</b>fficient <b>M</b>odels |
28 | 28 |
and <b>O</b>ptimization in <b>N</b>etworks. |
29 | 29 |
It is a C++ template |
30 | 30 |
library aimed at combinatorial optimization tasks which |
31 | 31 |
often involve in working |
32 | 32 |
with graphs. |
33 | 33 |
|
34 | 34 |
<b> |
35 | 35 |
LEMON is an <a class="el" href="http://opensource.org/">open source</a> |
36 | 36 |
project. |
37 | 37 |
You are free to use it in your commercial or |
38 | 38 |
non-commercial applications under very permissive |
39 | 39 |
\ref license "license terms". |
40 | 40 |
</b> |
41 | 41 |
|
42 | 42 |
\subsection howtoread How to read the documentation |
43 | 43 |
|
44 | 44 |
If you want to get a quick start and see the most important features then |
45 | 45 |
take a look at our \ref quicktour |
46 | 46 |
"Quick Tour to LEMON" which will guide you along. |
47 | 47 |
|
48 | 48 |
If you already feel like using our library, see the page that tells you |
49 | 49 |
\ref getstart "How to start using LEMON". |
50 | 50 |
|
51 | 51 |
If you |
52 | 52 |
want to see how LEMON works, see |
53 | 53 |
some \ref demoprograms "demo programs"! |
54 | 54 |
|
55 | 55 |
If you know what you are looking for then try to find it under the |
56 | 56 |
<a class="el" href="modules.html">Modules</a> |
57 | 57 |
section. |
58 | 58 |
|
59 | 59 |
|
60 | 60 |
*/ |
1 |
/* -*- C++ -*- |
|
1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
|
2 | 2 |
* |
3 |
* This file is a part of LEMON, a generic C++ optimization library |
|
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 |
/// The namespace of LEMON |
20 | 20 |
|
21 | 21 |
/// The namespace of LEMON |
22 | 22 |
/// |
23 | 23 |
namespace lemon { |
24 | 24 |
|
25 | 25 |
/// The namespace of LEMON concepts and concept checking classes |
26 | 26 |
|
27 | 27 |
/// The namespace of LEMON concepts and concept checking classes |
28 | 28 |
/// |
29 | 29 |
namespace concepts {} |
30 | 30 |
} |
1 |
/* -*- C++ -*- |
|
1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
|
2 | 2 |
* |
3 |
* This file is a part of LEMON, a generic C++ optimization library |
|
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 |
#ifndef LEMON_TEMPLATE_H |
20 | 20 |
#define LEMON_TEMPLATE_H |
21 | 21 |
|
22 | 22 |
#endif // LEMON_TEMPLATE_H |
1 |
/* -*- C++ -*- |
|
1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
|
2 | 2 |
* |
3 |
* This file is a part of LEMON, a generic C++ optimization library |
|
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 <lemon/arg_parser.h> |
20 | 20 |
|
21 | 21 |
namespace lemon { |
22 | 22 |
|
23 | 23 |
void ArgParser::_showHelp(void *p) |
24 | 24 |
{ |
25 | 25 |
(static_cast<ArgParser*>(p))->showHelp(); |
26 | 26 |
exit(1); |
27 | 27 |
} |
28 | 28 |
|
29 | 29 |
ArgParser::ArgParser(int argc, const char **argv) :_argc(argc), _argv(argv), |
30 | 30 |
_command_name(argv[0]) { |
31 | 31 |
funcOption("-help","Print a short help message",_showHelp,this); |
32 | 32 |
synonym("help","-help"); |
33 | 33 |
synonym("h","-help"); |
34 | 34 |
|
35 | 35 |
} |
36 | 36 |
|
37 | 37 |
ArgParser::~ArgParser() |
38 | 38 |
{ |
39 | 39 |
for(Opts::iterator i=_opts.begin();i!=_opts.end();++i) |
40 | 40 |
if(i->second.self_delete) |
41 | 41 |
switch(i->second.type) { |
42 | 42 |
case BOOL: |
43 | 43 |
delete i->second.bool_p; |
44 | 44 |
break; |
45 | 45 |
case STRING: |
46 | 46 |
delete i->second.string_p; |
47 | 47 |
break; |
48 | 48 |
case DOUBLE: |
49 | 49 |
delete i->second.double_p; |
50 | 50 |
break; |
51 | 51 |
case INTEGER: |
52 | 52 |
delete i->second.int_p; |
53 | 53 |
break; |
54 | 54 |
case UNKNOWN: |
55 | 55 |
break; |
56 | 56 |
case FUNC: |
57 | 57 |
break; |
58 | 58 |
} |
59 | 59 |
} |
60 | 60 |
|
61 | 61 |
|
62 | 62 |
ArgParser &ArgParser::intOption(const std::string &name, |
63 | 63 |
const std::string &help, |
64 | 64 |
int value, bool obl) |
65 | 65 |
{ |
66 | 66 |
ParData p; |
67 | 67 |
p.int_p=new int(value); |
68 | 68 |
p.self_delete=true; |
69 | 69 |
p.help=help; |
70 | 70 |
p.type=INTEGER; |
71 | 71 |
p.mandatory=obl; |
72 | 72 |
_opts[name]=p; |
73 | 73 |
return *this; |
74 | 74 |
} |
75 | 75 |
|
76 | 76 |
ArgParser &ArgParser::doubleOption(const std::string &name, |
77 | 77 |
const std::string &help, |
78 | 78 |
double value, bool obl) |
79 | 79 |
{ |
80 | 80 |
ParData p; |
81 | 81 |
p.double_p=new double(value); |
82 | 82 |
p.self_delete=true; |
83 | 83 |
p.help=help; |
84 | 84 |
p.type=DOUBLE; |
85 | 85 |
p.mandatory=obl; |
86 | 86 |
_opts[name]=p; |
87 | 87 |
return *this; |
88 | 88 |
} |
89 | 89 |
|
90 | 90 |
ArgParser &ArgParser::boolOption(const std::string &name, |
91 | 91 |
const std::string &help, |
92 | 92 |
bool value, bool obl) |
93 | 93 |
{ |
94 | 94 |
ParData p; |
95 | 95 |
p.bool_p=new bool(value); |
96 | 96 |
p.self_delete=true; |
97 | 97 |
p.help=help; |
98 | 98 |
p.type=BOOL; |
99 | 99 |
p.mandatory=obl; |
1 |
/* -*- C++ -*- |
|
1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
|
2 | 2 |
* |
3 |
* This file is a part of LEMON, a generic C++ optimization library |
|
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 |
#ifndef LEMON_ARG_PARSER |
20 | 20 |
#define LEMON_ARG_PARSER |
21 | 21 |
|
22 | 22 |
#include <vector> |
23 | 23 |
#include <map> |
24 | 24 |
#include <list> |
25 | 25 |
#include <string> |
26 | 26 |
#include <iostream> |
27 | 27 |
#include <sstream> |
28 | 28 |
#include <algorithm> |
29 | 29 |
#include <lemon/assert.h> |
30 | 30 |
|
31 | 31 |
///\ingroup misc |
32 | 32 |
///\file |
33 | 33 |
///\brief A tool to parse command line arguments. |
34 | 34 |
|
35 | 35 |
namespace lemon { |
36 | 36 |
|
37 | 37 |
///Command line arguments parser |
38 | 38 |
|
39 | 39 |
///\ingroup misc |
40 | 40 |
///Command line arguments parser. |
41 | 41 |
/// |
42 | 42 |
///For a complete example see the \ref arg_parser_demo.cc demo file. |
43 | 43 |
class ArgParser { |
44 | 44 |
|
45 | 45 |
static void _showHelp(void *p); |
46 | 46 |
protected: |
47 | 47 |
|
48 | 48 |
int _argc; |
49 | 49 |
const char **_argv; |
50 | 50 |
|
51 | 51 |
enum OptType { UNKNOWN=0, BOOL=1, STRING=2, DOUBLE=3, INTEGER=4, FUNC=5 }; |
52 | 52 |
|
53 | 53 |
class ParData { |
54 | 54 |
public: |
55 | 55 |
union { |
56 | 56 |
bool *bool_p; |
57 | 57 |
int *int_p; |
58 | 58 |
double *double_p; |
59 | 59 |
std::string *string_p; |
60 | 60 |
struct { |
61 | 61 |
void (*p)(void *); |
62 | 62 |
void *data; |
63 | 63 |
} func_p; |
64 | 64 |
|
65 | 65 |
}; |
66 | 66 |
std::string help; |
67 | 67 |
bool mandatory; |
68 | 68 |
OptType type; |
69 | 69 |
bool set; |
70 | 70 |
bool ingroup; |
71 | 71 |
bool has_syn; |
72 | 72 |
bool syn; |
73 | 73 |
bool self_delete; |
74 | 74 |
ParData() : mandatory(false), type(UNKNOWN), set(false), ingroup(false), |
75 | 75 |
has_syn(false), syn(false), self_delete(false) {} |
76 | 76 |
}; |
77 | 77 |
|
78 | 78 |
typedef std::map<std::string,ParData> Opts; |
79 | 79 |
Opts _opts; |
80 | 80 |
|
81 | 81 |
class GroupData |
82 | 82 |
{ |
83 | 83 |
public: |
84 | 84 |
typedef std::list<std::string> Opts; |
85 | 85 |
Opts opts; |
86 | 86 |
bool only_one; |
87 | 87 |
bool mandatory; |
88 | 88 |
GroupData() :only_one(false), mandatory(false) {} |
89 | 89 |
}; |
90 | 90 |
|
91 | 91 |
typedef std::map<std::string,GroupData> Groups; |
92 | 92 |
Groups _groups; |
93 | 93 |
|
94 | 94 |
struct OtherArg |
95 | 95 |
{ |
96 | 96 |
std::string name; |
97 | 97 |
std::string help; |
98 | 98 |
OtherArg(std::string n, std::string h) :name(n), help(h) {} |
99 | 99 |
1 |
/* -*- C++ -*- |
|
1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
|
2 | 2 |
* |
3 |
* This file is a part of LEMON, a generic C++ optimization library |
|
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 |
#ifndef LEMON_ASSERT_H |
20 | 20 |
#define LEMON_ASSERT_H |
21 | 21 |
|
22 | 22 |
/// \ingroup exceptions |
23 | 23 |
/// \file |
24 | 24 |
/// \brief Extended assertion handling |
25 | 25 |
|
26 | 26 |
#include <lemon/error.h> |
27 | 27 |
|
28 | 28 |
namespace lemon { |
29 | 29 |
|
30 | 30 |
inline void assert_fail_log(const char *file, int line, const char *function, |
31 | 31 |
const char *message, const char *assertion) |
32 | 32 |
{ |
33 | 33 |
std::cerr << file << ":" << line << ": "; |
34 | 34 |
if (function) |
35 | 35 |
std::cerr << function << ": "; |
36 | 36 |
std::cerr << message; |
37 | 37 |
if (assertion) |
38 | 38 |
std::cerr << " (assertion '" << assertion << "' failed)"; |
39 | 39 |
std::cerr << std::endl; |
40 | 40 |
} |
41 | 41 |
|
42 | 42 |
inline void assert_fail_abort(const char *file, int line, |
43 | 43 |
const char *function, const char* message, |
44 | 44 |
const char *assertion) |
45 | 45 |
{ |
46 | 46 |
assert_fail_log(file, line, function, message, assertion); |
47 | 47 |
std::abort(); |
48 | 48 |
} |
49 | 49 |
|
50 | 50 |
namespace _assert_bits { |
51 | 51 |
|
52 | 52 |
|
53 | 53 |
inline const char* cstringify(const std::string& str) { |
54 | 54 |
return str.c_str(); |
55 | 55 |
} |
56 | 56 |
|
57 | 57 |
inline const char* cstringify(const char* str) { |
58 | 58 |
return str; |
59 | 59 |
} |
60 | 60 |
} |
61 | 61 |
} |
62 | 62 |
|
63 | 63 |
#endif // LEMON_ASSERT_H |
64 | 64 |
|
65 | 65 |
#undef LEMON_ASSERT |
66 | 66 |
#undef LEMON_FIXME |
67 | 67 |
#undef LEMON_DEBUG |
68 | 68 |
|
69 | 69 |
#if (defined(LEMON_ASSERT_LOG) ? 1 : 0) + \ |
70 | 70 |
(defined(LEMON_ASSERT_ABORT) ? 1 : 0) + \ |
71 | 71 |
(defined(LEMON_ASSERT_CUSTOM) ? 1 : 0) > 1 |
72 | 72 |
#error "LEMON assertion system is not set properly" |
73 | 73 |
#endif |
74 | 74 |
|
75 | 75 |
#if ((defined(LEMON_ASSERT_LOG) ? 1 : 0) + \ |
76 | 76 |
(defined(LEMON_ASSERT_ABORT) ? 1 : 0) + \ |
77 | 77 |
(defined(LEMON_ASSERT_CUSTOM) ? 1 : 0) == 1 || \ |
78 | 78 |
defined(LEMON_ENABLE_ASSERTS)) && \ |
79 | 79 |
(defined(LEMON_DISABLE_ASSERTS) || \ |
80 | 80 |
defined(NDEBUG)) |
81 | 81 |
#error "LEMON assertion system is not set properly" |
82 | 82 |
#endif |
83 | 83 |
|
84 | 84 |
|
85 | 85 |
#if defined LEMON_ASSERT_LOG |
86 | 86 |
# undef LEMON_ASSERT_HANDLER |
87 | 87 |
# define LEMON_ASSERT_HANDLER ::lemon::assert_fail_log |
88 | 88 |
#elif defined LEMON_ASSERT_ABORT |
89 | 89 |
# undef LEMON_ASSERT_HANDLER |
90 | 90 |
# define LEMON_ASSERT_HANDLER ::lemon::assert_fail_abort |
91 | 91 |
#elif defined LEMON_ASSERT_CUSTOM |
92 | 92 |
# undef LEMON_ASSERT_HANDLER |
93 | 93 |
# ifndef LEMON_CUSTOM_ASSERT_HANDLER |
94 | 94 |
# error "LEMON_CUSTOM_ASSERT_HANDLER is not set" |
95 | 95 |
# endif |
96 | 96 |
# define LEMON_ASSERT_HANDLER LEMON_CUSTOM_ASSERT_HANDLER |
97 | 97 |
#elif defined LEMON_DISABLE_ASSERTS |
98 | 98 |
# undef LEMON_ASSERT_HANDLER |
99 | 99 |
#elif defined NDEBUG |
1 |
/* -*- C++ -*- |
|
1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
|
2 | 2 |
* |
3 |
* This file is a part of LEMON, a generic C++ optimization library |
|
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 |
///\file |
20 | 20 |
///\brief Some basic non-inline functions and static global data. |
21 | 21 |
|
22 | 22 |
#include<lemon/tolerance.h> |
23 | 23 |
#include<lemon/bits/invalid.h> |
24 | 24 |
namespace lemon { |
25 | 25 |
|
26 | 26 |
float Tolerance<float>::def_epsilon = 1e-4; |
27 | 27 |
double Tolerance<double>::def_epsilon = 1e-10; |
28 | 28 |
long double Tolerance<long double>::def_epsilon = 1e-14; |
29 | 29 |
|
30 | 30 |
#ifndef LEMON_ONLY_TEMPLATES |
31 | 31 |
const Invalid INVALID = Invalid(); |
32 | 32 |
#endif |
33 | 33 |
|
34 | 34 |
} //namespace lemon |
1 |
/* -*- C++ -*- |
|
1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
|
2 | 2 |
* |
3 |
* This file is a part of LEMON, a generic C++ optimization library |
|
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 |
#ifndef LEMON_BFS_H |
20 | 20 |
#define LEMON_BFS_H |
21 | 21 |
|
22 | 22 |
///\ingroup search |
23 | 23 |
///\file |
24 | 24 |
///\brief Bfs algorithm. |
25 | 25 |
|
26 | 26 |
#include <lemon/list_graph.h> |
27 | 27 |
#include <lemon/graph_utils.h> |
28 | 28 |
#include <lemon/bits/path_dump.h> |
29 | 29 |
#include <lemon/bits/invalid.h> |
30 | 30 |
#include <lemon/error.h> |
31 | 31 |
#include <lemon/maps.h> |
32 | 32 |
|
33 | 33 |
namespace lemon { |
34 | 34 |
|
35 | 35 |
|
36 | 36 |
|
37 | 37 |
///Default traits class of Bfs class. |
38 | 38 |
|
39 | 39 |
///Default traits class of Bfs class. |
40 | 40 |
///\tparam GR Digraph type. |
41 | 41 |
template<class GR> |
42 | 42 |
struct BfsDefaultTraits |
43 | 43 |
{ |
44 | 44 |
///The digraph type the algorithm runs on. |
45 | 45 |
typedef GR Digraph; |
46 | 46 |
///\brief The type of the map that stores the last |
47 | 47 |
///arcs of the shortest paths. |
48 | 48 |
/// |
49 | 49 |
///The type of the map that stores the last |
50 | 50 |
///arcs of the shortest paths. |
51 | 51 |
///It must meet the \ref concepts::WriteMap "WriteMap" concept. |
52 | 52 |
/// |
53 | 53 |
typedef typename Digraph::template NodeMap<typename GR::Arc> PredMap; |
54 | 54 |
///Instantiates a PredMap. |
55 | 55 |
|
56 | 56 |
///This function instantiates a \ref PredMap. |
57 | 57 |
///\param G is the digraph, to which we would like to define the PredMap. |
58 | 58 |
///\todo The digraph alone may be insufficient to initialize |
59 | 59 |
static PredMap *createPredMap(const GR &G) |
60 | 60 |
{ |
61 | 61 |
return new PredMap(G); |
62 | 62 |
} |
63 | 63 |
///The type of the map that indicates which nodes are processed. |
64 | 64 |
|
65 | 65 |
///The type of the map that indicates which nodes are processed. |
66 | 66 |
///It must meet the \ref concepts::WriteMap "WriteMap" concept. |
67 | 67 |
///\todo named parameter to set this type, function to read and write. |
68 | 68 |
typedef NullMap<typename Digraph::Node,bool> ProcessedMap; |
69 | 69 |
///Instantiates a ProcessedMap. |
70 | 70 |
|
71 | 71 |
///This function instantiates a \ref ProcessedMap. |
72 | 72 |
///\param g is the digraph, to which |
73 | 73 |
///we would like to define the \ref ProcessedMap |
74 | 74 |
#ifdef DOXYGEN |
75 | 75 |
static ProcessedMap *createProcessedMap(const GR &g) |
76 | 76 |
#else |
77 | 77 |
static ProcessedMap *createProcessedMap(const GR &) |
78 | 78 |
#endif |
79 | 79 |
{ |
80 | 80 |
return new ProcessedMap(); |
81 | 81 |
} |
82 | 82 |
///The type of the map that indicates which nodes are reached. |
83 | 83 |
|
84 | 84 |
///The type of the map that indicates which nodes are reached. |
85 | 85 |
///It must meet the \ref concepts::WriteMap "WriteMap" concept. |
86 | 86 |
///\todo named parameter to set this type, function to read and write. |
87 | 87 |
typedef typename Digraph::template NodeMap<bool> ReachedMap; |
88 | 88 |
///Instantiates a ReachedMap. |
89 | 89 |
|
90 | 90 |
///This function instantiates a \ref ReachedMap. |
91 | 91 |
///\param G is the digraph, to which |
92 | 92 |
///we would like to define the \ref ReachedMap. |
93 | 93 |
static ReachedMap *createReachedMap(const GR &G) |
94 | 94 |
{ |
95 | 95 |
return new ReachedMap(G); |
96 | 96 |
} |
97 | 97 |
///The type of the map that stores the dists of the nodes. |
98 | 98 |
|
99 | 99 |
///The type of the map that stores the dists of the nodes. |
1 |
/* -*- C++ -*- |
|
1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
|
2 | 2 |
* |
3 |
* This file is a part of LEMON, a generic C++ optimization library |
|
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 |
#ifndef LEMON_BIN_HEAP_H |
20 | 20 |
#define LEMON_BIN_HEAP_H |
21 | 21 |
|
22 | 22 |
///\ingroup auxdat |
23 | 23 |
///\file |
24 | 24 |
///\brief Binary Heap implementation. |
25 | 25 |
|
26 | 26 |
#include <vector> |
27 | 27 |
#include <utility> |
28 | 28 |
#include <functional> |
29 | 29 |
|
30 | 30 |
namespace lemon { |
31 | 31 |
|
32 | 32 |
///\ingroup auxdat |
33 | 33 |
/// |
34 | 34 |
///\brief A Binary Heap implementation. |
35 | 35 |
/// |
36 | 36 |
///This class implements the \e binary \e heap data structure. A \e heap |
37 | 37 |
///is a data structure for storing items with specified values called \e |
38 | 38 |
///priorities in such a way that finding the item with minimum priority is |
39 | 39 |
///efficient. \c Compare specifies the ordering of the priorities. In a heap |
40 | 40 |
///one can change the priority of an item, add or erase an item, etc. |
41 | 41 |
/// |
42 | 42 |
///\tparam _Prio Type of the priority of the items. |
43 | 43 |
///\tparam _ItemIntMap A read and writable Item int map, used internally |
44 | 44 |
///to handle the cross references. |
45 | 45 |
///\tparam _Compare A class for the ordering of the priorities. The |
46 | 46 |
///default is \c std::less<_Prio>. |
47 | 47 |
/// |
48 | 48 |
///\sa FibHeap |
49 | 49 |
///\sa Dijkstra |
50 | 50 |
template <typename _Prio, typename _ItemIntMap, |
51 | 51 |
typename _Compare = std::less<_Prio> > |
52 | 52 |
class BinHeap { |
53 | 53 |
|
54 | 54 |
public: |
55 | 55 |
///\e |
56 | 56 |
typedef _ItemIntMap ItemIntMap; |
57 | 57 |
///\e |
58 | 58 |
typedef _Prio Prio; |
59 | 59 |
///\e |
60 | 60 |
typedef typename ItemIntMap::Key Item; |
61 | 61 |
///\e |
62 | 62 |
typedef std::pair<Item,Prio> Pair; |
63 | 63 |
///\e |
64 | 64 |
typedef _Compare Compare; |
65 | 65 |
|
66 | 66 |
/// \brief Type to represent the items states. |
67 | 67 |
/// |
68 | 68 |
/// Each Item element have a state associated to it. It may be "in heap", |
69 | 69 |
/// "pre heap" or "post heap". The latter two are indifferent from the |
70 | 70 |
/// heap's point of view, but may be useful to the user. |
71 | 71 |
/// |
72 | 72 |
/// The ItemIntMap \e should be initialized in such way that it maps |
73 | 73 |
/// PRE_HEAP (-1) to any element to be put in the heap... |
74 | 74 |
enum State { |
75 | 75 |
IN_HEAP = 0, |
76 | 76 |
PRE_HEAP = -1, |
77 | 77 |
POST_HEAP = -2 |
78 | 78 |
}; |
79 | 79 |
|
80 | 80 |
private: |
81 | 81 |
std::vector<Pair> data; |
82 | 82 |
Compare comp; |
83 | 83 |
ItemIntMap &iim; |
84 | 84 |
|
85 | 85 |
public: |
86 | 86 |
/// \brief The constructor. |
87 | 87 |
/// |
88 | 88 |
/// The constructor. |
89 | 89 |
/// \param _iim should be given to the constructor, since it is used |
90 | 90 |
/// internally to handle the cross references. The value of the map |
91 | 91 |
/// should be PRE_HEAP (-1) for each element. |
92 | 92 |
explicit BinHeap(ItemIntMap &_iim) : iim(_iim) {} |
93 | 93 |
|
94 | 94 |
/// \brief The constructor. |
95 | 95 |
/// |
96 | 96 |
/// The constructor. |
97 | 97 |
/// \param _iim should be given to the constructor, since it is used |
98 | 98 |
/// internally to handle the cross references. The value of the map |
99 | 99 |
/// should be PRE_HEAP (-1) for each element. |
1 |
/* -*- C++ -*- |
|
1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
|
2 | 2 |
* |
3 |
* This file is a part of LEMON, a generic C++ optimization library |
|
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 |
#ifndef LEMON_BITS_ALTERATION_NOTIFIER_H |
20 | 20 |
#define LEMON_BITS_ALTERATION_NOTIFIER_H |
21 | 21 |
|
22 | 22 |
#include <vector> |
23 | 23 |
#include <list> |
24 | 24 |
|
25 | 25 |
#include <lemon/bits/utility.h> |
26 | 26 |
|
27 | 27 |
///\ingroup graphbits |
28 | 28 |
///\file |
29 | 29 |
///\brief Observer notifier for graph alteration observers. |
30 | 30 |
|
31 | 31 |
namespace lemon { |
32 | 32 |
|
33 | 33 |
/// \ingroup graphbits |
34 | 34 |
/// |
35 | 35 |
/// \brief Notifier class to notify observes about alterations in |
36 | 36 |
/// a container. |
37 | 37 |
/// |
38 | 38 |
/// The simple graph's can be refered as two containers, one node container |
39 | 39 |
/// and one edge container. But they are not standard containers they |
40 | 40 |
/// does not store values directly they are just key continars for more |
41 | 41 |
/// value containers which are the node and edge maps. |
42 | 42 |
/// |
43 | 43 |
/// The graph's node and edge sets can be changed as we add or erase |
44 | 44 |
/// nodes and edges in the graph. Lemon would like to handle easily |
45 | 45 |
/// that the node and edge maps should contain values for all nodes or |
46 | 46 |
/// edges. If we want to check on every indicing if the map contains |
47 | 47 |
/// the current indicing key that cause a drawback in the performance |
48 | 48 |
/// in the library. We use another solution we notify all maps about |
49 | 49 |
/// an alteration in the graph, which cause only drawback on the |
50 | 50 |
/// alteration of the graph. |
51 | 51 |
/// |
52 | 52 |
/// This class provides an interface to the container. The \e first() and \e |
53 | 53 |
/// next() member functions make possible to iterate on the keys of the |
54 | 54 |
/// container. The \e id() function returns an integer id for each key. |
55 | 55 |
/// The \e maxId() function gives back an upper bound of the ids. |
56 | 56 |
/// |
57 | 57 |
/// For the proper functonality of this class, we should notify it |
58 | 58 |
/// about each alteration in the container. The alterations have four type |
59 | 59 |
/// as \e add(), \e erase(), \e build() and \e clear(). The \e add() and |
60 | 60 |
/// \e erase() signals that only one or few items added or erased to or |
61 | 61 |
/// from the graph. If all items are erased from the graph or from an empty |
62 | 62 |
/// graph a new graph is builded then it can be signaled with the |
63 | 63 |
/// clear() and build() members. Important rule that if we erase items |
64 | 64 |
/// from graph we should first signal the alteration and after that erase |
65 | 65 |
/// them from the container, on the other way on item addition we should |
66 | 66 |
/// first extend the container and just after that signal the alteration. |
67 | 67 |
/// |
68 | 68 |
/// The alteration can be observed with a class inherited from the |
69 | 69 |
/// \e ObserverBase nested class. The signals can be handled with |
70 | 70 |
/// overriding the virtual functions defined in the base class. The |
71 | 71 |
/// observer base can be attached to the notifier with the |
72 | 72 |
/// \e attach() member and can be detached with detach() function. The |
73 | 73 |
/// alteration handlers should not call any function which signals |
74 | 74 |
/// an other alteration in the same notifier and should not |
75 | 75 |
/// detach any observer from the notifier. |
76 | 76 |
/// |
77 | 77 |
/// Alteration observers try to be exception safe. If an \e add() or |
78 | 78 |
/// a \e clear() function throws an exception then the remaining |
79 | 79 |
/// observeres will not be notified and the fulfilled additions will |
80 | 80 |
/// be rolled back by calling the \e erase() or \e clear() |
81 | 81 |
/// functions. Thence the \e erase() and \e clear() should not throw |
82 | 82 |
/// exception. Actullay, it can be throw only |
83 | 83 |
/// \ref AlterationObserver::ImmediateDetach ImmediateDetach |
84 | 84 |
/// exception which detach the observer from the notifier. |
85 | 85 |
/// |
86 | 86 |
/// There are some place when the alteration observing is not completly |
87 | 87 |
/// reliable. If we want to carry out the node degree in the graph |
88 | 88 |
/// as in the \ref InDegMap and we use the reverseEdge that cause |
89 | 89 |
/// unreliable functionality. Because the alteration observing signals |
90 | 90 |
/// only erasing and adding but not the reversing it will stores bad |
91 | 91 |
/// degrees. The sub graph adaptors cannot signal the alterations because |
92 | 92 |
/// just a setting in the filter map can modify the graph and this cannot |
93 | 93 |
/// be watched in any way. |
94 | 94 |
/// |
95 | 95 |
/// \param _Container The container which is observed. |
96 | 96 |
/// \param _Item The item type which is obserbved. |
97 | 97 |
|
98 | 98 |
template <typename _Container, typename _Item> |
99 | 99 |
class AlterationNotifier { |
1 |
/* -*- C++ -*- |
|
1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
|
2 | 2 |
* |
3 |
* This file is a part of LEMON, a generic C++ optimization library |
|
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 |
#ifndef LEMON_BITS_ARRAY_MAP_H |
20 | 20 |
#define LEMON_BITS_ARRAY_MAP_H |
21 | 21 |
|
22 | 22 |
#include <memory> |
23 | 23 |
|
24 | 24 |
#include <lemon/bits/traits.h> |
25 | 25 |
#include <lemon/bits/alteration_notifier.h> |
26 | 26 |
#include <lemon/concept_check.h> |
27 | 27 |
#include <lemon/concepts/maps.h> |
28 | 28 |
|
29 | 29 |
/// \ingroup graphbits |
30 | 30 |
/// \file |
31 | 31 |
/// \brief Graph map based on the array storage. |
32 | 32 |
|
33 | 33 |
namespace lemon { |
34 | 34 |
|
35 | 35 |
/// \ingroup graphbits |
36 | 36 |
/// |
37 | 37 |
/// \brief Graph map based on the array storage. |
38 | 38 |
/// |
39 | 39 |
/// The ArrayMap template class is graph map structure what |
40 | 40 |
/// automatically updates the map when a key is added to or erased from |
41 | 41 |
/// the map. This map uses the allocators to implement |
42 | 42 |
/// the container functionality. |
43 | 43 |
/// |
44 | 44 |
/// The template parameters are the Graph the current Item type and |
45 | 45 |
/// the Value type of the map. |
46 | 46 |
template <typename _Graph, typename _Item, typename _Value> |
47 | 47 |
class ArrayMap |
48 | 48 |
: public ItemSetTraits<_Graph, _Item>::ItemNotifier::ObserverBase { |
49 | 49 |
public: |
50 | 50 |
/// The graph type of the maps. |
51 | 51 |
typedef _Graph Graph; |
52 | 52 |
/// The item type of the map. |
53 | 53 |
typedef _Item Item; |
54 | 54 |
/// The reference map tag. |
55 | 55 |
typedef True ReferenceMapTag; |
56 | 56 |
|
57 | 57 |
/// The key type of the maps. |
58 | 58 |
typedef _Item Key; |
59 | 59 |
/// The value type of the map. |
60 | 60 |
typedef _Value Value; |
61 | 61 |
|
62 | 62 |
/// The const reference type of the map. |
63 | 63 |
typedef const _Value& ConstReference; |
64 | 64 |
/// The reference type of the map. |
65 | 65 |
typedef _Value& Reference; |
66 | 66 |
|
67 | 67 |
/// The notifier type. |
68 | 68 |
typedef typename ItemSetTraits<_Graph, _Item>::ItemNotifier Notifier; |
69 | 69 |
|
70 | 70 |
/// The MapBase of the Map which imlements the core regisitry function. |
71 | 71 |
typedef typename Notifier::ObserverBase Parent; |
72 | 72 |
|
73 | 73 |
private: |
74 | 74 |
typedef std::allocator<Value> Allocator; |
75 | 75 |
|
76 | 76 |
public: |
77 | 77 |
|
78 | 78 |
/// \brief Graph initialized map constructor. |
79 | 79 |
/// |
80 | 80 |
/// Graph initialized map constructor. |
81 | 81 |
explicit ArrayMap(const Graph& graph) { |
82 | 82 |
Parent::attach(graph.notifier(Item())); |
83 | 83 |
allocate_memory(); |
84 | 84 |
Notifier* nf = Parent::notifier(); |
85 | 85 |
Item it; |
86 | 86 |
for (nf->first(it); it != INVALID; nf->next(it)) { |
87 | 87 |
int id = nf->id(it);; |
88 | 88 |
allocator.construct(&(values[id]), Value()); |
89 | 89 |
} |
90 | 90 |
} |
91 | 91 |
|
92 | 92 |
/// \brief Constructor to use default value to initialize the map. |
93 | 93 |
/// |
94 | 94 |
/// It constructs a map and initialize all of the the map. |
95 | 95 |
ArrayMap(const Graph& graph, const Value& value) { |
96 | 96 |
Parent::attach(graph.notifier(Item())); |
97 | 97 |
allocate_memory(); |
98 | 98 |
Notifier* nf = Parent::notifier(); |
99 | 99 |
Item it; |
1 |
/* -*- C++ -*- |
|
1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
|
2 | 2 |
* |
3 |
* This file is a part of LEMON, a generic C++ optimization library |
|
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 |
#ifndef LEMON_BITS_BASE_EXTENDER_H |
20 | 20 |
#define LEMON_BITS_BASE_EXTENDER_H |
21 | 21 |
|
22 | 22 |
#include <lemon/bits/invalid.h> |
23 | 23 |
#include <lemon/error.h> |
24 | 24 |
|
25 | 25 |
#include <lemon/bits/map_extender.h> |
26 | 26 |
#include <lemon/bits/default_map.h> |
27 | 27 |
|
28 | 28 |
#include <lemon/concept_check.h> |
29 | 29 |
#include <lemon/concepts/maps.h> |
30 | 30 |
|
31 | 31 |
///\ingroup digraphbits |
32 | 32 |
///\file |
33 | 33 |
///\brief Extenders for the digraph types |
34 | 34 |
namespace lemon { |
35 | 35 |
|
36 | 36 |
/// \ingroup digraphbits |
37 | 37 |
/// |
38 | 38 |
/// \brief BaseDigraph to BaseGraph extender |
39 | 39 |
template <typename Base> |
40 | 40 |
class UndirDigraphExtender : public Base { |
41 | 41 |
|
42 | 42 |
public: |
43 | 43 |
|
44 | 44 |
typedef Base Parent; |
45 | 45 |
typedef typename Parent::Arc Edge; |
46 | 46 |
typedef typename Parent::Node Node; |
47 | 47 |
|
48 | 48 |
typedef True UndirectedTag; |
49 | 49 |
|
50 | 50 |
class Arc : public Edge { |
51 | 51 |
friend class UndirDigraphExtender; |
52 | 52 |
|
53 | 53 |
protected: |
54 | 54 |
bool forward; |
55 | 55 |
|
56 | 56 |
Arc(const Edge &ue, bool _forward) : |
57 | 57 |
Edge(ue), forward(_forward) {} |
58 | 58 |
|
59 | 59 |
public: |
60 | 60 |
Arc() {} |
61 | 61 |
|
62 | 62 |
/// Invalid arc constructor |
63 | 63 |
Arc(Invalid i) : Edge(i), forward(true) {} |
64 | 64 |
|
65 | 65 |
bool operator==(const Arc &that) const { |
66 | 66 |
return forward==that.forward && Edge(*this)==Edge(that); |
67 | 67 |
} |
68 | 68 |
bool operator!=(const Arc &that) const { |
69 | 69 |
return forward!=that.forward || Edge(*this)!=Edge(that); |
70 | 70 |
} |
71 | 71 |
bool operator<(const Arc &that) const { |
72 | 72 |
return forward<that.forward || |
73 | 73 |
(!(that.forward<forward) && Edge(*this)<Edge(that)); |
74 | 74 |
} |
75 | 75 |
}; |
76 | 76 |
|
77 | 77 |
|
78 | 78 |
|
79 | 79 |
using Parent::source; |
80 | 80 |
|
81 | 81 |
/// Source of the given Arc. |
82 | 82 |
Node source(const Arc &e) const { |
83 | 83 |
return e.forward ? Parent::source(e) : Parent::target(e); |
84 | 84 |
} |
85 | 85 |
|
86 | 86 |
using Parent::target; |
87 | 87 |
|
88 | 88 |
/// Target of the given Arc. |
89 | 89 |
Node target(const Arc &e) const { |
90 | 90 |
return e.forward ? Parent::target(e) : Parent::source(e); |
91 | 91 |
} |
92 | 92 |
|
93 | 93 |
/// \brief Directed arc from an edge. |
94 | 94 |
/// |
95 | 95 |
/// Returns a directed arc corresponding to the specified Edge. |
96 | 96 |
/// If the given bool is true the given edge and the |
97 | 97 |
/// returned arc have the same source node. |
98 | 98 |
static Arc direct(const Edge &ue, bool d) { |
99 | 99 |
return Arc(ue, d); |
1 |
/* -*- C++ -*- |
|
1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
|
2 | 2 |
* |
3 |
* This file is a part of LEMON, a generic C++ optimization library |
|
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 |
#ifndef LEMON_BEZIER_H |
20 | 20 |
#define LEMON_BEZIER_H |
21 | 21 |
|
22 | 22 |
///\ingroup misc |
23 | 23 |
///\file |
24 | 24 |
///\brief Classes to compute with Bezier curves. |
25 | 25 |
/// |
26 | 26 |
///Up to now this file is used internally by \ref graph_to_eps.h |
27 | 27 |
|
28 | 28 |
#include<lemon/dim2.h> |
29 | 29 |
|
30 | 30 |
namespace lemon { |
31 | 31 |
namespace dim2 { |
32 | 32 |
|
33 | 33 |
class BezierBase { |
34 | 34 |
public: |
35 | 35 |
typedef lemon::dim2::Point<double> Point; |
36 | 36 |
protected: |
37 | 37 |
static Point conv(Point x,Point y,double t) {return (1-t)*x+t*y;} |
38 | 38 |
}; |
39 | 39 |
|
40 | 40 |
class Bezier1 : public BezierBase |
41 | 41 |
{ |
42 | 42 |
public: |
43 | 43 |
Point p1,p2; |
44 | 44 |
|
45 | 45 |
Bezier1() {} |
46 | 46 |
Bezier1(Point _p1, Point _p2) :p1(_p1), p2(_p2) {} |
47 | 47 |
|
48 | 48 |
Point operator()(double t) const |
49 | 49 |
{ |
50 | 50 |
// return conv(conv(p1,p2,t),conv(p2,p3,t),t); |
51 | 51 |
return conv(p1,p2,t); |
52 | 52 |
} |
53 | 53 |
Bezier1 before(double t) const |
54 | 54 |
{ |
55 | 55 |
return Bezier1(p1,conv(p1,p2,t)); |
56 | 56 |
} |
57 | 57 |
|
58 | 58 |
Bezier1 after(double t) const |
59 | 59 |
{ |
60 | 60 |
return Bezier1(conv(p1,p2,t),p2); |
61 | 61 |
} |
62 | 62 |
|
63 | 63 |
Bezier1 revert() const { return Bezier1(p2,p1);} |
64 | 64 |
Bezier1 operator()(double a,double b) const { return before(b).after(a/b); } |
65 | 65 |
Point grad() const { return p2-p1; } |
66 | 66 |
Point norm() const { return rot90(p2-p1); } |
67 | 67 |
Point grad(double) const { return grad(); } |
68 | 68 |
Point norm(double t) const { return rot90(grad(t)); } |
69 | 69 |
}; |
70 | 70 |
|
71 | 71 |
class Bezier2 : public BezierBase |
72 | 72 |
{ |
73 | 73 |
public: |
74 | 74 |
Point p1,p2,p3; |
75 | 75 |
|
76 | 76 |
Bezier2() {} |
77 | 77 |
Bezier2(Point _p1, Point _p2, Point _p3) :p1(_p1), p2(_p2), p3(_p3) {} |
78 | 78 |
Bezier2(const Bezier1 &b) : p1(b.p1), p2(conv(b.p1,b.p2,.5)), p3(b.p2) {} |
79 | 79 |
Point operator()(double t) const |
80 | 80 |
{ |
81 | 81 |
// return conv(conv(p1,p2,t),conv(p2,p3,t),t); |
82 | 82 |
return ((1-t)*(1-t))*p1+(2*(1-t)*t)*p2+(t*t)*p3; |
83 | 83 |
} |
84 | 84 |
Bezier2 before(double t) const |
85 | 85 |
{ |
86 | 86 |
Point q(conv(p1,p2,t)); |
87 | 87 |
Point r(conv(p2,p3,t)); |
88 | 88 |
return Bezier2(p1,q,conv(q,r,t)); |
89 | 89 |
} |
90 | 90 |
|
91 | 91 |
Bezier2 after(double t) const |
92 | 92 |
{ |
93 | 93 |
Point q(conv(p1,p2,t)); |
94 | 94 |
Point r(conv(p2,p3,t)); |
95 | 95 |
return Bezier2(conv(q,r,t),r,p3); |
96 | 96 |
} |
97 | 97 |
Bezier2 revert() const { return Bezier2(p3,p2,p1);} |
98 | 98 |
Bezier2 operator()(double a,double b) const { return before(b).after(a/b); } |
99 | 99 |
Bezier1 grad() const { return Bezier1(2.0*(p2-p1),2.0*(p3-p2)); } |
1 |
/* -*- C++ -*- |
|
1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
|
2 | 2 |
* |
3 |
* This file is a part of LEMON, a generic C++ optimization library |
|
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 |
#ifndef LEMON_BITS_DEFAULT_MAP_H |
20 | 20 |
#define LEMON_BITS_DEFAULT_MAP_H |
21 | 21 |
|
22 | 22 |
|
23 | 23 |
#include <lemon/bits/array_map.h> |
24 | 24 |
#include <lemon/bits/vector_map.h> |
25 | 25 |
//#include <lemon/bits/debug_map.h> |
26 | 26 |
|
27 | 27 |
///\ingroup graphbits |
28 | 28 |
///\file |
29 | 29 |
///\brief Graph maps that construct and destruct their elements dynamically. |
30 | 30 |
|
31 | 31 |
namespace lemon { |
32 | 32 |
|
33 | 33 |
|
34 | 34 |
//#ifndef LEMON_USE_DEBUG_MAP |
35 | 35 |
|
36 | 36 |
template <typename _Graph, typename _Item, typename _Value> |
37 | 37 |
struct DefaultMapSelector { |
38 | 38 |
typedef ArrayMap<_Graph, _Item, _Value> Map; |
39 | 39 |
}; |
40 | 40 |
|
41 | 41 |
// bool |
42 | 42 |
template <typename _Graph, typename _Item> |
43 | 43 |
struct DefaultMapSelector<_Graph, _Item, bool> { |
44 | 44 |
typedef VectorMap<_Graph, _Item, bool> Map; |
45 | 45 |
}; |
46 | 46 |
|
47 | 47 |
// char |
48 | 48 |
template <typename _Graph, typename _Item> |
49 | 49 |
struct DefaultMapSelector<_Graph, _Item, char> { |
50 | 50 |
typedef VectorMap<_Graph, _Item, char> Map; |
51 | 51 |
}; |
52 | 52 |
|
53 | 53 |
template <typename _Graph, typename _Item> |
54 | 54 |
struct DefaultMapSelector<_Graph, _Item, signed char> { |
55 | 55 |
typedef VectorMap<_Graph, _Item, signed char> Map; |
56 | 56 |
}; |
57 | 57 |
|
58 | 58 |
template <typename _Graph, typename _Item> |
59 | 59 |
struct DefaultMapSelector<_Graph, _Item, unsigned char> { |
60 | 60 |
typedef VectorMap<_Graph, _Item, unsigned char> Map; |
61 | 61 |
}; |
62 | 62 |
|
63 | 63 |
|
64 | 64 |
// int |
65 | 65 |
template <typename _Graph, typename _Item> |
66 | 66 |
struct DefaultMapSelector<_Graph, _Item, signed int> { |
67 | 67 |
typedef VectorMap<_Graph, _Item, signed int> Map; |
68 | 68 |
}; |
69 | 69 |
|
70 | 70 |
template <typename _Graph, typename _Item> |
71 | 71 |
struct DefaultMapSelector<_Graph, _Item, unsigned int> { |
72 | 72 |
typedef VectorMap<_Graph, _Item, unsigned int> Map; |
73 | 73 |
}; |
74 | 74 |
|
75 | 75 |
|
76 | 76 |
// short |
77 | 77 |
template <typename _Graph, typename _Item> |
78 | 78 |
struct DefaultMapSelector<_Graph, _Item, signed short> { |
79 | 79 |
typedef VectorMap<_Graph, _Item, signed short> Map; |
80 | 80 |
}; |
81 | 81 |
|
82 | 82 |
template <typename _Graph, typename _Item> |
83 | 83 |
struct DefaultMapSelector<_Graph, _Item, unsigned short> { |
84 | 84 |
typedef VectorMap<_Graph, _Item, unsigned short> Map; |
85 | 85 |
}; |
86 | 86 |
|
87 | 87 |
|
88 | 88 |
// long |
89 | 89 |
template <typename _Graph, typename _Item> |
90 | 90 |
struct DefaultMapSelector<_Graph, _Item, signed long> { |
91 | 91 |
typedef VectorMap<_Graph, _Item, signed long> Map; |
92 | 92 |
}; |
93 | 93 |
|
94 | 94 |
template <typename _Graph, typename _Item> |
95 | 95 |
struct DefaultMapSelector<_Graph, _Item, unsigned long> { |
96 | 96 |
typedef VectorMap<_Graph, _Item, unsigned long> Map; |
97 | 97 |
}; |
98 | 98 |
|
99 | 99 |
1 |
/* -*- C++ -*- |
|
1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
|
2 | 2 |
* |
3 |
* This file is a part of LEMON, a generic C++ optimization library |
|
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 |
#ifndef LEMON_BITS_GRAPH_EXTENDER_H |
20 | 20 |
#define LEMON_BITS_GRAPH_EXTENDER_H |
21 | 21 |
|
22 | 22 |
#include <lemon/bits/invalid.h> |
23 | 23 |
#include <lemon/bits/utility.h> |
24 | 24 |
|
25 | 25 |
#include <lemon/bits/map_extender.h> |
26 | 26 |
#include <lemon/bits/default_map.h> |
27 | 27 |
|
28 | 28 |
#include <lemon/concept_check.h> |
29 | 29 |
#include <lemon/concepts/maps.h> |
30 | 30 |
|
31 | 31 |
///\ingroup graphbits |
32 | 32 |
///\file |
33 | 33 |
///\brief Extenders for the digraph types |
34 | 34 |
namespace lemon { |
35 | 35 |
|
36 | 36 |
/// \ingroup graphbits |
37 | 37 |
/// |
38 | 38 |
/// \brief Extender for the Digraphs |
39 | 39 |
template <typename Base> |
40 | 40 |
class DigraphExtender : public Base { |
41 | 41 |
public: |
42 | 42 |
|
43 | 43 |
typedef Base Parent; |
44 | 44 |
typedef DigraphExtender Digraph; |
45 | 45 |
|
46 | 46 |
// Base extensions |
47 | 47 |
|
48 | 48 |
typedef typename Parent::Node Node; |
49 | 49 |
typedef typename Parent::Arc Arc; |
50 | 50 |
|
51 | 51 |
int maxId(Node) const { |
52 | 52 |
return Parent::maxNodeId(); |
53 | 53 |
} |
54 | 54 |
|
55 | 55 |
int maxId(Arc) const { |
56 | 56 |
return Parent::maxArcId(); |
57 | 57 |
} |
58 | 58 |
|
59 | 59 |
Node fromId(int id, Node) const { |
60 | 60 |
return Parent::nodeFromId(id); |
61 | 61 |
} |
62 | 62 |
|
63 | 63 |
Arc fromId(int id, Arc) const { |
64 | 64 |
return Parent::arcFromId(id); |
65 | 65 |
} |
66 | 66 |
|
67 | 67 |
Node oppositeNode(const Node &node, const Arc &arc) const { |
68 | 68 |
if (node == Parent::source(arc)) |
69 | 69 |
return Parent::target(arc); |
70 | 70 |
else if(node == Parent::target(arc)) |
71 | 71 |
return Parent::source(arc); |
72 | 72 |
else |
73 | 73 |
return INVALID; |
74 | 74 |
} |
75 | 75 |
|
76 | 76 |
// Alterable extension |
77 | 77 |
|
78 | 78 |
typedef AlterationNotifier<DigraphExtender, Node> NodeNotifier; |
79 | 79 |
typedef AlterationNotifier<DigraphExtender, Arc> ArcNotifier; |
80 | 80 |
|
81 | 81 |
|
82 | 82 |
protected: |
83 | 83 |
|
84 | 84 |
mutable NodeNotifier node_notifier; |
85 | 85 |
mutable ArcNotifier arc_notifier; |
86 | 86 |
|
87 | 87 |
public: |
88 | 88 |
|
89 | 89 |
NodeNotifier& notifier(Node) const { |
90 | 90 |
return node_notifier; |
91 | 91 |
} |
92 | 92 |
|
93 | 93 |
ArcNotifier& notifier(Arc) const { |
94 | 94 |
return arc_notifier; |
95 | 95 |
} |
96 | 96 |
|
97 | 97 |
class NodeIt : public Node { |
98 | 98 |
const Digraph* _digraph; |
99 | 99 |
public: |
1 |
/* -*- C++ -*- |
|
1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
|
2 | 2 |
* |
3 |
* This file is a part of LEMON, a generic C++ optimization library |
|
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 |
#ifndef LEMON_BITS_INVALID_H |
20 | 20 |
#define LEMON_BITS_INVALID_H |
21 | 21 |
|
22 | 22 |
///\file |
23 | 23 |
///\brief Definition of INVALID. |
24 | 24 |
|
25 | 25 |
namespace lemon { |
26 | 26 |
|
27 | 27 |
/// \brief Dummy type to make it easier to create invalid iterators. |
28 | 28 |
/// |
29 | 29 |
/// Dummy type to make it easier to create invalid iterators. |
30 | 30 |
/// See \ref INVALID for the usage. |
31 | 31 |
struct Invalid { |
32 | 32 |
public: |
33 | 33 |
bool operator==(Invalid) { return true; } |
34 | 34 |
bool operator!=(Invalid) { return false; } |
35 | 35 |
bool operator< (Invalid) { return false; } |
36 | 36 |
}; |
37 | 37 |
|
38 | 38 |
/// \brief Invalid iterators. |
39 | 39 |
/// |
40 | 40 |
/// \ref Invalid is a global type that converts to each iterator |
41 | 41 |
/// in such a way that the value of the target iterator will be invalid. |
42 | 42 |
|
43 | 43 |
//Some people didn't like this: |
44 | 44 |
//const Invalid &INVALID = *(Invalid *)0; |
45 | 45 |
|
46 | 46 |
#ifdef LEMON_ONLY_TEMPLATES |
47 | 47 |
const Invalid INVALID = Invalid(); |
48 | 48 |
#else |
49 | 49 |
extern const Invalid INVALID; |
50 | 50 |
#endif |
51 | 51 |
|
52 | 52 |
} //namespace lemon |
53 | 53 |
|
54 | 54 |
#endif |
55 | 55 |
|
1 |
/* -*- C++ -*- |
|
1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
|
2 | 2 |
* |
3 |
* This file is a part of LEMON, a generic C++ optimization library |
|
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 |
#ifndef LEMON_BITS_MAP_EXTENDER_H |
20 | 20 |
#define LEMON_BITS_MAP_EXTENDER_H |
21 | 21 |
|
22 | 22 |
#include <iterator> |
23 | 23 |
|
24 | 24 |
#include <lemon/bits/traits.h> |
25 | 25 |
|
26 | 26 |
#include <lemon/concept_check.h> |
27 | 27 |
#include <lemon/concepts/maps.h> |
28 | 28 |
|
29 | 29 |
///\file |
30 | 30 |
///\brief Extenders for iterable maps. |
31 | 31 |
|
32 | 32 |
namespace lemon { |
33 | 33 |
|
34 | 34 |
/// \ingroup graphbits |
35 | 35 |
/// |
36 | 36 |
/// \brief Extender for maps |
37 | 37 |
template <typename _Map> |
38 | 38 |
class MapExtender : public _Map { |
39 | 39 |
public: |
40 | 40 |
|
41 | 41 |
typedef _Map Parent; |
42 | 42 |
typedef MapExtender Map; |
43 | 43 |
|
44 | 44 |
|
45 | 45 |
typedef typename Parent::Graph Graph; |
46 | 46 |
typedef typename Parent::Key Item; |
47 | 47 |
|
48 | 48 |
typedef typename Parent::Key Key; |
49 | 49 |
typedef typename Parent::Value Value; |
50 | 50 |
|
51 | 51 |
class MapIt; |
52 | 52 |
class ConstMapIt; |
53 | 53 |
|
54 | 54 |
friend class MapIt; |
55 | 55 |
friend class ConstMapIt; |
56 | 56 |
|
57 | 57 |
public: |
58 | 58 |
|
59 | 59 |
MapExtender(const Graph& graph) |
60 | 60 |
: Parent(graph) {} |
61 | 61 |
|
62 | 62 |
MapExtender(const Graph& graph, const Value& value) |
63 | 63 |
: Parent(graph, value) {} |
64 | 64 |
|
65 | 65 |
MapExtender& operator=(const MapExtender& cmap) { |
66 | 66 |
return operator=<MapExtender>(cmap); |
67 | 67 |
} |
68 | 68 |
|
69 | 69 |
template <typename CMap> |
70 | 70 |
MapExtender& operator=(const CMap& cmap) { |
71 | 71 |
Parent::operator=(cmap); |
72 | 72 |
return *this; |
73 | 73 |
} |
74 | 74 |
|
75 | 75 |
class MapIt : public Item { |
76 | 76 |
public: |
77 | 77 |
|
78 | 78 |
typedef Item Parent; |
79 | 79 |
typedef typename Map::Value Value; |
80 | 80 |
|
81 | 81 |
MapIt() {} |
82 | 82 |
|
83 | 83 |
MapIt(Invalid i) : Parent(i) { } |
84 | 84 |
|
85 | 85 |
explicit MapIt(Map& _map) : map(_map) { |
86 | 86 |
map.notifier()->first(*this); |
87 | 87 |
} |
88 | 88 |
|
89 | 89 |
MapIt(const Map& _map, const Item& item) |
90 | 90 |
: Parent(item), map(_map) {} |
91 | 91 |
|
92 | 92 |
MapIt& operator++() { |
93 | 93 |
map.notifier()->next(*this); |
94 | 94 |
return *this; |
95 | 95 |
} |
96 | 96 |
|
97 | 97 |
typename MapTraits<Map>::ConstReturnValue operator*() const { |
98 | 98 |
return map[*this]; |
99 | 99 |
} |
1 |
/* -*- C++ -*- |
|
1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
|
2 | 2 |
* |
3 |
* This file is a part of LEMON, a generic C++ optimization library |
|
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 |
#ifndef LEMON_BITS_PRED_MAP_PATH_H |
20 | 20 |
#define LEMON_BITS_PRED_MAP_PATH_H |
21 | 21 |
|
22 | 22 |
namespace lemon { |
23 | 23 |
|
24 | 24 |
template <typename _Digraph, typename _PredMap> |
25 | 25 |
class PredMapPath { |
26 | 26 |
public: |
27 | 27 |
typedef True RevPathTag; |
28 | 28 |
|
29 | 29 |
typedef _Digraph Digraph; |
30 | 30 |
typedef typename Digraph::Arc Arc; |
31 | 31 |
typedef _PredMap PredMap; |
32 | 32 |
|
33 | 33 |
PredMapPath(const Digraph& _digraph, const PredMap& _predMap, |
34 | 34 |
typename Digraph::Node _target) |
35 | 35 |
: digraph(_digraph), predMap(_predMap), target(_target) {} |
36 | 36 |
|
37 | 37 |
int length() const { |
38 | 38 |
int len = 0; |
39 | 39 |
typename Digraph::Node node = target; |
40 | 40 |
typename Digraph::Arc arc; |
41 | 41 |
while ((arc = predMap[node]) != INVALID) { |
42 | 42 |
node = digraph.source(arc); |
43 | 43 |
++len; |
44 | 44 |
} |
45 | 45 |
return len; |
46 | 46 |
} |
47 | 47 |
|
48 | 48 |
bool empty() const { |
49 | 49 |
return predMap[target] != INVALID; |
50 | 50 |
} |
51 | 51 |
|
52 | 52 |
class RevArcIt { |
53 | 53 |
public: |
54 | 54 |
RevArcIt() {} |
55 | 55 |
RevArcIt(Invalid) : path(0), current(INVALID) {} |
56 | 56 |
RevArcIt(const PredMapPath& _path) |
57 | 57 |
: path(&_path), current(_path.target) { |
58 | 58 |
if (path->predMap[current] == INVALID) current = INVALID; |
59 | 59 |
} |
60 | 60 |
|
61 | 61 |
operator const typename Digraph::Arc() const { |
62 | 62 |
return path->predMap[current]; |
63 | 63 |
} |
64 | 64 |
|
65 | 65 |
RevArcIt& operator++() { |
66 | 66 |
current = path->digraph.source(path->predMap[current]); |
67 | 67 |
if (path->predMap[current] == INVALID) current = INVALID; |
68 | 68 |
return *this; |
69 | 69 |
} |
70 | 70 |
|
71 | 71 |
bool operator==(const RevArcIt& e) const { |
72 | 72 |
return current == e.current; |
73 | 73 |
} |
74 | 74 |
|
75 | 75 |
bool operator!=(const RevArcIt& e) const { |
76 | 76 |
return current != e.current; |
77 | 77 |
} |
78 | 78 |
|
79 | 79 |
bool operator<(const RevArcIt& e) const { |
80 | 80 |
return current < e.current; |
81 | 81 |
} |
82 | 82 |
|
83 | 83 |
private: |
84 | 84 |
const PredMapPath* path; |
85 | 85 |
typename Digraph::Node current; |
86 | 86 |
}; |
87 | 87 |
|
88 | 88 |
private: |
89 | 89 |
const Digraph& digraph; |
90 | 90 |
const PredMap& predMap; |
91 | 91 |
typename Digraph::Node target; |
92 | 92 |
}; |
93 | 93 |
|
94 | 94 |
|
95 | 95 |
template <typename _Digraph, typename _PredMatrixMap> |
96 | 96 |
class PredMatrixMapPath { |
97 | 97 |
public: |
98 | 98 |
typedef True RevPathTag; |
99 | 99 |
1 |
|
|
2 |
/* -*- C++ -*- |
|
1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
|
3 | 2 |
* |
4 |
* This file is a part of LEMON, a generic C++ optimization library |
|
3 |
* This file is a part of LEMON, a generic C++ optimization library. |
|
5 | 4 |
* |
6 | 5 |
* Copyright (C) 2003-2008 |
7 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
8 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
9 | 8 |
* |
10 | 9 |
* Permission to use, modify and distribute this software is granted |
11 | 10 |
* provided that this copyright notice appears in all copies. For |
12 | 11 |
* precise terms see the accompanying LICENSE file. |
13 | 12 |
* |
14 | 13 |
* This software is provided "AS IS" with no warranty of any kind, |
15 | 14 |
* express or implied, and with no claim as to its suitability for any |
16 | 15 |
* purpose. |
17 | 16 |
* |
18 | 17 |
*/ |
19 | 18 |
|
20 | 19 |
#ifndef LEMON_BITS_TRAITS_H |
21 | 20 |
#define LEMON_BITS_TRAITS_H |
22 | 21 |
|
23 | 22 |
#include <lemon/bits/utility.h> |
24 | 23 |
|
25 | 24 |
///\file |
26 | 25 |
///\brief Traits for graphs and maps |
27 | 26 |
/// |
28 | 27 |
|
29 | 28 |
namespace lemon { |
30 | 29 |
template <typename _Graph, typename _Item> |
31 | 30 |
class ItemSetTraits {}; |
32 | 31 |
|
33 | 32 |
|
34 | 33 |
template <typename Graph, typename Enable = void> |
35 | 34 |
struct NodeNotifierIndicator { |
36 | 35 |
typedef InvalidType Type; |
37 | 36 |
}; |
38 | 37 |
template <typename Graph> |
39 | 38 |
struct NodeNotifierIndicator< |
40 | 39 |
Graph, |
41 | 40 |
typename enable_if<typename Graph::NodeNotifier::Notifier, void>::type |
42 | 41 |
> { |
43 | 42 |
typedef typename Graph::NodeNotifier Type; |
44 | 43 |
}; |
45 | 44 |
|
46 | 45 |
template <typename _Graph> |
47 | 46 |
class ItemSetTraits<_Graph, typename _Graph::Node> { |
48 | 47 |
public: |
49 | 48 |
|
50 | 49 |
typedef _Graph Graph; |
51 | 50 |
|
52 | 51 |
typedef typename Graph::Node Item; |
53 | 52 |
typedef typename Graph::NodeIt ItemIt; |
54 | 53 |
|
55 | 54 |
typedef typename NodeNotifierIndicator<Graph>::Type ItemNotifier; |
56 | 55 |
|
57 | 56 |
template <typename _Value> |
58 | 57 |
class Map : public Graph::template NodeMap<_Value> { |
59 | 58 |
public: |
60 | 59 |
typedef typename Graph::template NodeMap<_Value> Parent; |
61 | 60 |
typedef typename Graph::template NodeMap<_Value> Type; |
62 | 61 |
typedef typename Parent::Value Value; |
63 | 62 |
|
64 | 63 |
Map(const Graph& _digraph) : Parent(_digraph) {} |
65 | 64 |
Map(const Graph& _digraph, const Value& _value) |
66 | 65 |
: Parent(_digraph, _value) {} |
67 | 66 |
|
68 | 67 |
}; |
69 | 68 |
|
70 | 69 |
}; |
71 | 70 |
|
72 | 71 |
template <typename Graph, typename Enable = void> |
73 | 72 |
struct ArcNotifierIndicator { |
74 | 73 |
typedef InvalidType Type; |
75 | 74 |
}; |
76 | 75 |
template <typename Graph> |
77 | 76 |
struct ArcNotifierIndicator< |
78 | 77 |
Graph, |
79 | 78 |
typename enable_if<typename Graph::ArcNotifier::Notifier, void>::type |
80 | 79 |
> { |
81 | 80 |
typedef typename Graph::ArcNotifier Type; |
82 | 81 |
}; |
83 | 82 |
|
84 | 83 |
template <typename _Graph> |
85 | 84 |
class ItemSetTraits<_Graph, typename _Graph::Arc> { |
86 | 85 |
public: |
87 | 86 |
|
88 | 87 |
typedef _Graph Graph; |
89 | 88 |
|
90 | 89 |
typedef typename Graph::Arc Item; |
91 | 90 |
typedef typename Graph::ArcIt ItemIt; |
92 | 91 |
|
93 | 92 |
typedef typename ArcNotifierIndicator<Graph>::Type ItemNotifier; |
94 | 93 |
|
95 | 94 |
template <typename _Value> |
96 | 95 |
class Map : public Graph::template ArcMap<_Value> { |
97 | 96 |
public: |
98 | 97 |
typedef typename Graph::template ArcMap<_Value> Parent; |
99 | 98 |
typedef typename Graph::template ArcMap<_Value> Type; |
100 | 99 |
typedef typename Parent::Value Value; |
1 |
/* -*- C++ -*- |
|
1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
|
2 | 2 |
* |
3 |
* This file is a part of LEMON, a generic C++ optimization library |
|
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 |
// This file contains a modified version of the enable_if library from BOOST. |
20 | 20 |
// See the appropriate copyright notice below. |
21 | 21 |
|
22 | 22 |
// Boost enable_if library |
23 | 23 |
|
24 | 24 |
// Copyright 2003 (c) The Trustees of Indiana University. |
25 | 25 |
|
26 | 26 |
// Use, modification, and distribution is subject to the Boost Software |
27 | 27 |
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at |
28 | 28 |
// http://www.boost.org/LICENSE_1_0.txt) |
29 | 29 |
|
30 | 30 |
// Authors: Jaakko Jarvi (jajarvi at osl.iu.edu) |
31 | 31 |
// Jeremiah Willcock (jewillco at osl.iu.edu) |
32 | 32 |
// Andrew Lumsdaine (lums at osl.iu.edu) |
33 | 33 |
|
34 | 34 |
|
35 | 35 |
#ifndef LEMON_BITS_UTILITY_H |
36 | 36 |
#define LEMON_BITS_UTILITY_H |
37 | 37 |
|
38 | 38 |
///\file |
39 | 39 |
///\brief Miscellaneous basic utilities |
40 | 40 |
/// |
41 | 41 |
///\todo Please rethink the organisation of the basic files like this. |
42 | 42 |
///E.g. this file might be merged with invalid.h. |
43 | 43 |
|
44 | 44 |
|
45 | 45 |
namespace lemon |
46 | 46 |
{ |
47 | 47 |
|
48 | 48 |
/// Basic type for defining "tags". A "YES" condition for \c enable_if. |
49 | 49 |
|
50 | 50 |
/// Basic type for defining "tags". A "YES" condition for \c enable_if. |
51 | 51 |
/// |
52 | 52 |
///\sa False |
53 | 53 |
/// |
54 | 54 |
/// \todo This should go to a separate "basic_types.h" (or something) |
55 | 55 |
/// file. |
56 | 56 |
struct True { |
57 | 57 |
///\e |
58 | 58 |
static const bool value = true; |
59 | 59 |
}; |
60 | 60 |
|
61 | 61 |
/// Basic type for defining "tags". A "NO" condition for \c enable_if. |
62 | 62 |
|
63 | 63 |
/// Basic type for defining "tags". A "NO" condition for \c enable_if. |
64 | 64 |
/// |
65 | 65 |
///\sa True |
66 | 66 |
struct False { |
67 | 67 |
///\e |
68 | 68 |
static const bool value = false; |
69 | 69 |
}; |
70 | 70 |
|
71 | 71 |
|
72 | 72 |
struct InvalidType { |
73 | 73 |
}; |
74 | 74 |
|
75 | 75 |
template <typename T> |
76 | 76 |
struct Wrap { |
77 | 77 |
const T &value; |
78 | 78 |
Wrap(const T &t) : value(t) {} |
79 | 79 |
}; |
80 | 80 |
|
81 | 81 |
/**************** dummy class to avoid ambiguity ****************/ |
82 | 82 |
|
83 | 83 |
template<int T> struct dummy { dummy(int) {} }; |
84 | 84 |
|
85 | 85 |
/**************** enable_if from BOOST ****************/ |
86 | 86 |
|
87 | 87 |
template <typename Type, typename T = void> |
88 | 88 |
struct exists { |
89 | 89 |
typedef T type; |
90 | 90 |
}; |
91 | 91 |
|
92 | 92 |
|
93 | 93 |
template <bool B, class T = void> |
94 | 94 |
struct enable_if_c { |
95 | 95 |
typedef T type; |
96 | 96 |
}; |
97 | 97 |
|
98 | 98 |
template <class T> |
99 | 99 |
struct enable_if_c<false, T> {}; |
1 |
/* -*- C++ -*- |
|
1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
|
2 | 2 |
* |
3 |
* This file is a part of LEMON, a generic C++ optimization library |
|
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 |
#ifndef LEMON_BITS_VECTOR_MAP_H |
20 | 20 |
#define LEMON_BITS_VECTOR_MAP_H |
21 | 21 |
|
22 | 22 |
#include <vector> |
23 | 23 |
#include <algorithm> |
24 | 24 |
|
25 | 25 |
#include <lemon/bits/traits.h> |
26 | 26 |
#include <lemon/bits/utility.h> |
27 | 27 |
|
28 | 28 |
#include <lemon/bits/alteration_notifier.h> |
29 | 29 |
|
30 | 30 |
#include <lemon/concept_check.h> |
31 | 31 |
#include <lemon/concepts/maps.h> |
32 | 32 |
|
33 | 33 |
///\ingroup graphbits |
34 | 34 |
/// |
35 | 35 |
///\file |
36 | 36 |
///\brief Vector based graph maps. |
37 | 37 |
namespace lemon { |
38 | 38 |
|
39 | 39 |
/// \ingroup graphbits |
40 | 40 |
/// |
41 | 41 |
/// \brief Graph map based on the std::vector storage. |
42 | 42 |
/// |
43 | 43 |
/// The VectorMap template class is graph map structure what |
44 | 44 |
/// automatically updates the map when a key is added to or erased from |
45 | 45 |
/// the map. This map type uses the std::vector to store the values. |
46 | 46 |
/// |
47 | 47 |
/// \tparam _Notifier The AlterationNotifier that will notify this map. |
48 | 48 |
/// \tparam _Item The item type of the graph items. |
49 | 49 |
/// \tparam _Value The value type of the map. |
50 | 50 |
/// \todo Fix the doc: there is _Graph parameter instead of _Notifier. |
51 | 51 |
template <typename _Graph, typename _Item, typename _Value> |
52 | 52 |
class VectorMap |
53 | 53 |
: public ItemSetTraits<_Graph, _Item>::ItemNotifier::ObserverBase { |
54 | 54 |
private: |
55 | 55 |
|
56 | 56 |
/// The container type of the map. |
57 | 57 |
typedef std::vector<_Value> Container; |
58 | 58 |
|
59 | 59 |
public: |
60 | 60 |
|
61 | 61 |
/// The graph type of the map. |
62 | 62 |
typedef _Graph Graph; |
63 | 63 |
/// The item type of the map. |
64 | 64 |
typedef _Item Item; |
65 | 65 |
/// The reference map tag. |
66 | 66 |
typedef True ReferenceMapTag; |
67 | 67 |
|
68 | 68 |
/// The key type of the map. |
69 | 69 |
typedef _Item Key; |
70 | 70 |
/// The value type of the map. |
71 | 71 |
typedef _Value Value; |
72 | 72 |
|
73 | 73 |
/// The notifier type. |
74 | 74 |
typedef typename ItemSetTraits<_Graph, _Item>::ItemNotifier Notifier; |
75 | 75 |
|
76 | 76 |
/// The map type. |
77 | 77 |
typedef VectorMap Map; |
78 | 78 |
/// The base class of the map. |
79 | 79 |
typedef typename Notifier::ObserverBase Parent; |
80 | 80 |
|
81 | 81 |
/// The reference type of the map; |
82 | 82 |
typedef typename Container::reference Reference; |
83 | 83 |
/// The const reference type of the map; |
84 | 84 |
typedef typename Container::const_reference ConstReference; |
85 | 85 |
|
86 | 86 |
|
87 | 87 |
/// \brief Constructor to attach the new map into the notifier. |
88 | 88 |
/// |
89 | 89 |
/// It constructs a map and attachs it into the notifier. |
90 | 90 |
/// It adds all the items of the graph to the map. |
91 | 91 |
VectorMap(const Graph& graph) { |
92 | 92 |
Parent::attach(graph.notifier(Item())); |
93 | 93 |
container.resize(Parent::notifier()->maxId() + 1); |
94 | 94 |
} |
95 | 95 |
|
96 | 96 |
/// \brief Constructor uses given value to initialize the map. |
97 | 97 |
/// |
98 | 98 |
/// It constructs a map uses a given value to initialize the map. |
99 | 99 |
/// It adds all the items of the graph to the map. |
1 |
/* -*- C++ -*- |
|
1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
|
2 | 2 |
* |
3 |
* This file is a part of LEMON, a generic C++ optimization library |
|
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 |
///\file |
20 | 20 |
///\brief Color constants |
21 | 21 |
|
22 | 22 |
#include<lemon/color.h> |
23 | 23 |
|
24 | 24 |
namespace lemon { |
25 | 25 |
|
26 | 26 |
const Color WHITE(1,1,1); |
27 | 27 |
|
28 | 28 |
const Color BLACK(0,0,0); |
29 | 29 |
const Color RED(1,0,0); |
30 | 30 |
const Color GREEN(0,1,0); |
31 | 31 |
const Color BLUE(0,0,1); |
32 | 32 |
const Color YELLOW(1,1,0); |
33 | 33 |
const Color MAGENTA(1,0,1); |
34 | 34 |
const Color CYAN(0,1,1); |
35 | 35 |
|
36 | 36 |
const Color GREY(0,0,0); |
37 | 37 |
const Color DARK_RED(.5,0,0); |
38 | 38 |
const Color DARK_GREEN(0,.5,0); |
39 | 39 |
const Color DARK_BLUE(0,0,.5); |
40 | 40 |
const Color DARK_YELLOW(.5,.5,0); |
41 | 41 |
const Color DARK_MAGENTA(.5,0,.5); |
42 | 42 |
const Color DARK_CYAN(0,.5,.5); |
43 | 43 |
|
44 | 44 |
} //namespace lemon |
1 |
/* -*- C++ -*- |
|
1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
|
2 | 2 |
* |
3 |
* This file is a part of LEMON, a generic C++ optimization library |
|
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 |
#ifndef LEMON_COLOR_H |
20 | 20 |
#define LEMON_COLOR_H |
21 | 21 |
|
22 | 22 |
#include<vector> |
23 | 23 |
#include<lemon/math.h> |
24 | 24 |
#include<lemon/maps.h> |
25 | 25 |
|
26 | 26 |
|
27 | 27 |
///\ingroup misc |
28 | 28 |
///\file |
29 | 29 |
///\brief Tools to manage RGB colors. |
30 | 30 |
|
31 | 31 |
namespace lemon { |
32 | 32 |
|
33 | 33 |
|
34 | 34 |
/// \addtogroup misc |
35 | 35 |
/// @{ |
36 | 36 |
|
37 | 37 |
///Data structure representing RGB colors. |
38 | 38 |
|
39 | 39 |
///Data structure representing RGB colors. |
40 | 40 |
class Color |
41 | 41 |
{ |
42 | 42 |
double _r,_g,_b; |
43 | 43 |
public: |
44 | 44 |
///Default constructor |
45 | 45 |
Color() {} |
46 | 46 |
///Constructor |
47 | 47 |
Color(double r,double g,double b) :_r(r),_g(g),_b(b) {}; |
48 | 48 |
///Set the red component |
49 | 49 |
double & red() {return _r;} |
50 | 50 |
///Return the red component |
51 | 51 |
const double & red() const {return _r;} |
52 | 52 |
///Set the green component |
53 | 53 |
double & green() {return _g;} |
54 | 54 |
///Return the green component |
55 | 55 |
const double & green() const {return _g;} |
56 | 56 |
///Set the blue component |
57 | 57 |
double & blue() {return _b;} |
58 | 58 |
///Return the blue component |
59 | 59 |
const double & blue() const {return _b;} |
60 | 60 |
///Set the color components |
61 | 61 |
void set(double r,double g,double b) { _r=r;_g=g;_b=b; }; |
62 | 62 |
}; |
63 | 63 |
|
64 | 64 |
/// White color constant |
65 | 65 |
extern const Color WHITE; |
66 | 66 |
/// Black color constant |
67 | 67 |
extern const Color BLACK; |
68 | 68 |
/// Red color constant |
69 | 69 |
extern const Color RED; |
70 | 70 |
/// Green color constant |
71 | 71 |
extern const Color GREEN; |
72 | 72 |
/// Blue color constant |
73 | 73 |
extern const Color BLUE; |
74 | 74 |
/// Yellow color constant |
75 | 75 |
extern const Color YELLOW; |
76 | 76 |
/// Magenta color constant |
77 | 77 |
extern const Color MAGENTA; |
78 | 78 |
/// Cyan color constant |
79 | 79 |
extern const Color CYAN; |
80 | 80 |
/// Grey color constant |
81 | 81 |
extern const Color GREY; |
82 | 82 |
/// Dark red color constant |
83 | 83 |
extern const Color DARK_RED; |
84 | 84 |
/// Dark green color constant |
85 | 85 |
extern const Color DARK_GREEN; |
86 | 86 |
/// Drak blue color constant |
87 | 87 |
extern const Color DARK_BLUE; |
88 | 88 |
/// Dark yellow color constant |
89 | 89 |
extern const Color DARK_YELLOW; |
90 | 90 |
/// Dark magenta color constant |
91 | 91 |
extern const Color DARK_MAGENTA; |
92 | 92 |
/// Dark cyan color constant |
93 | 93 |
extern const Color DARK_CYAN; |
94 | 94 |
|
95 | 95 |
///Map <tt>int</tt>s to different \ref Color "Color"s |
96 | 96 |
|
97 | 97 |
///This map assigns one of the predefined \ref Color "Color"s to |
98 | 98 |
///each <tt>int</tt>. It is possible to change the colors as well as |
99 | 99 |
///their number. The integer range is cyclically mapped to the |
1 |
/* -*- C++ -*- |
|
1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
|
2 | 2 |
* |
3 |
* This file is a part of LEMON, a generic C++ optimization library |
|
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 |
// This file contains a modified version of the concept checking |
20 | 20 |
// utility from BOOST. |
21 | 21 |
// See the appropriate copyright notice below. |
22 | 22 |
|
23 | 23 |
// (C) Copyright Jeremy Siek 2000. |
24 | 24 |
// Distributed under the Boost Software License, Version 1.0. (See |
25 | 25 |
// accompanying file LICENSE_1_0.txt or copy at |
26 | 26 |
// http://www.boost.org/LICENSE_1_0.txt) |
27 | 27 |
// |
28 | 28 |
// Revision History: |
29 | 29 |
// 05 May 2001: Workarounds for HP aCC from Thomas Matelich. (Jeremy Siek) |
30 | 30 |
// 02 April 2001: Removed limits header altogether. (Jeremy Siek) |
31 | 31 |
// 01 April 2001: Modified to use new <boost/limits.hpp> header. (JMaddock) |
32 | 32 |
// |
33 | 33 |
|
34 | 34 |
// See http://www.boost.org/libs/concept_check for documentation. |
35 | 35 |
|
36 | 36 |
///\file |
37 | 37 |
///\brief Basic utilities for concept checking. |
38 | 38 |
/// |
39 | 39 |
///\todo Are we still using BOOST concept checking utility? |
40 | 40 |
///Is the BOOST copyright notice necessary? |
41 | 41 |
|
42 | 42 |
#ifndef LEMON_CONCEPT_CHECK_H |
43 | 43 |
#define LEMON_CONCEPT_CHECK_H |
44 | 44 |
|
45 | 45 |
namespace lemon { |
46 | 46 |
|
47 | 47 |
/* |
48 | 48 |
"inline" is used for ignore_unused_variable_warning() |
49 | 49 |
and function_requires() to make sure there is no |
50 | 50 |
overtarget with g++. |
51 | 51 |
*/ |
52 | 52 |
|
53 | 53 |
template <class T> inline void ignore_unused_variable_warning(const T&) { } |
54 | 54 |
|
55 | 55 |
///\e |
56 | 56 |
template <class Concept> |
57 | 57 |
inline void function_requires() |
58 | 58 |
{ |
59 | 59 |
#if !defined(NDEBUG) |
60 | 60 |
void (Concept::*x)() = & Concept::constraints; |
61 | 61 |
ignore_unused_variable_warning(x); |
62 | 62 |
#endif |
63 | 63 |
} |
64 | 64 |
|
65 | 65 |
///\e |
66 | 66 |
template <typename Concept, typename Type> |
67 | 67 |
inline void checkConcept() { |
68 | 68 |
#if !defined(NDEBUG) |
69 | 69 |
typedef typename Concept::template Constraints<Type> ConceptCheck; |
70 | 70 |
void (ConceptCheck::*x)() = & ConceptCheck::constraints; |
71 | 71 |
ignore_unused_variable_warning(x); |
72 | 72 |
#endif |
73 | 73 |
} |
74 | 74 |
|
75 | 75 |
} // namespace lemon |
76 | 76 |
|
77 | 77 |
#endif // LEMON_CONCEPT_CHECK_H |
1 |
/* -*- C++ -*- |
|
1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
|
2 | 2 |
* |
3 |
* This file is a part of LEMON, a generic C++ optimization library |
|
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 |
#ifndef LEMON_CONCEPT_DIGRAPH_H |
20 | 20 |
#define LEMON_CONCEPT_DIGRAPH_H |
21 | 21 |
|
22 | 22 |
///\ingroup graph_concepts |
23 | 23 |
///\file |
24 | 24 |
///\brief The concept of directed graphs. |
25 | 25 |
|
26 | 26 |
#include <lemon/bits/invalid.h> |
27 | 27 |
#include <lemon/bits/utility.h> |
28 | 28 |
#include <lemon/concepts/maps.h> |
29 | 29 |
#include <lemon/concept_check.h> |
30 | 30 |
#include <lemon/concepts/graph_components.h> |
31 | 31 |
|
32 | 32 |
namespace lemon { |
33 | 33 |
namespace concepts { |
34 | 34 |
|
35 | 35 |
/// \ingroup graph_concepts |
36 | 36 |
/// |
37 | 37 |
/// \brief Class describing the concept of directed graphs. |
38 | 38 |
/// |
39 | 39 |
/// This class describes the \ref concept "concept" of the |
40 | 40 |
/// immutable directed digraphs. |
41 | 41 |
/// |
42 | 42 |
/// Note that actual digraph implementation like @ref ListDigraph or |
43 | 43 |
/// @ref SmartDigraph may have several additional functionality. |
44 | 44 |
/// |
45 | 45 |
/// \sa concept |
46 | 46 |
class Digraph { |
47 | 47 |
private: |
48 | 48 |
///Digraphs are \e not copy constructible. Use DigraphCopy() instead. |
49 | 49 |
|
50 | 50 |
///Digraphs are \e not copy constructible. Use DigraphCopy() instead. |
51 | 51 |
/// |
52 | 52 |
Digraph(const Digraph &) {}; |
53 | 53 |
///\brief Assignment of \ref Digraph "Digraph"s to another ones are |
54 | 54 |
///\e not allowed. Use DigraphCopy() instead. |
55 | 55 |
|
56 | 56 |
///Assignment of \ref Digraph "Digraph"s to another ones are |
57 | 57 |
///\e not allowed. Use DigraphCopy() instead. |
58 | 58 |
|
59 | 59 |
void operator=(const Digraph &) {} |
60 | 60 |
public: |
61 | 61 |
///\e |
62 | 62 |
|
63 | 63 |
/// Defalult constructor. |
64 | 64 |
|
65 | 65 |
/// Defalult constructor. |
66 | 66 |
/// |
67 | 67 |
Digraph() { } |
68 | 68 |
/// Class for identifying a node of the digraph |
69 | 69 |
|
70 | 70 |
/// This class identifies a node of the digraph. It also serves |
71 | 71 |
/// as a base class of the node iterators, |
72 | 72 |
/// thus they will convert to this type. |
73 | 73 |
class Node { |
74 | 74 |
public: |
75 | 75 |
/// Default constructor |
76 | 76 |
|
77 | 77 |
/// @warning The default constructor sets the iterator |
78 | 78 |
/// to an undefined value. |
79 | 79 |
Node() { } |
80 | 80 |
/// Copy constructor. |
81 | 81 |
|
82 | 82 |
/// Copy constructor. |
83 | 83 |
/// |
84 | 84 |
Node(const Node&) { } |
85 | 85 |
|
86 | 86 |
/// Invalid constructor \& conversion. |
87 | 87 |
|
88 | 88 |
/// This constructor initializes the iterator to be invalid. |
89 | 89 |
/// \sa Invalid for more details. |
90 | 90 |
Node(Invalid) { } |
91 | 91 |
/// Equality operator |
92 | 92 |
|
93 | 93 |
/// Two iterators are equal if and only if they point to the |
94 | 94 |
/// same object or both are invalid. |
95 | 95 |
bool operator==(Node) const { return true; } |
96 | 96 |
|
97 | 97 |
/// Inequality operator |
98 | 98 |
|
99 | 99 |
/// \sa operator==(Node n) |
1 |
/* -*- C++ -*- |
|
1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
|
2 | 2 |
* |
3 |
* This file is a part of LEMON, a generic C++ optimization library |
|
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 |
///\ingroup graph_concepts |
20 | 20 |
///\file |
21 | 21 |
///\brief The concept of Undirected Graphs. |
22 | 22 |
|
23 | 23 |
#ifndef LEMON_CONCEPT_GRAPH_H |
24 | 24 |
#define LEMON_CONCEPT_GRAPH_H |
25 | 25 |
|
26 | 26 |
#include <lemon/concepts/graph_components.h> |
27 | 27 |
#include <lemon/concepts/graph.h> |
28 | 28 |
#include <lemon/bits/utility.h> |
29 | 29 |
|
30 | 30 |
namespace lemon { |
31 | 31 |
namespace concepts { |
32 | 32 |
|
33 | 33 |
/// \ingroup graph_concepts |
34 | 34 |
/// |
35 | 35 |
/// \brief Class describing the concept of Undirected Graphs. |
36 | 36 |
/// |
37 | 37 |
/// This class describes the common interface of all Undirected |
38 | 38 |
/// Graphs. |
39 | 39 |
/// |
40 | 40 |
/// As all concept describing classes it provides only interface |
41 | 41 |
/// without any sensible implementation. So any algorithm for |
42 | 42 |
/// undirected graph should compile with this class, but it will not |
43 | 43 |
/// run properly, of course. |
44 | 44 |
/// |
45 | 45 |
/// The LEMON undirected graphs also fulfill the concept of |
46 | 46 |
/// directed graphs (\ref lemon::concepts::Digraph "Digraph |
47 | 47 |
/// Concept"). Each edges can be seen as two opposite |
48 | 48 |
/// directed arc and consequently the undirected graph can be |
49 | 49 |
/// seen as the direceted graph of these directed arcs. The |
50 | 50 |
/// Graph has the Edge inner class for the edges and |
51 | 51 |
/// the Arc type for the directed arcs. The Arc type is |
52 | 52 |
/// convertible to Edge or inherited from it so from a directed |
53 | 53 |
/// arc we can get the represented edge. |
54 | 54 |
/// |
55 | 55 |
/// In the sense of the LEMON each edge has a default |
56 | 56 |
/// direction (it should be in every computer implementation, |
57 | 57 |
/// because the order of edge's nodes defines an |
58 | 58 |
/// orientation). With the default orientation we can define that |
59 | 59 |
/// the directed arc is forward or backward directed. With the \c |
60 | 60 |
/// direction() and \c direct() function we can get the direction |
61 | 61 |
/// of the directed arc and we can direct an edge. |
62 | 62 |
/// |
63 | 63 |
/// The EdgeIt is an iterator for the edges. We can use |
64 | 64 |
/// the EdgeMap to map values for the edges. The InArcIt and |
65 | 65 |
/// OutArcIt iterates on the same edges but with opposite |
66 | 66 |
/// direction. The IncEdgeIt iterates also on the same edges |
67 | 67 |
/// as the OutArcIt and InArcIt but it is not convertible to Arc just |
68 | 68 |
/// to Edge. |
69 | 69 |
class Graph { |
70 | 70 |
public: |
71 | 71 |
/// \brief The undirected graph should be tagged by the |
72 | 72 |
/// UndirectedTag. |
73 | 73 |
/// |
74 | 74 |
/// The undirected graph should be tagged by the UndirectedTag. This |
75 | 75 |
/// tag helps the enable_if technics to make compile time |
76 | 76 |
/// specializations for undirected graphs. |
77 | 77 |
typedef True UndirectedTag; |
78 | 78 |
|
79 | 79 |
/// \brief The base type of node iterators, |
80 | 80 |
/// or in other words, the trivial node iterator. |
81 | 81 |
/// |
82 | 82 |
/// This is the base type of each node iterator, |
83 | 83 |
/// thus each kind of node iterator converts to this. |
84 | 84 |
/// More precisely each kind of node iterator should be inherited |
85 | 85 |
/// from the trivial node iterator. |
86 | 86 |
class Node { |
87 | 87 |
public: |
88 | 88 |
/// Default constructor |
89 | 89 |
|
90 | 90 |
/// @warning The default constructor sets the iterator |
91 | 91 |
/// to an undefined value. |
92 | 92 |
Node() { } |
93 | 93 |
/// Copy constructor. |
94 | 94 |
|
95 | 95 |
/// Copy constructor. |
96 | 96 |
/// |
97 | 97 |
Node(const Node&) { } |
98 | 98 |
|
99 | 99 |
/// Invalid constructor \& conversion. |
1 |
/* -*- C++ -*- |
|
1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
|
2 | 2 |
* |
3 |
* This file is a part of LEMON, a generic C++ optimization library |
|
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 |
///\ingroup graph_concepts |
20 | 20 |
///\file |
21 | 21 |
///\brief The concept of graph components. |
22 | 22 |
|
23 | 23 |
|
24 | 24 |
#ifndef LEMON_CONCEPT_GRAPH_COMPONENTS_H |
25 | 25 |
#define LEMON_CONCEPT_GRAPH_COMPONENTS_H |
26 | 26 |
|
27 | 27 |
#include <lemon/bits/invalid.h> |
28 | 28 |
#include <lemon/concepts/maps.h> |
29 | 29 |
|
30 | 30 |
#include <lemon/bits/alteration_notifier.h> |
31 | 31 |
|
32 | 32 |
namespace lemon { |
33 | 33 |
namespace concepts { |
34 | 34 |
|
35 | 35 |
/// \brief Skeleton class for graph Node and Arc types |
36 | 36 |
/// |
37 | 37 |
/// This class describes the interface of Node and Arc (and Edge |
38 | 38 |
/// in undirected graphs) subtypes of graph types. |
39 | 39 |
/// |
40 | 40 |
/// \note This class is a template class so that we can use it to |
41 | 41 |
/// create graph skeleton classes. The reason for this is than Node |
42 | 42 |
/// and Arc types should \em not derive from the same base class. |
43 | 43 |
/// For Node you should instantiate it with character 'n' and for Arc |
44 | 44 |
/// with 'a'. |
45 | 45 |
|
46 | 46 |
#ifndef DOXYGEN |
47 | 47 |
template <char _selector = '0'> |
48 | 48 |
#endif |
49 | 49 |
class GraphItem { |
50 | 50 |
public: |
51 | 51 |
/// \brief Default constructor. |
52 | 52 |
/// |
53 | 53 |
/// \warning The default constructor is not required to set |
54 | 54 |
/// the item to some well-defined value. So you should consider it |
55 | 55 |
/// as uninitialized. |
56 | 56 |
GraphItem() {} |
57 | 57 |
/// \brief Copy constructor. |
58 | 58 |
/// |
59 | 59 |
/// Copy constructor. |
60 | 60 |
/// |
61 | 61 |
GraphItem(const GraphItem &) {} |
62 | 62 |
/// \brief Invalid constructor \& conversion. |
63 | 63 |
/// |
64 | 64 |
/// This constructor initializes the item to be invalid. |
65 | 65 |
/// \sa Invalid for more details. |
66 | 66 |
GraphItem(Invalid) {} |
67 | 67 |
/// \brief Assign operator for nodes. |
68 | 68 |
/// |
69 | 69 |
/// The nodes are assignable. |
70 | 70 |
/// |
71 | 71 |
GraphItem& operator=(GraphItem const&) { return *this; } |
72 | 72 |
/// \brief Equality operator. |
73 | 73 |
/// |
74 | 74 |
/// Two iterators are equal if and only if they represents the |
75 | 75 |
/// same node in the graph or both are invalid. |
76 | 76 |
bool operator==(GraphItem) const { return false; } |
77 | 77 |
/// \brief Inequality operator. |
78 | 78 |
/// |
79 | 79 |
/// \sa operator==(const Node& n) |
80 | 80 |
/// |
81 | 81 |
bool operator!=(GraphItem) const { return false; } |
82 | 82 |
|
83 | 83 |
/// \brief Artificial ordering operator. |
84 | 84 |
/// |
85 | 85 |
/// To allow the use of graph descriptors as key type in std::map or |
86 | 86 |
/// similar associative container we require this. |
87 | 87 |
/// |
88 | 88 |
/// \note This operator only have to define some strict ordering of |
89 | 89 |
/// the items; this order has nothing to do with the iteration |
90 | 90 |
/// ordering of the items. |
91 | 91 |
bool operator<(GraphItem) const { return false; } |
92 | 92 |
|
93 | 93 |
template<typename _GraphItem> |
94 | 94 |
struct Constraints { |
95 | 95 |
void constraints() { |
96 | 96 |
_GraphItem i1; |
97 | 97 |
_GraphItem i2 = i1; |
98 | 98 |
_GraphItem i3 = INVALID; |
99 | 99 |
|
1 |
/* -*- C++ -*- |
|
1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
|
2 | 2 |
* |
3 |
* This file is a part of LEMON, a generic C++ optimization library |
|
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 |
///\ingroup concept |
20 | 20 |
///\file |
21 | 21 |
///\brief The concept of heaps. |
22 | 22 |
|
23 | 23 |
#ifndef LEMON_CONCEPT_HEAP_H |
24 | 24 |
#define LEMON_CONCEPT_HEAP_H |
25 | 25 |
|
26 | 26 |
#include <lemon/bits/invalid.h> |
27 | 27 |
|
28 | 28 |
namespace lemon { |
29 | 29 |
|
30 | 30 |
namespace concepts { |
31 | 31 |
|
32 | 32 |
/// \addtogroup concept |
33 | 33 |
/// @{ |
34 | 34 |
|
35 | 35 |
/// \brief The heap concept. |
36 | 36 |
/// |
37 | 37 |
/// Concept class describing the main interface of heaps. |
38 | 38 |
template <typename Priority, typename ItemIntMap> |
39 | 39 |
class Heap { |
40 | 40 |
public: |
41 | 41 |
|
42 | 42 |
/// Type of the items stored in the heap. |
43 | 43 |
typedef typename ItemIntMap::Key Item; |
44 | 44 |
|
45 | 45 |
/// Type of the priorities. |
46 | 46 |
typedef Priority Prio; |
47 | 47 |
|
48 | 48 |
/// \brief Type to represent the states of the items. |
49 | 49 |
/// |
50 | 50 |
/// Each item has a state associated to it. It can be "in heap", |
51 | 51 |
/// "pre heap" or "post heap". The later two are indifferent |
52 | 52 |
/// from the point of view of the heap, but may be useful for |
53 | 53 |
/// the user. |
54 | 54 |
/// |
55 | 55 |
/// The \c ItemIntMap must be initialized in such a way, that it |
56 | 56 |
/// assigns \c PRE_HEAP (<tt>-1</tt>) to every item. |
57 | 57 |
enum State { |
58 | 58 |
IN_HEAP = 0, |
59 | 59 |
PRE_HEAP = -1, |
60 | 60 |
POST_HEAP = -2 |
61 | 61 |
}; |
62 | 62 |
|
63 | 63 |
/// \brief The constructor. |
64 | 64 |
/// |
65 | 65 |
/// The constructor. |
66 | 66 |
/// \param map A map that assigns \c int values to keys of type |
67 | 67 |
/// \c Item. It is used internally by the heap implementations to |
68 | 68 |
/// handle the cross references. The assigned value must be |
69 | 69 |
/// \c PRE_HEAP (<tt>-1</tt>) for every item. |
70 | 70 |
explicit Heap(ItemIntMap &map) {} |
71 | 71 |
|
72 | 72 |
/// \brief The number of items stored in the heap. |
73 | 73 |
/// |
74 | 74 |
/// Returns the number of items stored in the heap. |
75 | 75 |
int size() const { return 0; } |
76 | 76 |
|
77 | 77 |
/// \brief Checks if the heap is empty. |
78 | 78 |
/// |
79 | 79 |
/// Returns \c true if the heap is empty. |
80 | 80 |
bool empty() const { return false; } |
81 | 81 |
|
82 | 82 |
/// \brief Makes the heap empty. |
83 | 83 |
/// |
84 | 84 |
/// Makes the heap empty. |
85 | 85 |
void clear(); |
86 | 86 |
|
87 | 87 |
/// \brief Inserts an item into the heap with the given priority. |
88 | 88 |
/// |
89 | 89 |
/// Inserts the given item into the heap with the given priority. |
90 | 90 |
/// \param i The item to insert. |
91 | 91 |
/// \param p The priority of the item. |
92 | 92 |
void push(const Item &i, const Prio &p) {} |
93 | 93 |
|
94 | 94 |
/// \brief Returns the item having minimum priority. |
95 | 95 |
/// |
96 | 96 |
/// Returns the item having minimum priority. |
97 | 97 |
/// \pre The heap must be non-empty. |
98 | 98 |
Item top() const {} |
99 | 99 |
1 |
/* -*- C++ -*- |
|
1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
|
2 | 2 |
* |
3 |
* This file is a part of LEMON, a generic C++ optimization library |
|
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 |
#ifndef LEMON_CONCEPT_MAPS_H |
20 | 20 |
#define LEMON_CONCEPT_MAPS_H |
21 | 21 |
|
22 | 22 |
#include <lemon/bits/utility.h> |
23 | 23 |
#include <lemon/concept_check.h> |
24 | 24 |
|
25 | 25 |
///\ingroup concept |
26 | 26 |
///\file |
27 | 27 |
///\brief The concept of maps. |
28 | 28 |
|
29 | 29 |
namespace lemon { |
30 | 30 |
|
31 | 31 |
namespace concepts { |
32 | 32 |
|
33 | 33 |
/// \addtogroup concept |
34 | 34 |
/// @{ |
35 | 35 |
|
36 | 36 |
/// Readable map concept |
37 | 37 |
|
38 | 38 |
/// Readable map concept. |
39 | 39 |
/// |
40 | 40 |
template<typename K, typename T> |
41 | 41 |
class ReadMap |
42 | 42 |
{ |
43 | 43 |
public: |
44 | 44 |
/// The key type of the map. |
45 | 45 |
typedef K Key; |
46 | 46 |
/// The value type of the map. (The type of objects associated with the keys). |
47 | 47 |
typedef T Value; |
48 | 48 |
|
49 | 49 |
/// Returns the value associated with the given key. |
50 | 50 |
Value operator[](const Key &) const { |
51 | 51 |
return *static_cast<Value *>(0); |
52 | 52 |
} |
53 | 53 |
|
54 | 54 |
template<typename _ReadMap> |
55 | 55 |
struct Constraints { |
56 | 56 |
void constraints() { |
57 | 57 |
Value val = m[key]; |
58 | 58 |
val = m[key]; |
59 | 59 |
typename _ReadMap::Value own_val = m[own_key]; |
60 | 60 |
own_val = m[own_key]; |
61 | 61 |
|
62 | 62 |
ignore_unused_variable_warning(key); |
63 | 63 |
ignore_unused_variable_warning(val); |
64 | 64 |
ignore_unused_variable_warning(own_key); |
65 | 65 |
ignore_unused_variable_warning(own_val); |
66 | 66 |
} |
67 | 67 |
const Key& key; |
68 | 68 |
const typename _ReadMap::Key& own_key; |
69 | 69 |
const _ReadMap& m; |
70 | 70 |
}; |
71 | 71 |
|
72 | 72 |
}; |
73 | 73 |
|
74 | 74 |
|
75 | 75 |
/// Writable map concept |
76 | 76 |
|
77 | 77 |
/// Writable map concept. |
78 | 78 |
/// |
79 | 79 |
template<typename K, typename T> |
80 | 80 |
class WriteMap |
81 | 81 |
{ |
82 | 82 |
public: |
83 | 83 |
/// The key type of the map. |
84 | 84 |
typedef K Key; |
85 | 85 |
/// The value type of the map. (The type of objects associated with the keys). |
86 | 86 |
typedef T Value; |
87 | 87 |
|
88 | 88 |
/// Sets the value associated with the given key. |
89 | 89 |
void set(const Key &, const Value &) {} |
90 | 90 |
|
91 | 91 |
/// Default constructor. |
92 | 92 |
WriteMap() {} |
93 | 93 |
|
94 | 94 |
template <typename _WriteMap> |
95 | 95 |
struct Constraints { |
96 | 96 |
void constraints() { |
97 | 97 |
m.set(key, val); |
98 | 98 |
m.set(own_key, own_val); |
99 | 99 |
1 |
/* -*- C++ -*- |
|
1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
|
2 | 2 |
* |
3 |
* This file is a part of LEMON, a generic C++ optimization library |
|
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 |
///\ingroup concept |
20 | 20 |
///\file |
21 | 21 |
///\brief Classes for representing paths in digraphs. |
22 | 22 |
/// |
23 | 23 |
///\todo Iterators have obsolete style |
24 | 24 |
|
25 | 25 |
#ifndef LEMON_CONCEPT_PATH_H |
26 | 26 |
#define LEMON_CONCEPT_PATH_H |
27 | 27 |
|
28 | 28 |
#include <lemon/bits/invalid.h> |
29 | 29 |
#include <lemon/bits/utility.h> |
30 | 30 |
#include <lemon/concept_check.h> |
31 | 31 |
|
32 | 32 |
namespace lemon { |
33 | 33 |
namespace concepts { |
34 | 34 |
|
35 | 35 |
/// \addtogroup concept |
36 | 36 |
/// @{ |
37 | 37 |
|
38 | 38 |
/// \brief A skeleton structure for representing directed paths in |
39 | 39 |
/// a digraph. |
40 | 40 |
/// |
41 | 41 |
/// A skeleton structure for representing directed paths in a |
42 | 42 |
/// digraph. |
43 | 43 |
/// \tparam _Digraph The digraph type in which the path is. |
44 | 44 |
/// |
45 | 45 |
/// In a sense, the path can be treated as a list of arcs. The |
46 | 46 |
/// lemon path type stores just this list. As a consequence it |
47 | 47 |
/// cannot enumerate the nodes in the path and the zero length |
48 | 48 |
/// paths cannot store the source. |
49 | 49 |
/// |
50 | 50 |
template <typename _Digraph> |
51 | 51 |
class Path { |
52 | 52 |
public: |
53 | 53 |
|
54 | 54 |
/// Type of the underlying digraph. |
55 | 55 |
typedef _Digraph Digraph; |
56 | 56 |
/// Arc type of the underlying digraph. |
57 | 57 |
typedef typename Digraph::Arc Arc; |
58 | 58 |
|
59 | 59 |
class ArcIt; |
60 | 60 |
|
61 | 61 |
/// \brief Default constructor |
62 | 62 |
Path() {} |
63 | 63 |
|
64 | 64 |
/// \brief Template constructor |
65 | 65 |
template <typename CPath> |
66 | 66 |
Path(const CPath& cpath) {} |
67 | 67 |
|
68 | 68 |
/// \brief Template assigment |
69 | 69 |
template <typename CPath> |
70 | 70 |
Path& operator=(const CPath& cpath) {} |
71 | 71 |
|
72 | 72 |
/// Length of the path ie. the number of arcs in the path. |
73 | 73 |
int length() const { return 0;} |
74 | 74 |
|
75 | 75 |
/// Returns whether the path is empty. |
76 | 76 |
bool empty() const { return true;} |
77 | 77 |
|
78 | 78 |
/// Resets the path to an empty path. |
79 | 79 |
void clear() {} |
80 | 80 |
|
81 | 81 |
/// \brief Lemon style iterator for path arcs |
82 | 82 |
/// |
83 | 83 |
/// This class is used to iterate on the arcs of the paths. |
84 | 84 |
class ArcIt { |
85 | 85 |
public: |
86 | 86 |
/// Default constructor |
87 | 87 |
ArcIt() {} |
88 | 88 |
/// Invalid constructor |
89 | 89 |
ArcIt(Invalid) {} |
90 | 90 |
/// Constructor for first arc |
91 | 91 |
ArcIt(const Path &) {} |
92 | 92 |
|
93 | 93 |
/// Conversion to Arc |
94 | 94 |
operator Arc() const { return INVALID; } |
95 | 95 |
|
96 | 96 |
/// Next arc |
97 | 97 |
ArcIt& operator++() {return *this;} |
98 | 98 |
|
99 | 99 |
/// Comparison operator |
1 |
/* -*- C++ -*- |
|
1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
|
2 | 2 |
* |
3 |
* This file is a part of LEMON, a generic C++ optimization library |
|
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 |
#ifndef LEMON_COUNTER_H |
20 | 20 |
#define LEMON_COUNTER_H |
21 | 21 |
|
22 | 22 |
#include <string> |
23 | 23 |
#include <iostream> |
24 | 24 |
|
25 | 25 |
///\ingroup timecount |
26 | 26 |
///\file |
27 | 27 |
///\brief Tools for counting steps and events |
28 | 28 |
|
29 | 29 |
namespace lemon |
30 | 30 |
{ |
31 | 31 |
|
32 | 32 |
template<class P> class _NoSubCounter; |
33 | 33 |
|
34 | 34 |
template<class P> |
35 | 35 |
class _SubCounter |
36 | 36 |
{ |
37 | 37 |
P &_parent; |
38 | 38 |
std::string _title; |
39 | 39 |
std::ostream &_os; |
40 | 40 |
int count; |
41 | 41 |
public: |
42 | 42 |
|
43 | 43 |
typedef _SubCounter<_SubCounter<P> > SubCounter; |
44 | 44 |
typedef _NoSubCounter<_SubCounter<P> > NoSubCounter; |
45 | 45 |
|
46 | 46 |
_SubCounter(P &parent) |
47 | 47 |
: _parent(parent), _title(), _os(std::cerr), count(0) {} |
48 | 48 |
_SubCounter(P &parent,std::string title,std::ostream &os=std::cerr) |
49 | 49 |
: _parent(parent), _title(title), _os(os), count(0) {} |
50 | 50 |
_SubCounter(P &parent,const char *title,std::ostream &os=std::cerr) |
51 | 51 |
: _parent(parent), _title(title), _os(os), count(0) {} |
52 | 52 |
~_SubCounter() { |
53 | 53 |
_os << _title << count <<std::endl; |
54 | 54 |
_parent+=count; |
55 | 55 |
} |
56 | 56 |
_SubCounter &operator++() { count++; return *this;} |
57 | 57 |
int operator++(int) { return count++; } |
58 | 58 |
_SubCounter &operator--() { count--; return *this;} |
59 | 59 |
int operator--(int) { return count--; } |
60 | 60 |
_SubCounter &operator+=(int c) { count+=c; return *this;} |
61 | 61 |
_SubCounter &operator-=(int c) { count-=c; return *this;} |
62 | 62 |
operator int() {return count;} |
63 | 63 |
}; |
64 | 64 |
|
65 | 65 |
template<class P> |
66 | 66 |
class _NoSubCounter |
67 | 67 |
{ |
68 | 68 |
P &_parent; |
69 | 69 |
public: |
70 | 70 |
typedef _NoSubCounter<_NoSubCounter<P> > SubCounter; |
71 | 71 |
typedef _NoSubCounter<_NoSubCounter<P> > NoSubCounter; |
72 | 72 |
|
73 | 73 |
_NoSubCounter(P &parent) :_parent(parent) {} |
74 | 74 |
_NoSubCounter(P &parent,std::string,std::ostream &) |
75 | 75 |
:_parent(parent) {} |
76 | 76 |
_NoSubCounter(P &parent,std::string) |
77 | 77 |
:_parent(parent) {} |
78 | 78 |
_NoSubCounter(P &parent,const char *,std::ostream &) |
79 | 79 |
:_parent(parent) {} |
80 | 80 |
_NoSubCounter(P &parent,const char *) |
81 | 81 |
:_parent(parent) {} |
82 | 82 |
~_NoSubCounter() {} |
83 | 83 |
_NoSubCounter &operator++() { ++_parent; return *this;} |
84 | 84 |
int operator++(int) { _parent++; return 0;} |
85 | 85 |
_NoSubCounter &operator--() { --_parent; return *this;} |
86 | 86 |
int operator--(int) { _parent--; return 0;} |
87 | 87 |
_NoSubCounter &operator+=(int c) { _parent+=c; return *this;} |
88 | 88 |
_NoSubCounter &operator-=(int c) { _parent-=c; return *this;} |
89 | 89 |
operator int() {return 0;} |
90 | 90 |
}; |
91 | 91 |
|
92 | 92 |
|
93 | 93 |
/// \addtogroup timecount |
94 | 94 |
/// @{ |
95 | 95 |
|
96 | 96 |
/// A counter class |
97 | 97 |
|
98 | 98 |
/// This class makes it easier to count certain events (e.g. for debug |
99 | 99 |
/// reasons). |
1 |
/* -*- C++ -*- |
|
1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
|
2 | 2 |
* |
3 |
* This file is a part of LEMON, a generic C++ optimization library |
|
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 |
#ifndef LEMON_DFS_H |
20 | 20 |
#define LEMON_DFS_H |
21 | 21 |
|
22 | 22 |
///\ingroup search |
23 | 23 |
///\file |
24 | 24 |
///\brief Dfs algorithm. |
25 | 25 |
|
26 | 26 |
#include <lemon/list_graph.h> |
27 | 27 |
#include <lemon/graph_utils.h> |
28 | 28 |
#include <lemon/bits/path_dump.h> |
29 | 29 |
#include <lemon/bits/invalid.h> |
30 | 30 |
#include <lemon/error.h> |
31 | 31 |
#include <lemon/maps.h> |
32 | 32 |
|
33 | 33 |
#include <lemon/concept_check.h> |
34 | 34 |
|
35 | 35 |
namespace lemon { |
36 | 36 |
|
37 | 37 |
|
38 | 38 |
///Default traits class of Dfs class. |
39 | 39 |
|
40 | 40 |
///Default traits class of Dfs class. |
41 | 41 |
///\tparam GR Digraph type. |
42 | 42 |
template<class GR> |
43 | 43 |
struct DfsDefaultTraits |
44 | 44 |
{ |
45 | 45 |
///The digraph type the algorithm runs on. |
46 | 46 |
typedef GR Digraph; |
47 | 47 |
///\brief The type of the map that stores the last |
48 | 48 |
///arcs of the %DFS paths. |
49 | 49 |
/// |
50 | 50 |
///The type of the map that stores the last |
51 | 51 |
///arcs of the %DFS paths. |
52 | 52 |
///It must meet the \ref concepts::WriteMap "WriteMap" concept. |
53 | 53 |
/// |
54 | 54 |
typedef typename Digraph::template NodeMap<typename GR::Arc> PredMap; |
55 | 55 |
///Instantiates a PredMap. |
56 | 56 |
|
57 | 57 |
///This function instantiates a \ref PredMap. |
58 | 58 |
///\param G is the digraph, to which we would like to define the PredMap. |
59 | 59 |
///\todo The digraph alone may be insufficient to initialize |
60 | 60 |
static PredMap *createPredMap(const GR &G) |
61 | 61 |
{ |
62 | 62 |
return new PredMap(G); |
63 | 63 |
} |
64 | 64 |
|
65 | 65 |
///The type of the map that indicates which nodes are processed. |
66 | 66 |
|
67 | 67 |
///The type of the map that indicates which nodes are processed. |
68 | 68 |
///It must meet the \ref concepts::WriteMap "WriteMap" concept. |
69 | 69 |
///\todo named parameter to set this type, function to read and write. |
70 | 70 |
typedef NullMap<typename Digraph::Node,bool> ProcessedMap; |
71 | 71 |
///Instantiates a ProcessedMap. |
72 | 72 |
|
73 | 73 |
///This function instantiates a \ref ProcessedMap. |
74 | 74 |
///\param g is the digraph, to which |
75 | 75 |
///we would like to define the \ref ProcessedMap |
76 | 76 |
#ifdef DOXYGEN |
77 | 77 |
static ProcessedMap *createProcessedMap(const GR &g) |
78 | 78 |
#else |
79 | 79 |
static ProcessedMap *createProcessedMap(const GR &) |
80 | 80 |
#endif |
81 | 81 |
{ |
82 | 82 |
return new ProcessedMap(); |
83 | 83 |
} |
84 | 84 |
///The type of the map that indicates which nodes are reached. |
85 | 85 |
|
86 | 86 |
///The type of the map that indicates which nodes are reached. |
87 | 87 |
///It must meet the \ref concepts::WriteMap "WriteMap" concept. |
88 | 88 |
///\todo named parameter to set this type, function to read and write. |
89 | 89 |
typedef typename Digraph::template NodeMap<bool> ReachedMap; |
90 | 90 |
///Instantiates a ReachedMap. |
91 | 91 |
|
92 | 92 |
///This function instantiates a \ref ReachedMap. |
93 | 93 |
///\param G is the digraph, to which |
94 | 94 |
///we would like to define the \ref ReachedMap. |
95 | 95 |
static ReachedMap *createReachedMap(const GR &G) |
96 | 96 |
{ |
97 | 97 |
return new ReachedMap(G); |
98 | 98 |
} |
99 | 99 |
///The type of the map that stores the dists of the nodes. |
1 |
/* -*- C++ -*- |
|
1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
|
2 | 2 |
* |
3 |
* This file is a part of LEMON, a generic C++ optimization library |
|
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 |
#ifndef LEMON_DIJKSTRA_H |
20 | 20 |
#define LEMON_DIJKSTRA_H |
21 | 21 |
|
22 | 22 |
///\ingroup shortest_path |
23 | 23 |
///\file |
24 | 24 |
///\brief Dijkstra algorithm. |
25 | 25 |
|
26 | 26 |
#include <limits> |
27 | 27 |
#include <lemon/list_graph.h> |
28 | 28 |
#include <lemon/bin_heap.h> |
29 | 29 |
#include <lemon/bits/path_dump.h> |
30 | 30 |
#include <lemon/bits/invalid.h> |
31 | 31 |
#include <lemon/error.h> |
32 | 32 |
#include <lemon/maps.h> |
33 | 33 |
|
34 | 34 |
namespace lemon { |
35 | 35 |
|
36 | 36 |
/// \brief Default OperationTraits for the Dijkstra algorithm class. |
37 | 37 |
/// |
38 | 38 |
/// It defines all computational operations and constants which are |
39 | 39 |
/// used in the Dijkstra algorithm. |
40 | 40 |
template <typename Value> |
41 | 41 |
struct DijkstraDefaultOperationTraits { |
42 | 42 |
/// \brief Gives back the zero value of the type. |
43 | 43 |
static Value zero() { |
44 | 44 |
return static_cast<Value>(0); |
45 | 45 |
} |
46 | 46 |
/// \brief Gives back the sum of the given two elements. |
47 | 47 |
static Value plus(const Value& left, const Value& right) { |
48 | 48 |
return left + right; |
49 | 49 |
} |
50 | 50 |
/// \brief Gives back true only if the first value less than the second. |
51 | 51 |
static bool less(const Value& left, const Value& right) { |
52 | 52 |
return left < right; |
53 | 53 |
} |
54 | 54 |
}; |
55 | 55 |
|
56 | 56 |
/// \brief Widest path OperationTraits for the Dijkstra algorithm class. |
57 | 57 |
/// |
58 | 58 |
/// It defines all computational operations and constants which are |
59 | 59 |
/// used in the Dijkstra algorithm for widest path computation. |
60 | 60 |
template <typename Value> |
61 | 61 |
struct DijkstraWidestPathOperationTraits { |
62 | 62 |
/// \brief Gives back the maximum value of the type. |
63 | 63 |
static Value zero() { |
64 | 64 |
return std::numeric_limits<Value>::max(); |
65 | 65 |
} |
66 | 66 |
/// \brief Gives back the minimum of the given two elements. |
67 | 67 |
static Value plus(const Value& left, const Value& right) { |
68 | 68 |
return std::min(left, right); |
69 | 69 |
} |
70 | 70 |
/// \brief Gives back true only if the first value less than the second. |
71 | 71 |
static bool less(const Value& left, const Value& right) { |
72 | 72 |
return left < right; |
73 | 73 |
} |
74 | 74 |
}; |
75 | 75 |
|
76 | 76 |
///Default traits class of Dijkstra class. |
77 | 77 |
|
78 | 78 |
///Default traits class of Dijkstra class. |
79 | 79 |
///\tparam GR Digraph type. |
80 | 80 |
///\tparam LM Type of length map. |
81 | 81 |
template<class GR, class LM> |
82 | 82 |
struct DijkstraDefaultTraits |
83 | 83 |
{ |
84 | 84 |
///The digraph type the algorithm runs on. |
85 | 85 |
typedef GR Digraph; |
86 | 86 |
///The type of the map that stores the arc lengths. |
87 | 87 |
|
88 | 88 |
///The type of the map that stores the arc lengths. |
89 | 89 |
///It must meet the \ref concepts::ReadMap "ReadMap" concept. |
90 | 90 |
typedef LM LengthMap; |
91 | 91 |
//The type of the length of the arcs. |
92 | 92 |
typedef typename LM::Value Value; |
93 | 93 |
/// Operation traits for Dijkstra algorithm. |
94 | 94 |
|
95 | 95 |
/// It defines the used operation by the algorithm. |
96 | 96 |
/// \see DijkstraDefaultOperationTraits |
97 | 97 |
typedef DijkstraDefaultOperationTraits<Value> OperationTraits; |
98 | 98 |
/// The cross reference type used by heap. |
99 | 99 |
1 |
/* -*- C++ -*- |
|
1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
|
2 | 2 |
* |
3 |
* This file is a part of LEMON, a generic C++ optimization library |
|
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 |
#ifndef LEMON_DIM2_H |
20 | 20 |
#define LEMON_DIM2_H |
21 | 21 |
|
22 | 22 |
#include <iostream> |
23 | 23 |
#include <lemon/bits/utility.h> |
24 | 24 |
|
25 | 25 |
///\ingroup misc |
26 | 26 |
///\file |
27 | 27 |
///\brief A simple two dimensional vector and a bounding box implementation |
28 | 28 |
/// |
29 | 29 |
/// The class \ref lemon::dim2::Point "dim2::Point" implements |
30 | 30 |
/// a two dimensional vector with the usual operations. |
31 | 31 |
/// |
32 | 32 |
/// The class \ref lemon::dim2::BoundingBox "dim2::BoundingBox" |
33 | 33 |
/// can be used to determine |
34 | 34 |
/// the rectangular bounding box of a set of |
35 | 35 |
/// \ref lemon::dim2::Point "dim2::Point"'s. |
36 | 36 |
|
37 | 37 |
namespace lemon { |
38 | 38 |
|
39 | 39 |
///Tools for handling two dimensional coordinates |
40 | 40 |
|
41 | 41 |
///This namespace is a storage of several |
42 | 42 |
///tools for handling two dimensional coordinates |
43 | 43 |
namespace dim2 { |
44 | 44 |
|
45 | 45 |
/// \addtogroup misc |
46 | 46 |
/// @{ |
47 | 47 |
|
48 | 48 |
/// A simple two dimensional vector (plainvector) implementation |
49 | 49 |
|
50 | 50 |
/// A simple two dimensional vector (plainvector) implementation |
51 | 51 |
/// with the usual vector operations. |
52 | 52 |
template<typename T> |
53 | 53 |
class Point { |
54 | 54 |
|
55 | 55 |
public: |
56 | 56 |
|
57 | 57 |
typedef T Value; |
58 | 58 |
|
59 | 59 |
///First coordinate |
60 | 60 |
T x; |
61 | 61 |
///Second coordinate |
62 | 62 |
T y; |
63 | 63 |
|
64 | 64 |
///Default constructor |
65 | 65 |
Point() {} |
66 | 66 |
|
67 | 67 |
///Construct an instance from coordinates |
68 | 68 |
Point(T a, T b) : x(a), y(b) { } |
69 | 69 |
|
70 | 70 |
///Returns the dimension of the vector (i.e. returns 2). |
71 | 71 |
|
72 | 72 |
///The dimension of the vector. |
73 | 73 |
///This function always returns 2. |
74 | 74 |
int size() const { return 2; } |
75 | 75 |
|
76 | 76 |
///Subscripting operator |
77 | 77 |
|
78 | 78 |
///\c p[0] is \c p.x and \c p[1] is \c p.y |
79 | 79 |
/// |
80 | 80 |
T& operator[](int idx) { return idx == 0 ? x : y; } |
81 | 81 |
|
82 | 82 |
///Const subscripting operator |
83 | 83 |
|
84 | 84 |
///\c p[0] is \c p.x and \c p[1] is \c p.y |
85 | 85 |
/// |
86 | 86 |
const T& operator[](int idx) const { return idx == 0 ? x : y; } |
87 | 87 |
|
88 | 88 |
///Conversion constructor |
89 | 89 |
template<class TT> Point(const Point<TT> &p) : x(p.x), y(p.y) {} |
90 | 90 |
|
91 | 91 |
///Give back the square of the norm of the vector |
92 | 92 |
T normSquare() const { |
93 | 93 |
return x*x+y*y; |
94 | 94 |
} |
95 | 95 |
|
96 | 96 |
///Increment the left hand side by \c u |
97 | 97 |
Point<T>& operator +=(const Point<T>& u) { |
98 | 98 |
x += u.x; |
99 | 99 |
y += u.y; |
1 |
/* -*- C++ -*- |
|
1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
|
2 | 2 |
* |
3 |
* This file is a part of LEMON, a generic C++ optimization library |
|
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 |
#ifndef LEMON_ERROR_H |
20 | 20 |
#define LEMON_ERROR_H |
21 | 21 |
|
22 | 22 |
/// \ingroup exceptions |
23 | 23 |
/// \file |
24 | 24 |
/// \brief Basic exception classes and error handling. |
25 | 25 |
|
26 | 26 |
#include <exception> |
27 | 27 |
#include <string> |
28 | 28 |
#include <sstream> |
29 | 29 |
#include <iostream> |
30 | 30 |
#include <cstdlib> |
31 | 31 |
#include <memory> |
32 | 32 |
|
33 | 33 |
namespace lemon { |
34 | 34 |
|
35 | 35 |
/// \addtogroup exceptions |
36 | 36 |
/// @{ |
37 | 37 |
|
38 | 38 |
/// \brief Exception safe wrapper class. |
39 | 39 |
/// |
40 | 40 |
/// Exception safe wrapper class to implement the members of exceptions. |
41 | 41 |
template <typename _Type> |
42 | 42 |
class ExceptionMember { |
43 | 43 |
public: |
44 | 44 |
typedef _Type Type; |
45 | 45 |
|
46 | 46 |
ExceptionMember() throw() { |
47 | 47 |
try { |
48 | 48 |
ptr.reset(new Type()); |
49 | 49 |
} catch (...) {} |
50 | 50 |
} |
51 | 51 |
|
52 | 52 |
ExceptionMember(const Type& type) throw() { |
53 | 53 |
try { |
54 | 54 |
ptr.reset(new Type()); |
55 | 55 |
if (ptr.get() == 0) return; |
56 | 56 |
*ptr = type; |
57 | 57 |
} catch (...) {} |
58 | 58 |
} |
59 | 59 |
|
60 | 60 |
ExceptionMember(const ExceptionMember& copy) throw() { |
61 | 61 |
try { |
62 | 62 |
if (!copy.valid()) return; |
63 | 63 |
ptr.reset(new Type()); |
64 | 64 |
if (ptr.get() == 0) return; |
65 | 65 |
*ptr = copy.get(); |
66 | 66 |
} catch (...) {} |
67 | 67 |
} |
68 | 68 |
|
69 | 69 |
ExceptionMember& operator=(const ExceptionMember& copy) throw() { |
70 | 70 |
if (ptr.get() == 0) return; |
71 | 71 |
try { |
72 | 72 |
if (!copy.valid()) return; |
73 | 73 |
*ptr = copy.get(); |
74 | 74 |
} catch (...) {} |
75 | 75 |
} |
76 | 76 |
|
77 | 77 |
void set(const Type& type) throw() { |
78 | 78 |
if (ptr.get() == 0) return; |
79 | 79 |
try { |
80 | 80 |
*ptr = type; |
81 | 81 |
} catch (...) {} |
82 | 82 |
} |
83 | 83 |
|
84 | 84 |
const Type& get() const { |
85 | 85 |
return *ptr; |
86 | 86 |
} |
87 | 87 |
|
88 | 88 |
bool valid() const throw() { |
89 | 89 |
return ptr.get() != 0; |
90 | 90 |
} |
91 | 91 |
|
92 | 92 |
private: |
93 | 93 |
std::auto_ptr<_Type> ptr; |
94 | 94 |
}; |
95 | 95 |
|
96 | 96 |
/// Exception-safe convenient error message builder class. |
97 | 97 |
|
98 | 98 |
/// Helper class which provides a convenient ostream-like (operator << |
99 | 99 |
/// based) interface to create a string message. Mostly useful in |
1 |
/* -*- C++ -*- |
|
1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
|
2 | 2 |
* |
3 |
* This file is a part of LEMON, a generic C++ optimization library |
|
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 |
#ifndef LEMON_GRAPH_TO_EPS_H |
20 | 20 |
#define LEMON_GRAPH_TO_EPS_H |
21 | 21 |
|
22 | 22 |
#include<iostream> |
23 | 23 |
#include<fstream> |
24 | 24 |
#include<sstream> |
25 | 25 |
#include<algorithm> |
26 | 26 |
#include<vector> |
27 | 27 |
|
28 | 28 |
#ifndef WIN32 |
29 | 29 |
#include<sys/time.h> |
30 | 30 |
#include<ctime> |
31 | 31 |
#else |
32 | 32 |
#define WIN32_LEAN_AND_MEAN |
33 | 33 |
#define NOMINMAX |
34 | 34 |
#include<windows.h> |
35 | 35 |
#endif |
36 | 36 |
|
37 | 37 |
#include<lemon/math.h> |
38 | 38 |
#include<lemon/bits/invalid.h> |
39 | 39 |
#include<lemon/dim2.h> |
40 | 40 |
#include<lemon/maps.h> |
41 | 41 |
#include<lemon/color.h> |
42 | 42 |
#include<lemon/bits/bezier.h> |
43 | 43 |
|
44 | 44 |
|
45 | 45 |
///\ingroup eps_io |
46 | 46 |
///\file |
47 | 47 |
///\brief A well configurable tool for visualizing graphs |
48 | 48 |
|
49 | 49 |
namespace lemon { |
50 | 50 |
|
51 | 51 |
namespace _graph_to_eps_bits { |
52 | 52 |
template<class MT> |
53 | 53 |
class _NegY { |
54 | 54 |
public: |
55 | 55 |
typedef typename MT::Key Key; |
56 | 56 |
typedef typename MT::Value Value; |
57 | 57 |
const MT ↦ |
58 | 58 |
int yscale; |
59 | 59 |
_NegY(const MT &m,bool b) : map(m), yscale(1-b*2) {} |
60 | 60 |
Value operator[](Key n) { return Value(map[n].x,map[n].y*yscale);} |
61 | 61 |
}; |
62 | 62 |
} |
63 | 63 |
|
64 | 64 |
///Default traits class of \ref GraphToEps |
65 | 65 |
|
66 | 66 |
///Default traits class of \ref GraphToEps. |
67 | 67 |
/// |
68 | 68 |
///\c G is the type of the underlying graph. |
69 | 69 |
template<class G> |
70 | 70 |
struct DefaultGraphToEpsTraits |
71 | 71 |
{ |
72 | 72 |
typedef G Graph; |
73 | 73 |
typedef typename Graph::Node Node; |
74 | 74 |
typedef typename Graph::NodeIt NodeIt; |
75 | 75 |
typedef typename Graph::Arc Arc; |
76 | 76 |
typedef typename Graph::ArcIt ArcIt; |
77 | 77 |
typedef typename Graph::InArcIt InArcIt; |
78 | 78 |
typedef typename Graph::OutArcIt OutArcIt; |
79 | 79 |
|
80 | 80 |
|
81 | 81 |
const Graph &g; |
82 | 82 |
|
83 | 83 |
std::ostream& os; |
84 | 84 |
|
85 | 85 |
typedef ConstMap<typename Graph::Node,dim2::Point<double> > CoordsMapType; |
86 | 86 |
CoordsMapType _coords; |
87 | 87 |
ConstMap<typename Graph::Node,double > _nodeSizes; |
88 | 88 |
ConstMap<typename Graph::Node,int > _nodeShapes; |
89 | 89 |
|
90 | 90 |
ConstMap<typename Graph::Node,Color > _nodeColors; |
91 | 91 |
ConstMap<typename Graph::Arc,Color > _arcColors; |
92 | 92 |
|
93 | 93 |
ConstMap<typename Graph::Arc,double > _arcWidths; |
94 | 94 |
|
95 | 95 |
double _arcWidthScale; |
96 | 96 |
|
97 | 97 |
double _nodeScale; |
98 | 98 |
double _xBorder, _yBorder; |
99 | 99 |
double _scale; |
1 |
/* -*- C++ -*- |
|
1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
|
2 | 2 |
* |
3 |
* This file is a part of LEMON, a generic C++ optimization library |
|
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 |
#ifndef LEMON_GRAPH_UTILS_H |
20 | 20 |
#define LEMON_GRAPH_UTILS_H |
21 | 21 |
|
22 | 22 |
#include <iterator> |
23 | 23 |
#include <vector> |
24 | 24 |
#include <map> |
25 | 25 |
#include <cmath> |
26 | 26 |
#include <algorithm> |
27 | 27 |
|
28 | 28 |
#include <lemon/bits/invalid.h> |
29 | 29 |
#include <lemon/bits/utility.h> |
30 | 30 |
#include <lemon/maps.h> |
31 | 31 |
#include <lemon/bits/traits.h> |
32 | 32 |
|
33 | 33 |
#include <lemon/bits/alteration_notifier.h> |
34 | 34 |
#include <lemon/bits/default_map.h> |
35 | 35 |
|
36 | 36 |
///\ingroup gutils |
37 | 37 |
///\file |
38 | 38 |
///\brief Graph utilities. |
39 | 39 |
|
40 | 40 |
namespace lemon { |
41 | 41 |
|
42 | 42 |
/// \addtogroup gutils |
43 | 43 |
/// @{ |
44 | 44 |
|
45 | 45 |
///Creates convenience typedefs for the digraph types and iterators |
46 | 46 |
|
47 | 47 |
///This \c \#define creates convenience typedefs for the following types |
48 | 48 |
///of \c Digraph: \c Node, \c NodeIt, \c Arc, \c ArcIt, \c InArcIt, |
49 | 49 |
///\c OutArcIt, \c BoolNodeMap, \c IntNodeMap, \c DoubleNodeMap, |
50 | 50 |
///\c BoolArcMap, \c IntArcMap, \c DoubleArcMap. |
51 | 51 |
/// |
52 | 52 |
///\note If the graph type is a dependent type, ie. the graph type depend |
53 | 53 |
///on a template parameter, then use \c TEMPLATE_DIGRAPH_TYPEDEFS() |
54 | 54 |
///macro. |
55 | 55 |
#define DIGRAPH_TYPEDEFS(Digraph) \ |
56 | 56 |
typedef Digraph::Node Node; \ |
57 | 57 |
typedef Digraph::NodeIt NodeIt; \ |
58 | 58 |
typedef Digraph::Arc Arc; \ |
59 | 59 |
typedef Digraph::ArcIt ArcIt; \ |
60 | 60 |
typedef Digraph::InArcIt InArcIt; \ |
61 | 61 |
typedef Digraph::OutArcIt OutArcIt; \ |
62 | 62 |
typedef Digraph::NodeMap<bool> BoolNodeMap; \ |
63 | 63 |
typedef Digraph::NodeMap<int> IntNodeMap; \ |
64 | 64 |
typedef Digraph::NodeMap<double> DoubleNodeMap; \ |
65 | 65 |
typedef Digraph::ArcMap<bool> BoolArcMap; \ |
66 | 66 |
typedef Digraph::ArcMap<int> IntArcMap; \ |
67 | 67 |
typedef Digraph::ArcMap<double> DoubleArcMap |
68 | 68 |
|
69 | 69 |
///Creates convenience typedefs for the digraph types and iterators |
70 | 70 |
|
71 | 71 |
///\see DIGRAPH_TYPEDEFS |
72 | 72 |
/// |
73 | 73 |
///\note Use this macro, if the graph type is a dependent type, |
74 | 74 |
///ie. the graph type depend on a template parameter. |
75 | 75 |
#define TEMPLATE_DIGRAPH_TYPEDEFS(Digraph) \ |
76 | 76 |
typedef typename Digraph::Node Node; \ |
77 | 77 |
typedef typename Digraph::NodeIt NodeIt; \ |
78 | 78 |
typedef typename Digraph::Arc Arc; \ |
79 | 79 |
typedef typename Digraph::ArcIt ArcIt; \ |
80 | 80 |
typedef typename Digraph::InArcIt InArcIt; \ |
81 | 81 |
typedef typename Digraph::OutArcIt OutArcIt; \ |
82 | 82 |
typedef typename Digraph::template NodeMap<bool> BoolNodeMap; \ |
83 | 83 |
typedef typename Digraph::template NodeMap<int> IntNodeMap; \ |
84 | 84 |
typedef typename Digraph::template NodeMap<double> DoubleNodeMap; \ |
85 | 85 |
typedef typename Digraph::template ArcMap<bool> BoolArcMap; \ |
86 | 86 |
typedef typename Digraph::template ArcMap<int> IntArcMap; \ |
87 | 87 |
typedef typename Digraph::template ArcMap<double> DoubleArcMap |
88 | 88 |
|
89 | 89 |
///Creates convenience typedefs for the graph types and iterators |
90 | 90 |
|
91 | 91 |
///This \c \#define creates the same convenience typedefs as defined |
92 | 92 |
///by \ref DIGRAPH_TYPEDEFS(Graph) and six more, namely it creates |
93 | 93 |
///\c Edge, \c EdgeIt, \c IncEdgeIt, \c BoolEdgeMap, \c IntEdgeMap, |
94 | 94 |
///\c DoubleEdgeMap. |
95 | 95 |
/// |
96 | 96 |
///\note If the graph type is a dependent type, ie. the graph type depend |
97 | 97 |
///on a template parameter, then use \c TEMPLATE_DIGRAPH_TYPEDEFS() |
98 | 98 |
///macro. |
99 | 99 |
#define GRAPH_TYPEDEFS(Graph) \ |
1 |
/* -*- C++ -*- |
|
1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
|
2 | 2 |
* |
3 |
* This file is a part of LEMON, a generic C++ optimization library |
|
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 |
#ifndef LEMON_KRUSKAL_H |
20 | 20 |
#define LEMON_KRUSKAL_H |
21 | 21 |
|
22 | 22 |
#include <algorithm> |
23 | 23 |
#include <vector> |
24 | 24 |
#include <lemon/unionfind.h> |
25 | 25 |
// #include <lemon/graph_utils.h> |
26 | 26 |
#include <lemon/maps.h> |
27 | 27 |
|
28 | 28 |
// #include <lemon/radix_sort.h> |
29 | 29 |
|
30 | 30 |
#include <lemon/bits/utility.h> |
31 | 31 |
#include <lemon/bits/traits.h> |
32 | 32 |
|
33 | 33 |
///\ingroup spantree |
34 | 34 |
///\file |
35 | 35 |
///\brief Kruskal's algorithm to compute a minimum cost spanning tree |
36 | 36 |
/// |
37 | 37 |
///Kruskal's algorithm to compute a minimum cost spanning tree. |
38 | 38 |
/// |
39 | 39 |
|
40 | 40 |
namespace lemon { |
41 | 41 |
|
42 | 42 |
namespace _kruskal_bits { |
43 | 43 |
|
44 | 44 |
// Kruskal for directed graphs. |
45 | 45 |
|
46 | 46 |
template <typename Digraph, typename In, typename Out> |
47 | 47 |
typename disable_if<lemon::UndirectedTagIndicator<Digraph>, |
48 | 48 |
typename In::value_type::second_type >::type |
49 | 49 |
kruskal(const Digraph& digraph, const In& in, Out& out,dummy<0> = 0) { |
50 | 50 |
typedef typename In::value_type::second_type Value; |
51 | 51 |
typedef typename Digraph::template NodeMap<int> IndexMap; |
52 | 52 |
typedef typename Digraph::Node Node; |
53 | 53 |
|
54 | 54 |
IndexMap index(digraph); |
55 | 55 |
UnionFind<IndexMap> uf(index); |
56 | 56 |
for (typename Digraph::NodeIt it(digraph); it != INVALID; ++it) { |
57 | 57 |
uf.insert(it); |
58 | 58 |
} |
59 | 59 |
|
60 | 60 |
Value tree_value = 0; |
61 | 61 |
for (typename In::const_iterator it = in.begin(); it != in.end(); ++it) { |
62 | 62 |
if (uf.join(digraph.target(it->first),digraph.source(it->first))) { |
63 | 63 |
out.set(it->first, true); |
64 | 64 |
tree_value += it->second; |
65 | 65 |
} |
66 | 66 |
else { |
67 | 67 |
out.set(it->first, false); |
68 | 68 |
} |
69 | 69 |
} |
70 | 70 |
return tree_value; |
71 | 71 |
} |
72 | 72 |
|
73 | 73 |
// Kruskal for undirected graphs. |
74 | 74 |
|
75 | 75 |
template <typename Graph, typename In, typename Out> |
76 | 76 |
typename enable_if<lemon::UndirectedTagIndicator<Graph>, |
77 | 77 |
typename In::value_type::second_type >::type |
78 | 78 |
kruskal(const Graph& graph, const In& in, Out& out,dummy<1> = 1) { |
79 | 79 |
typedef typename In::value_type::second_type Value; |
80 | 80 |
typedef typename Graph::template NodeMap<int> IndexMap; |
81 | 81 |
typedef typename Graph::Node Node; |
82 | 82 |
|
83 | 83 |
IndexMap index(graph); |
84 | 84 |
UnionFind<IndexMap> uf(index); |
85 | 85 |
for (typename Graph::NodeIt it(graph); it != INVALID; ++it) { |
86 | 86 |
uf.insert(it); |
87 | 87 |
} |
88 | 88 |
|
89 | 89 |
Value tree_value = 0; |
90 | 90 |
for (typename In::const_iterator it = in.begin(); it != in.end(); ++it) { |
91 | 91 |
if (uf.join(graph.u(it->first),graph.v(it->first))) { |
92 | 92 |
out.set(it->first, true); |
93 | 93 |
tree_value += it->second; |
94 | 94 |
} |
95 | 95 |
else { |
96 | 96 |
out.set(it->first, false); |
97 | 97 |
} |
98 | 98 |
} |
99 | 99 |
return tree_value; |
1 |
/* -*- C++ -*- |
|
1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
|
2 | 2 |
* |
3 |
* This file is a part of LEMON, a generic C++ optimization library |
|
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 |
///\ingroup lemon_io |
20 | 20 |
///\file |
21 | 21 |
///\brief \ref lgf-format "Lemon Graph Format" reader. |
22 | 22 |
|
23 | 23 |
|
24 | 24 |
#ifndef LEMON_LGF_READER_H |
25 | 25 |
#define LEMON_LGF_READER_H |
26 | 26 |
|
27 | 27 |
#include <iostream> |
28 | 28 |
#include <fstream> |
29 | 29 |
#include <sstream> |
30 | 30 |
|
31 | 31 |
#include <set> |
32 | 32 |
#include <map> |
33 | 33 |
|
34 | 34 |
#include <lemon/assert.h> |
35 | 35 |
#include <lemon/graph_utils.h> |
36 | 36 |
|
37 | 37 |
#include <lemon/lgf_writer.h> |
38 | 38 |
|
39 | 39 |
#include <lemon/concept_check.h> |
40 | 40 |
#include <lemon/concepts/maps.h> |
41 | 41 |
|
42 | 42 |
namespace lemon { |
43 | 43 |
|
44 | 44 |
namespace _reader_bits { |
45 | 45 |
|
46 | 46 |
template <typename Value> |
47 | 47 |
struct DefaultConverter { |
48 | 48 |
Value operator()(const std::string& str) { |
49 | 49 |
std::istringstream is(str); |
50 | 50 |
Value value; |
51 | 51 |
is >> value; |
52 | 52 |
|
53 | 53 |
char c; |
54 | 54 |
if (is >> std::ws >> c) { |
55 | 55 |
throw DataFormatError("Remaining characters in token"); |
56 | 56 |
} |
57 | 57 |
return value; |
58 | 58 |
} |
59 | 59 |
}; |
60 | 60 |
|
61 | 61 |
template <> |
62 | 62 |
struct DefaultConverter<std::string> { |
63 | 63 |
std::string operator()(const std::string& str) { |
64 | 64 |
return str; |
65 | 65 |
} |
66 | 66 |
}; |
67 | 67 |
|
68 | 68 |
template <typename _Item> |
69 | 69 |
class MapStorageBase { |
70 | 70 |
public: |
71 | 71 |
typedef _Item Item; |
72 | 72 |
|
73 | 73 |
public: |
74 | 74 |
MapStorageBase() {} |
75 | 75 |
virtual ~MapStorageBase() {} |
76 | 76 |
|
77 | 77 |
virtual void set(const Item& item, const std::string& value) = 0; |
78 | 78 |
|
79 | 79 |
}; |
80 | 80 |
|
81 | 81 |
template <typename _Item, typename _Map, |
82 | 82 |
typename _Converter = DefaultConverter<typename _Map::Value> > |
83 | 83 |
class MapStorage : public MapStorageBase<_Item> { |
84 | 84 |
public: |
85 | 85 |
typedef _Map Map; |
86 | 86 |
typedef _Converter Converter; |
87 | 87 |
typedef _Item Item; |
88 | 88 |
|
89 | 89 |
private: |
90 | 90 |
Map& _map; |
91 | 91 |
Converter _converter; |
92 | 92 |
|
93 | 93 |
public: |
94 | 94 |
MapStorage(Map& map, const Converter& converter = Converter()) |
95 | 95 |
: _map(map), _converter(converter) {} |
96 | 96 |
virtual ~MapStorage() {} |
97 | 97 |
|
98 | 98 |
virtual void set(const Item& item ,const std::string& value) { |
99 | 99 |
_map.set(item, _converter(value)); |
1 |
/* -*- C++ -*- |
|
1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
|
2 | 2 |
* |
3 |
* This file is a part of LEMON, a generic C++ optimization library |
|
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 |
///\ingroup lemon_io |
20 | 20 |
///\file |
21 | 21 |
///\brief \ref lgf-format "Lemon Graph Format" writer. |
22 | 22 |
|
23 | 23 |
|
24 | 24 |
#ifndef LEMON_LGF_WRITER_H |
25 | 25 |
#define LEMON_LGF_WRITER_H |
26 | 26 |
|
27 | 27 |
#include <iostream> |
28 | 28 |
#include <fstream> |
29 | 29 |
#include <sstream> |
30 | 30 |
|
31 | 31 |
#include <algorithm> |
32 | 32 |
|
33 | 33 |
#include <vector> |
34 | 34 |
#include <functional> |
35 | 35 |
|
36 | 36 |
#include <lemon/assert.h> |
37 | 37 |
#include <lemon/graph_utils.h> |
38 | 38 |
|
39 | 39 |
namespace lemon { |
40 | 40 |
|
41 | 41 |
namespace _writer_bits { |
42 | 42 |
|
43 | 43 |
template <typename Value> |
44 | 44 |
struct DefaultConverter { |
45 | 45 |
std::string operator()(const Value& value) { |
46 | 46 |
std::ostringstream os; |
47 | 47 |
os << value; |
48 | 48 |
return os.str(); |
49 | 49 |
} |
50 | 50 |
}; |
51 | 51 |
|
52 | 52 |
template <typename T> |
53 | 53 |
bool operator<(const T&, const T&) { |
54 | 54 |
throw DataFormatError("Label map is not comparable"); |
55 | 55 |
} |
56 | 56 |
|
57 | 57 |
template <typename _Map> |
58 | 58 |
class MapLess { |
59 | 59 |
public: |
60 | 60 |
typedef _Map Map; |
61 | 61 |
typedef typename Map::Key Item; |
62 | 62 |
|
63 | 63 |
private: |
64 | 64 |
const Map& _map; |
65 | 65 |
|
66 | 66 |
public: |
67 | 67 |
MapLess(const Map& map) : _map(map) {} |
68 | 68 |
|
69 | 69 |
bool operator()(const Item& left, const Item& right) { |
70 | 70 |
return _map[left] < _map[right]; |
71 | 71 |
} |
72 | 72 |
}; |
73 | 73 |
|
74 | 74 |
template <typename _Graph, bool _dir, typename _Map> |
75 | 75 |
class GraphArcMapLess { |
76 | 76 |
public: |
77 | 77 |
typedef _Map Map; |
78 | 78 |
typedef _Graph Graph; |
79 | 79 |
typedef typename Graph::Edge Item; |
80 | 80 |
|
81 | 81 |
private: |
82 | 82 |
const Graph& _graph; |
83 | 83 |
const Map& _map; |
84 | 84 |
|
85 | 85 |
public: |
86 | 86 |
GraphArcMapLess(const Graph& graph, const Map& map) |
87 | 87 |
: _graph(graph), _map(map) {} |
88 | 88 |
|
89 | 89 |
bool operator()(const Item& left, const Item& right) { |
90 | 90 |
return _map[_graph.direct(left, _dir)] < |
91 | 91 |
_map[_graph.direct(right, _dir)]; |
92 | 92 |
} |
93 | 93 |
}; |
94 | 94 |
|
95 | 95 |
template <typename _Item> |
96 | 96 |
class MapStorageBase { |
97 | 97 |
public: |
98 | 98 |
typedef _Item Item; |
99 | 99 |
1 |
/* -*- C++ -*- |
|
1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
|
2 | 2 |
* |
3 |
* This file is a part of LEMON, a generic C++ optimization library |
|
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 |
#ifndef LEMON_LIST_GRAPH_H |
20 | 20 |
#define LEMON_LIST_GRAPH_H |
21 | 21 |
|
22 | 22 |
///\ingroup graphs |
23 | 23 |
///\file |
24 | 24 |
///\brief ListDigraph, ListGraph classes. |
25 | 25 |
|
26 | 26 |
#include <lemon/bits/graph_extender.h> |
27 | 27 |
|
28 | 28 |
#include <vector> |
29 | 29 |
#include <list> |
30 | 30 |
|
31 | 31 |
namespace lemon { |
32 | 32 |
|
33 | 33 |
class ListDigraphBase { |
34 | 34 |
|
35 | 35 |
protected: |
36 | 36 |
struct NodeT { |
37 | 37 |
int first_in, first_out; |
38 | 38 |
int prev, next; |
39 | 39 |
}; |
40 | 40 |
|
41 | 41 |
struct ArcT { |
42 | 42 |
int target, source; |
43 | 43 |
int prev_in, prev_out; |
44 | 44 |
int next_in, next_out; |
45 | 45 |
}; |
46 | 46 |
|
47 | 47 |
std::vector<NodeT> nodes; |
48 | 48 |
|
49 | 49 |
int first_node; |
50 | 50 |
|
51 | 51 |
int first_free_node; |
52 | 52 |
|
53 | 53 |
std::vector<ArcT> arcs; |
54 | 54 |
|
55 | 55 |
int first_free_arc; |
56 | 56 |
|
57 | 57 |
public: |
58 | 58 |
|
59 | 59 |
typedef ListDigraphBase Digraph; |
60 | 60 |
|
61 | 61 |
class Node { |
62 | 62 |
friend class ListDigraphBase; |
63 | 63 |
protected: |
64 | 64 |
|
65 | 65 |
int id; |
66 | 66 |
explicit Node(int pid) { id = pid;} |
67 | 67 |
|
68 | 68 |
public: |
69 | 69 |
Node() {} |
70 | 70 |
Node (Invalid) { id = -1; } |
71 | 71 |
bool operator==(const Node& node) const {return id == node.id;} |
72 | 72 |
bool operator!=(const Node& node) const {return id != node.id;} |
73 | 73 |
bool operator<(const Node& node) const {return id < node.id;} |
74 | 74 |
}; |
75 | 75 |
|
76 | 76 |
class Arc { |
77 | 77 |
friend class ListDigraphBase; |
78 | 78 |
protected: |
79 | 79 |
|
80 | 80 |
int id; |
81 | 81 |
explicit Arc(int pid) { id = pid;} |
82 | 82 |
|
83 | 83 |
public: |
84 | 84 |
Arc() {} |
85 | 85 |
Arc (Invalid) { id = -1; } |
86 | 86 |
bool operator==(const Arc& arc) const {return id == arc.id;} |
87 | 87 |
bool operator!=(const Arc& arc) const {return id != arc.id;} |
88 | 88 |
bool operator<(const Arc& arc) const {return id < arc.id;} |
89 | 89 |
}; |
90 | 90 |
|
91 | 91 |
|
92 | 92 |
|
93 | 93 |
ListDigraphBase() |
94 | 94 |
: nodes(), first_node(-1), |
95 | 95 |
first_free_node(-1), arcs(), first_free_arc(-1) {} |
96 | 96 |
|
97 | 97 |
|
98 | 98 |
int maxNodeId() const { return nodes.size()-1; } |
99 | 99 |
int maxArcId() const { return arcs.size()-1; } |
1 |
/* -*- C++ -*- |
|
1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
|
2 | 2 |
* |
3 |
* This file is a part of LEMON, a generic C++ optimization library |
|
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 |
#ifndef LEMON_MAPS_H |
20 | 20 |
#define LEMON_MAPS_H |
21 | 21 |
|
22 | 22 |
#include <iterator> |
23 | 23 |
#include <functional> |
24 | 24 |
#include <vector> |
25 | 25 |
|
26 | 26 |
#include <lemon/bits/utility.h> |
27 | 27 |
#include <lemon/bits/traits.h> |
28 | 28 |
|
29 | 29 |
///\file |
30 | 30 |
///\ingroup maps |
31 | 31 |
///\brief Miscellaneous property maps |
32 | 32 |
|
33 | 33 |
#include <map> |
34 | 34 |
|
35 | 35 |
namespace lemon { |
36 | 36 |
|
37 | 37 |
/// \addtogroup maps |
38 | 38 |
/// @{ |
39 | 39 |
|
40 | 40 |
/// Base class of maps. |
41 | 41 |
|
42 | 42 |
/// Base class of maps. It provides the necessary type definitions |
43 | 43 |
/// required by the map %concepts. |
44 | 44 |
template<typename K, typename V> |
45 | 45 |
class MapBase { |
46 | 46 |
public: |
47 | 47 |
/// \biref The key type of the map. |
48 | 48 |
typedef K Key; |
49 | 49 |
/// \brief The value type of the map. |
50 | 50 |
/// (The type of objects associated with the keys). |
51 | 51 |
typedef V Value; |
52 | 52 |
}; |
53 | 53 |
|
54 | 54 |
|
55 | 55 |
/// Null map. (a.k.a. DoNothingMap) |
56 | 56 |
|
57 | 57 |
/// This map can be used if you have to provide a map only for |
58 | 58 |
/// its type definitions, or if you have to provide a writable map, |
59 | 59 |
/// but data written to it is not required (i.e. it will be sent to |
60 | 60 |
/// <tt>/dev/null</tt>). |
61 | 61 |
/// It conforms the \ref concepts::ReadWriteMap "ReadWriteMap" concept. |
62 | 62 |
/// |
63 | 63 |
/// \sa ConstMap |
64 | 64 |
template<typename K, typename V> |
65 | 65 |
class NullMap : public MapBase<K, V> { |
66 | 66 |
public: |
67 | 67 |
typedef MapBase<K, V> Parent; |
68 | 68 |
typedef typename Parent::Key Key; |
69 | 69 |
typedef typename Parent::Value Value; |
70 | 70 |
|
71 | 71 |
/// Gives back a default constructed element. |
72 | 72 |
Value operator[](const Key&) const { return Value(); } |
73 | 73 |
/// Absorbs the value. |
74 | 74 |
void set(const Key&, const Value&) {} |
75 | 75 |
}; |
76 | 76 |
|
77 | 77 |
/// Returns a \ref NullMap class |
78 | 78 |
|
79 | 79 |
/// This function just returns a \ref NullMap class. |
80 | 80 |
/// \relates NullMap |
81 | 81 |
template <typename K, typename V> |
82 | 82 |
NullMap<K, V> nullMap() { |
83 | 83 |
return NullMap<K, V>(); |
84 | 84 |
} |
85 | 85 |
|
86 | 86 |
|
87 | 87 |
/// Constant map. |
88 | 88 |
|
89 | 89 |
/// This \ref concepts::ReadMap "readable map" assigns a specified |
90 | 90 |
/// value to each key. |
91 | 91 |
/// |
92 | 92 |
/// In other aspects it is equivalent to \ref NullMap. |
93 | 93 |
/// So it conforms the \ref concepts::ReadWriteMap "ReadWriteMap" |
94 | 94 |
/// concept, but it absorbs the data written to it. |
95 | 95 |
/// |
96 | 96 |
/// The simplest way of using this map is through the constMap() |
97 | 97 |
/// function. |
98 | 98 |
/// |
99 | 99 |
/// \sa NullMap |
1 |
/* -*- C++ -*- |
|
1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
|
2 | 2 |
* |
3 |
* This file is a part of LEMON, a generic C++ optimization library |
|
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 |
#ifndef LEMON_MATH_H |
20 | 20 |
#define LEMON_MATH_H |
21 | 21 |
|
22 | 22 |
///\ingroup misc |
23 | 23 |
///\file |
24 | 24 |
///\brief Some extensions to the standard \c cmath library. |
25 | 25 |
/// |
26 | 26 |
///Some extensions to the standard \c cmath library. |
27 | 27 |
/// |
28 | 28 |
///This file includes the standard math library (cmath). |
29 | 29 |
|
30 | 30 |
#include<cmath> |
31 | 31 |
|
32 | 32 |
namespace lemon { |
33 | 33 |
|
34 | 34 |
/// \addtogroup misc |
35 | 35 |
/// @{ |
36 | 36 |
|
37 | 37 |
/// The Euler constant |
38 | 38 |
const long double E = 2.7182818284590452353602874713526625L; |
39 | 39 |
/// log_2(e) |
40 | 40 |
const long double LOG2E = 1.4426950408889634073599246810018921L; |
41 | 41 |
/// log_10(e) |
42 | 42 |
const long double LOG10E = 0.4342944819032518276511289189166051L; |
43 | 43 |
/// ln(2) |
44 | 44 |
const long double LN2 = 0.6931471805599453094172321214581766L; |
45 | 45 |
/// ln(10) |
46 | 46 |
const long double LN10 = 2.3025850929940456840179914546843642L; |
47 | 47 |
/// pi |
48 | 48 |
const long double PI = 3.1415926535897932384626433832795029L; |
49 | 49 |
/// pi/2 |
50 | 50 |
const long double PI_2 = 1.5707963267948966192313216916397514L; |
51 | 51 |
/// pi/4 |
52 | 52 |
const long double PI_4 = 0.7853981633974483096156608458198757L; |
53 | 53 |
/// sqrt(2) |
54 | 54 |
const long double SQRT2 = 1.4142135623730950488016887242096981L; |
55 | 55 |
/// 1/sqrt(2) |
56 | 56 |
const long double SQRT1_2 = 0.7071067811865475244008443621048490L; |
57 | 57 |
|
58 | 58 |
|
59 | 59 |
/// @} |
60 | 60 |
|
61 | 61 |
} //namespace lemon |
62 | 62 |
|
63 | 63 |
#endif //LEMON_TOLERANCE_H |
1 |
/* -*- C++ -*- |
|
1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
|
2 | 2 |
* |
3 |
* This file is a part of LEMON, a generic C++ optimization library |
|
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 |
///\ingroup paths |
20 | 20 |
///\file |
21 | 21 |
///\brief Classes for representing paths in digraphs. |
22 | 22 |
/// |
23 | 23 |
|
24 | 24 |
#ifndef LEMON_PATH_H |
25 | 25 |
#define LEMON_PATH_H |
26 | 26 |
|
27 | 27 |
#include <vector> |
28 | 28 |
#include <algorithm> |
29 | 29 |
|
30 | 30 |
#include <lemon/error.h> |
31 | 31 |
#include <lemon/bits/invalid.h> |
32 | 32 |
#include <lemon/concepts/path.h> |
33 | 33 |
|
34 | 34 |
namespace lemon { |
35 | 35 |
|
36 | 36 |
/// \addtogroup paths |
37 | 37 |
/// @{ |
38 | 38 |
|
39 | 39 |
|
40 | 40 |
/// \brief A structure for representing directed paths in a digraph. |
41 | 41 |
/// |
42 | 42 |
/// A structure for representing directed path in a digraph. |
43 | 43 |
/// \tparam _Digraph The digraph type in which the path is. |
44 | 44 |
/// |
45 | 45 |
/// In a sense, the path can be treated as a list of arcs. The |
46 | 46 |
/// lemon path type stores just this list. As a consequence, it |
47 | 47 |
/// cannot enumerate the nodes of the path and the source node of |
48 | 48 |
/// a zero length path is undefined. |
49 | 49 |
/// |
50 | 50 |
/// This implementation is a back and front insertable and erasable |
51 | 51 |
/// path type. It can be indexed in O(1) time. The front and back |
52 | 52 |
/// insertion and erase is done in O(1) (amortized) time. The |
53 | 53 |
/// implementation uses two vectors for storing the front and back |
54 | 54 |
/// insertions. |
55 | 55 |
template <typename _Digraph> |
56 | 56 |
class Path { |
57 | 57 |
public: |
58 | 58 |
|
59 | 59 |
typedef _Digraph Digraph; |
60 | 60 |
typedef typename Digraph::Arc Arc; |
61 | 61 |
|
62 | 62 |
/// \brief Default constructor |
63 | 63 |
/// |
64 | 64 |
/// Default constructor |
65 | 65 |
Path() {} |
66 | 66 |
|
67 | 67 |
/// \brief Template copy constructor |
68 | 68 |
/// |
69 | 69 |
/// This constuctor initializes the path from any other path type. |
70 | 70 |
/// It simply makes a copy of the given path. |
71 | 71 |
template <typename CPath> |
72 | 72 |
Path(const CPath& cpath) { |
73 | 73 |
copyPath(*this, cpath); |
74 | 74 |
} |
75 | 75 |
|
76 | 76 |
/// \brief Template copy assignment |
77 | 77 |
/// |
78 | 78 |
/// This operator makes a copy of a path of any other type. |
79 | 79 |
template <typename CPath> |
80 | 80 |
Path& operator=(const CPath& cpath) { |
81 | 81 |
copyPath(*this, cpath); |
82 | 82 |
return *this; |
83 | 83 |
} |
84 | 84 |
|
85 | 85 |
/// \brief Lemon style iterator for path arcs |
86 | 86 |
/// |
87 | 87 |
/// This class is used to iterate on the arcs of the paths. |
88 | 88 |
class ArcIt { |
89 | 89 |
friend class Path; |
90 | 90 |
public: |
91 | 91 |
/// \brief Default constructor |
92 | 92 |
ArcIt() {} |
93 | 93 |
/// \brief Invalid constructor |
94 | 94 |
ArcIt(Invalid) : path(0), idx(-1) {} |
95 | 95 |
/// \brief Initializate the iterator to the first arc of path |
96 | 96 |
ArcIt(const Path &_path) |
97 | 97 |
: path(&_path), idx(_path.empty() ? -1 : 0) {} |
98 | 98 |
|
99 | 99 |
private: |
1 |
/* -*- C++ -*- |
|
1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
|
2 | 2 |
* |
3 |
* This file is a part of LEMON, a generic C++ optimization library |
|
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 |
///\file |
20 | 20 |
///\brief Instantiation of the Random class. |
21 | 21 |
|
22 | 22 |
#include <lemon/random.h> |
23 | 23 |
|
24 | 24 |
namespace lemon { |
25 | 25 |
/// \brief Global random number generator instance |
26 | 26 |
/// |
27 | 27 |
/// A global Mersenne Twister random number generator instance. |
28 | 28 |
Random rnd; |
29 | 29 |
} |
1 |
/* -*- C++ -*- |
|
1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
|
2 | 2 |
* |
3 |
* This file is a part of LEMON, a generic C++ optimization library |
|
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 |
/* |
20 | 20 |
* This file contains the reimplemented version of the Mersenne Twister |
21 | 21 |
* Generator of Matsumoto and Nishimura. |
22 | 22 |
* |
23 | 23 |
* See the appropriate copyright notice below. |
24 | 24 |
* |
25 | 25 |
* Copyright (C) 1997 - 2002, Makoto Matsumoto and Takuji Nishimura, |
26 | 26 |
* All rights reserved. |
27 | 27 |
* |
28 | 28 |
* Redistribution and use in source and binary forms, with or without |
29 | 29 |
* modification, are permitted provided that the following conditions |
30 | 30 |
* are met: |
31 | 31 |
* |
32 | 32 |
* 1. Redistributions of source code must retain the above copyright |
33 | 33 |
* notice, this list of conditions and the following disclaimer. |
34 | 34 |
* |
35 | 35 |
* 2. Redistributions in binary form must reproduce the above copyright |
36 | 36 |
* notice, this list of conditions and the following disclaimer in the |
37 | 37 |
* documentation and/or other materials provided with the distribution. |
38 | 38 |
* |
39 | 39 |
* 3. The names of its contributors may not be used to endorse or promote |
40 | 40 |
* products derived from this software without specific prior written |
41 | 41 |
* permission. |
42 | 42 |
* |
43 | 43 |
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
44 | 44 |
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
45 | 45 |
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
46 | 46 |
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
47 | 47 |
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
48 | 48 |
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
49 | 49 |
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
50 | 50 |
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
51 | 51 |
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
52 | 52 |
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
53 | 53 |
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED |
54 | 54 |
* OF THE POSSIBILITY OF SUCH DAMAGE. |
55 | 55 |
* |
56 | 56 |
* |
57 | 57 |
* Any feedback is very welcome. |
58 | 58 |
* http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt.html |
59 | 59 |
* email: m-mat @ math.sci.hiroshima-u.ac.jp (remove space) |
60 | 60 |
*/ |
61 | 61 |
|
62 | 62 |
#ifndef LEMON_RANDOM_H |
63 | 63 |
#define LEMON_RANDOM_H |
64 | 64 |
|
65 | 65 |
#include <algorithm> |
66 | 66 |
#include <iterator> |
67 | 67 |
#include <vector> |
68 | 68 |
#include <limits> |
69 | 69 |
#include <fstream> |
70 | 70 |
|
71 | 71 |
#include <lemon/math.h> |
72 | 72 |
#include <lemon/dim2.h> |
73 | 73 |
|
74 | 74 |
#ifndef WIN32 |
75 | 75 |
#include <sys/time.h> |
76 | 76 |
#include <ctime> |
77 | 77 |
#include <sys/types.h> |
78 | 78 |
#include <unistd.h> |
79 | 79 |
#else |
80 | 80 |
#include <windows.h> |
81 | 81 |
#endif |
82 | 82 |
|
83 | 83 |
///\ingroup misc |
84 | 84 |
///\file |
85 | 85 |
///\brief Mersenne Twister random number generator |
86 | 86 |
|
87 | 87 |
namespace lemon { |
88 | 88 |
|
89 | 89 |
namespace _random_bits { |
90 | 90 |
|
91 | 91 |
template <typename _Word, int _bits = std::numeric_limits<_Word>::digits> |
92 | 92 |
struct RandomTraits {}; |
93 | 93 |
|
94 | 94 |
template <typename _Word> |
95 | 95 |
struct RandomTraits<_Word, 32> { |
96 | 96 |
|
97 | 97 |
typedef _Word Word; |
98 | 98 |
static const int bits = 32; |
99 | 99 |
1 |
/* -*- C++ -*- |
|
1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
|
2 | 2 |
* |
3 |
* This file is a part of LEMON, a generic C++ optimization library |
|
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 |
#ifndef LEMON_SMART_GRAPH_H |
20 | 20 |
#define LEMON_SMART_GRAPH_H |
21 | 21 |
|
22 | 22 |
///\ingroup graphs |
23 | 23 |
///\file |
24 | 24 |
///\brief SmartDigraph and SmartGraph classes. |
25 | 25 |
|
26 | 26 |
#include <vector> |
27 | 27 |
|
28 | 28 |
#include <lemon/bits/invalid.h> |
29 | 29 |
|
30 | 30 |
#include <lemon/bits/base_extender.h> |
31 | 31 |
#include <lemon/bits/graph_extender.h> |
32 | 32 |
|
33 | 33 |
#include <lemon/bits/utility.h> |
34 | 34 |
#include <lemon/error.h> |
35 | 35 |
|
36 | 36 |
#include <lemon/bits/graph_extender.h> |
37 | 37 |
|
38 | 38 |
namespace lemon { |
39 | 39 |
|
40 | 40 |
class SmartDigraph; |
41 | 41 |
///Base of SmartDigraph |
42 | 42 |
|
43 | 43 |
///Base of SmartDigraph |
44 | 44 |
/// |
45 | 45 |
class SmartDigraphBase { |
46 | 46 |
protected: |
47 | 47 |
|
48 | 48 |
struct NodeT |
49 | 49 |
{ |
50 | 50 |
int first_in, first_out; |
51 | 51 |
NodeT() {} |
52 | 52 |
}; |
53 | 53 |
struct ArcT |
54 | 54 |
{ |
55 | 55 |
int target, source, next_in, next_out; |
56 | 56 |
ArcT() {} |
57 | 57 |
}; |
58 | 58 |
|
59 | 59 |
std::vector<NodeT> nodes; |
60 | 60 |
std::vector<ArcT> arcs; |
61 | 61 |
|
62 | 62 |
public: |
63 | 63 |
|
64 | 64 |
typedef SmartDigraphBase Graph; |
65 | 65 |
|
66 | 66 |
class Node; |
67 | 67 |
class Arc; |
68 | 68 |
|
69 | 69 |
public: |
70 | 70 |
|
71 | 71 |
SmartDigraphBase() : nodes(), arcs() { } |
72 | 72 |
SmartDigraphBase(const SmartDigraphBase &_g) |
73 | 73 |
: nodes(_g.nodes), arcs(_g.arcs) { } |
74 | 74 |
|
75 | 75 |
typedef True NodeNumTag; |
76 | 76 |
typedef True EdgeNumTag; |
77 | 77 |
|
78 | 78 |
int nodeNum() const { return nodes.size(); } |
79 | 79 |
int arcNum() const { return arcs.size(); } |
80 | 80 |
|
81 | 81 |
int maxNodeId() const { return nodes.size()-1; } |
82 | 82 |
int maxArcId() const { return arcs.size()-1; } |
83 | 83 |
|
84 | 84 |
Node addNode() { |
85 | 85 |
int n = nodes.size(); |
86 | 86 |
nodes.push_back(NodeT()); |
87 | 87 |
nodes[n].first_in = -1; |
88 | 88 |
nodes[n].first_out = -1; |
89 | 89 |
return Node(n); |
90 | 90 |
} |
91 | 91 |
|
92 | 92 |
Arc addArc(Node u, Node v) { |
93 | 93 |
int n = arcs.size(); |
94 | 94 |
arcs.push_back(ArcT()); |
95 | 95 |
arcs[n].source = u._id; |
96 | 96 |
arcs[n].target = v._id; |
97 | 97 |
arcs[n].next_out = nodes[u._id].first_out; |
98 | 98 |
arcs[n].next_in = nodes[v._id].first_in; |
99 | 99 |
nodes[u._id].first_out = nodes[v._id].first_in = n; |
1 |
/* -*- C++ -*- |
|
1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
|
2 | 2 |
* |
3 |
* This file is a part of LEMON, a generic C++ optimization library |
|
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 |
#ifndef LEMON_TIME_MEASURE_H |
20 | 20 |
#define LEMON_TIME_MEASURE_H |
21 | 21 |
|
22 | 22 |
///\ingroup timecount |
23 | 23 |
///\file |
24 | 24 |
///\brief Tools for measuring cpu usage |
25 | 25 |
|
26 | 26 |
#ifdef WIN32 |
27 | 27 |
#define WIN32_LEAN_AND_MEAN |
28 | 28 |
#define NOMINMAX |
29 | 29 |
#include <windows.h> |
30 | 30 |
#include <cmath> |
31 | 31 |
#else |
32 | 32 |
#include <sys/times.h> |
33 | 33 |
#include <sys/time.h> |
34 | 34 |
#endif |
35 | 35 |
|
36 | 36 |
#include <string> |
37 | 37 |
#include <fstream> |
38 | 38 |
#include <iostream> |
39 | 39 |
|
40 | 40 |
namespace lemon { |
41 | 41 |
|
42 | 42 |
/// \addtogroup timecount |
43 | 43 |
/// @{ |
44 | 44 |
|
45 | 45 |
/// A class to store (cpu)time instances. |
46 | 46 |
|
47 | 47 |
/// This class stores five time values. |
48 | 48 |
/// - a real time |
49 | 49 |
/// - a user cpu time |
50 | 50 |
/// - a system cpu time |
51 | 51 |
/// - a user cpu time of children |
52 | 52 |
/// - a system cpu time of children |
53 | 53 |
/// |
54 | 54 |
/// TimeStamp's can be added to or substracted from each other and |
55 | 55 |
/// they can be pushed to a stream. |
56 | 56 |
/// |
57 | 57 |
/// In most cases, perhaps the \ref Timer or the \ref TimeReport |
58 | 58 |
/// class is what you want to use instead. |
59 | 59 |
|
60 | 60 |
class TimeStamp |
61 | 61 |
{ |
62 | 62 |
double utime; |
63 | 63 |
double stime; |
64 | 64 |
double cutime; |
65 | 65 |
double cstime; |
66 | 66 |
double rtime; |
67 | 67 |
|
68 | 68 |
void _reset() { |
69 | 69 |
utime = stime = cutime = cstime = rtime = 0; |
70 | 70 |
} |
71 | 71 |
|
72 | 72 |
public: |
73 | 73 |
|
74 | 74 |
///Read the current time values of the process |
75 | 75 |
void stamp() |
76 | 76 |
{ |
77 | 77 |
#ifndef WIN32 |
78 | 78 |
timeval tv; |
79 | 79 |
gettimeofday(&tv, 0); |
80 | 80 |
rtime=tv.tv_sec+double(tv.tv_usec)/1e6; |
81 | 81 |
|
82 | 82 |
tms ts; |
83 | 83 |
double tck=sysconf(_SC_CLK_TCK); |
84 | 84 |
times(&ts); |
85 | 85 |
utime=ts.tms_utime/tck; |
86 | 86 |
stime=ts.tms_stime/tck; |
87 | 87 |
cutime=ts.tms_cutime/tck; |
88 | 88 |
cstime=ts.tms_cstime/tck; |
89 | 89 |
#else |
90 | 90 |
static const double ch = 4294967296.0e-7; |
91 | 91 |
static const double cl = 1.0e-7; |
92 | 92 |
|
93 | 93 |
FILETIME system; |
94 | 94 |
GetSystemTimeAsFileTime(&system); |
95 | 95 |
rtime = ch * system.dwHighDateTime + cl * system.dwLowDateTime; |
96 | 96 |
|
97 | 97 |
FILETIME create, exit, kernel, user; |
98 | 98 |
if (GetProcessTimes(GetCurrentProcess(),&create, &exit, &kernel, &user)) { |
99 | 99 |
utime = ch * user.dwHighDateTime + cl * user.dwLowDateTime; |
1 |
/* -*- C++ -*- |
|
1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
|
2 | 2 |
* |
3 |
* This file is a part of LEMON, a generic C++ optimization library |
|
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 |
#ifndef LEMON_TOLERANCE_H |
20 | 20 |
#define LEMON_TOLERANCE_H |
21 | 21 |
|
22 | 22 |
///\ingroup misc |
23 | 23 |
///\file |
24 | 24 |
///\brief A basic tool to handle the anomalies of calculation with |
25 | 25 |
///floating point numbers. |
26 | 26 |
/// |
27 | 27 |
///\todo It should be in a module like "Basic tools" |
28 | 28 |
|
29 | 29 |
|
30 | 30 |
namespace lemon { |
31 | 31 |
|
32 | 32 |
/// \addtogroup misc |
33 | 33 |
/// @{ |
34 | 34 |
|
35 | 35 |
///\brief A class to provide a basic way to |
36 | 36 |
///handle the comparison of numbers that are obtained |
37 | 37 |
///as a result of a probably inexact computation. |
38 | 38 |
/// |
39 | 39 |
///\ref Tolerance is a class to provide a basic way to |
40 | 40 |
///handle the comparison of numbers that are obtained |
41 | 41 |
///as a result of a probably inexact computation. |
42 | 42 |
/// |
43 | 43 |
///This is an abstract class, it should be specialized for all |
44 | 44 |
///numerical data types. These specialized classes like |
45 | 45 |
///Tolerance<double> may offer additional tuning parameters. |
46 | 46 |
/// |
47 | 47 |
///\sa Tolerance<float> |
48 | 48 |
///\sa Tolerance<double> |
49 | 49 |
///\sa Tolerance<long double> |
50 | 50 |
///\sa Tolerance<int> |
51 | 51 |
///\sa Tolerance<long long int> |
52 | 52 |
///\sa Tolerance<unsigned int> |
53 | 53 |
///\sa Tolerance<unsigned long long int> |
54 | 54 |
|
55 | 55 |
template<class T> |
56 | 56 |
class Tolerance |
57 | 57 |
{ |
58 | 58 |
public: |
59 | 59 |
typedef T Value; |
60 | 60 |
|
61 | 61 |
///\name Comparisons |
62 | 62 |
///The concept is that these bool functions return \c true only if |
63 | 63 |
///the related comparisons hold even if some numerical error appeared |
64 | 64 |
///during the computations. |
65 | 65 |
|
66 | 66 |
///@{ |
67 | 67 |
|
68 | 68 |
///Returns \c true if \c a is \e surely strictly less than \c b |
69 | 69 |
static bool less(Value a,Value b) {return false;} |
70 | 70 |
///Returns \c true if \c a is \e surely different from \c b |
71 | 71 |
static bool different(Value a,Value b) {return false;} |
72 | 72 |
///Returns \c true if \c a is \e surely positive |
73 | 73 |
static bool positive(Value a) {return false;} |
74 | 74 |
///Returns \c true if \c a is \e surely negative |
75 | 75 |
static bool negative(Value a) {return false;} |
76 | 76 |
///Returns \c true if \c a is \e surely non-zero |
77 | 77 |
static bool nonZero(Value a) {return false;} |
78 | 78 |
|
79 | 79 |
///@} |
80 | 80 |
|
81 | 81 |
///Returns the zero value. |
82 | 82 |
static Value zero() {return T();} |
83 | 83 |
|
84 | 84 |
// static bool finite(Value a) {} |
85 | 85 |
// static Value big() {} |
86 | 86 |
// static Value negativeBig() {} |
87 | 87 |
}; |
88 | 88 |
|
89 | 89 |
|
90 | 90 |
///Float specialization of Tolerance. |
91 | 91 |
|
92 | 92 |
///Float specialization of Tolerance. |
93 | 93 |
///\sa Tolerance |
94 | 94 |
///\relates Tolerance |
95 | 95 |
template<> |
96 | 96 |
class Tolerance<float> |
97 | 97 |
{ |
98 | 98 |
static float def_epsilon; |
99 | 99 |
float _epsilon; |
1 |
/* -*- C++ -*- |
|
1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
|
2 | 2 |
* |
3 |
* This file is a part of LEMON, a generic C++ optimization library |
|
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 |
#ifndef LEMON_UNION_FIND_H |
20 | 20 |
#define LEMON_UNION_FIND_H |
21 | 21 |
|
22 | 22 |
//!\ingroup auxdat |
23 | 23 |
//!\file |
24 | 24 |
//!\brief Union-Find data structures. |
25 | 25 |
//! |
26 | 26 |
|
27 | 27 |
#include <vector> |
28 | 28 |
#include <list> |
29 | 29 |
#include <utility> |
30 | 30 |
#include <algorithm> |
31 | 31 |
#include <functional> |
32 | 32 |
|
33 | 33 |
#include <lemon/bits/invalid.h> |
34 | 34 |
|
35 | 35 |
namespace lemon { |
36 | 36 |
|
37 | 37 |
/// \ingroup auxdat |
38 | 38 |
/// |
39 | 39 |
/// \brief A \e Union-Find data structure implementation |
40 | 40 |
/// |
41 | 41 |
/// The class implements the \e Union-Find data structure. |
42 | 42 |
/// The union operation uses rank heuristic, while |
43 | 43 |
/// the find operation uses path compression. |
44 | 44 |
/// This is a very simple but efficient implementation, providing |
45 | 45 |
/// only four methods: join (union), find, insert and size. |
46 | 46 |
/// For more features see the \ref UnionFindEnum class. |
47 | 47 |
/// |
48 | 48 |
/// It is primarily used in Kruskal algorithm for finding minimal |
49 | 49 |
/// cost spanning tree in a graph. |
50 | 50 |
/// \sa kruskal() |
51 | 51 |
/// |
52 | 52 |
/// \pre You need to add all the elements by the \ref insert() |
53 | 53 |
/// method. |
54 | 54 |
template <typename _ItemIntMap> |
55 | 55 |
class UnionFind { |
56 | 56 |
public: |
57 | 57 |
|
58 | 58 |
typedef _ItemIntMap ItemIntMap; |
59 | 59 |
typedef typename ItemIntMap::Key Item; |
60 | 60 |
|
61 | 61 |
private: |
62 | 62 |
// If the items vector stores negative value for an item then |
63 | 63 |
// that item is root item and it has -items[it] component size. |
64 | 64 |
// Else the items[it] contains the index of the parent. |
65 | 65 |
std::vector<int> items; |
66 | 66 |
ItemIntMap& index; |
67 | 67 |
|
68 | 68 |
bool rep(int idx) const { |
69 | 69 |
return items[idx] < 0; |
70 | 70 |
} |
71 | 71 |
|
72 | 72 |
int repIndex(int idx) const { |
73 | 73 |
int k = idx; |
74 | 74 |
while (!rep(k)) { |
75 | 75 |
k = items[k] ; |
76 | 76 |
} |
77 | 77 |
while (idx != k) { |
78 | 78 |
int next = items[idx]; |
79 | 79 |
const_cast<int&>(items[idx]) = k; |
80 | 80 |
idx = next; |
81 | 81 |
} |
82 | 82 |
return k; |
83 | 83 |
} |
84 | 84 |
|
85 | 85 |
public: |
86 | 86 |
|
87 | 87 |
/// \brief Constructor |
88 | 88 |
/// |
89 | 89 |
/// Constructor of the UnionFind class. You should give an item to |
90 | 90 |
/// integer map which will be used from the data structure. If you |
91 | 91 |
/// modify directly this map that may cause segmentation fault, |
92 | 92 |
/// invalid data structure, or infinite loop when you use again |
93 | 93 |
/// the union-find. |
94 | 94 |
UnionFind(ItemIntMap& m) : index(m) {} |
95 | 95 |
|
96 | 96 |
/// \brief Returns the index of the element's component. |
97 | 97 |
/// |
98 | 98 |
/// The method returns the index of the element's component. |
99 | 99 |
/// This is an integer between zero and the number of inserted elements. |
1 |
/* -*- C++ -*- |
|
1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
|
2 | 2 |
* |
3 |
* This file is a part of LEMON, a generic C++ optimization library |
|
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 <lemon/concepts/digraph.h> |
20 | 20 |
#include <lemon/smart_graph.h> |
21 | 21 |
#include <lemon/list_graph.h> |
22 | 22 |
#include <lemon/bfs.h> |
23 | 23 |
#include <lemon/path.h> |
24 | 24 |
|
25 | 25 |
#include "graph_test.h" |
26 | 26 |
#include "test_tools.h" |
27 | 27 |
|
28 | 28 |
using namespace lemon; |
29 | 29 |
|
30 | 30 |
void checkBfsCompile() |
31 | 31 |
{ |
32 | 32 |
typedef concepts::Digraph Digraph; |
33 | 33 |
typedef Bfs<Digraph> BType; |
34 | 34 |
|
35 | 35 |
Digraph G; |
36 | 36 |
Digraph::Node n; |
37 | 37 |
Digraph::Arc e; |
38 | 38 |
int l; |
39 | 39 |
bool b; |
40 | 40 |
BType::DistMap d(G); |
41 | 41 |
BType::PredMap p(G); |
42 | 42 |
// BType::PredNodeMap pn(G); |
43 | 43 |
|
44 | 44 |
BType bfs_test(G); |
45 | 45 |
|
46 | 46 |
bfs_test.run(n); |
47 | 47 |
|
48 | 48 |
l = bfs_test.dist(n); |
49 | 49 |
e = bfs_test.predArc(n); |
50 | 50 |
n = bfs_test.predNode(n); |
51 | 51 |
d = bfs_test.distMap(); |
52 | 52 |
p = bfs_test.predMap(); |
53 | 53 |
// pn = bfs_test.predNodeMap(); |
54 | 54 |
b = bfs_test.reached(n); |
55 | 55 |
|
56 | 56 |
Path<Digraph> pp = bfs_test.path(n); |
57 | 57 |
} |
58 | 58 |
|
59 | 59 |
void checkBfsFunctionCompile() |
60 | 60 |
{ |
61 | 61 |
typedef int VType; |
62 | 62 |
typedef concepts::Digraph Digraph; |
63 | 63 |
typedef Digraph::Arc Arc; |
64 | 64 |
typedef Digraph::Node Node; |
65 | 65 |
|
66 | 66 |
Digraph g; |
67 | 67 |
bfs(g,Node()).run(); |
68 | 68 |
bfs(g).source(Node()).run(); |
69 | 69 |
bfs(g) |
70 | 70 |
.predMap(concepts::WriteMap<Node,Arc>()) |
71 | 71 |
.distMap(concepts::WriteMap<Node,VType>()) |
72 | 72 |
.reachedMap(concepts::ReadWriteMap<Node,bool>()) |
73 | 73 |
.processedMap(concepts::WriteMap<Node,bool>()) |
74 | 74 |
.run(Node()); |
75 | 75 |
} |
76 | 76 |
|
77 | 77 |
template <class Digraph> |
78 | 78 |
void checkBfs() { |
79 | 79 |
TEMPLATE_DIGRAPH_TYPEDEFS(Digraph); |
80 | 80 |
|
81 | 81 |
Digraph G; |
82 | 82 |
Node s, t; |
83 | 83 |
PetStruct<Digraph> ps = addPetersen(G, 5); |
84 | 84 |
|
85 | 85 |
s=ps.outer[2]; |
86 | 86 |
t=ps.inner[0]; |
87 | 87 |
|
88 | 88 |
Bfs<Digraph> bfs_test(G); |
89 | 89 |
bfs_test.run(s); |
90 | 90 |
|
91 | 91 |
check(bfs_test.dist(t)==3,"Bfs found a wrong path." << bfs_test.dist(t)); |
92 | 92 |
|
93 | 93 |
Path<Digraph> p = bfs_test.path(t); |
94 | 94 |
check(p.length()==3,"path() found a wrong path."); |
95 | 95 |
check(checkPath(G, p),"path() found a wrong path."); |
96 | 96 |
check(pathSource(G, p) == s,"path() found a wrong path."); |
97 | 97 |
check(pathTarget(G, p) == t,"path() found a wrong path."); |
98 | 98 |
|
99 | 99 |
1 |
/* -*- C++ -*- |
|
1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
|
2 | 2 |
* |
3 |
* This file is a part of LEMON, a generic C++ optimization library |
|
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 <lemon/counter.h> |
20 | 20 |
#include <vector> |
21 | 21 |
|
22 | 22 |
using namespace lemon; |
23 | 23 |
|
24 | 24 |
template <typename T> |
25 | 25 |
void bubbleSort(std::vector<T>& v) { |
26 | 26 |
Counter op("Bubble Sort - Operations: "); |
27 | 27 |
Counter::NoSubCounter as(op, "Assignments: "); |
28 | 28 |
Counter::NoSubCounter co(op, "Comparisons: "); |
29 | 29 |
for (int i = v.size()-1; i > 0; --i) { |
30 | 30 |
for (int j = 0; j < i; ++j) { |
31 | 31 |
if (v[j] > v[j+1]) { |
32 | 32 |
T tmp = v[j]; |
33 | 33 |
v[j] = v[j+1]; |
34 | 34 |
v[j+1] = tmp; |
35 | 35 |
as += 3; |
36 | 36 |
} |
37 | 37 |
++co; |
38 | 38 |
} |
39 | 39 |
} |
40 | 40 |
} |
41 | 41 |
|
42 | 42 |
template <typename T> |
43 | 43 |
void insertionSort(std::vector<T>& v) { |
44 | 44 |
Counter op("Insertion Sort - Operations: "); |
45 | 45 |
Counter::NoSubCounter as(op, "Assignments: "); |
46 | 46 |
Counter::NoSubCounter co(op, "Comparisons: "); |
47 | 47 |
for (int i = 1; i < int(v.size()); ++i) { |
48 | 48 |
T value = v[i]; |
49 | 49 |
++as; |
50 | 50 |
int j = i; |
51 | 51 |
while (j > 0 && v[j-1] > value) { |
52 | 52 |
v[j] = v[j-1]; |
53 | 53 |
--j; |
54 | 54 |
++co; ++as; |
55 | 55 |
} |
56 | 56 |
v[j] = value; |
57 | 57 |
++as; |
58 | 58 |
} |
59 | 59 |
} |
60 | 60 |
|
61 | 61 |
template <typename MyCounter> |
62 | 62 |
void counterTest() { |
63 | 63 |
MyCounter c("Main Counter: "); |
64 | 64 |
c++; |
65 | 65 |
typename MyCounter::SubCounter d(c, "SubCounter: "); |
66 | 66 |
d++; |
67 | 67 |
typename MyCounter::SubCounter::NoSubCounter e(d, "SubSubCounter: "); |
68 | 68 |
e++; |
69 | 69 |
d+=3; |
70 | 70 |
c-=4; |
71 | 71 |
e-=2; |
72 | 72 |
c.reset(2); |
73 | 73 |
c.reset(); |
74 | 74 |
} |
75 | 75 |
|
76 | 76 |
void init(std::vector<int>& v) { |
77 | 77 |
v[0] = 10; v[1] = 60; v[2] = 20; v[3] = 90; v[4] = 100; |
78 | 78 |
v[5] = 80; v[6] = 40; v[7] = 30; v[8] = 50; v[9] = 70; |
79 | 79 |
} |
80 | 80 |
|
81 | 81 |
int main() |
82 | 82 |
{ |
83 | 83 |
counterTest<Counter>(); |
84 | 84 |
counterTest<NoCounter>(); |
85 | 85 |
|
86 | 86 |
std::vector<int> x(10); |
87 | 87 |
init(x); bubbleSort(x); |
88 | 88 |
init(x); insertionSort(x); |
89 | 89 |
|
90 | 90 |
return 0; |
91 | 91 |
} |
1 |
/* -*- C++ -*- |
|
1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
|
2 | 2 |
* |
3 |
* This file is a part of LEMON, a generic C++ optimization library |
|
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 <lemon/concepts/digraph.h> |
20 | 20 |
#include <lemon/smart_graph.h> |
21 | 21 |
#include <lemon/list_graph.h> |
22 | 22 |
#include <lemon/dfs.h> |
23 | 23 |
#include <lemon/path.h> |
24 | 24 |
|
25 | 25 |
#include "graph_test.h" |
26 | 26 |
#include "test_tools.h" |
27 | 27 |
|
28 | 28 |
using namespace lemon; |
29 | 29 |
|
30 | 30 |
void checkDfsCompile() |
31 | 31 |
{ |
32 | 32 |
typedef concepts::Digraph Digraph; |
33 | 33 |
typedef Dfs<Digraph> DType; |
34 | 34 |
|
35 | 35 |
Digraph G; |
36 | 36 |
Digraph::Node n; |
37 | 37 |
Digraph::Arc e; |
38 | 38 |
int l; |
39 | 39 |
bool b; |
40 | 40 |
DType::DistMap d(G); |
41 | 41 |
DType::PredMap p(G); |
42 | 42 |
// DType::PredNodeMap pn(G); |
43 | 43 |
|
44 | 44 |
DType dfs_test(G); |
45 | 45 |
|
46 | 46 |
dfs_test.run(n); |
47 | 47 |
|
48 | 48 |
l = dfs_test.dist(n); |
49 | 49 |
e = dfs_test.predArc(n); |
50 | 50 |
n = dfs_test.predNode(n); |
51 | 51 |
d = dfs_test.distMap(); |
52 | 52 |
p = dfs_test.predMap(); |
53 | 53 |
// pn = dfs_test.predNodeMap(); |
54 | 54 |
b = dfs_test.reached(n); |
55 | 55 |
|
56 | 56 |
Path<Digraph> pp = dfs_test.path(n); |
57 | 57 |
} |
58 | 58 |
|
59 | 59 |
void checkDfsFunctionCompile() |
60 | 60 |
{ |
61 | 61 |
typedef int VType; |
62 | 62 |
typedef concepts::Digraph Digraph; |
63 | 63 |
typedef Digraph::Arc Arc; |
64 | 64 |
typedef Digraph::Node Node; |
65 | 65 |
|
66 | 66 |
Digraph g; |
67 | 67 |
dfs(g,Node()).run(); |
68 | 68 |
dfs(g).source(Node()).run(); |
69 | 69 |
dfs(g) |
70 | 70 |
.predMap(concepts::WriteMap<Node,Arc>()) |
71 | 71 |
.distMap(concepts::WriteMap<Node,VType>()) |
72 | 72 |
.reachedMap(concepts::ReadWriteMap<Node,bool>()) |
73 | 73 |
.processedMap(concepts::WriteMap<Node,bool>()) |
74 | 74 |
.run(Node()); |
75 | 75 |
} |
76 | 76 |
|
77 | 77 |
template <class Digraph> |
78 | 78 |
void checkDfs() { |
79 | 79 |
TEMPLATE_DIGRAPH_TYPEDEFS(Digraph); |
80 | 80 |
|
81 | 81 |
Digraph G; |
82 | 82 |
Node s, t; |
83 | 83 |
PetStruct<Digraph> ps = addPetersen(G, 5); |
84 | 84 |
|
85 | 85 |
s=ps.outer[2]; |
86 | 86 |
t=ps.inner[0]; |
87 | 87 |
|
88 | 88 |
Dfs<Digraph> dfs_test(G); |
89 | 89 |
dfs_test.run(s); |
90 | 90 |
|
91 | 91 |
Path<Digraph> p = dfs_test.path(t); |
92 | 92 |
check(p.length() == dfs_test.dist(t),"path() found a wrong path."); |
93 | 93 |
check(checkPath(G, p),"path() found a wrong path."); |
94 | 94 |
check(pathSource(G, p) == s,"path() found a wrong path."); |
95 | 95 |
check(pathTarget(G, p) == t,"path() found a wrong path."); |
96 | 96 |
|
97 | 97 |
for(NodeIt v(G); v!=INVALID; ++v) { |
98 | 98 |
check(dfs_test.reached(v),"Each node should be reached."); |
99 | 99 |
if ( dfs_test.predArc(v)!=INVALID ) { |
1 |
/* -*- C++ -*- |
|
1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
|
2 | 2 |
* |
3 |
* This file is a part of LEMON, a generic C++ optimization library |
|
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 <lemon/concepts/digraph.h> |
20 | 20 |
#include <lemon/list_graph.h> |
21 | 21 |
#include <lemon/smart_graph.h> |
22 | 22 |
//#include <lemon/full_graph.h> |
23 | 23 |
//#include <lemon/hypercube_graph.h> |
24 | 24 |
|
25 | 25 |
#include "test_tools.h" |
26 | 26 |
#include "graph_test.h" |
27 | 27 |
#include "graph_maps_test.h" |
28 | 28 |
|
29 | 29 |
using namespace lemon; |
30 | 30 |
using namespace lemon::concepts; |
31 | 31 |
|
32 | 32 |
void check_concepts() { |
33 | 33 |
{ // Checking digraph components |
34 | 34 |
checkConcept<BaseDigraphComponent, BaseDigraphComponent >(); |
35 | 35 |
|
36 | 36 |
checkConcept<IDableDigraphComponent<>, |
37 | 37 |
IDableDigraphComponent<> >(); |
38 | 38 |
|
39 | 39 |
checkConcept<IterableDigraphComponent<>, |
40 | 40 |
IterableDigraphComponent<> >(); |
41 | 41 |
|
42 | 42 |
checkConcept<MappableDigraphComponent<>, |
43 | 43 |
MappableDigraphComponent<> >(); |
44 | 44 |
} |
45 | 45 |
{ // Checking skeleton digraph |
46 | 46 |
checkConcept<Digraph, Digraph>(); |
47 | 47 |
} |
48 | 48 |
{ // Checking ListDigraph |
49 | 49 |
checkConcept<Digraph, ListDigraph>(); |
50 | 50 |
checkConcept<AlterableDigraphComponent<>, ListDigraph>(); |
51 | 51 |
checkConcept<ExtendableDigraphComponent<>, ListDigraph>(); |
52 | 52 |
checkConcept<ClearableDigraphComponent<>, ListDigraph>(); |
53 | 53 |
checkConcept<ErasableDigraphComponent<>, ListDigraph>(); |
54 | 54 |
checkDigraphIterators<ListDigraph>(); |
55 | 55 |
} |
56 | 56 |
{ // Checking SmartDigraph |
57 | 57 |
checkConcept<Digraph, SmartDigraph>(); |
58 | 58 |
checkConcept<AlterableDigraphComponent<>, SmartDigraph>(); |
59 | 59 |
checkConcept<ExtendableDigraphComponent<>, SmartDigraph>(); |
60 | 60 |
checkConcept<ClearableDigraphComponent<>, SmartDigraph>(); |
61 | 61 |
checkDigraphIterators<SmartDigraph>(); |
62 | 62 |
} |
63 | 63 |
// { // Checking FullDigraph |
64 | 64 |
// checkConcept<Digraph, FullDigraph>(); |
65 | 65 |
// checkDigraphIterators<FullDigraph>(); |
66 | 66 |
// } |
67 | 67 |
// { // Checking HyperCubeDigraph |
68 | 68 |
// checkConcept<Digraph, HyperCubeDigraph>(); |
69 | 69 |
// checkDigraphIterators<HyperCubeDigraph>(); |
70 | 70 |
// } |
71 | 71 |
} |
72 | 72 |
|
73 | 73 |
template <typename Digraph> |
74 | 74 |
void check_graph_validity() { |
75 | 75 |
TEMPLATE_DIGRAPH_TYPEDEFS(Digraph); |
76 | 76 |
Digraph g; |
77 | 77 |
|
78 | 78 |
Node |
79 | 79 |
n1 = g.addNode(), |
80 | 80 |
n2 = g.addNode(), |
81 | 81 |
n3 = g.addNode(); |
82 | 82 |
|
83 | 83 |
Arc |
84 | 84 |
e1 = g.addArc(n1, n2), |
85 | 85 |
e2 = g.addArc(n2, n3); |
86 | 86 |
|
87 | 87 |
check(g.valid(n1), "Wrong validity check"); |
88 | 88 |
check(g.valid(e1), "Wrong validity check"); |
89 | 89 |
|
90 | 90 |
check(!g.valid(g.nodeFromId(-1)), "Wrong validity check"); |
91 | 91 |
check(!g.valid(g.arcFromId(-1)), "Wrong validity check"); |
92 | 92 |
} |
93 | 93 |
|
94 | 94 |
template <typename Digraph> |
95 | 95 |
void check_graph_validity_erase() { |
96 | 96 |
TEMPLATE_DIGRAPH_TYPEDEFS(Digraph); |
97 | 97 |
Digraph g; |
98 | 98 |
|
99 | 99 |
Node |
1 |
/* -*- C++ -*- |
|
1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
|
2 | 2 |
* |
3 |
* This file is a part of LEMON, a generic C++ optimization library |
|
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 <lemon/concepts/digraph.h> |
20 | 20 |
#include <lemon/smart_graph.h> |
21 | 21 |
#include <lemon/list_graph.h> |
22 | 22 |
#include <lemon/graph_utils.h> |
23 | 23 |
#include <lemon/dijkstra.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 |
void checkDijkstraCompile() |
32 | 32 |
{ |
33 | 33 |
typedef int VType; |
34 | 34 |
typedef concepts::Digraph Digraph; |
35 | 35 |
typedef concepts::ReadMap<Digraph::Arc,VType> LengthMap; |
36 | 36 |
typedef Dijkstra<Digraph, LengthMap> DType; |
37 | 37 |
|
38 | 38 |
Digraph G; |
39 | 39 |
Digraph::Node n; |
40 | 40 |
Digraph::Arc e; |
41 | 41 |
VType l; |
42 | 42 |
bool b; |
43 | 43 |
DType::DistMap d(G); |
44 | 44 |
DType::PredMap p(G); |
45 | 45 |
// DType::PredNodeMap pn(G); |
46 | 46 |
LengthMap length; |
47 | 47 |
|
48 | 48 |
DType dijkstra_test(G,length); |
49 | 49 |
|
50 | 50 |
dijkstra_test.run(n); |
51 | 51 |
|
52 | 52 |
l = dijkstra_test.dist(n); |
53 | 53 |
e = dijkstra_test.predArc(n); |
54 | 54 |
n = dijkstra_test.predNode(n); |
55 | 55 |
d = dijkstra_test.distMap(); |
56 | 56 |
p = dijkstra_test.predMap(); |
57 | 57 |
// pn = dijkstra_test.predNodeMap(); |
58 | 58 |
b = dijkstra_test.reached(n); |
59 | 59 |
|
60 | 60 |
Path<Digraph> pp = dijkstra_test.path(n); |
61 | 61 |
} |
62 | 62 |
|
63 | 63 |
void checkDijkstraFunctionCompile() |
64 | 64 |
{ |
65 | 65 |
typedef int VType; |
66 | 66 |
typedef concepts::Digraph Digraph; |
67 | 67 |
typedef Digraph::Arc Arc; |
68 | 68 |
typedef Digraph::Node Node; |
69 | 69 |
typedef concepts::ReadMap<Digraph::Arc,VType> LengthMap; |
70 | 70 |
|
71 | 71 |
Digraph g; |
72 | 72 |
dijkstra(g,LengthMap(),Node()).run(); |
73 | 73 |
dijkstra(g,LengthMap()).source(Node()).run(); |
74 | 74 |
dijkstra(g,LengthMap()) |
75 | 75 |
.predMap(concepts::WriteMap<Node,Arc>()) |
76 | 76 |
.distMap(concepts::WriteMap<Node,VType>()) |
77 | 77 |
.run(Node()); |
78 | 78 |
} |
79 | 79 |
|
80 | 80 |
template <class Digraph> |
81 | 81 |
void checkDijkstra() { |
82 | 82 |
TEMPLATE_DIGRAPH_TYPEDEFS(Digraph); |
83 | 83 |
typedef typename Digraph::template ArcMap<int> LengthMap; |
84 | 84 |
|
85 | 85 |
Digraph G; |
86 | 86 |
Node s, t; |
87 | 87 |
LengthMap length(G); |
88 | 88 |
PetStruct<Digraph> ps = addPetersen(G, 5); |
89 | 89 |
|
90 | 90 |
for(int i=0;i<5;i++) { |
91 | 91 |
length[ps.outcir[i]]=4; |
92 | 92 |
length[ps.incir[i]]=1; |
93 | 93 |
length[ps.chords[i]]=10; |
94 | 94 |
} |
95 | 95 |
s=ps.outer[0]; |
96 | 96 |
t=ps.inner[1]; |
97 | 97 |
|
98 | 98 |
Dijkstra<Digraph, LengthMap> |
99 | 99 |
dijkstra_test(G, length); |
1 |
/* -*- C++ -*- |
|
1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
|
2 | 2 |
* |
3 |
* This file is a part of LEMON, a generic C++ optimization library |
|
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 <lemon/dim2.h> |
20 | 20 |
#include <iostream> |
21 | 21 |
#include "test_tools.h" |
22 | 22 |
|
23 | 23 |
using namespace std; |
24 | 24 |
using namespace lemon; |
25 | 25 |
|
26 | 26 |
int main() |
27 | 27 |
{ |
28 | 28 |
typedef dim2::Point<int> Point; |
29 | 29 |
|
30 | 30 |
Point p; |
31 | 31 |
check(p.size()==2, "Wrong dim2::Point initialization."); |
32 | 32 |
|
33 | 33 |
Point a(1,2); |
34 | 34 |
Point b(3,4); |
35 | 35 |
check(a[0]==1 && a[1]==2, "Wrong dim2::Point initialization."); |
36 | 36 |
|
37 | 37 |
p = a+b; |
38 | 38 |
check(p.x==4 && p.y==6, "Wrong dim2::Point addition."); |
39 | 39 |
|
40 | 40 |
p = a-b; |
41 | 41 |
check(p.x==-2 && p.y==-2, "Wrong dim2::Point subtraction."); |
42 | 42 |
|
43 | 43 |
check(a.normSquare()==5,"Wrong dim2::Point norm calculation."); |
44 | 44 |
check(a*b==11, "Wrong dim2::Point scalar product."); |
45 | 45 |
|
46 | 46 |
int l=2; |
47 | 47 |
p = a*l; |
48 | 48 |
check(p.x==2 && p.y==4, "Wrong dim2::Point multiplication by a scalar."); |
49 | 49 |
|
50 | 50 |
p = b/l; |
51 | 51 |
check(p.x==1 && p.y==2, "Wrong dim2::Point division by a scalar."); |
52 | 52 |
|
53 | 53 |
typedef dim2::BoundingBox<int> BB; |
54 | 54 |
BB box1; |
55 | 55 |
check(box1.empty(), "Wrong empty() in dim2::BoundingBox."); |
56 | 56 |
|
57 | 57 |
box1.add(a); |
58 | 58 |
check(!box1.empty(), "Wrong empty() in dim2::BoundingBox."); |
59 | 59 |
box1.add(b); |
60 | 60 |
|
61 | 61 |
check(box1.bottomLeft().x==1 && |
62 | 62 |
box1.bottomLeft().y==2 && |
63 | 63 |
box1.topRight().x==3 && |
64 | 64 |
box1.topRight().y==4, |
65 | 65 |
"Wrong addition of points to dim2::BoundingBox."); |
66 | 66 |
|
67 | 67 |
p.x=2; p.y=3; |
68 | 68 |
check(box1.inside(p), "Wrong inside() in dim2::BoundingBox."); |
69 | 69 |
|
70 | 70 |
p.x=1; p.y=3; |
71 | 71 |
check(box1.inside(p), "Wrong inside() in dim2::BoundingBox."); |
72 | 72 |
|
73 | 73 |
p.x=0; p.y=3; |
74 | 74 |
check(!box1.inside(p), "Wrong inside() in dim2::BoundingBox."); |
75 | 75 |
|
76 | 76 |
BB box2(p); |
77 | 77 |
check(!box2.empty(), "Wrong empty() in dim2::BoundingBox."); |
78 | 78 |
|
79 | 79 |
box2.add(box1); |
80 | 80 |
check(box2.inside(p), "Wrong inside() in dim2::BoundingBox."); |
81 | 81 |
|
82 | 82 |
return 0; |
83 | 83 |
} |
1 |
/* -*- C++ -*- |
|
1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
|
2 | 2 |
* |
3 |
* This file is a part of LEMON, a generic C++ optimization library |
|
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 <iostream> |
20 | 20 |
|
21 | 21 |
#include <lemon/error.h> |
22 | 22 |
#include "test_tools.h" |
23 | 23 |
|
24 | 24 |
using namespace lemon; |
25 | 25 |
|
26 | 26 |
#ifdef LEMON_ENABLE_ASSERTS |
27 | 27 |
#undef LEMON_ENABLE_ASSERTS |
28 | 28 |
#endif |
29 | 29 |
|
30 | 30 |
#ifdef LEMON_DISABLE_ASSERTS |
31 | 31 |
#undef LEMON_DISABLE_ASSERTS |
32 | 32 |
#endif |
33 | 33 |
|
34 | 34 |
//checking disabled asserts |
35 | 35 |
#define LEMON_DISABLE_ASSERTS |
36 | 36 |
#include <lemon/assert.h> |
37 | 37 |
|
38 | 38 |
void no_assertion_text_disable() { |
39 | 39 |
LEMON_ASSERT(true, "This is a fault message"); |
40 | 40 |
} |
41 | 41 |
|
42 | 42 |
void assertion_text_disable() { |
43 | 43 |
LEMON_ASSERT(false, "This is a fault message"); |
44 | 44 |
} |
45 | 45 |
|
46 | 46 |
void fixme_disable() { |
47 | 47 |
LEMON_FIXME("fixme_disable() is fixme!"); |
48 | 48 |
} |
49 | 49 |
|
50 | 50 |
void check_assertion_disable() { |
51 | 51 |
no_assertion_text_disable(); |
52 | 52 |
assertion_text_disable(); |
53 | 53 |
fixme_disable(); |
54 | 54 |
} |
55 | 55 |
#undef LEMON_DISABLE_ASSERTS |
56 | 56 |
|
57 | 57 |
//checking custom assert handler |
58 | 58 |
#define LEMON_ASSERT_CUSTOM |
59 | 59 |
|
60 | 60 |
static int cnt = 0; |
61 | 61 |
void my_assert_handler(const char*, int, const char*, |
62 | 62 |
const char*, const char*) { |
63 | 63 |
++cnt; |
64 | 64 |
} |
65 | 65 |
|
66 | 66 |
#define LEMON_CUSTOM_ASSERT_HANDLER my_assert_handler |
67 | 67 |
#include <lemon/assert.h> |
68 | 68 |
|
69 | 69 |
void no_assertion_text_custom() { |
70 | 70 |
LEMON_ASSERT(true, "This is a fault message"); |
71 | 71 |
} |
72 | 72 |
|
73 | 73 |
void assertion_text_custom() { |
74 | 74 |
LEMON_ASSERT(false, "This is a fault message"); |
75 | 75 |
} |
76 | 76 |
|
77 | 77 |
void fixme_custom() { |
78 | 78 |
LEMON_FIXME("fixme_custom() is fixme!"); |
79 | 79 |
} |
80 | 80 |
|
81 | 81 |
void check_assertion_custom() { |
82 | 82 |
no_assertion_text_custom(); |
83 | 83 |
assertion_text_custom(); |
84 | 84 |
fixme_custom(); |
85 | 85 |
check(cnt == 2, "The custom assert handler does not work"); |
86 | 86 |
} |
87 | 87 |
|
88 | 88 |
#undef LEMON_ASSERT_CUSTOM |
89 | 89 |
|
90 | 90 |
|
91 | 91 |
int main() { |
92 | 92 |
check_assertion_disable(); |
93 | 93 |
check_assertion_custom(); |
94 | 94 |
|
95 | 95 |
return 0; |
96 | 96 |
} |
1 |
/* -*- C++ -*- |
|
1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
|
2 | 2 |
* |
3 |
* This file is a part of LEMON, a generic C++ optimization library |
|
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 <lemon/smart_graph.h> |
20 | 20 |
#include <lemon/list_graph.h> |
21 | 21 |
#include <lemon/lgf_reader.h> |
22 | 22 |
#include <lemon/graph_utils.h> |
23 | 23 |
#include <lemon/error.h> |
24 | 24 |
|
25 | 25 |
#include "test_tools.h" |
26 | 26 |
|
27 | 27 |
using namespace std; |
28 | 28 |
using namespace lemon; |
29 | 29 |
|
30 | 30 |
void digraph_copy_test() { |
31 | 31 |
const int nn = 10; |
32 | 32 |
|
33 | 33 |
SmartDigraph from; |
34 | 34 |
SmartDigraph::NodeMap<int> fnm(from); |
35 | 35 |
SmartDigraph::ArcMap<int> fam(from); |
36 | 36 |
SmartDigraph::Node fn = INVALID; |
37 | 37 |
SmartDigraph::Arc fa = INVALID; |
38 | 38 |
|
39 | 39 |
std::vector<SmartDigraph::Node> fnv; |
40 | 40 |
for (int i = 0; i < nn; ++i) { |
41 | 41 |
SmartDigraph::Node node = from.addNode(); |
42 | 42 |
fnv.push_back(node); |
43 | 43 |
fnm[node] = i * i; |
44 | 44 |
if (i == 0) fn = node; |
45 | 45 |
} |
46 | 46 |
|
47 | 47 |
for (int i = 0; i < nn; ++i) { |
48 | 48 |
for (int j = 0; j < nn; ++j) { |
49 | 49 |
SmartDigraph::Arc arc = from.addArc(fnv[i], fnv[j]); |
50 | 50 |
fam[arc] = i + j * j; |
51 | 51 |
if (i == 0 && j == 0) fa = arc; |
52 | 52 |
} |
53 | 53 |
} |
54 | 54 |
|
55 | 55 |
ListDigraph to; |
56 | 56 |
ListDigraph::NodeMap<int> tnm(to); |
57 | 57 |
ListDigraph::ArcMap<int> tam(to); |
58 | 58 |
ListDigraph::Node tn; |
59 | 59 |
ListDigraph::Arc ta; |
60 | 60 |
|
61 | 61 |
SmartDigraph::NodeMap<ListDigraph::Node> nr(from); |
62 | 62 |
SmartDigraph::ArcMap<ListDigraph::Arc> er(from); |
63 | 63 |
|
64 | 64 |
ListDigraph::NodeMap<SmartDigraph::Node> ncr(to); |
65 | 65 |
ListDigraph::ArcMap<SmartDigraph::Arc> ecr(to); |
66 | 66 |
|
67 | 67 |
DigraphCopy<ListDigraph, SmartDigraph>(to, from). |
68 | 68 |
nodeMap(tnm, fnm).arcMap(tam, fam). |
69 | 69 |
nodeRef(nr).arcRef(er). |
70 | 70 |
nodeCrossRef(ncr).arcCrossRef(ecr). |
71 | 71 |
node(tn, fn).arc(ta, fa).run(); |
72 | 72 |
|
73 | 73 |
for (SmartDigraph::NodeIt it(from); it != INVALID; ++it) { |
74 | 74 |
check(ncr[nr[it]] == it, "Wrong copy."); |
75 | 75 |
check(fnm[it] == tnm[nr[it]], "Wrong copy."); |
76 | 76 |
} |
77 | 77 |
|
78 | 78 |
for (SmartDigraph::ArcIt it(from); it != INVALID; ++it) { |
79 | 79 |
check(ecr[er[it]] == it, "Wrong copy."); |
80 | 80 |
check(fam[it] == tam[er[it]], "Wrong copy."); |
81 | 81 |
check(nr[from.source(it)] == to.source(er[it]), "Wrong copy."); |
82 | 82 |
check(nr[from.target(it)] == to.target(er[it]), "Wrong copy."); |
83 | 83 |
} |
84 | 84 |
|
85 | 85 |
for (ListDigraph::NodeIt it(to); it != INVALID; ++it) { |
86 | 86 |
check(nr[ncr[it]] == it, "Wrong copy."); |
87 | 87 |
} |
88 | 88 |
|
89 | 89 |
for (ListDigraph::ArcIt it(to); it != INVALID; ++it) { |
90 | 90 |
check(er[ecr[it]] == it, "Wrong copy."); |
91 | 91 |
} |
92 | 92 |
check(tn == nr[fn], "Wrong copy."); |
93 | 93 |
check(ta == er[fa], "Wrong copy."); |
94 | 94 |
} |
95 | 95 |
|
96 | 96 |
void graph_copy_test() { |
97 | 97 |
const int nn = 10; |
98 | 98 |
|
99 | 99 |
SmartGraph from; |
1 |
/* -*- C++ -*- |
|
1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
|
2 | 2 |
* |
3 |
* This file is a part of LEMON, a generic C++ optimization library |
|
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 |
#ifndef LEMON_TEST_MAP_TEST_H |
20 | 20 |
#define LEMON_TEST_MAP_TEST_H |
21 | 21 |
|
22 | 22 |
#include <vector> |
23 | 23 |
#include <lemon/maps.h> |
24 | 24 |
|
25 | 25 |
#include "test_tools.h" |
26 | 26 |
|
27 | 27 |
namespace lemon { |
28 | 28 |
|
29 | 29 |
template <typename Graph> |
30 | 30 |
void checkGraphNodeMap() { |
31 | 31 |
Graph graph; |
32 | 32 |
const int num = 16; |
33 | 33 |
|
34 | 34 |
typedef typename Graph::Node Node; |
35 | 35 |
|
36 | 36 |
std::vector<Node> nodes; |
37 | 37 |
for (int i = 0; i < num; ++i) { |
38 | 38 |
nodes.push_back(graph.addNode()); |
39 | 39 |
} |
40 | 40 |
typedef typename Graph::template NodeMap<int> IntNodeMap; |
41 | 41 |
IntNodeMap map(graph, 42); |
42 | 42 |
for (int i = 0; i < int(nodes.size()); ++i) { |
43 | 43 |
check(map[nodes[i]] == 42, "Wrong map constructor."); |
44 | 44 |
} |
45 | 45 |
for (int i = 0; i < num; ++i) { |
46 | 46 |
nodes.push_back(graph.addNode()); |
47 | 47 |
map[nodes.back()] = 23; |
48 | 48 |
check(map[nodes.back()] == 23, "Wrong operator[]."); |
49 | 49 |
} |
50 | 50 |
map = constMap<Node>(12); |
51 | 51 |
for (int i = 0; i < int(nodes.size()); ++i) { |
52 | 52 |
check(map[nodes[i]] == 12, "Wrong map constructor."); |
53 | 53 |
} |
54 | 54 |
graph.clear(); |
55 | 55 |
nodes.clear(); |
56 | 56 |
} |
57 | 57 |
|
58 | 58 |
template <typename Graph> |
59 | 59 |
void checkGraphArcMap() { |
60 | 60 |
Graph graph; |
61 | 61 |
const int num = 16; |
62 | 62 |
|
63 | 63 |
typedef typename Graph::Node Node; |
64 | 64 |
typedef typename Graph::Arc Arc; |
65 | 65 |
|
66 | 66 |
std::vector<Node> nodes; |
67 | 67 |
for (int i = 0; i < num; ++i) { |
68 | 68 |
nodes.push_back(graph.addNode()); |
69 | 69 |
} |
70 | 70 |
|
71 | 71 |
std::vector<Arc> arcs; |
72 | 72 |
for (int i = 0; i < num; ++i) { |
73 | 73 |
for (int j = 0; j < i; ++j) { |
74 | 74 |
arcs.push_back(graph.addArc(nodes[i], nodes[j])); |
75 | 75 |
} |
76 | 76 |
} |
77 | 77 |
|
78 | 78 |
typedef typename Graph::template ArcMap<int> IntArcMap; |
79 | 79 |
IntArcMap map(graph, 42); |
80 | 80 |
|
81 | 81 |
for (int i = 0; i < int(arcs.size()); ++i) { |
82 | 82 |
check(map[arcs[i]] == 42, "Wrong map constructor."); |
83 | 83 |
} |
84 | 84 |
|
85 | 85 |
for (int i = 0; i < num; ++i) { |
86 | 86 |
for (int j = i + 1; j < num; ++j) { |
87 | 87 |
arcs.push_back(graph.addArc(nodes[i], nodes[j])); |
88 | 88 |
map[arcs.back()] = 23; |
89 | 89 |
check(map[arcs.back()] == 23, "Wrong operator[]."); |
90 | 90 |
} |
91 | 91 |
} |
92 | 92 |
map = constMap<Arc>(12); |
93 | 93 |
for (int i = 0; i < int(arcs.size()); ++i) { |
94 | 94 |
check(map[arcs[i]] == 12, "Wrong map constructor."); |
95 | 95 |
} |
96 | 96 |
graph.clear(); |
97 | 97 |
arcs.clear(); |
98 | 98 |
} |
99 | 99 |
1 |
/* -*- C++ -*- |
|
1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
|
2 | 2 |
* |
3 |
* This file is a part of LEMON, a generic C++ optimization library |
|
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 <lemon/concepts/graph.h> |
20 | 20 |
#include <lemon/list_graph.h> |
21 | 21 |
#include <lemon/smart_graph.h> |
22 | 22 |
// #include <lemon/full_graph.h> |
23 | 23 |
// #include <lemon/grid_graph.h> |
24 | 24 |
|
25 | 25 |
#include "test_tools.h" |
26 | 26 |
#include "graph_test.h" |
27 | 27 |
#include "graph_maps_test.h" |
28 | 28 |
|
29 | 29 |
using namespace lemon; |
30 | 30 |
using namespace lemon::concepts; |
31 | 31 |
|
32 | 32 |
void check_concepts() { |
33 | 33 |
{ // Checking graph components |
34 | 34 |
checkConcept<BaseGraphComponent, BaseGraphComponent >(); |
35 | 35 |
|
36 | 36 |
checkConcept<IDableGraphComponent<>, |
37 | 37 |
IDableGraphComponent<> >(); |
38 | 38 |
|
39 | 39 |
checkConcept<IterableGraphComponent<>, |
40 | 40 |
IterableGraphComponent<> >(); |
41 | 41 |
|
42 | 42 |
checkConcept<MappableGraphComponent<>, |
43 | 43 |
MappableGraphComponent<> >(); |
44 | 44 |
} |
45 | 45 |
{ // Checking skeleton graph |
46 | 46 |
checkConcept<Graph, Graph>(); |
47 | 47 |
} |
48 | 48 |
{ // Checking ListGraph |
49 | 49 |
checkConcept<Graph, ListGraph>(); |
50 | 50 |
checkConcept<AlterableGraphComponent<>, ListGraph>(); |
51 | 51 |
checkConcept<ExtendableGraphComponent<>, ListGraph>(); |
52 | 52 |
checkConcept<ClearableGraphComponent<>, ListGraph>(); |
53 | 53 |
checkConcept<ErasableGraphComponent<>, ListGraph>(); |
54 | 54 |
checkGraphIterators<ListGraph>(); |
55 | 55 |
} |
56 | 56 |
{ // Checking SmartGraph |
57 | 57 |
checkConcept<Graph, SmartGraph>(); |
58 | 58 |
checkConcept<AlterableGraphComponent<>, SmartGraph>(); |
59 | 59 |
checkConcept<ExtendableGraphComponent<>, SmartGraph>(); |
60 | 60 |
checkConcept<ClearableGraphComponent<>, SmartGraph>(); |
61 | 61 |
checkGraphIterators<SmartGraph>(); |
62 | 62 |
} |
63 | 63 |
// { // Checking FullGraph |
64 | 64 |
// checkConcept<Graph, FullGraph>(); |
65 | 65 |
// checkGraphIterators<FullGraph>(); |
66 | 66 |
// } |
67 | 67 |
// { // Checking GridGraph |
68 | 68 |
// checkConcept<Graph, GridGraph>(); |
69 | 69 |
// checkGraphIterators<GridGraph>(); |
70 | 70 |
// } |
71 | 71 |
} |
72 | 72 |
|
73 | 73 |
template <typename Graph> |
74 | 74 |
void check_graph_validity() { |
75 | 75 |
TEMPLATE_GRAPH_TYPEDEFS(Graph); |
76 | 76 |
Graph g; |
77 | 77 |
|
78 | 78 |
Node |
79 | 79 |
n1 = g.addNode(), |
80 | 80 |
n2 = g.addNode(), |
81 | 81 |
n3 = g.addNode(); |
82 | 82 |
|
83 | 83 |
Edge |
84 | 84 |
e1 = g.addEdge(n1, n2), |
85 | 85 |
e2 = g.addEdge(n2, n3); |
86 | 86 |
|
87 | 87 |
check(g.valid(n1), "Wrong validity check"); |
88 | 88 |
check(g.valid(e1), "Wrong validity check"); |
89 | 89 |
check(g.valid(g.direct(e1, true)), "Wrong validity check"); |
90 | 90 |
|
91 | 91 |
check(!g.valid(g.nodeFromId(-1)), "Wrong validity check"); |
92 | 92 |
check(!g.valid(g.edgeFromId(-1)), "Wrong validity check"); |
93 | 93 |
check(!g.valid(g.arcFromId(-1)), "Wrong validity check"); |
94 | 94 |
} |
95 | 95 |
|
96 | 96 |
template <typename Graph> |
97 | 97 |
void check_graph_validity_erase() { |
98 | 98 |
TEMPLATE_GRAPH_TYPEDEFS(Graph); |
99 | 99 |
Graph g; |
1 |
/* -*- C++ -*- |
|
1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
|
2 | 2 |
* |
3 |
* This file is a part of LEMON, a generic C++ optimization library |
|
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 |
#ifndef LEMON_TEST_GRAPH_TEST_H |
20 | 20 |
#define LEMON_TEST_GRAPH_TEST_H |
21 | 21 |
|
22 | 22 |
#include <lemon/graph_utils.h> |
23 | 23 |
#include "test_tools.h" |
24 | 24 |
|
25 | 25 |
namespace lemon { |
26 | 26 |
|
27 | 27 |
template<class Graph> |
28 | 28 |
void checkGraphNodeList(const Graph &G, int cnt) |
29 | 29 |
{ |
30 | 30 |
typename Graph::NodeIt n(G); |
31 | 31 |
for(int i=0;i<cnt;i++) { |
32 | 32 |
check(n!=INVALID,"Wrong Node list linking."); |
33 | 33 |
++n; |
34 | 34 |
} |
35 | 35 |
check(n==INVALID,"Wrong Node list linking."); |
36 | 36 |
check(countNodes(G)==cnt,"Wrong Node number."); |
37 | 37 |
} |
38 | 38 |
|
39 | 39 |
template<class Graph> |
40 | 40 |
void checkGraphArcList(const Graph &G, int cnt) |
41 | 41 |
{ |
42 | 42 |
typename Graph::ArcIt e(G); |
43 | 43 |
for(int i=0;i<cnt;i++) { |
44 | 44 |
check(e!=INVALID,"Wrong Arc list linking."); |
45 | 45 |
++e; |
46 | 46 |
} |
47 | 47 |
check(e==INVALID,"Wrong Arc list linking."); |
48 | 48 |
check(countArcs(G)==cnt,"Wrong Arc number."); |
49 | 49 |
} |
50 | 50 |
|
51 | 51 |
template<class Graph> |
52 | 52 |
void checkGraphOutArcList(const Graph &G, typename Graph::Node n, int cnt) |
53 | 53 |
{ |
54 | 54 |
typename Graph::OutArcIt e(G,n); |
55 | 55 |
for(int i=0;i<cnt;i++) { |
56 | 56 |
check(e!=INVALID,"Wrong OutArc list linking."); |
57 | 57 |
check(n==G.source(e),"Wrong OutArc list linking."); |
58 | 58 |
++e; |
59 | 59 |
} |
60 | 60 |
check(e==INVALID,"Wrong OutArc list linking."); |
61 | 61 |
check(countOutArcs(G,n)==cnt,"Wrong OutArc number."); |
62 | 62 |
} |
63 | 63 |
|
64 | 64 |
template<class Graph> |
65 | 65 |
void checkGraphInArcList(const Graph &G, typename Graph::Node n, int cnt) |
66 | 66 |
{ |
67 | 67 |
typename Graph::InArcIt e(G,n); |
68 | 68 |
for(int i=0;i<cnt;i++) { |
69 | 69 |
check(e!=INVALID,"Wrong InArc list linking."); |
70 | 70 |
check(n==G.target(e),"Wrong InArc list linking."); |
71 | 71 |
++e; |
72 | 72 |
} |
73 | 73 |
check(e==INVALID,"Wrong InArc list linking."); |
74 | 74 |
check(countInArcs(G,n)==cnt,"Wrong InArc number."); |
75 | 75 |
} |
76 | 76 |
|
77 | 77 |
template<class Graph> |
78 | 78 |
void checkGraphEdgeList(const Graph &G, int cnt) |
79 | 79 |
{ |
80 | 80 |
typename Graph::EdgeIt e(G); |
81 | 81 |
for(int i=0;i<cnt;i++) { |
82 | 82 |
check(e!=INVALID,"Wrong Edge list linking."); |
83 | 83 |
++e; |
84 | 84 |
} |
85 | 85 |
check(e==INVALID,"Wrong Edge list linking."); |
86 | 86 |
check(countEdges(G)==cnt,"Wrong Edge number."); |
87 | 87 |
} |
88 | 88 |
|
89 | 89 |
template<class Graph> |
90 | 90 |
void checkGraphIncEdgeList(const Graph &G, typename Graph::Node n, int cnt) |
91 | 91 |
{ |
92 | 92 |
typename Graph::IncEdgeIt e(G,n); |
93 | 93 |
for(int i=0;i<cnt;i++) { |
94 | 94 |
check(e!=INVALID,"Wrong IncEdge list linking."); |
95 | 95 |
check(n==G.u(e) || n==G.v(e),"Wrong IncEdge list linking."); |
96 | 96 |
++e; |
97 | 97 |
} |
98 | 98 |
check(e==INVALID,"Wrong IncEdge list linking."); |
99 | 99 |
check(countIncEdges(G,n)==cnt,"Wrong IncEdge number."); |
1 |
/* -*- C++ -*- |
|
1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
|
2 | 2 |
* |
3 |
* This file is a part of LEMON, a generic C++ optimization library |
|
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 <cstdlib> |
20 | 20 |
#include <ctime> |
21 | 21 |
|
22 | 22 |
#include <lemon/random.h> |
23 | 23 |
#include <lemon/graph_utils.h> |
24 | 24 |
#include <lemon/list_graph.h> |
25 | 25 |
#include <lemon/smart_graph.h> |
26 | 26 |
|
27 | 27 |
#include "graph_test.h" |
28 | 28 |
#include "test_tools.h" |
29 | 29 |
|
30 | 30 |
using namespace lemon; |
31 | 31 |
|
32 | 32 |
template <typename Digraph> |
33 | 33 |
void checkFindArcs() { |
34 | 34 |
TEMPLATE_DIGRAPH_TYPEDEFS(Digraph); |
35 | 35 |
|
36 | 36 |
{ |
37 | 37 |
Digraph digraph; |
38 | 38 |
for (int i = 0; i < 10; ++i) { |
39 | 39 |
digraph.addNode(); |
40 | 40 |
} |
41 | 41 |
DescriptorMap<Digraph, Node> nodes(digraph); |
42 | 42 |
typename DescriptorMap<Digraph, Node>::InverseMap invNodes(nodes); |
43 | 43 |
for (int i = 0; i < 100; ++i) { |
44 | 44 |
int src = rnd[invNodes.size()]; |
45 | 45 |
int trg = rnd[invNodes.size()]; |
46 | 46 |
digraph.addArc(invNodes[src], invNodes[trg]); |
47 | 47 |
} |
48 | 48 |
typename Digraph::template ArcMap<bool> found(digraph, false); |
49 | 49 |
DescriptorMap<Digraph, Arc> arcs(digraph); |
50 | 50 |
for (NodeIt src(digraph); src != INVALID; ++src) { |
51 | 51 |
for (NodeIt trg(digraph); trg != INVALID; ++trg) { |
52 | 52 |
for (ConArcIt<Digraph> con(digraph, src, trg); con != INVALID; ++con) { |
53 | 53 |
check(digraph.source(con) == src, "Wrong source."); |
54 | 54 |
check(digraph.target(con) == trg, "Wrong target."); |
55 | 55 |
check(found[con] == false, "The arc found already."); |
56 | 56 |
found[con] = true; |
57 | 57 |
} |
58 | 58 |
} |
59 | 59 |
} |
60 | 60 |
for (ArcIt it(digraph); it != INVALID; ++it) { |
61 | 61 |
check(found[it] == true, "The arc is not found."); |
62 | 62 |
} |
63 | 63 |
} |
64 | 64 |
|
65 | 65 |
{ |
66 | 66 |
int num = 5; |
67 | 67 |
Digraph fg; |
68 | 68 |
std::vector<Node> nodes; |
69 | 69 |
for (int i = 0; i < num; ++i) { |
70 | 70 |
nodes.push_back(fg.addNode()); |
71 | 71 |
} |
72 | 72 |
for (int i = 0; i < num * num; ++i) { |
73 | 73 |
fg.addArc(nodes[i / num], nodes[i % num]); |
74 | 74 |
} |
75 | 75 |
check(countNodes(fg) == num, "Wrong node number."); |
76 | 76 |
check(countArcs(fg) == num*num, "Wrong arc number."); |
77 | 77 |
for (NodeIt src(fg); src != INVALID; ++src) { |
78 | 78 |
for (NodeIt trg(fg); trg != INVALID; ++trg) { |
79 | 79 |
ConArcIt<Digraph> con(fg, src, trg); |
80 | 80 |
check(con != INVALID, "There is no connecting arc."); |
81 | 81 |
check(fg.source(con) == src, "Wrong source."); |
82 | 82 |
check(fg.target(con) == trg, "Wrong target."); |
83 | 83 |
check(++con == INVALID, "There is more connecting arc."); |
84 | 84 |
} |
85 | 85 |
} |
86 | 86 |
ArcLookUp<Digraph> al1(fg); |
87 | 87 |
DynArcLookUp<Digraph> al2(fg); |
88 | 88 |
AllArcLookUp<Digraph> al3(fg); |
89 | 89 |
for (NodeIt src(fg); src != INVALID; ++src) { |
90 | 90 |
for (NodeIt trg(fg); trg != INVALID; ++trg) { |
91 | 91 |
Arc con1 = al1(src, trg); |
92 | 92 |
Arc con2 = al2(src, trg); |
93 | 93 |
Arc con3 = al3(src, trg); |
94 | 94 |
Arc con4 = findArc(fg, src, trg); |
95 | 95 |
check(con1 == con2 && con2 == con3 && con3 == con4, "Different results.") |
96 | 96 |
check(con1 != INVALID, "There is no connecting arc."); |
97 | 97 |
check(fg.source(con1) == src, "Wrong source."); |
98 | 98 |
check(fg.target(con1) == trg, "Wrong target."); |
99 | 99 |
check(al3(src, trg, con3) == INVALID, "There is more connecting arc."); |
1 |
/* -*- C++ -*- |
|
1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
|
2 | 2 |
* |
3 |
* This file is a part of LEMON, a generic C++ optimization library |
|
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 <iostream> |
20 | 20 |
#include <fstream> |
21 | 21 |
#include <string> |
22 | 22 |
#include <vector> |
23 | 23 |
|
24 | 24 |
#include <lemon/concept_check.h> |
25 | 25 |
#include <lemon/concepts/heap.h> |
26 | 26 |
|
27 | 27 |
#include <lemon/smart_graph.h> |
28 | 28 |
|
29 | 29 |
#include <lemon/lgf_reader.h> |
30 | 30 |
#include <lemon/dijkstra.h> |
31 | 31 |
#include <lemon/maps.h> |
32 | 32 |
|
33 | 33 |
#include <lemon/bin_heap.h> |
34 | 34 |
|
35 | 35 |
#include "test_tools.h" |
36 | 36 |
|
37 | 37 |
using namespace lemon; |
38 | 38 |
using namespace lemon::concepts; |
39 | 39 |
|
40 | 40 |
typedef ListDigraph Digraph; |
41 | 41 |
DIGRAPH_TYPEDEFS(Digraph); |
42 | 42 |
|
43 | 43 |
char test_lgf[] = |
44 | 44 |
"@nodes\n" |
45 | 45 |
"label\n" |
46 | 46 |
"0\n" |
47 | 47 |
"1\n" |
48 | 48 |
"2\n" |
49 | 49 |
"3\n" |
50 | 50 |
"4\n" |
51 | 51 |
"5\n" |
52 | 52 |
"6\n" |
53 | 53 |
"7\n" |
54 | 54 |
"8\n" |
55 | 55 |
"9\n" |
56 | 56 |
"@arcs\n" |
57 | 57 |
" label capacity\n" |
58 | 58 |
"0 5 0 94\n" |
59 | 59 |
"3 9 1 11\n" |
60 | 60 |
"8 7 2 83\n" |
61 | 61 |
"1 2 3 94\n" |
62 | 62 |
"5 7 4 35\n" |
63 | 63 |
"7 4 5 84\n" |
64 | 64 |
"9 5 6 38\n" |
65 | 65 |
"0 4 7 96\n" |
66 | 66 |
"6 7 8 6\n" |
67 | 67 |
"3 1 9 27\n" |
68 | 68 |
"5 2 10 77\n" |
69 | 69 |
"5 6 11 69\n" |
70 | 70 |
"6 5 12 41\n" |
71 | 71 |
"4 6 13 70\n" |
72 | 72 |
"3 2 14 45\n" |
73 | 73 |
"7 9 15 93\n" |
74 | 74 |
"5 9 16 50\n" |
75 | 75 |
"9 0 17 94\n" |
76 | 76 |
"9 6 18 67\n" |
77 | 77 |
"0 9 19 86\n" |
78 | 78 |
"@attributes\n" |
79 | 79 |
"source 3\n"; |
80 | 80 |
|
81 | 81 |
int test_seq[] = { 2, 28, 19, 27, 33, 25, 13, 41, 10, 26, 1, 9, 4, 34}; |
82 | 82 |
int test_inc[] = {20, 28, 34, 16, 0, 46, 44, 0, 42, 32, 14, 8, 6, 37}; |
83 | 83 |
|
84 | 84 |
int test_len = sizeof(test_seq) / sizeof(test_seq[0]); |
85 | 85 |
|
86 | 86 |
template <typename Heap> |
87 | 87 |
void heapSortTest() { |
88 | 88 |
RangeMap<int> map(test_len, -1); |
89 | 89 |
|
90 | 90 |
Heap heap(map); |
91 | 91 |
|
92 | 92 |
std::vector<int> v(test_len); |
93 | 93 |
|
94 | 94 |
for (int i = 0; i < test_len; ++i) { |
95 | 95 |
v[i] = test_seq[i]; |
96 | 96 |
heap.push(i, v[i]); |
97 | 97 |
} |
98 | 98 |
std::sort(v.begin(), v.end()); |
99 | 99 |
for (int i = 0; i < test_len; ++i) { |
1 |
/* -*- C++ -*- |
|
1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
|
2 | 2 |
* |
3 |
* This file is a part of LEMON, a generic C++ optimization library |
|
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 <iostream> |
20 | 20 |
#include <vector> |
21 | 21 |
|
22 | 22 |
#include "test_tools.h" |
23 | 23 |
#include <lemon/maps.h> |
24 | 24 |
#include <lemon/kruskal.h> |
25 | 25 |
#include <lemon/list_graph.h> |
26 | 26 |
|
27 | 27 |
#include <lemon/concepts/maps.h> |
28 | 28 |
#include <lemon/concepts/digraph.h> |
29 | 29 |
#include <lemon/concepts/graph.h> |
30 | 30 |
|
31 | 31 |
using namespace std; |
32 | 32 |
using namespace lemon; |
33 | 33 |
|
34 | 34 |
void checkCompileKruskal() |
35 | 35 |
{ |
36 | 36 |
concepts::WriteMap<concepts::Digraph::Arc,bool> w; |
37 | 37 |
concepts::WriteMap<concepts::Graph::Edge,bool> uw; |
38 | 38 |
|
39 | 39 |
concepts::ReadMap<concepts::Digraph::Arc,int> r; |
40 | 40 |
concepts::ReadMap<concepts::Graph::Edge,int> ur; |
41 | 41 |
|
42 | 42 |
concepts::Digraph g; |
43 | 43 |
concepts::Graph ug; |
44 | 44 |
|
45 | 45 |
kruskal(g, r, w); |
46 | 46 |
kruskal(ug, ur, uw); |
47 | 47 |
|
48 | 48 |
std::vector<std::pair<concepts::Digraph::Arc, int> > rs; |
49 | 49 |
std::vector<std::pair<concepts::Graph::Edge, int> > urs; |
50 | 50 |
|
51 | 51 |
kruskal(g, rs, w); |
52 | 52 |
kruskal(ug, urs, uw); |
53 | 53 |
|
54 | 54 |
std::vector<concepts::Digraph::Arc> ws; |
55 | 55 |
std::vector<concepts::Graph::Edge> uws; |
56 | 56 |
|
57 | 57 |
kruskal(g, r, ws.begin()); |
58 | 58 |
kruskal(ug, ur, uws.begin()); |
59 | 59 |
} |
60 | 60 |
|
61 | 61 |
int main() { |
62 | 62 |
|
63 | 63 |
typedef ListGraph::Node Node; |
64 | 64 |
typedef ListGraph::Edge Edge; |
65 | 65 |
typedef ListGraph::NodeIt NodeIt; |
66 | 66 |
typedef ListGraph::ArcIt ArcIt; |
67 | 67 |
|
68 | 68 |
ListGraph G; |
69 | 69 |
|
70 | 70 |
Node s=G.addNode(); |
71 | 71 |
Node v1=G.addNode(); |
72 | 72 |
Node v2=G.addNode(); |
73 | 73 |
Node v3=G.addNode(); |
74 | 74 |
Node v4=G.addNode(); |
75 | 75 |
Node t=G.addNode(); |
76 | 76 |
|
77 | 77 |
Edge e1 = G.addEdge(s, v1); |
78 | 78 |
Edge e2 = G.addEdge(s, v2); |
79 | 79 |
Edge e3 = G.addEdge(v1, v2); |
80 | 80 |
Edge e4 = G.addEdge(v2, v1); |
81 | 81 |
Edge e5 = G.addEdge(v1, v3); |
82 | 82 |
Edge e6 = G.addEdge(v3, v2); |
83 | 83 |
Edge e7 = G.addEdge(v2, v4); |
84 | 84 |
Edge e8 = G.addEdge(v4, v3); |
85 | 85 |
Edge e9 = G.addEdge(v3, t); |
86 | 86 |
Edge e10 = G.addEdge(v4, t); |
87 | 87 |
|
88 | 88 |
typedef ListGraph::EdgeMap<int> ECostMap; |
89 | 89 |
typedef ListGraph::EdgeMap<bool> EBoolMap; |
90 | 90 |
|
91 | 91 |
ECostMap edge_cost_map(G, 2); |
92 | 92 |
EBoolMap tree_map(G); |
93 | 93 |
|
94 | 94 |
|
95 | 95 |
//Test with const map. |
96 | 96 |
check(kruskal(G, ConstMap<ListGraph::Edge,int>(2), tree_map)==10, |
97 | 97 |
"Total cost should be 10"); |
98 | 98 |
//Test with an edge map (filled with uniform costs). |
99 | 99 |
check(kruskal(G, edge_cost_map, tree_map)==10, |
1 |
/* -*- C++ -*- |
|
1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
|
2 | 2 |
* |
3 |
* This file is a part of LEMON, a generic C++ optimization library |
|
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 <deque> |
20 | 20 |
#include <set> |
21 | 21 |
|
22 | 22 |
#include <lemon/concept_check.h> |
23 | 23 |
#include <lemon/concepts/maps.h> |
24 | 24 |
#include <lemon/maps.h> |
25 | 25 |
|
26 | 26 |
#include "test_tools.h" |
27 | 27 |
|
28 | 28 |
using namespace lemon; |
29 | 29 |
using namespace lemon::concepts; |
30 | 30 |
|
31 | 31 |
struct A {}; |
32 | 32 |
inline bool operator<(A, A) { return true; } |
33 | 33 |
struct B {}; |
34 | 34 |
|
35 | 35 |
class C { |
36 | 36 |
int x; |
37 | 37 |
public: |
38 | 38 |
C(int _x) : x(_x) {} |
39 | 39 |
}; |
40 | 40 |
|
41 | 41 |
class F { |
42 | 42 |
public: |
43 | 43 |
typedef A argument_type; |
44 | 44 |
typedef B result_type; |
45 | 45 |
|
46 | 46 |
B operator()(const A&) const { return B(); } |
47 | 47 |
private: |
48 | 48 |
F& operator=(const F&); |
49 | 49 |
}; |
50 | 50 |
|
51 | 51 |
int func(A) { return 3; } |
52 | 52 |
|
53 | 53 |
int binc(int a, B) { return a+1; } |
54 | 54 |
|
55 | 55 |
typedef ReadMap<A, double> DoubleMap; |
56 | 56 |
typedef ReadWriteMap<A, double> DoubleWriteMap; |
57 | 57 |
typedef ReferenceMap<A, double, double&, const double&> DoubleRefMap; |
58 | 58 |
|
59 | 59 |
typedef ReadMap<A, bool> BoolMap; |
60 | 60 |
typedef ReadWriteMap<A, bool> BoolWriteMap; |
61 | 61 |
typedef ReferenceMap<A, bool, bool&, const bool&> BoolRefMap; |
62 | 62 |
|
63 | 63 |
int main() |
64 | 64 |
{ |
65 | 65 |
// Map concepts |
66 | 66 |
checkConcept<ReadMap<A,B>, ReadMap<A,B> >(); |
67 | 67 |
checkConcept<ReadMap<A,C>, ReadMap<A,C> >(); |
68 | 68 |
checkConcept<WriteMap<A,B>, WriteMap<A,B> >(); |
69 | 69 |
checkConcept<WriteMap<A,C>, WriteMap<A,C> >(); |
70 | 70 |
checkConcept<ReadWriteMap<A,B>, ReadWriteMap<A,B> >(); |
71 | 71 |
checkConcept<ReadWriteMap<A,C>, ReadWriteMap<A,C> >(); |
72 | 72 |
checkConcept<ReferenceMap<A,B,B&,const B&>, ReferenceMap<A,B,B&,const B&> >(); |
73 | 73 |
checkConcept<ReferenceMap<A,C,C&,const C&>, ReferenceMap<A,C,C&,const C&> >(); |
74 | 74 |
|
75 | 75 |
// NullMap |
76 | 76 |
{ |
77 | 77 |
checkConcept<ReadWriteMap<A,B>, NullMap<A,B> >(); |
78 | 78 |
NullMap<A,B> map1; |
79 | 79 |
NullMap<A,B> map2 = map1; |
80 | 80 |
map1 = nullMap<A,B>(); |
81 | 81 |
} |
82 | 82 |
|
83 | 83 |
// ConstMap |
84 | 84 |
{ |
85 | 85 |
checkConcept<ReadWriteMap<A,B>, ConstMap<A,B> >(); |
86 | 86 |
checkConcept<ReadWriteMap<A,C>, ConstMap<A,C> >(); |
87 | 87 |
ConstMap<A,B> map1; |
88 | 88 |
ConstMap<A,B> map2 = B(); |
89 | 89 |
ConstMap<A,B> map3 = map1; |
90 | 90 |
map1 = constMap<A>(B()); |
91 | 91 |
map1 = constMap<A,B>(); |
92 | 92 |
map1.setAll(B()); |
93 | 93 |
ConstMap<A,C> map4(C(1)); |
94 | 94 |
ConstMap<A,C> map5 = map4; |
95 | 95 |
map4 = constMap<A>(C(2)); |
96 | 96 |
map4.setAll(C(3)); |
97 | 97 |
|
98 | 98 |
checkConcept<ReadWriteMap<A,int>, ConstMap<A,int> >(); |
99 | 99 |
check(constMap<A>(10)[A()] == 10, "Something is wrong with ConstMap"); |
1 |
/* -*- C++ -*- |
|
1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
|
2 | 2 |
* |
3 |
* This file is a part of LEMON, a generic C++ optimization library |
|
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 <string> |
20 | 20 |
#include <iostream> |
21 | 21 |
|
22 | 22 |
#include <lemon/concepts/path.h> |
23 | 23 |
#include <lemon/concepts/digraph.h> |
24 | 24 |
|
25 | 25 |
#include <lemon/path.h> |
26 | 26 |
#include <lemon/list_graph.h> |
27 | 27 |
|
28 | 28 |
#include "test_tools.h" |
29 | 29 |
|
30 | 30 |
using namespace std; |
31 | 31 |
using namespace lemon; |
32 | 32 |
|
33 | 33 |
void check_concepts() { |
34 | 34 |
checkConcept<concepts::Path<ListDigraph>, concepts::Path<ListDigraph> >(); |
35 | 35 |
checkConcept<concepts::Path<ListDigraph>, Path<ListDigraph> >(); |
36 | 36 |
checkConcept<concepts::Path<ListDigraph>, SimplePath<ListDigraph> >(); |
37 | 37 |
checkConcept<concepts::Path<ListDigraph>, StaticPath<ListDigraph> >(); |
38 | 38 |
checkConcept<concepts::Path<ListDigraph>, ListPath<ListDigraph> >(); |
39 | 39 |
} |
40 | 40 |
|
41 | 41 |
int main() { |
42 | 42 |
check_concepts(); |
43 | 43 |
return 0; |
44 | 44 |
} |
1 |
/* -*- C++ -*- |
|
1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
|
2 | 2 |
* |
3 |
* This file is a part of LEMON, a generic C++ optimization library |
|
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 <lemon/random.h> |
20 | 20 |
#include "test_tools.h" |
21 | 21 |
|
22 | 22 |
int seed_array[] = {1, 2}; |
23 | 23 |
|
24 | 24 |
int main() |
25 | 25 |
{ |
26 | 26 |
double a=lemon::rnd(); |
27 | 27 |
check(a<1.0&&a>0.0,"This should be in [0,1)"); |
28 | 28 |
a=lemon::rnd.gauss(); |
29 | 29 |
a=lemon::rnd.gamma(3.45,0); |
30 | 30 |
a=lemon::rnd.gamma(4); |
31 | 31 |
//Does gamma work with integer k? |
32 | 32 |
a=lemon::rnd.gamma(4.0,0); |
33 | 33 |
a=lemon::rnd.poisson(.5); |
34 | 34 |
|
35 | 35 |
lemon::rnd.seed(100); |
36 | 36 |
lemon::rnd.seed(seed_array, seed_array + |
37 | 37 |
(sizeof(seed_array) / sizeof(seed_array[0]))); |
38 | 38 |
|
39 | 39 |
return 0; |
40 | 40 |
} |
1 |
/* -*- C++ -*- |
|
1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
|
2 | 2 |
* |
3 |
* This file is a part of LEMON, a generic C++ optimization library |
|
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 |
#ifndef LEMON_TEST_TEST_TOOLS_H |
20 | 20 |
#define LEMON_TEST_TEST_TOOLS_H |
21 | 21 |
|
22 | 22 |
///\ingroup misc |
23 | 23 |
///\file |
24 | 24 |
///\brief Some utilities to write test programs. |
25 | 25 |
|
26 | 26 |
#include <iostream> |
27 | 27 |
#include <stdlib.h> |
28 | 28 |
|
29 | 29 |
///If \c rc is fail, writes an error message and exits. |
30 | 30 |
|
31 | 31 |
///If \c rc is fail, writes an error message and exits. |
32 | 32 |
///The error message contains the file name and the line number of the |
33 | 33 |
///source code in a standard from, which makes it possible to go there |
34 | 34 |
///using good source browsers like e.g. \c emacs. |
35 | 35 |
/// |
36 | 36 |
///For example |
37 | 37 |
///\code check(0==1,"This is obviously false.");\endcode will |
38 | 38 |
///print something like this (and then exits). |
39 | 39 |
///\verbatim file_name.cc:123: error: This is obviously false. \endverbatim |
40 | 40 |
#define check(rc, msg) \ |
41 | 41 |
if(!(rc)) { \ |
42 | 42 |
std::cerr << __FILE__ ":" << __LINE__ << ": error: " << msg << std::endl; \ |
43 | 43 |
abort(); \ |
44 | 44 |
} else { } \ |
45 | 45 |
|
46 | 46 |
#endif |
1 |
/* -*- C++ -*- |
|
1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
|
2 | 2 |
* |
3 |
* This file is a part of LEMON, a generic C++ optimization library |
|
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 "test_tools.h" |
20 | 20 |
|
21 | 21 |
int main() |
22 | 22 |
{ |
23 | 23 |
check(false, "Don't panic. Failing is the right behaviour here."); |
24 | 24 |
return 0; |
25 | 25 |
} |
1 |
/* -*- C++ -*- |
|
1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
|
2 | 2 |
* |
3 |
* This file is a part of LEMON, a generic C++ optimization library |
|
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 "test_tools.h" |
20 | 20 |
|
21 | 21 |
int main() |
22 | 22 |
{ |
23 | 23 |
check(true, "It should pass."); |
24 | 24 |
return 0; |
25 | 25 |
} |
1 |
/* -*- C++ -*- |
|
1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
|
2 | 2 |
* |
3 |
* This file is a part of LEMON, a generic C++ optimization library |
|
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 <lemon/time_measure.h> |
20 | 20 |
|
21 | 21 |
using namespace lemon; |
22 | 22 |
|
23 | 23 |
void f() |
24 | 24 |
{ |
25 | 25 |
double d=0; |
26 | 26 |
for(int i=0;i<1000;i++) |
27 | 27 |
d+=0.1; |
28 | 28 |
} |
29 | 29 |
|
30 | 30 |
void g() |
31 | 31 |
{ |
32 | 32 |
static Timer T; |
33 | 33 |
|
34 | 34 |
for(int i=0;i<1000;i++) |
35 | 35 |
TimeStamp x(T); |
36 | 36 |
} |
37 | 37 |
|
38 | 38 |
int main() |
39 | 39 |
{ |
40 | 40 |
Timer T; |
41 | 41 |
unsigned int n; |
42 | 42 |
for(n=0;T.realTime()<1.0;n++) ; |
43 | 43 |
std::cout << T << " (" << n << " time queries)\n"; |
44 | 44 |
T.restart(); |
45 | 45 |
while(T.realTime()<2.0) ; |
46 | 46 |
std::cout << T << '\n'; |
47 | 47 |
TimeStamp full; |
48 | 48 |
TimeStamp t; |
49 | 49 |
t=runningTimeTest(f,1,&n,&full); |
50 | 50 |
std::cout << t << " (" << n << " tests)\n"; |
51 | 51 |
std::cout << "Total: " << full << "\n"; |
52 | 52 |
|
53 | 53 |
t=runningTimeTest(g,1,&n,&full); |
54 | 54 |
std::cout << t << " (" << n << " tests)\n"; |
55 | 55 |
std::cout << "Total: " << full << "\n"; |
56 | 56 |
|
57 | 57 |
return 0; |
58 | 58 |
} |
1 |
/* -*- C++ -*- |
|
1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
|
2 | 2 |
* |
3 |
* This file is a part of LEMON, a generic C++ optimization library |
|
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 <lemon/list_graph.h> |
20 | 20 |
#include <lemon/maps.h> |
21 | 21 |
#include <lemon/unionfind.h> |
22 | 22 |
#include "test_tools.h" |
23 | 23 |
|
24 | 24 |
using namespace lemon; |
25 | 25 |
using namespace std; |
26 | 26 |
|
27 | 27 |
typedef UnionFindEnum<ListGraph::NodeMap<int> > UFE; |
28 | 28 |
|
29 | 29 |
int main() { |
30 | 30 |
ListGraph g; |
31 | 31 |
ListGraph::NodeMap<int> base(g); |
32 | 32 |
UFE U(base); |
33 | 33 |
vector<ListGraph::Node> n; |
34 | 34 |
|
35 | 35 |
for(int i=0;i<20;i++) n.push_back(g.addNode()); |
36 | 36 |
|
37 | 37 |
U.insert(n[1]); |
38 | 38 |
U.insert(n[2]); |
39 | 39 |
|
40 | 40 |
check(U.join(n[1],n[2]) != -1, "Something is wrong with UnionFindEnum"); |
41 | 41 |
|
42 | 42 |
U.insert(n[3]); |
43 | 43 |
U.insert(n[4]); |
44 | 44 |
U.insert(n[5]); |
45 | 45 |
U.insert(n[6]); |
46 | 46 |
U.insert(n[7]); |
47 | 47 |
|
48 | 48 |
|
49 | 49 |
check(U.join(n[1],n[4]) != -1, "Something is wrong with UnionFindEnum"); |
50 | 50 |
check(U.join(n[2],n[4]) == -1, "Something is wrong with UnionFindEnum"); |
51 | 51 |
check(U.join(n[3],n[5]) != -1, "Something is wrong with UnionFindEnum"); |
52 | 52 |
|
53 | 53 |
|
54 | 54 |
U.insert(n[8],U.find(n[5])); |
55 | 55 |
|
56 | 56 |
|
57 | 57 |
check(U.size(U.find(n[4])) == 3, "Something is wrong with UnionFindEnum"); |
58 | 58 |
check(U.size(U.find(n[5])) == 3, "Something is wrong with UnionFindEnum"); |
59 | 59 |
check(U.size(U.find(n[6])) == 1, "Something is wrong with UnionFindEnum"); |
60 | 60 |
check(U.size(U.find(n[2])) == 3, "Something is wrong with UnionFindEnum"); |
61 | 61 |
|
62 | 62 |
|
63 | 63 |
U.insert(n[9]); |
64 | 64 |
U.insert(n[10],U.find(n[9])); |
65 | 65 |
|
66 | 66 |
|
67 | 67 |
check(U.join(n[8],n[10]) != -1, "Something is wrong with UnionFindEnum"); |
68 | 68 |
|
69 | 69 |
|
70 | 70 |
check(U.size(U.find(n[4])) == 3, "Something is wrong with UnionFindEnum"); |
71 | 71 |
check(U.size(U.find(n[9])) == 5, "Something is wrong with UnionFindEnum"); |
72 | 72 |
|
73 | 73 |
check(U.size(U.find(n[8])) == 5, "Something is wrong with UnionFindEnum"); |
74 | 74 |
|
75 | 75 |
U.erase(n[9]); |
76 | 76 |
U.erase(n[1]); |
77 | 77 |
|
78 | 78 |
check(U.size(U.find(n[10])) == 4, "Something is wrong with UnionFindEnum"); |
79 | 79 |
check(U.size(U.find(n[2])) == 2, "Something is wrong with UnionFindEnum"); |
80 | 80 |
|
81 | 81 |
U.erase(n[6]); |
82 | 82 |
U.split(U.find(n[8])); |
83 | 83 |
|
84 | 84 |
|
85 | 85 |
check(U.size(U.find(n[4])) == 2, "Something is wrong with UnionFindEnum"); |
86 | 86 |
check(U.size(U.find(n[3])) == 1, "Something is wrong with UnionFindEnum"); |
87 | 87 |
check(U.size(U.find(n[2])) == 2, "Something is wrong with UnionFindEnum"); |
88 | 88 |
|
89 | 89 |
|
90 | 90 |
check(U.join(n[3],n[4]) != -1, "Something is wrong with UnionFindEnum"); |
91 | 91 |
check(U.join(n[2],n[4]) == -1, "Something is wrong with UnionFindEnum"); |
92 | 92 |
|
93 | 93 |
|
94 | 94 |
check(U.size(U.find(n[4])) == 3, "Something is wrong with UnionFindEnum"); |
95 | 95 |
check(U.size(U.find(n[3])) == 3, "Something is wrong with UnionFindEnum"); |
96 | 96 |
check(U.size(U.find(n[2])) == 3, "Something is wrong with UnionFindEnum"); |
97 | 97 |
|
98 | 98 |
U.eraseClass(U.find(n[4])); |
99 | 99 |
U.eraseClass(U.find(n[7])); |
0 comments (0 inline)