↑ Collapse diff ↑
Ignore white space 6 line context
1 1
/* -*- mode: C++; indent-tabs-mode: nil; -*-
2 2
 *
3 3
 * This file is a part of LEMON, a generic C++ optimization library.
4 4
 *
5
 * Copyright (C) 2003-2008
5
 * Copyright (C) 2003-2011
6 6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 7
 * (Egervary Research Group on Combinatorial Optimization, EGRES).
8 8
 *
9 9
 * Permission to use, modify and distribute this software is granted
10 10
 * provided that this copyright notice appears in all copies. For
11 11
 * precise terms see the accompanying LICENSE file.
12 12
 *
13 13
 * This software is provided "AS IS" with no warranty of any kind,
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 applications.
22 22

	
23 23
This directory contains several simple demo applications, 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
This directory contains some auxiliary pages and the whole generated
32 32
documentation.
33 33
*/
34 34

	
35 35
/**
36 36
\dir test
37 37
\brief Test programs.
38 38

	
39 39
This directory contains several test programs that check the consistency
40 40
of the code.
41 41
*/
42 42

	
43 43
/**
44 44
\dir tools
45 45
\brief Some useful executables.
46 46

	
47 47
This directory contains the sources of some useful complete executables.
48 48
*/
49 49

	
50 50
/**
51 51
\dir lemon
52 52
\brief Base include directory of LEMON.
53 53

	
54 54
This is the base directory of LEMON includes, so each include file must be
55 55
prefixed with this, e.g.
56 56
\code
57 57
#include<lemon/list_graph.h>
58 58
#include<lemon/dijkstra.h>
59 59
\endcode
60 60
*/
61 61

	
62 62
/**
63 63
\dir concepts
64 64
\brief Concept descriptors and checking classes.
65 65

	
66 66
This directory contains the concept descriptors and concept checking tools.
67 67
For more information see the \ref concept "Concepts" module.
68 68
*/
69 69

	
70 70
/**
71 71
\dir bits
72 72
\brief Auxiliary tools for implementation.
73 73

	
74
This directory contains some auxiliary classes for implementing graphs, 
74
This directory contains some auxiliary classes for implementing graphs,
75 75
maps and some other classes.
76 76
As a user you typically don't have to deal with these files.
77 77
*/
Ignore white space 6 line context
1 1
/* -*- mode: C++; indent-tabs-mode: nil; -*-
2 2
 *
3 3
 * This file is a part of LEMON, a generic C++ optimization library.
4 4
 *
5
 * Copyright (C) 2003-2008
5
 * Copyright (C) 2003-2011
6 6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 7
 * (Egervary Research Group on Combinatorial Optimization, EGRES).
8 8
 *
9 9
 * Permission to use, modify and distribute this software is granted
10 10
 * provided that this copyright notice appears in all copies. For
11 11
 * precise terms see the accompanying LICENSE file.
12 12
 *
13 13
 * This software is provided "AS IS" with no warranty of any kind,
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
You are free to use the graph structure that fit your requirements
44 44
the best, most graph algorithms and auxiliary data structures can be used
45 45
with any graph structure.
46 46

	
47 47
<b>See also:</b> \ref graph_concepts "Graph Structure Concepts".
48 48
*/
49 49

	
50 50
/**
51 51
@defgroup maps Maps
52 52
@ingroup datas
53 53
\brief Map structures implemented in LEMON.
... ...
@@ -258,63 +258,63 @@
258 258
\brief General \c EPS drawer and graph exporter
259 259

	
260 260
This group describes general \c EPS drawing methods and special
261 261
graph exporting tools.
262 262
*/
263 263

	
264 264
/**
265 265
@defgroup concept Concepts
266 266
\brief Skeleton classes and concept checking classes
267 267

	
268 268
This group describes the data/algorithm skeletons and concept checking
269 269
classes implemented in LEMON.
270 270

	
271 271
The purpose of the classes in this group is fourfold.
272 272

	
273 273
- These classes contain the documentations of the %concepts. In order
274 274
  to avoid document multiplications, an implementation of a concept
275 275
  simply refers to the corresponding concept class.
276 276

	
277 277
- These classes declare every functions, <tt>typedef</tt>s etc. an
278 278
  implementation of the %concepts should provide, however completely
279 279
  without implementations and real data structures behind the
280 280
  interface. On the other hand they should provide nothing else. All
281 281
  the algorithms working on a data structure meeting a certain concept
282 282
  should compile with these classes. (Though it will not run properly,
283 283
  of course.) In this way it is easily to check if an algorithm
284 284
  doesn't use any extra feature of a certain implementation.
285 285

	
286 286
- The concept descriptor classes also provide a <em>checker class</em>
287 287
  that makes it possible to check whether a certain implementation of a
288 288
  concept indeed provides all the required features.
289 289

	
290 290
- Finally, They can serve as a skeleton of a new implementation of a concept.
291 291
*/
292 292

	
293 293
/**
294 294
@defgroup graph_concepts Graph Structure Concepts
295 295
@ingroup concept
296 296
\brief Skeleton and concept checking classes for graph structures
297 297

	
298 298
This group describes the skeletons and concept checking classes of LEMON's
299 299
graph structures and helper classes used to implement these.
300 300
*/
301 301

	
302 302
/**
303 303
@defgroup map_concepts Map Concepts
304 304
@ingroup concept
305 305
\brief Skeleton and concept checking classes for maps
306
 
306

	
307 307
This group describes the skeletons and concept checking classes of maps.
308 308
*/
309 309

	
310 310
/**
311 311
\anchor demoprograms
312 312

	
313 313
@defgroup demos Demo programs
314 314

	
315 315
Some demo programs are listed here. Their full source codes can be found in
316 316
the \c demo subdirectory of the source tree.
317 317

	
318 318
It order to compile them, use <tt>--enable-demo</tt> configure option when
319 319
build the library.
320 320
*/
Ignore white space 6 line context
1 1
/* -*- mode: C++; indent-tabs-mode: nil; -*-
2 2
 *
3 3
 * This file is a part of LEMON, a generic C++ optimization library.
4 4
 *
5
 * Copyright (C) 2003-2008
5
 * Copyright (C) 2003-2011
6 6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 7
 * (Egervary Research Group on Combinatorial Optimization, EGRES).
8 8
 *
9 9
 * Permission to use, modify and distribute this software is granted
10 10
 * provided that this copyright notice appears in all copies. For
11 11
 * precise terms see the accompanying LICENSE file.
12 12
 *
13 13
 * This software is provided "AS IS" with no warranty of any kind,
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
Ignore white space 6 line context
1 1
/* -*- mode: C++; indent-tabs-mode: nil; -*-
2 2
 *
3 3
 * This file is a part of LEMON, a generic C++ optimization library.
4 4
 *
5
 * Copyright (C) 2003-2008
5
 * Copyright (C) 2003-2011
6 6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 7
 * (Egervary Research Group on Combinatorial Optimization, EGRES).
8 8
 *
9 9
 * Permission to use, modify and distribute this software is granted
10 10
 * provided that this copyright notice appears in all copies. For
11 11
 * precise terms see the accompanying LICENSE file.
12 12
 *
13 13
 * This software is provided "AS IS" with no warranty of any kind,
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/core.h>
24 24
namespace lemon {
25 25

	
26 26
  float Tolerance<float>::def_epsilon = static_cast<float>(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
Ignore white space 6 line context
1 1
/* -*- mode: C++; indent-tabs-mode: nil; -*-
2 2
 *
3 3
 * This file is a part of LEMON, a generic C++ optimization library.
4 4
 *
5
 * Copyright (C) 2003-2008
5
 * Copyright (C) 2003-2011
6 6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 7
 * (Egervary Research Group on Combinatorial Optimization, EGRES).
8 8
 *
9 9
 * Permission to use, modify and distribute this software is granted
10 10
 * provided that this copyright notice appears in all copies. For
11 11
 * precise terms see the accompanying LICENSE file.
12 12
 *
13 13
 * This software is provided "AS IS" with no warranty of any kind,
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
#include <lemon/config.h>
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>
Ignore white space 96 line context
1 1
/* -*- mode: C++; indent-tabs-mode: nil; -*-
2 2
 *
3 3
 * This file is a part of LEMON, a generic C++ optimization library.
4 4
 *
5
 * Copyright (C) 2003-2008
5
 * Copyright (C) 2003-2011
6 6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 7
 * (Egervary Research Group on Combinatorial Optimization, EGRES).
8 8
 *
9 9
 * Permission to use, modify and distribute this software is granted
10 10
 * provided that this copyright notice appears in all copies. For
11 11
 * precise terms see the accompanying LICENSE file.
12 12
 *
13 13
 * This software is provided "AS IS" with no warranty of any kind,
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

	
Ignore white space 6 line context
1 1
/* -*- mode: C++; indent-tabs-mode: nil; -*-
2 2
 *
3 3
 * This file is a part of LEMON, a generic C++ optimization library.
4 4
 *
5
 * Copyright (C) 2003-2008
5
 * Copyright (C) 2003-2011
6 6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 7
 * (Egervary Research Group on Combinatorial Optimization, EGRES).
8 8
 *
9 9
 * Permission to use, modify and distribute this software is granted
10 10
 * provided that this copyright notice appears in all copies. For
11 11
 * precise terms see the accompanying LICENSE file.
12 12
 *
13 13
 * This software is provided "AS IS" with no warranty of any kind,
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:
Ignore white space 6 line context
1 1
/* -*- mode: C++; indent-tabs-mode: nil; -*-
2 2
 *
3 3
 * This file is a part of LEMON, a generic C++ optimization library.
4 4
 *
5
 * Copyright (C) 2003-2009
5
 * Copyright (C) 2003-2011
6 6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 7
 * (Egervary Research Group on Combinatorial Optimization, EGRES).
8 8
 *
9 9
 * Permission to use, modify and distribute this software is granted
10 10
 * provided that this copyright notice appears in all copies. For
11 11
 * precise terms see the accompanying LICENSE file.
12 12
 *
13 13
 * This software is provided "AS IS" with no warranty of any kind,
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/bits/windows.h>
23 23

	
24 24
#ifdef WIN32
25 25
#ifndef WIN32_LEAN_AND_MEAN
26 26
#define WIN32_LEAN_AND_MEAN
27 27
#endif
28 28
#ifndef NOMINMAX
29 29
#define NOMINMAX
30 30
#endif
31 31
#ifdef UNICODE
32 32
#undef UNICODE
33 33
#endif
34 34
#include <windows.h>
35 35
#ifdef LOCALE_INVARIANT
36 36
#define MY_LOCALE LOCALE_INVARIANT
37 37
#else
38 38
#define MY_LOCALE LOCALE_NEUTRAL
39 39
#endif
40 40
#else
41 41
#include <unistd.h>
42 42
#include <ctime>
43 43
#include <sys/times.h>
44 44
#include <sys/time.h>
45 45
#endif
46 46

	
47 47
#include <cmath>
48 48
#include <sstream>
49 49

	
50 50
namespace lemon {
51 51
  namespace bits {
52 52
    void getWinProcTimes(double &rtime,
53 53
                         double &utime, double &stime,
54 54
                         double &cutime, double &cstime)
55 55
    {
56 56
#ifdef WIN32
57 57
      static const double ch = 4294967296.0e-7;
58 58
      static const double cl = 1.0e-7;
59 59

	
60 60
      FILETIME system;
61 61
      GetSystemTimeAsFileTime(&system);
62 62
      rtime = ch * system.dwHighDateTime + cl * system.dwLowDateTime;
63 63

	
64 64
      FILETIME create, exit, kernel, user;
65 65
      if (GetProcessTimes(GetCurrentProcess(),&create, &exit, &kernel, &user)) {
66 66
        utime = ch * user.dwHighDateTime + cl * user.dwLowDateTime;
67 67
        stime = ch * kernel.dwHighDateTime + cl * kernel.dwLowDateTime;
68 68
        cutime = 0;
69 69
        cstime = 0;
70 70
      } else {
71 71
        rtime = 0;
72 72
        utime = 0;
73 73
        stime = 0;
74 74
        cutime = 0;
75 75
        cstime = 0;
76 76
      }
77 77
#else
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
#endif
90 90
    }
91 91

	
92 92
    std::string getWinFormattedDate()
93 93
    {
94 94
      std::ostringstream os;
95 95
#ifdef WIN32
96 96
      SYSTEMTIME time;
97 97
      GetSystemTime(&time);
98 98
      char buf1[11], buf2[9], buf3[5];
99
	  if (GetDateFormat(MY_LOCALE, 0, &time,
99
          if (GetDateFormat(MY_LOCALE, 0, &time,
100 100
                        ("ddd MMM dd"), buf1, 11) &&
101 101
          GetTimeFormat(MY_LOCALE, 0, &time,
102 102
                        ("HH':'mm':'ss"), buf2, 9) &&
103 103
          GetDateFormat(MY_LOCALE, 0, &time,
104 104
                        ("yyyy"), buf3, 5)) {
105 105
        os << buf1 << ' ' << buf2 << ' ' << buf3;
106 106
      }
107 107
      else os << "unknown";
108 108
#else
109 109
      timeval tv;
110 110
      gettimeofday(&tv, 0);
111 111

	
112 112
      char cbuf[26];
113 113
      ctime_r(&tv.tv_sec,cbuf);
114 114
      os << cbuf;
115 115
#endif
116 116
      return os.str();
117 117
    }
118 118

	
119 119
    int getWinRndSeed()
120 120
    {
121 121
#ifdef WIN32
122 122
      FILETIME time;
123 123
      GetSystemTimeAsFileTime(&time);
124 124
      return GetCurrentProcessId() + time.dwHighDateTime + time.dwLowDateTime;
125 125
#else
126 126
      timeval tv;
127 127
      gettimeofday(&tv, 0);
128 128
      return getpid() + tv.tv_sec + tv.tv_usec;
129 129
#endif
130 130
    }
131 131
  }
132 132
}
Ignore white space 6 line context
1 1
/* -*- mode: C++; indent-tabs-mode: nil; -*-
2 2
 *
3 3
 * This file is a part of LEMON, a generic C++ optimization library.
4 4
 *
5
 * Copyright (C) 2003-2008
5
 * Copyright (C) 2003-2011
6 6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 7
 * (Egervary Research Group on Combinatorial Optimization, EGRES).
8 8
 *
9 9
 * Permission to use, modify and distribute this software is granted
10 10
 * provided that this copyright notice appears in all copies. For
11 11
 * precise terms see the accompanying LICENSE file.
12 12
 *
13 13
 * This software is provided "AS IS" with no warranty of any kind,
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_CORE_H
20 20
#define LEMON_CORE_H
21 21

	
22 22
#include <vector>
23 23
#include <algorithm>
24 24

	
25 25
#include <lemon/config.h>
26 26
#include <lemon/bits/enable_if.h>
27 27
#include <lemon/bits/traits.h>
28 28
#include <lemon/assert.h>
29 29

	
30 30
///\file
31 31
///\brief LEMON core utilities.
32 32
///
33 33
///This header file contains core utilities for LEMON.
34 34
///It is automatically included by all graph types, therefore it usually
35 35
///do not have to be included directly.
36 36

	
37 37
namespace lemon {
38 38

	
39 39
  /// \brief Dummy type to make it easier to create invalid iterators.
40 40
  ///
41 41
  /// Dummy type to make it easier to create invalid iterators.
42 42
  /// See \ref INVALID for the usage.
43 43
  struct Invalid {
44 44
  public:
45 45
    bool operator==(Invalid) { return true;  }
46 46
    bool operator!=(Invalid) { return false; }
47 47
    bool operator< (Invalid) { return false; }
48 48
  };
49 49

	
50 50
  /// \brief Invalid iterators.
51 51
  ///
52 52
  /// \ref Invalid is a global type that converts to each iterator
53 53
  /// in such a way that the value of the target iterator will be invalid.
Ignore white space 6 line context
1 1
/* -*- mode: C++; indent-tabs-mode: nil; -*-
2 2
 *
3 3
 * This file is a part of LEMON, a generic C++ optimization library.
4 4
 *
5
 * Copyright (C) 2003-2008
5
 * Copyright (C) 2003-2011
6 6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 7
 * (Egervary Research Group on Combinatorial Optimization, EGRES).
8 8
 *
9 9
 * Permission to use, modify and distribute this software is granted
10 10
 * provided that this copyright notice appears in all copies. For
11 11
 * precise terms see the accompanying LICENSE file.
12 12
 *
13 13
 * This software is provided "AS IS" with no warranty of any kind,
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/bits/path_dump.h>
28 28
#include <lemon/core.h>
29 29
#include <lemon/error.h>
30 30
#include <lemon/maps.h>
31 31
#include <lemon/path.h>
32 32

	
33 33
namespace lemon {
34 34

	
35 35
  ///Default traits class of Dfs class.
36 36

	
37 37
  ///Default traits class of Dfs class.
38 38
  ///\tparam GR Digraph type.
39 39
  template<class GR>
40 40
  struct DfsDefaultTraits
41 41
  {
42 42
    ///The type of the digraph the algorithm runs on.
43 43
    typedef GR Digraph;
44 44

	
45 45
    ///\brief The type of the map that stores the predecessor
46 46
    ///arcs of the %DFS paths.
47 47
    ///
48 48
    ///The type of the map that stores the predecessor
49 49
    ///arcs of the %DFS paths.
50 50
    ///It must meet the \ref concepts::WriteMap "WriteMap" concept.
51 51
    typedef typename Digraph::template NodeMap<typename Digraph::Arc> PredMap;
52 52
    ///Instantiates a PredMap.
53 53

	
Ignore white space 6 line context
1 1
/* -*- mode: C++; indent-tabs-mode: nil; -*-
2 2
 *
3 3
 * This file is a part of LEMON, a generic C++ optimization library.
4 4
 *
5
 * Copyright (C) 2003-2008
5
 * Copyright (C) 2003-2011
6 6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 7
 * (Egervary Research Group on Combinatorial Optimization, EGRES).
8 8
 *
9 9
 * Permission to use, modify and distribute this software is granted
10 10
 * provided that this copyright notice appears in all copies. For
11 11
 * precise terms see the accompanying LICENSE file.
12 12
 *
13 13
 * This software is provided "AS IS" with no warranty of any kind,
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
#include<lemon/bits/windows.h>
33 33
#endif
34 34

	
35 35
#include<lemon/math.h>
36 36
#include<lemon/core.h>
37 37
#include<lemon/dim2.h>
38 38
#include<lemon/maps.h>
39 39
#include<lemon/color.h>
40 40
#include<lemon/bits/bezier.h>
41 41
#include<lemon/error.h>
42 42

	
43 43

	
44 44
///\ingroup eps_io
45 45
///\file
46 46
///\brief A well configurable tool for visualizing graphs
47 47

	
48 48
namespace lemon {
49 49

	
50 50
  namespace _graph_to_eps_bits {
51 51
    template<class MT>
52 52
    class _NegY {
53 53
    public:
Ignore white space 6 line context
... ...
@@ -346,97 +346,97 @@
346 346
            getline(is, line);
347 347
            ++line_num;
348 348
          } else if (!isWhiteSpace(c)) {
349 349
            is.putback(c);
350 350
            getline(is, line);
351 351
            _functor(line);
352 352
            ++line_num;
353 353
          }
354 354
        }
355 355
        if (is) is.putback(c);
356 356
        else if (is.eof()) is.clear();
357 357
      }
358 358
    };
359 359

	
360 360
    template <typename Functor>
361 361
    class StreamSection : public Section {
362 362
    private:
363 363

	
364 364
      Functor _functor;
365 365

	
366 366
    public:
367 367

	
368 368
      StreamSection(const Functor& functor) : _functor(functor) {}
369 369
      virtual ~StreamSection() {}
370 370

	
371 371
      virtual void process(std::istream& is, int& line_num) {
372 372
        _functor(is, line_num);
373 373
        char c;
374 374
        std::string line;
375 375
        while (is.get(c) && c != '@') {
376 376
          if (c == '\n') {
377 377
            ++line_num;
378 378
          } else if (!isWhiteSpace(c)) {
379 379
            getline(is, line);
380 380
            ++line_num;
381 381
          }
382 382
        }
383 383
        if (is) is.putback(c);
384 384
        else if (is.eof()) is.clear();
385 385
      }
386 386
    };
387 387

	
388 388
  }
389 389

	
390 390
  template <typename Digraph>
391 391
  class DigraphReader;
392 392

	
393 393
  template <typename Digraph>
394
  DigraphReader<Digraph> digraphReader(Digraph& digraph, 
394
  DigraphReader<Digraph> digraphReader(Digraph& digraph,
395 395
                                       std::istream& is = std::cin);
396 396
  template <typename Digraph>
397 397
  DigraphReader<Digraph> digraphReader(Digraph& digraph, const std::string& fn);
398 398
  template <typename Digraph>
399 399
  DigraphReader<Digraph> digraphReader(Digraph& digraph, const char *fn);
400 400

	
401 401
  /// \ingroup lemon_io
402 402
  ///
403 403
  /// \brief \ref lgf-format "LGF" reader for directed graphs
404 404
  ///
405 405
  /// This utility reads an \ref lgf-format "LGF" file.
406 406
  ///
407 407
  /// The reading method does a batch processing. The user creates a
408 408
  /// reader object, then various reading rules can be added to the
409 409
  /// reader, and eventually the reading is executed with the \c run()
410 410
  /// member function. A map reading rule can be added to the reader
411 411
  /// with the \c nodeMap() or \c arcMap() members. An optional
412 412
  /// converter parameter can also be added as a standard functor
413 413
  /// converting from \c std::string to the value type of the map. If it
414 414
  /// is set, it will determine how the tokens in the file should be
415 415
  /// converted to the value type of the map. If the functor is not set,
416 416
  /// then a default conversion will be used. One map can be read into
417 417
  /// multiple map objects at the same time. The \c attribute(), \c
418 418
  /// node() and \c arc() functions are used to add attribute reading
419 419
  /// rules.
420 420
  ///
421 421
  ///\code
422 422
  /// DigraphReader<Digraph>(digraph, std::cin).
423 423
  ///   nodeMap("coordinates", coord_map).
424 424
  ///   arcMap("capacity", cap_map).
425 425
  ///   node("source", src).
426 426
  ///   node("target", trg).
427 427
  ///   attribute("caption", caption).
428 428
  ///   run();
429 429
  ///\endcode
430 430
  ///
431 431
  /// By default the reader uses the first section in the file of the
432 432
  /// proper type. If a section has an optional name, then it can be
433 433
  /// selected for reading by giving an optional name parameter to the
434 434
  /// \c nodes(), \c arcs() or \c attributes() functions.
435 435
  ///
436 436
  /// The \c useNodes() and \c useArcs() functions are used to tell the reader
437 437
  /// that the nodes or arcs should not be constructed (added to the
438 438
  /// graph) during the reading, but instead the label map of the items
439 439
  /// are given as a parameter of these functions. An
440 440
  /// application of these functions is multipass reading, which is
441 441
  /// important if two \c \@arcs sections must be read from the
442 442
  /// file. In this case the first phase would read the node set and one
... ...
@@ -518,97 +518,97 @@
518 518
        delete _is;
519 519
        throw IoError("Cannot open file", fn);
520 520
      }
521 521
    }
522 522

	
523 523
    /// \brief Constructor
524 524
    ///
525 525
    /// Construct a directed graph reader, which reads from the given
526 526
    /// file.
527 527
    DigraphReader(Digraph& digraph, const char* fn)
528 528
      : _is(new std::ifstream(fn)), local_is(true),
529 529
        _filename(fn), _digraph(digraph),
530 530
        _use_nodes(false), _use_arcs(false),
531 531
        _skip_nodes(false), _skip_arcs(false) {
532 532
      if (!(*_is)) {
533 533
        delete _is;
534 534
        throw IoError("Cannot open file", fn);
535 535
      }
536 536
    }
537 537

	
538 538
    /// \brief Destructor
539 539
    ~DigraphReader() {
540 540
      for (typename NodeMaps::iterator it = _node_maps.begin();
541 541
           it != _node_maps.end(); ++it) {
542 542
        delete it->second;
543 543
      }
544 544

	
545 545
      for (typename ArcMaps::iterator it = _arc_maps.begin();
546 546
           it != _arc_maps.end(); ++it) {
547 547
        delete it->second;
548 548
      }
549 549

	
550 550
      for (typename Attributes::iterator it = _attributes.begin();
551 551
           it != _attributes.end(); ++it) {
552 552
        delete it->second;
553 553
      }
554 554

	
555 555
      if (local_is) {
556 556
        delete _is;
557 557
      }
558 558

	
559 559
    }
560 560

	
561 561
  private:
562 562

	
563 563
    template <typename DGR>
564 564
    friend DigraphReader<DGR> digraphReader(DGR& digraph, std::istream& is);
565 565
    template <typename DGR>
566
    friend DigraphReader<DGR> digraphReader(DGR& digraph, 
566
    friend DigraphReader<DGR> digraphReader(DGR& digraph,
567 567
                                            const std::string& fn);
568 568
    template <typename DGR>
569 569
    friend DigraphReader<DGR> digraphReader(DGR& digraph, const char *fn);
570 570

	
571 571
    DigraphReader(DigraphReader& other)
572 572
      : _is(other._is), local_is(other.local_is), _digraph(other._digraph),
573 573
        _use_nodes(other._use_nodes), _use_arcs(other._use_arcs),
574 574
        _skip_nodes(other._skip_nodes), _skip_arcs(other._skip_arcs) {
575 575

	
576 576
      other._is = 0;
577 577
      other.local_is = false;
578 578

	
579 579
      _node_index.swap(other._node_index);
580 580
      _arc_index.swap(other._arc_index);
581 581

	
582 582
      _node_maps.swap(other._node_maps);
583 583
      _arc_maps.swap(other._arc_maps);
584 584
      _attributes.swap(other._attributes);
585 585

	
586 586
      _nodes_caption = other._nodes_caption;
587 587
      _arcs_caption = other._arcs_caption;
588 588
      _attributes_caption = other._attributes_caption;
589 589

	
590 590
    }
591 591

	
592 592
    DigraphReader& operator=(const DigraphReader&);
593 593

	
594 594
  public:
595 595

	
596 596
    /// \name Reading rules
597 597
    /// @{
598 598

	
599 599
    /// \brief Node map reading rule
600 600
    ///
601 601
    /// Add a node map reading rule to the reader.
602 602
    template <typename Map>
603 603
    DigraphReader& nodeMap(const std::string& caption, Map& map) {
604 604
      checkConcept<concepts::WriteMap<Node, typename Map::Value>, Map>();
605 605
      _reader_bits::MapStorageBase<Node>* storage =
606 606
        new _reader_bits::MapStorage<Node, Map>(map);
607 607
      _node_maps.push_back(std::make_pair(caption, storage));
608 608
      return *this;
609 609
    }
610 610

	
611 611
    /// \brief Node map reading rule
612 612
    ///
613 613
    /// Add a node map reading rule with specialized converter to the
614 614
    /// reader.
... ...
@@ -1184,99 +1184,99 @@
1184 1184

	
1185 1185
      if (!arcs_done) {
1186 1186
        throw FormatError("Section @arcs not found");
1187 1187
      }
1188 1188

	
1189 1189
      if (!attributes_done && !_attributes.empty()) {
1190 1190
        throw FormatError("Section @attributes not found");
1191 1191
      }
1192 1192

	
1193 1193
    }
1194 1194

	
1195 1195
    /// @}
1196 1196

	
1197 1197
  };
1198 1198

	
1199 1199
  /// \brief Return a \ref DigraphReader class
1200 1200
  ///
1201 1201
  /// This function just returns a \ref DigraphReader class.
1202 1202
  /// \relates DigraphReader
1203 1203
  template <typename Digraph>
1204 1204
  DigraphReader<Digraph> digraphReader(Digraph& digraph, std::istream& is) {
1205 1205
    DigraphReader<Digraph> tmp(digraph, is);
1206 1206
    return tmp;
1207 1207
  }
1208 1208

	
1209 1209
  /// \brief Return a \ref DigraphReader class
1210 1210
  ///
1211 1211
  /// This function just returns a \ref DigraphReader class.
1212 1212
  /// \relates DigraphReader
1213 1213
  template <typename Digraph>
1214 1214
  DigraphReader<Digraph> digraphReader(Digraph& digraph,
1215 1215
                                       const std::string& fn) {
1216 1216
    DigraphReader<Digraph> tmp(digraph, fn);
1217 1217
    return tmp;
1218 1218
  }
1219 1219

	
1220 1220
  /// \brief Return a \ref DigraphReader class
1221 1221
  ///
1222 1222
  /// This function just returns a \ref DigraphReader class.
1223 1223
  /// \relates DigraphReader
1224 1224
  template <typename Digraph>
1225 1225
  DigraphReader<Digraph> digraphReader(Digraph& digraph, const char* fn) {
1226 1226
    DigraphReader<Digraph> tmp(digraph, fn);
1227 1227
    return tmp;
1228 1228
  }
1229 1229

	
1230 1230
  template <typename Graph>
1231 1231
  class GraphReader;
1232
 
1232

	
1233 1233
  template <typename Graph>
1234
  GraphReader<Graph> graphReader(Graph& graph, 
1234
  GraphReader<Graph> graphReader(Graph& graph,
1235 1235
                                 std::istream& is = std::cin);
1236 1236
  template <typename Graph>
1237 1237
  GraphReader<Graph> graphReader(Graph& graph, const std::string& fn);
1238 1238
  template <typename Graph>
1239 1239
  GraphReader<Graph> graphReader(Graph& graph, const char *fn);
1240 1240

	
1241 1241
  /// \ingroup lemon_io
1242 1242
  ///
1243 1243
  /// \brief \ref lgf-format "LGF" reader for undirected graphs
1244 1244
  ///
1245 1245
  /// This utility reads an \ref lgf-format "LGF" file.
1246 1246
  ///
1247 1247
  /// It can be used almost the same way as \c DigraphReader.
1248 1248
  /// The only difference is that this class can handle edges and
1249 1249
  /// edge maps as well as arcs and arc maps.
1250 1250
  ///
1251 1251
  /// The columns in the \c \@edges (or \c \@arcs) section are the
1252 1252
  /// edge maps. However, if there are two maps with the same name
1253 1253
  /// prefixed with \c '+' and \c '-', then these can be read into an
1254 1254
  /// arc map.  Similarly, an attribute can be read into an arc, if
1255 1255
  /// it's value is an edge label prefixed with \c '+' or \c '-'.
1256 1256
  template <typename _Graph>
1257 1257
  class GraphReader {
1258 1258
  public:
1259 1259

	
1260 1260
    typedef _Graph Graph;
1261 1261
    TEMPLATE_GRAPH_TYPEDEFS(Graph);
1262 1262

	
1263 1263
  private:
1264 1264

	
1265 1265
    std::istream* _is;
1266 1266
    bool local_is;
1267 1267
    std::string _filename;
1268 1268

	
1269 1269
    Graph& _graph;
1270 1270

	
1271 1271
    std::string _nodes_caption;
1272 1272
    std::string _edges_caption;
1273 1273
    std::string _attributes_caption;
1274 1274

	
1275 1275
    typedef std::map<std::string, Node> NodeIndex;
1276 1276
    NodeIndex _node_index;
1277 1277
    typedef std::map<std::string, Edge> EdgeIndex;
1278 1278
    EdgeIndex _edge_index;
1279 1279

	
1280 1280
    typedef std::vector<std::pair<std::string,
1281 1281
      _reader_bits::MapStorageBase<Node>*> > NodeMaps;
1282 1282
    NodeMaps _node_maps;
... ...
@@ -1321,97 +1321,97 @@
1321 1321
      if (!(*_is)) {
1322 1322
        delete _is;
1323 1323
        throw IoError("Cannot open file", fn);
1324 1324
      }
1325 1325
    }
1326 1326

	
1327 1327
    /// \brief Constructor
1328 1328
    ///
1329 1329
    /// Construct an undirected graph reader, which reads from the given
1330 1330
    /// file.
1331 1331
    GraphReader(Graph& graph, const char* fn)
1332 1332
      : _is(new std::ifstream(fn)), local_is(true),
1333 1333
        _filename(fn), _graph(graph),
1334 1334
        _use_nodes(false), _use_edges(false),
1335 1335
        _skip_nodes(false), _skip_edges(false) {
1336 1336
      if (!(*_is)) {
1337 1337
        delete _is;
1338 1338
        throw IoError("Cannot open file", fn);
1339 1339
      }
1340 1340
    }
1341 1341

	
1342 1342
    /// \brief Destructor
1343 1343
    ~GraphReader() {
1344 1344
      for (typename NodeMaps::iterator it = _node_maps.begin();
1345 1345
           it != _node_maps.end(); ++it) {
1346 1346
        delete it->second;
1347 1347
      }
1348 1348

	
1349 1349
      for (typename EdgeMaps::iterator it = _edge_maps.begin();
1350 1350
           it != _edge_maps.end(); ++it) {
1351 1351
        delete it->second;
1352 1352
      }
1353 1353

	
1354 1354
      for (typename Attributes::iterator it = _attributes.begin();
1355 1355
           it != _attributes.end(); ++it) {
1356 1356
        delete it->second;
1357 1357
      }
1358 1358

	
1359 1359
      if (local_is) {
1360 1360
        delete _is;
1361 1361
      }
1362 1362

	
1363 1363
    }
1364 1364

	
1365 1365
  private:
1366 1366
    template <typename GR>
1367 1367
    friend GraphReader<GR> graphReader(GR& graph, std::istream& is);
1368 1368
    template <typename GR>
1369
    friend GraphReader<GR> graphReader(GR& graph, const std::string& fn); 
1369
    friend GraphReader<GR> graphReader(GR& graph, const std::string& fn);
1370 1370
    template <typename GR>
1371 1371
    friend GraphReader<GR> graphReader(GR& graph, const char *fn);
1372 1372

	
1373 1373
    GraphReader(GraphReader& other)
1374 1374
      : _is(other._is), local_is(other.local_is), _graph(other._graph),
1375 1375
        _use_nodes(other._use_nodes), _use_edges(other._use_edges),
1376 1376
        _skip_nodes(other._skip_nodes), _skip_edges(other._skip_edges) {
1377 1377

	
1378 1378
      other._is = 0;
1379 1379
      other.local_is = false;
1380 1380

	
1381 1381
      _node_index.swap(other._node_index);
1382 1382
      _edge_index.swap(other._edge_index);
1383 1383

	
1384 1384
      _node_maps.swap(other._node_maps);
1385 1385
      _edge_maps.swap(other._edge_maps);
1386 1386
      _attributes.swap(other._attributes);
1387 1387

	
1388 1388
      _nodes_caption = other._nodes_caption;
1389 1389
      _edges_caption = other._edges_caption;
1390 1390
      _attributes_caption = other._attributes_caption;
1391 1391

	
1392 1392
    }
1393 1393

	
1394 1394
    GraphReader& operator=(const GraphReader&);
1395 1395

	
1396 1396
  public:
1397 1397

	
1398 1398
    /// \name Reading rules
1399 1399
    /// @{
1400 1400

	
1401 1401
    /// \brief Node map reading rule
1402 1402
    ///
1403 1403
    /// Add a node map reading rule to the reader.
1404 1404
    template <typename Map>
1405 1405
    GraphReader& nodeMap(const std::string& caption, Map& map) {
1406 1406
      checkConcept<concepts::WriteMap<Node, typename Map::Value>, Map>();
1407 1407
      _reader_bits::MapStorageBase<Node>* storage =
1408 1408
        new _reader_bits::MapStorage<Node, Map>(map);
1409 1409
      _node_maps.push_back(std::make_pair(caption, storage));
1410 1410
      return *this;
1411 1411
    }
1412 1412

	
1413 1413
    /// \brief Node map reading rule
1414 1414
    ///
1415 1415
    /// Add a node map reading rule with specialized converter to the
1416 1416
    /// reader.
1417 1417
    template <typename Map, typename Converter>
Ignore white space 6 line context
1 1
/* -*- mode: C++; indent-tabs-mode: nil; -*-
2 2
 *
3 3
 * This file is a part of LEMON, a generic C++ optimization library.
4 4
 *
5
 * Copyright (C) 2003-2008
5
 * Copyright (C) 2003-2011
6 6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 7
 * (Egervary Research Group on Combinatorial Optimization, EGRES).
8 8
 *
9 9
 * Permission to use, modify and distribute this software is granted
10 10
 * provided that this copyright notice appears in all copies. For
11 11
 * precise terms see the accompanying LICENSE file.
12 12
 *
13 13
 * This software is provided "AS IS" with no warranty of any kind,
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/core.h>
37 37
#include <lemon/maps.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 _writer_bits {
45 45

	
46 46
    template <typename Value>
47 47
    struct DefaultConverter {
48 48
      std::string operator()(const Value& value) {
49 49
        std::ostringstream os;
50 50
        os << value;
51 51
        return os.str();
52 52
      }
53 53
    };
... ...
@@ -461,97 +461,97 @@
461 461
    /// output file.
462 462
    DigraphWriter(const Digraph& digraph, const std::string& fn)
463 463
      : _os(new std::ofstream(fn.c_str())), local_os(true), _digraph(digraph),
464 464
        _skip_nodes(false), _skip_arcs(false) {
465 465
      if (!(*_os)) {
466 466
        delete _os;
467 467
        throw IoError("Cannot write file", fn);
468 468
      }
469 469
    }
470 470

	
471 471
    /// \brief Constructor
472 472
    ///
473 473
    /// Construct a directed graph writer, which writes to the given
474 474
    /// output file.
475 475
    DigraphWriter(const Digraph& digraph, const char* fn)
476 476
      : _os(new std::ofstream(fn)), local_os(true), _digraph(digraph),
477 477
        _skip_nodes(false), _skip_arcs(false) {
478 478
      if (!(*_os)) {
479 479
        delete _os;
480 480
        throw IoError("Cannot write file", fn);
481 481
      }
482 482
    }
483 483

	
484 484
    /// \brief Destructor
485 485
    ~DigraphWriter() {
486 486
      for (typename NodeMaps::iterator it = _node_maps.begin();
487 487
           it != _node_maps.end(); ++it) {
488 488
        delete it->second;
489 489
      }
490 490

	
491 491
      for (typename ArcMaps::iterator it = _arc_maps.begin();
492 492
           it != _arc_maps.end(); ++it) {
493 493
        delete it->second;
494 494
      }
495 495

	
496 496
      for (typename Attributes::iterator it = _attributes.begin();
497 497
           it != _attributes.end(); ++it) {
498 498
        delete it->second;
499 499
      }
500 500

	
501 501
      if (local_os) {
502 502
        delete _os;
503 503
      }
504 504
    }
505 505

	
506 506
  private:
507 507

	
508 508
    template <typename DGR>
509
    friend DigraphWriter<DGR> digraphWriter(const DGR& digraph, 
509
    friend DigraphWriter<DGR> digraphWriter(const DGR& digraph,
510 510
                                            std::ostream& os);
511 511
    template <typename DGR>
512 512
    friend DigraphWriter<DGR> digraphWriter(const DGR& digraph,
513 513
                                            const std::string& fn);
514 514
    template <typename DGR>
515 515
    friend DigraphWriter<DGR> digraphWriter(const DGR& digraph,
516 516
                                            const char *fn);
517 517

	
518 518
    DigraphWriter(DigraphWriter& other)
519 519
      : _os(other._os), local_os(other.local_os), _digraph(other._digraph),
520 520
        _skip_nodes(other._skip_nodes), _skip_arcs(other._skip_arcs) {
521 521

	
522 522
      other._os = 0;
523 523
      other.local_os = false;
524 524

	
525 525
      _node_index.swap(other._node_index);
526 526
      _arc_index.swap(other._arc_index);
527 527

	
528 528
      _node_maps.swap(other._node_maps);
529 529
      _arc_maps.swap(other._arc_maps);
530 530
      _attributes.swap(other._attributes);
531 531

	
532 532
      _nodes_caption = other._nodes_caption;
533 533
      _arcs_caption = other._arcs_caption;
534 534
      _attributes_caption = other._attributes_caption;
535 535
    }
536 536

	
537 537
    DigraphWriter& operator=(const DigraphWriter&);
538 538

	
539 539
  public:
540 540

	
541 541
    /// \name Writing rules
542 542
    /// @{
543 543

	
544 544
    /// \brief Node map writing rule
545 545
    ///
546 546
    /// Add a node map writing rule to the writer.
547 547
    template <typename Map>
548 548
    DigraphWriter& nodeMap(const std::string& caption, const Map& map) {
549 549
      checkConcept<concepts::ReadMap<Node, typename Map::Value>, Map>();
550 550
      _writer_bits::MapStorageBase<Node>* storage =
551 551
        new _writer_bits::MapStorage<Node, Map>(map);
552 552
      _node_maps.push_back(std::make_pair(caption, storage));
553 553
      return *this;
554 554
    }
555 555

	
556 556
    /// \brief Node map writing rule
557 557
    ///
... ...
@@ -1037,97 +1037,97 @@
1037 1037
    }
1038 1038

	
1039 1039
    /// \brief Constructor
1040 1040
    ///
1041 1041
    /// Construct a directed graph writer, which writes to the given
1042 1042
    /// output file.
1043 1043
    GraphWriter(const Graph& graph, const char* fn)
1044 1044
      : _os(new std::ofstream(fn)), local_os(true), _graph(graph),
1045 1045
        _skip_nodes(false), _skip_edges(false) {
1046 1046
      if (!(*_os)) {
1047 1047
        delete _os;
1048 1048
        throw IoError("Cannot write file", fn);
1049 1049
      }
1050 1050
    }
1051 1051

	
1052 1052
    /// \brief Destructor
1053 1053
    ~GraphWriter() {
1054 1054
      for (typename NodeMaps::iterator it = _node_maps.begin();
1055 1055
           it != _node_maps.end(); ++it) {
1056 1056
        delete it->second;
1057 1057
      }
1058 1058

	
1059 1059
      for (typename EdgeMaps::iterator it = _edge_maps.begin();
1060 1060
           it != _edge_maps.end(); ++it) {
1061 1061
        delete it->second;
1062 1062
      }
1063 1063

	
1064 1064
      for (typename Attributes::iterator it = _attributes.begin();
1065 1065
           it != _attributes.end(); ++it) {
1066 1066
        delete it->second;
1067 1067
      }
1068 1068

	
1069 1069
      if (local_os) {
1070 1070
        delete _os;
1071 1071
      }
1072 1072
    }
1073 1073

	
1074 1074
  private:
1075 1075

	
1076 1076
    template <typename GR>
1077 1077
    friend GraphWriter<GR> graphWriter(const GR& graph,
1078 1078
                                       std::ostream& os);
1079 1079
    template <typename GR>
1080 1080
    friend GraphWriter<GR> graphWriter(const GR& graph,
1081 1081
                                       const std::string& fn);
1082 1082
    template <typename GR>
1083 1083
    friend GraphWriter<GR> graphWriter(const GR& graph,
1084 1084
                                       const char *fn);
1085
    
1085

	
1086 1086
    GraphWriter(GraphWriter& other)
1087 1087
      : _os(other._os), local_os(other.local_os), _graph(other._graph),
1088 1088
        _skip_nodes(other._skip_nodes), _skip_edges(other._skip_edges) {
1089 1089

	
1090 1090
      other._os = 0;
1091 1091
      other.local_os = false;
1092 1092

	
1093 1093
      _node_index.swap(other._node_index);
1094 1094
      _edge_index.swap(other._edge_index);
1095 1095

	
1096 1096
      _node_maps.swap(other._node_maps);
1097 1097
      _edge_maps.swap(other._edge_maps);
1098 1098
      _attributes.swap(other._attributes);
1099 1099

	
1100 1100
      _nodes_caption = other._nodes_caption;
1101 1101
      _edges_caption = other._edges_caption;
1102 1102
      _attributes_caption = other._attributes_caption;
1103 1103
    }
1104 1104

	
1105 1105
    GraphWriter& operator=(const GraphWriter&);
1106 1106

	
1107 1107
  public:
1108 1108

	
1109 1109
    /// \name Writing rules
1110 1110
    /// @{
1111 1111

	
1112 1112
    /// \brief Node map writing rule
1113 1113
    ///
1114 1114
    /// Add a node map writing rule to the writer.
1115 1115
    template <typename Map>
1116 1116
    GraphWriter& nodeMap(const std::string& caption, const Map& map) {
1117 1117
      checkConcept<concepts::ReadMap<Node, typename Map::Value>, Map>();
1118 1118
      _writer_bits::MapStorageBase<Node>* storage =
1119 1119
        new _writer_bits::MapStorage<Node, Map>(map);
1120 1120
      _node_maps.push_back(std::make_pair(caption, storage));
1121 1121
      return *this;
1122 1122
    }
1123 1123

	
1124 1124
    /// \brief Node map writing rule
1125 1125
    ///
1126 1126
    /// Add a node map writing rule with specialized converter to the
1127 1127
    /// writer.
1128 1128
    template <typename Map, typename Converter>
1129 1129
    GraphWriter& nodeMap(const std::string& caption, const Map& map,
1130 1130
                           const Converter& converter = Converter()) {
1131 1131
      checkConcept<concepts::ReadMap<Node, typename Map::Value>, Map>();
1132 1132
      _writer_bits::MapStorageBase<Node>* storage =
1133 1133
        new _writer_bits::MapStorage<Node, Map, Converter>(map, converter);
Ignore white space 6 line context
1 1
/* -*- mode: C++; indent-tabs-mode: nil; -*-
2 2
 *
3 3
 * This file is a part of LEMON, a generic C++ optimization library.
4 4
 *
5
 * Copyright (C) 2003-2008
5
 * Copyright (C) 2003-2011
6 6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 7
 * (Egervary Research Group on Combinatorial Optimization, EGRES).
8 8
 *
9 9
 * Permission to use, modify and distribute this software is granted
10 10
 * provided that this copyright notice appears in all copies. For
11 11
 * precise terms see the accompanying LICENSE file.
12 12
 *
13 13
 * This software is provided "AS IS" with no warranty of any kind,
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/core.h>
27 27
#include <lemon/error.h>
28 28
#include <lemon/bits/graph_extender.h>
29 29

	
30 30
#include <vector>
31 31
#include <list>
32 32

	
33 33
namespace lemon {
34 34

	
35 35
  class ListDigraphBase {
36 36

	
37 37
  protected:
38 38
    struct NodeT {
39 39
      int first_in, first_out;
40 40
      int prev, next;
41 41
    };
42 42

	
43 43
    struct ArcT {
44 44
      int target, source;
45 45
      int prev_in, prev_out;
46 46
      int next_in, next_out;
47 47
    };
48 48

	
49 49
    std::vector<NodeT> nodes;
50 50

	
51 51
    int first_node;
52 52

	
53 53
    int first_free_node;
... ...
@@ -795,98 +795,98 @@
795 795
    int first_free_arc;
796 796

	
797 797
  public:
798 798

	
799 799
    typedef ListGraphBase Digraph;
800 800

	
801 801
    class Node;
802 802
    class Arc;
803 803
    class Edge;
804 804

	
805 805
    class Node {
806 806
      friend class ListGraphBase;
807 807
    protected:
808 808

	
809 809
      int id;
810 810
      explicit Node(int pid) { id = pid;}
811 811

	
812 812
    public:
813 813
      Node() {}
814 814
      Node (Invalid) { id = -1; }
815 815
      bool operator==(const Node& node) const {return id == node.id;}
816 816
      bool operator!=(const Node& node) const {return id != node.id;}
817 817
      bool operator<(const Node& node) const {return id < node.id;}
818 818
    };
819 819

	
820 820
    class Edge {
821 821
      friend class ListGraphBase;
822 822
    protected:
823 823

	
824 824
      int id;
825 825
      explicit Edge(int pid) { id = pid;}
826 826

	
827 827
    public:
828 828
      Edge() {}
829 829
      Edge (Invalid) { id = -1; }
830 830
      bool operator==(const Edge& edge) const {return id == edge.id;}
831 831
      bool operator!=(const Edge& edge) const {return id != edge.id;}
832 832
      bool operator<(const Edge& edge) const {return id < edge.id;}
833 833
    };
834 834

	
835 835
    class Arc {
836 836
      friend class ListGraphBase;
837 837
    protected:
838 838

	
839 839
      int id;
840 840
      explicit Arc(int pid) { id = pid;}
841 841

	
842 842
    public:
843
      operator Edge() const { 
844
        return id != -1 ? edgeFromId(id / 2) : INVALID; 
843
      operator Edge() const {
844
        return id != -1 ? edgeFromId(id / 2) : INVALID;
845 845
      }
846 846

	
847 847
      Arc() {}
848 848
      Arc (Invalid) { id = -1; }
849 849
      bool operator==(const Arc& arc) const {return id == arc.id;}
850 850
      bool operator!=(const Arc& arc) const {return id != arc.id;}
851 851
      bool operator<(const Arc& arc) const {return id < arc.id;}
852 852
    };
853 853

	
854 854

	
855 855

	
856 856
    ListGraphBase()
857 857
      : nodes(), first_node(-1),
858 858
        first_free_node(-1), arcs(), first_free_arc(-1) {}
859 859

	
860 860

	
861 861
    int maxNodeId() const { return nodes.size()-1; }
862 862
    int maxEdgeId() const { return arcs.size() / 2 - 1; }
863 863
    int maxArcId() const { return arcs.size()-1; }
864 864

	
865 865
    Node source(Arc e) const { return Node(arcs[e.id ^ 1].target); }
866 866
    Node target(Arc e) const { return Node(arcs[e.id].target); }
867 867

	
868 868
    Node u(Edge e) const { return Node(arcs[2 * e.id].target); }
869 869
    Node v(Edge e) const { return Node(arcs[2 * e.id + 1].target); }
870 870

	
871 871
    static bool direction(Arc e) {
872 872
      return (e.id & 1) == 1;
873 873
    }
874 874

	
875 875
    static Arc direct(Edge e, bool d) {
876 876
      return Arc(e.id * 2 + (d ? 1 : 0));
877 877
    }
878 878

	
879 879
    void first(Node& node) const {
880 880
      node.id = first_node;
881 881
    }
882 882

	
883 883
    void next(Node& node) const {
884 884
      node.id = nodes[node.id].next;
885 885
    }
886 886

	
887 887
    void first(Arc& e) const {
888 888
      int n = first_node;
889 889
      while (n != -1 && nodes[n].first_out == -1) {
890 890
        n = nodes[n].next;
891 891
      }
892 892
      e.id = (n == -1) ? -1 : nodes[n].first_out;
Ignore white space 6 line context
1 1
/* -*- mode: C++; indent-tabs-mode: nil; -*-
2 2
 *
3 3
 * This file is a part of LEMON, a generic C++ optimization library.
4 4
 *
5
 * Copyright (C) 2003-2008
5
 * Copyright (C) 2003-2011
6 6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 7
 * (Egervary Research Group on Combinatorial Optimization, EGRES).
8 8
 *
9 9
 * Permission to use, modify and distribute this software is granted
10 10
 * provided that this copyright notice appears in all copies. For
11 11
 * precise terms see the accompanying LICENSE file.
12 12
 *
13 13
 * This software is provided "AS IS" with no warranty of any kind,
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/core.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
... ...
@@ -921,110 +921,110 @@
921 921
    };
922 922

	
923 923
    template <typename Path>
924 924
    struct BuildTagIndicator<
925 925
      Path,
926 926
      typename enable_if<typename Path::BuildTag, void>::type
927 927
    > {
928 928
      static const bool value = true;
929 929
    };
930 930

	
931 931
    template <typename From, typename To,
932 932
              bool buildEnable = BuildTagIndicator<To>::value>
933 933
    struct PathCopySelectorForward {
934 934
      static void copy(const From& from, To& to) {
935 935
        to.clear();
936 936
        for (typename From::ArcIt it(from); it != INVALID; ++it) {
937 937
          to.addBack(it);
938 938
        }
939 939
      }
940 940
    };
941 941

	
942 942
    template <typename From, typename To>
943 943
    struct PathCopySelectorForward<From, To, true> {
944 944
      static void copy(const From& from, To& to) {
945 945
        to.clear();
946 946
        to.build(from);
947 947
      }
948 948
    };
949 949

	
950 950
    template <typename From, typename To,
951 951
              bool buildEnable = BuildTagIndicator<To>::value>
952 952
    struct PathCopySelectorBackward {
953 953
      static void copy(const From& from, To& to) {
954 954
        to.clear();
955 955
        for (typename From::RevArcIt it(from); it != INVALID; ++it) {
956 956
          to.addFront(it);
957 957
        }
958 958
      }
959 959
    };
960 960

	
961 961
    template <typename From, typename To>
962 962
    struct PathCopySelectorBackward<From, To, true> {
963 963
      static void copy(const From& from, To& to) {
964 964
        to.clear();
965 965
        to.buildRev(from);
966 966
      }
967 967
    };
968 968

	
969
    
969

	
970 970
    template <typename From, typename To,
971 971
              bool revEnable = RevPathTagIndicator<From>::value>
972 972
    struct PathCopySelector {
973 973
      static void copy(const From& from, To& to) {
974 974
        PathCopySelectorForward<From, To>::copy(from, to);
975
      }      
975
      }
976 976
    };
977 977

	
978 978
    template <typename From, typename To>
979 979
    struct PathCopySelector<From, To, true> {
980 980
      static void copy(const From& from, To& to) {
981 981
        PathCopySelectorBackward<From, To>::copy(from, to);
982
      }      
982
      }
983 983
    };
984 984

	
985 985
  }
986 986

	
987 987

	
988 988
  /// \brief Make a copy of a path.
989 989
  ///
990 990
  /// This function makes a copy of a path.
991 991
  template <typename From, typename To>
992 992
  void pathCopy(const From& from, To& to) {
993 993
    checkConcept<concepts::PathDumper<typename From::Digraph>, From>();
994 994
    _path_bits::PathCopySelector<From, To>::copy(from, to);
995 995
  }
996 996

	
997 997
  /// \brief Deprecated version of \ref pathCopy().
998 998
  ///
999 999
  /// Deprecated version of \ref pathCopy() (only for reverse compatibility).
1000 1000
  template <typename To, typename From>
1001 1001
  void copyPath(To& to, const From& from) {
1002 1002
    pathCopy(from, to);
1003 1003
  }
1004 1004

	
1005 1005
  /// \brief Check the consistency of a path.
1006 1006
  ///
1007 1007
  /// This function checks that the target of each arc is the same
1008 1008
  /// as the source of the next one.
1009 1009
  ///
1010 1010
  template <typename Digraph, typename Path>
1011 1011
  bool checkPath(const Digraph& digraph, const Path& path) {
1012 1012
    typename Path::ArcIt it(path);
1013 1013
    if (it == INVALID) return true;
1014 1014
    typename Digraph::Node node = digraph.target(it);
1015 1015
    ++it;
1016 1016
    while (it != INVALID) {
1017 1017
      if (digraph.source(it) != node) return false;
1018 1018
      node = digraph.target(it);
1019 1019
      ++it;
1020 1020
    }
1021 1021
    return true;
1022 1022
  }
1023 1023

	
1024 1024
  /// \brief The source of a path
1025 1025
  ///
1026 1026
  /// This function returns the source node of the given path.
1027 1027
  /// If the path is empty, then it returns \c INVALID.
1028 1028
  template <typename Digraph, typename Path>
1029 1029
  typename Digraph::Node pathSource(const Digraph& digraph, const Path& path) {
1030 1030
    return path.empty() ? INVALID : digraph.source(path.front());
Ignore white space 6 line context
1 1
/* -*- mode: C++; indent-tabs-mode: nil; -*-
2 2
 *
3 3
 * This file is a part of LEMON, a generic C++ optimization library.
4 4
 *
5
 * Copyright (C) 2003-2008
5
 * Copyright (C) 2003-2011
6 6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 7
 * (Egervary Research Group on Combinatorial Optimization, EGRES).
8 8
 *
9 9
 * Permission to use, modify and distribute this software is granted
10 10
 * provided that this copyright notice appears in all copies. For
11 11
 * precise terms see the accompanying LICENSE file.
12 12
 *
13 13
 * This software is provided "AS IS" with no warranty of any kind,
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
Ignore white space 6 line context
1 1
/* -*- mode: C++; indent-tabs-mode: nil; -*-
2 2
 *
3 3
 * This file is a part of LEMON, a generic C++ optimization library.
4 4
 *
5
 * Copyright (C) 2003-2008
5
 * Copyright (C) 2003-2011
6 6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 7
 * (Egervary Research Group on Combinatorial Optimization, EGRES).
8 8
 *
9 9
 * Permission to use, modify and distribute this software is granted
10 10
 * provided that this copyright notice appears in all copies. For
11 11
 * precise terms see the accompanying LICENSE file.
12 12
 *
13 13
 * This software is provided "AS IS" with no warranty of any kind,
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/core.h>
29 29
#include <lemon/error.h>
30 30
#include <lemon/bits/graph_extender.h>
31 31

	
32 32
namespace lemon {
33 33

	
34 34
  class SmartDigraph;
35 35
  ///Base of SmartDigraph
36 36

	
37 37
  ///Base of SmartDigraph
38 38
  ///
39 39
  class SmartDigraphBase {
40 40
  protected:
41 41

	
42 42
    struct NodeT
43 43
    {
44 44
      int first_in, first_out;
45 45
      NodeT() {}
46 46
    };
47 47
    struct ArcT
48 48
    {
49 49
      int target, source, next_in, next_out;
50 50
      ArcT() {}
51 51
    };
52 52

	
53 53
    std::vector<NodeT> nodes;
... ...
@@ -421,98 +421,98 @@
421 421
    int first_free_arc;
422 422

	
423 423
  public:
424 424

	
425 425
    typedef SmartGraphBase Digraph;
426 426

	
427 427
    class Node;
428 428
    class Arc;
429 429
    class Edge;
430 430

	
431 431
    class Node {
432 432
      friend class SmartGraphBase;
433 433
    protected:
434 434

	
435 435
      int _id;
436 436
      explicit Node(int id) { _id = id;}
437 437

	
438 438
    public:
439 439
      Node() {}
440 440
      Node (Invalid) { _id = -1; }
441 441
      bool operator==(const Node& node) const {return _id == node._id;}
442 442
      bool operator!=(const Node& node) const {return _id != node._id;}
443 443
      bool operator<(const Node& node) const {return _id < node._id;}
444 444
    };
445 445

	
446 446
    class Edge {
447 447
      friend class SmartGraphBase;
448 448
    protected:
449 449

	
450 450
      int _id;
451 451
      explicit Edge(int id) { _id = id;}
452 452

	
453 453
    public:
454 454
      Edge() {}
455 455
      Edge (Invalid) { _id = -1; }
456 456
      bool operator==(const Edge& arc) const {return _id == arc._id;}
457 457
      bool operator!=(const Edge& arc) const {return _id != arc._id;}
458 458
      bool operator<(const Edge& arc) const {return _id < arc._id;}
459 459
    };
460 460

	
461 461
    class Arc {
462 462
      friend class SmartGraphBase;
463 463
    protected:
464 464

	
465 465
      int _id;
466 466
      explicit Arc(int id) { _id = id;}
467 467

	
468 468
    public:
469
      operator Edge() const { 
470
        return _id != -1 ? edgeFromId(_id / 2) : INVALID; 
469
      operator Edge() const {
470
        return _id != -1 ? edgeFromId(_id / 2) : INVALID;
471 471
      }
472 472

	
473 473
      Arc() {}
474 474
      Arc (Invalid) { _id = -1; }
475 475
      bool operator==(const Arc& arc) const {return _id == arc._id;}
476 476
      bool operator!=(const Arc& arc) const {return _id != arc._id;}
477 477
      bool operator<(const Arc& arc) const {return _id < arc._id;}
478 478
    };
479 479

	
480 480

	
481 481

	
482 482
    SmartGraphBase()
483 483
      : nodes(), arcs() {}
484 484

	
485 485

	
486 486
    int maxNodeId() const { return nodes.size()-1; }
487 487
    int maxEdgeId() const { return arcs.size() / 2 - 1; }
488 488
    int maxArcId() const { return arcs.size()-1; }
489 489

	
490 490
    Node source(Arc e) const { return Node(arcs[e._id ^ 1].target); }
491 491
    Node target(Arc e) const { return Node(arcs[e._id].target); }
492 492

	
493 493
    Node u(Edge e) const { return Node(arcs[2 * e._id].target); }
494 494
    Node v(Edge e) const { return Node(arcs[2 * e._id + 1].target); }
495 495

	
496 496
    static bool direction(Arc e) {
497 497
      return (e._id & 1) == 1;
498 498
    }
499 499

	
500 500
    static Arc direct(Edge e, bool d) {
501 501
      return Arc(e._id * 2 + (d ? 1 : 0));
502 502
    }
503 503

	
504 504
    void first(Node& node) const {
505 505
      node._id = nodes.size() - 1;
506 506
    }
507 507

	
508 508
    void next(Node& node) const {
509 509
      --node._id;
510 510
    }
511 511

	
512 512
    void first(Arc& arc) const {
513 513
      arc._id = arcs.size() - 1;
514 514
    }
515 515

	
516 516
    void next(Arc& arc) const {
517 517
      --arc._id;
518 518
    }
Ignore white space 6 line context
1 1
/* -*- mode: C++; indent-tabs-mode: nil; -*-
2 2
 *
3 3
 * This file is a part of LEMON, a generic C++ optimization library.
4 4
 *
5
 * Copyright (C) 2003-2008
5
 * Copyright (C) 2003-2011
6 6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 7
 * (Egervary Research Group on Combinatorial Optimization, EGRES).
8 8
 *
9 9
 * Permission to use, modify and distribute this software is granted
10 10
 * provided that this copyright notice appears in all copies. For
11 11
 * precise terms see the accompanying LICENSE file.
12 12
 *
13 13
 * This software is provided "AS IS" with no warranty of any kind,
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
#include <lemon/bits/windows.h>
28 28
#else
29 29
#include <unistd.h>
30 30
#include <sys/times.h>
31 31
#include <sys/time.h>
32 32
#endif
33 33

	
34 34
#include <string>
35 35
#include <fstream>
36 36
#include <iostream>
37 37

	
38 38
namespace lemon {
39 39

	
40 40
  /// \addtogroup timecount
41 41
  /// @{
42 42

	
43 43
  /// A class to store (cpu)time instances.
44 44

	
45 45
  /// This class stores five time values.
46 46
  /// - a real time
47 47
  /// - a user cpu time
48 48
  /// - a system cpu time
49 49
  /// - a user cpu time of children
50 50
  /// - a system cpu time of children
51 51
  ///
52 52
  /// TimeStamp's can be added to or substracted from each other and
53 53
  /// they can be pushed to a stream.
Ignore white space 6 line context
1 1
/* -*- mode: C++; indent-tabs-mode: nil; -*-
2 2
 *
3 3
 * This file is a part of LEMON, a generic C++ optimization library.
4 4
 *
5
 * Copyright (C) 2003-2008
5
 * Copyright (C) 2003-2011
6 6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 7
 * (Egervary Research Group on Combinatorial Optimization, EGRES).
8 8
 *
9 9
 * Permission to use, modify and distribute this software is granted
10 10
 * provided that this copyright notice appears in all copies. For
11 11
 * precise terms see the accompanying LICENSE file.
12 12
 *
13 13
 * This software is provided "AS IS" with no warranty of any kind,
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

	
28 28
namespace lemon {
29 29

	
30 30
  /// \addtogroup misc
31 31
  /// @{
32 32

	
33 33
  ///\brief A class to provide a basic way to
34 34
  ///handle the comparison of numbers that are obtained
35 35
  ///as a result of a probably inexact computation.
36 36
  ///
37 37
  ///\ref Tolerance is a class to provide a basic way to
38 38
  ///handle the comparison of numbers that are obtained
39 39
  ///as a result of a probably inexact computation.
40 40
  ///
41 41
  ///The general implementation is suitable only if the data type is exact,
42 42
  ///like the integer types, otherwise a specialized version must be
43 43
  ///implemented. These specialized classes like
44 44
  ///Tolerance<double> may offer additional tuning parameters.
45 45
  ///
46 46
  ///\sa Tolerance<float>
47 47
  ///\sa Tolerance<double>
48 48
  ///\sa Tolerance<long double>
49 49

	
50 50
  template<class T>
51 51
  class Tolerance
52 52
  {
53 53
  public:
Ignore white space 6 line context
1 1
/* -*- mode: C++; indent-tabs-mode: nil; -*-
2 2
 *
3 3
 * This file is a part of LEMON, a generic C++ optimization library.
4 4
 *
5
 * Copyright (C) 2003-2008
5
 * Copyright (C) 2003-2011
6 6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 7
 * (Egervary Research Group on Combinatorial Optimization, EGRES).
8 8
 *
9 9
 * Permission to use, modify and distribute this software is granted
10 10
 * provided that this copyright notice appears in all copies. For
11 11
 * precise terms see the accompanying LICENSE file.
12 12
 *
13 13
 * This software is provided "AS IS" with no warranty of any kind,
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/core.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.
... ...
@@ -1144,97 +1144,97 @@
1144 1144
      }
1145 1145
      nodes[kd].size -= num;
1146 1146
      nodes[jd].size = num;
1147 1147
    }
1148 1148

	
1149 1149
    void pushLeft(int id, int jd) {
1150 1150
      nodes[id].size += 1;
1151 1151
      nodes[jd].next = nodes[id].left;
1152 1152
      nodes[jd].prev = -1;
1153 1153
      nodes[nodes[id].left].prev = jd;
1154 1154
      nodes[id].left = jd;
1155 1155
      nodes[jd].parent = id;
1156 1156
    }
1157 1157

	
1158 1158
    void popLeft(int id) {
1159 1159
      nodes[id].size -= 1;
1160 1160
      int jd = nodes[id].left;
1161 1161
      nodes[nodes[jd].next].prev = -1;
1162 1162
      nodes[id].left = nodes[jd].next;
1163 1163
    }
1164 1164

	
1165 1165
    void repairLeft(int id) {
1166 1166
      int jd = ~(classes[id].parent);
1167 1167
      while (nodes[jd].left != -1) {
1168 1168
        int kd = nodes[jd].left;
1169 1169
        if (nodes[jd].size == 1) {
1170 1170
          if (nodes[jd].parent < 0) {
1171 1171
            classes[id].parent = ~kd;
1172 1172
            classes[id].depth -= 1;
1173 1173
            nodes[kd].parent = ~id;
1174 1174
            deleteNode(jd);
1175 1175
            jd = kd;
1176 1176
          } else {
1177 1177
            int pd = nodes[jd].parent;
1178 1178
            if (nodes[nodes[jd].next].size < cmax) {
1179 1179
              pushLeft(nodes[jd].next, nodes[jd].left);
1180 1180
              if (less(jd, nodes[jd].next) ||
1181 1181
                  nodes[jd].item == nodes[pd].item) {
1182 1182
                nodes[nodes[jd].next].prio = nodes[jd].prio;
1183 1183
                nodes[nodes[jd].next].item = nodes[jd].item;
1184 1184
              }
1185 1185
              popLeft(pd);
1186 1186
              deleteNode(jd);
1187 1187
              jd = pd;
1188 1188
            } else {
1189 1189
              int ld = nodes[nodes[jd].next].left;
1190 1190
              popLeft(nodes[jd].next);
1191 1191
              pushRight(jd, ld);
1192
              if (less(ld, nodes[jd].left) || 
1192
              if (less(ld, nodes[jd].left) ||
1193 1193
                  nodes[ld].item == nodes[pd].item) {
1194 1194
                nodes[jd].item = nodes[ld].item;
1195 1195
                nodes[jd].prio = nodes[ld].prio;
1196 1196
              }
1197 1197
              if (nodes[nodes[jd].next].item == nodes[ld].item) {
1198 1198
                setPrio(nodes[jd].next);
1199 1199
              }
1200 1200
              jd = nodes[jd].left;
1201 1201
            }
1202 1202
          }
1203 1203
        } else {
1204 1204
          jd = nodes[jd].left;
1205 1205
        }
1206 1206
      }
1207 1207
    }
1208 1208

	
1209 1209
    void repairRight(int id) {
1210 1210
      int jd = ~(classes[id].parent);
1211 1211
      while (nodes[jd].right != -1) {
1212 1212
        int kd = nodes[jd].right;
1213 1213
        if (nodes[jd].size == 1) {
1214 1214
          if (nodes[jd].parent < 0) {
1215 1215
            classes[id].parent = ~kd;
1216 1216
            classes[id].depth -= 1;
1217 1217
            nodes[kd].parent = ~id;
1218 1218
            deleteNode(jd);
1219 1219
            jd = kd;
1220 1220
          } else {
1221 1221
            int pd = nodes[jd].parent;
1222 1222
            if (nodes[nodes[jd].prev].size < cmax) {
1223 1223
              pushRight(nodes[jd].prev, nodes[jd].right);
1224 1224
              if (less(jd, nodes[jd].prev) ||
1225 1225
                  nodes[jd].item == nodes[pd].item) {
1226 1226
                nodes[nodes[jd].prev].prio = nodes[jd].prio;
1227 1227
                nodes[nodes[jd].prev].item = nodes[jd].item;
1228 1228
              }
1229 1229
              popRight(pd);
1230 1230
              deleteNode(jd);
1231 1231
              jd = pd;
1232 1232
            } else {
1233 1233
              int ld = nodes[nodes[jd].prev].right;
1234 1234
              popRight(nodes[jd].prev);
1235 1235
              pushLeft(jd, ld);
1236 1236
              if (less(ld, nodes[jd].right) ||
1237 1237
                  nodes[ld].item == nodes[pd].item) {
1238 1238
                nodes[jd].item = nodes[ld].item;
1239 1239
                nodes[jd].prio = nodes[ld].prio;
1240 1240
              }
Ignore white space 6 line context
1 1
/* -*- mode: C++; indent-tabs-mode: nil; -*-
2 2
 *
3 3
 * This file is a part of LEMON, a generic C++ optimization library.
4 4
 *
5
 * Copyright (C) 2003-2008
5
 * Copyright (C) 2003-2011
6 6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 7
 * (Egervary Research Group on Combinatorial Optimization, EGRES).
8 8
 *
9 9
 * Permission to use, modify and distribute this software is granted
10 10
 * provided that this copyright notice appears in all copies. For
11 11
 * precise terms see the accompanying LICENSE file.
12 12
 *
13 13
 * This software is provided "AS IS" with no warranty of any kind,
14 14
 * express or implied, and with no claim as to its suitability for any
15 15
 * purpose.
16 16
 *
17 17
 */
18 18

	
19 19
#include <lemon/concepts/digraph.h>
20 20
#include <lemon/smart_graph.h>
21 21
#include <lemon/list_graph.h>
22 22
#include <lemon/lgf_reader.h>
23 23
#include <lemon/dfs.h>
24 24
#include <lemon/path.h>
25 25

	
26 26
#include "graph_test.h"
27 27
#include "test_tools.h"
28 28

	
29 29
using namespace lemon;
30 30

	
31 31
char test_lgf[] =
32 32
  "@nodes\n"
33 33
  "label\n"
34 34
  "0\n"
35 35
  "1\n"
36 36
  "2\n"
37 37
  "3\n"
38 38
  "4\n"
39 39
  "5\n"
40 40
  "6\n"
41 41
  "@arcs\n"
42 42
  "     label\n"
43 43
  "0 1  0\n"
44 44
  "1 2  1\n"
45 45
  "2 3  2\n"
46 46
  "1 4  3\n"
47 47
  "4 2  4\n"
48 48
  "4 5  5\n"
49 49
  "5 0  6\n"
50 50
  "6 3  7\n"
51 51
  "@attributes\n"
52 52
  "source 0\n"
53 53
  "target 5\n"
... ...
@@ -139,61 +139,61 @@
139 139
    .reachedMap(concepts::ReadWriteMap<Node,bool>())
140 140
    .processedMap(concepts::WriteMap<Node,bool>())
141 141
    .run();
142 142
}
143 143

	
144 144
template <class Digraph>
145 145
void checkDfs() {
146 146
  TEMPLATE_DIGRAPH_TYPEDEFS(Digraph);
147 147

	
148 148
  Digraph G;
149 149
  Node s, t;
150 150
  Node s1, t1;
151 151

	
152 152
  std::istringstream input(test_lgf);
153 153
  digraphReader(G, input).
154 154
    node("source", s).
155 155
    node("target", t).
156 156
    node("source1", s1).
157 157
    node("target1", t1).
158 158
    run();
159 159

	
160 160
  Dfs<Digraph> dfs_test(G);
161 161
  dfs_test.run(s);
162 162

	
163 163
  Path<Digraph> p = dfs_test.path(t);
164 164
  check(p.length() == dfs_test.dist(t),"path() found a wrong path.");
165 165
  check(checkPath(G, p),"path() found a wrong path.");
166 166
  check(pathSource(G, p) == s,"path() found a wrong path.");
167 167
  check(pathTarget(G, p) == t,"path() found a wrong path.");
168 168

	
169 169
  for(NodeIt v(G); v!=INVALID; ++v) {
170 170
    if (dfs_test.reached(v)) {
171 171
      check(v==s || dfs_test.predArc(v)!=INVALID, "Wrong tree.");
172 172
      if (dfs_test.predArc(v)!=INVALID ) {
173 173
        Arc e=dfs_test.predArc(v);
174 174
        Node u=G.source(e);
175 175
        check(u==dfs_test.predNode(v),"Wrong tree.");
176 176
        check(dfs_test.dist(v) - dfs_test.dist(u) == 1,
177 177
              "Wrong distance. (" << dfs_test.dist(u) << "->"
178 178
              << dfs_test.dist(v) << ")");
179 179
      }
180 180
    }
181 181
  }
182 182

	
183 183
  {
184 184
  Dfs<Digraph> dfs(G);
185 185
  check(dfs.run(s1,t1) && dfs.reached(t1),"Node 3 is reachable from Node 6.");
186 186
  }
187
  
187

	
188 188
  {
189 189
    NullMap<Node,Arc> myPredMap;
190 190
    dfs(G).predMap(myPredMap).run(s);
191 191
  }
192 192
}
193 193

	
194 194
int main()
195 195
{
196 196
  checkDfs<ListDigraph>();
197 197
  checkDfs<SmartDigraph>();
198 198
  return 0;
199 199
}
Ignore white space 6 line context
1 1
/* -*- mode: C++; indent-tabs-mode: nil; -*-
2 2
 *
3 3
 * This file is a part of LEMON, a generic C++ optimization library.
4 4
 *
5
 * Copyright (C) 2003-2008
5
 * Copyright (C) 2003-2011
6 6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 7
 * (Egervary Research Group on Combinatorial Optimization, EGRES).
8 8
 *
9 9
 * Permission to use, modify and distribute this software is granted
10 10
 * provided that this copyright notice appears in all copies. For
11 11
 * precise terms see the accompanying LICENSE file.
12 12
 *
13 13
 * This software is provided "AS IS" with no warranty of any kind,
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/error.h>
23 23

	
24 24
#include "test_tools.h"
25 25

	
26 26
using namespace std;
27 27
using namespace lemon;
28 28

	
29 29
void digraph_copy_test() {
30 30
  const int nn = 10;
31 31

	
32 32
  // Build a digraph
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
  // Test digraph copy
56 56
  ListDigraph to;
57 57
  ListDigraph::NodeMap<int> tnm(to);
58 58
  ListDigraph::ArcMap<int> tam(to);
59 59
  ListDigraph::Node tn;
60 60
  ListDigraph::Arc ta;
61 61

	
62 62
  SmartDigraph::NodeMap<ListDigraph::Node> nr(from);
63 63
  SmartDigraph::ArcMap<ListDigraph::Arc> er(from);
64 64

	
65 65
  ListDigraph::NodeMap<SmartDigraph::Node> ncr(to);
66 66
  ListDigraph::ArcMap<SmartDigraph::Arc> ecr(to);
67 67

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

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

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

	
82 82
  for (SmartDigraph::ArcIt it(from); it != INVALID; ++it) {
83 83
    check(ecr[er[it]] == it, "Wrong copy.");
84 84
    check(fam[it] == tam[er[it]], "Wrong copy.");
85 85
    check(nr[from.source(it)] == to.source(er[it]), "Wrong copy.");
86 86
    check(nr[from.target(it)] == to.target(er[it]), "Wrong copy.");
87 87
  }
88 88

	
89 89
  for (ListDigraph::NodeIt it(to); it != INVALID; ++it) {
90 90
    check(nr[ncr[it]] == it, "Wrong copy.");
91 91
  }
92 92

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

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

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

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

	
109 109
  // Build a graph
110 110
  SmartGraph from;
111 111
  SmartGraph::NodeMap<int> fnm(from);
112 112
  SmartGraph::ArcMap<int> fam(from);
113 113
  SmartGraph::EdgeMap<int> fem(from);
114 114
  SmartGraph::Node fn = INVALID;
115 115
  SmartGraph::Arc fa = INVALID;
116 116
  SmartGraph::Edge fe = INVALID;
117 117

	
118 118
  std::vector<SmartGraph::Node> fnv;
119 119
  for (int i = 0; i < nn; ++i) {
120 120
    SmartGraph::Node node = from.addNode();
121 121
    fnv.push_back(node);
122 122
    fnm[node] = i * i;
123 123
    if (i == 0) fn = node;
124 124
  }
125 125

	
126 126
  for (int i = 0; i < nn; ++i) {
127 127
    for (int j = 0; j < nn; ++j) {
128 128
      SmartGraph::Edge edge = from.addEdge(fnv[i], fnv[j]);
129 129
      fem[edge] = i * i + j * j;
130 130
      fam[from.direct(edge, true)] = i + j * j;
131 131
      fam[from.direct(edge, false)] = i * i + j;
132 132
      if (i == 0 && j == 0) fa = from.direct(edge, true);
133 133
      if (i == 0 && j == 0) fe = edge;
134 134
    }
135 135
  }
136 136

	
137 137
  // Test graph copy
138 138
  ListGraph to;
139 139
  ListGraph::NodeMap<int> tnm(to);
140 140
  ListGraph::ArcMap<int> tam(to);
141 141
  ListGraph::EdgeMap<int> tem(to);
142 142
  ListGraph::Node tn;
143 143
  ListGraph::Arc ta;
144 144
  ListGraph::Edge te;
145 145

	
146 146
  SmartGraph::NodeMap<ListGraph::Node> nr(from);
147 147
  SmartGraph::ArcMap<ListGraph::Arc> ar(from);
148 148
  SmartGraph::EdgeMap<ListGraph::Edge> er(from);
149 149

	
... ...
@@ -155,61 +155,61 @@
155 155
    nodeMap(fnm, tnm).arcMap(fam, tam).edgeMap(fem, tem).
156 156
    nodeRef(nr).arcRef(ar).edgeRef(er).
157 157
    nodeCrossRef(ncr).arcCrossRef(acr).edgeCrossRef(ecr).
158 158
    node(fn, tn).arc(fa, ta).edge(fe, te).run();
159 159

	
160 160
  check(countNodes(from) == countNodes(to), "Wrong copy.");
161 161
  check(countEdges(from) == countEdges(to), "Wrong copy.");
162 162
  check(countArcs(from) == countArcs(to), "Wrong copy.");
163 163

	
164 164
  for (SmartGraph::NodeIt it(from); it != INVALID; ++it) {
165 165
    check(ncr[nr[it]] == it, "Wrong copy.");
166 166
    check(fnm[it] == tnm[nr[it]], "Wrong copy.");
167 167
  }
168 168

	
169 169
  for (SmartGraph::ArcIt it(from); it != INVALID; ++it) {
170 170
    check(acr[ar[it]] == it, "Wrong copy.");
171 171
    check(fam[it] == tam[ar[it]], "Wrong copy.");
172 172
    check(nr[from.source(it)] == to.source(ar[it]), "Wrong copy.");
173 173
    check(nr[from.target(it)] == to.target(ar[it]), "Wrong copy.");
174 174
  }
175 175

	
176 176
  for (SmartGraph::EdgeIt it(from); it != INVALID; ++it) {
177 177
    check(ecr[er[it]] == it, "Wrong copy.");
178 178
    check(fem[it] == tem[er[it]], "Wrong copy.");
179 179
    check(nr[from.u(it)] == to.u(er[it]) || nr[from.u(it)] == to.v(er[it]),
180 180
          "Wrong copy.");
181 181
    check(nr[from.v(it)] == to.u(er[it]) || nr[from.v(it)] == to.v(er[it]),
182 182
          "Wrong copy.");
183 183
    check((from.u(it) != from.v(it)) == (to.u(er[it]) != to.v(er[it])),
184 184
          "Wrong copy.");
185 185
  }
186 186

	
187 187
  for (ListGraph::NodeIt it(to); it != INVALID; ++it) {
188 188
    check(nr[ncr[it]] == it, "Wrong copy.");
189 189
  }
190 190

	
191 191
  for (ListGraph::ArcIt it(to); it != INVALID; ++it) {
192 192
    check(ar[acr[it]] == it, "Wrong copy.");
193 193
  }
194 194
  for (ListGraph::EdgeIt it(to); it != INVALID; ++it) {
195 195
    check(er[ecr[it]] == it, "Wrong copy.");
196 196
  }
197 197
  check(tn == nr[fn], "Wrong copy.");
198 198
  check(ta == ar[fa], "Wrong copy.");
199 199
  check(te == er[fe], "Wrong copy.");
200 200

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

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

	
209 209

	
210 210
int main() {
211 211
  digraph_copy_test();
212 212
  graph_copy_test();
213 213

	
214 214
  return 0;
215 215
}
Ignore white space 6 line context
... ...
@@ -18,152 +18,152 @@
18 18

	
19 19
#include <lemon/list_graph.h>
20 20
#include <lemon/lgf_reader.h>
21 21
#include "test_tools.h"
22 22

	
23 23
using namespace lemon;
24 24

	
25 25
char test_lgf[] =
26 26
  "@nodes\n"
27 27
  "label\n"
28 28
  "0\n"
29 29
  "1\n"
30 30
  "@arcs\n"
31 31
  "     label\n"
32 32
  "0 1  0\n"
33 33
  "1 0  1\n"
34 34
  "@attributes\n"
35 35
  "source 0\n"
36 36
  "target 1\n";
37 37

	
38 38
char test_lgf_nomap[] =
39 39
  "@nodes\n"
40 40
  "label\n"
41 41
  "0\n"
42 42
  "1\n"
43 43
  "@arcs\n"
44 44
  "     -\n"
45 45
  "0 1\n";
46 46

	
47 47
char test_lgf_bad1[] =
48 48
  "@nodes\n"
49 49
  "label\n"
50 50
  "0\n"
51 51
  "1\n"
52 52
  "@arcs\n"
53 53
  "     - another\n"
54 54
  "0 1\n";
55 55

	
56 56
char test_lgf_bad2[] =
57 57
  "@nodes\n"
58 58
  "label\n"
59 59
  "0\n"
60 60
  "1\n"
61 61
  "@arcs\n"
62 62
  "     label -\n"
63 63
  "0 1\n";
64 64

	
65 65

	
66
int main() 
66
int main()
67 67
{
68 68
  {
69
    ListDigraph d; 
69
    ListDigraph d;
70 70
    ListDigraph::Node s,t;
71 71
    ListDigraph::ArcMap<int> label(d);
72 72
    std::istringstream input(test_lgf);
73 73
    digraphReader(d, input).
74 74
      node("source", s).
75 75
      node("target", t).
76 76
      arcMap("label", label).
77 77
      run();
78 78
    check(countNodes(d) == 2,"There should be 2 nodes");
79 79
    check(countArcs(d) == 2,"There should be 2 arcs");
80 80
  }
81 81
  {
82 82
    ListGraph g;
83 83
    ListGraph::Node s,t;
84 84
    ListGraph::EdgeMap<int> label(g);
85 85
    std::istringstream input(test_lgf);
86 86
    graphReader(g, input).
87 87
      node("source", s).
88 88
      node("target", t).
89 89
      edgeMap("label", label).
90 90
      run();
91 91
    check(countNodes(g) == 2,"There should be 2 nodes");
92 92
    check(countEdges(g) == 2,"There should be 2 arcs");
93 93
  }
94 94

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

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

	
141 141
  {
142
    ListDigraph d; 
142
    ListDigraph d;
143 143
    std::istringstream input(test_lgf_bad2);
144 144
    bool ok=false;
145 145
    try {
146 146
      digraphReader(d, input).
147 147
        run();
148 148
    }
149 149
    catch (FormatError& error)
150 150
      {
151 151
        ok = true;
152 152
      }
153 153
    check(ok,"FormatError exception should have occured");
154 154
  }
155 155
  {
156 156
    ListGraph g;
157 157
    std::istringstream input(test_lgf_bad2);
158 158
    bool ok=false;
159 159
    try {
160 160
      graphReader(g, input).
161 161
        run();
162 162
    }
163 163
    catch (FormatError& error)
164 164
      {
165 165
        ok = true;
166 166
      }
167 167
    check(ok,"FormatError exception should have occured");
168 168
  }
169 169
}
Ignore white space 6 line context
1 1
/* -*- mode: C++; indent-tabs-mode: nil; -*-
2 2
 *
3 3
 * This file is a part of LEMON, a generic C++ optimization library.
4 4
 *
5
 * Copyright (C) 2003-2008
5
 * Copyright (C) 2003-2011
6 6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 7
 * (Egervary Research Group on Combinatorial Optimization, EGRES).
8 8
 *
9 9
 * Permission to use, modify and distribute this software is granted
10 10
 * provided that this copyright notice appears in all copies. For
11 11
 * precise terms see the accompanying LICENSE file.
12 12
 *
13 13
 * This software is provided "AS IS" with no warranty of any kind,
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
  checkConcept<ReferenceMap<A,B,B&,const B&>, ReferenceMap<A,B,B&,const B&> >();
73
  checkConcept<ReferenceMap<A,C,C&,const C&>, ReferenceMap<A,C,C&,const C&> >();
72
  checkConcept<ReferenceMap<A,B,B&,const B&>,
73
               ReferenceMap<A,B,B&,const B&> >();
74
  checkConcept<ReferenceMap<A,C,C&,const C&>,
75
               ReferenceMap<A,C,C&,const C&> >();
74 76

	
75 77
  // NullMap
76 78
  {
77 79
    checkConcept<ReadWriteMap<A,B>, NullMap<A,B> >();
78 80
    NullMap<A,B> map1;
79 81
    NullMap<A,B> map2 = map1;
80 82
    map1 = nullMap<A,B>();
81 83
  }
82 84

	
83 85
  // ConstMap
84 86
  {
85 87
    checkConcept<ReadWriteMap<A,B>, ConstMap<A,B> >();
86 88
    checkConcept<ReadWriteMap<A,C>, ConstMap<A,C> >();
87 89
    ConstMap<A,B> map1;
88 90
    ConstMap<A,B> map2 = B();
89 91
    ConstMap<A,B> map3 = map1;
90 92
    map1 = constMap<A>(B());
91 93
    map1 = constMap<A,B>();
92 94
    map1.setAll(B());
93 95
    ConstMap<A,C> map4(C(1));
94 96
    ConstMap<A,C> map5 = map4;
95 97
    map4 = constMap<A>(C(2));
96 98
    map4.setAll(C(3));
97 99

	
98 100
    checkConcept<ReadWriteMap<A,int>, ConstMap<A,int> >();
99 101
    check(constMap<A>(10)[A()] == 10, "Something is wrong with ConstMap");
100 102

	
101 103
    checkConcept<ReadWriteMap<A,int>, ConstMap<A,Const<int,10> > >();
102 104
    ConstMap<A,Const<int,10> > map6;
103 105
    ConstMap<A,Const<int,10> > map7 = map6;
104 106
    map6 = constMap<A,int,10>();
105 107
    map7 = constMap<A,Const<int,10> >();
106 108
    check(map6[A()] == 10 && map7[A()] == 10,
107 109
          "Something is wrong with ConstMap");
108 110
  }
109 111

	
110 112
  // IdentityMap
111 113
  {
112 114
    checkConcept<ReadMap<A,A>, IdentityMap<A> >();
113 115
    IdentityMap<A> map1;
114 116
    IdentityMap<A> map2 = map1;
115 117
    map1 = identityMap<A>();
116 118

	
117 119
    checkConcept<ReadMap<double,double>, IdentityMap<double> >();
118 120
    check(identityMap<double>()[1.0] == 1.0 &&
119 121
          identityMap<double>()[3.14] == 3.14,
120 122
          "Something is wrong with IdentityMap");
121 123
  }
... ...
@@ -154,97 +156,98 @@
154 156
    std::map<double, int> m;
155 157
    SparseMap<double, int> map5(m);
156 158
    SparseMap<double, int> map6(m,10);
157 159
    SparseMap<double, int> map7 = sparseMap(m);
158 160
    SparseMap<double, int> map8 = sparseMap(m,10);
159 161

	
160 162
    check(map5[1.0] == 0 && map5[3.14] == 0 &&
161 163
          map6[1.0] == 10 && map6[3.14] == 10,
162 164
          "Something is wrong with SparseMap");
163 165
    map5[1.0] = map6[3.14] = 100;
164 166
    check(map5[1.0] == 100 && map5[3.14] == 0 &&
165 167
          map6[1.0] == 10 && map6[3.14] == 100,
166 168
          "Something is wrong with SparseMap");
167 169
  }
168 170

	
169 171
  // ComposeMap
170 172
  {
171 173
    typedef ComposeMap<DoubleMap, ReadMap<B,A> > CompMap;
172 174
    checkConcept<ReadMap<B,double>, CompMap>();
173 175
    CompMap map1 = CompMap(DoubleMap(),ReadMap<B,A>());
174 176
    CompMap map2 = composeMap(DoubleMap(), ReadMap<B,A>());
175 177

	
176 178
    SparseMap<double, bool> m1(false); m1[3.14] = true;
177 179
    RangeMap<double> m2(2); m2[0] = 3.0; m2[1] = 3.14;
178 180
    check(!composeMap(m1,m2)[0] && composeMap(m1,m2)[1],
179 181
          "Something is wrong with ComposeMap")
180 182
  }
181 183

	
182 184
  // CombineMap
183 185
  {
184 186
    typedef CombineMap<DoubleMap, DoubleMap, std::plus<double> > CombMap;
185 187
    checkConcept<ReadMap<A,double>, CombMap>();
186 188
    CombMap map1 = CombMap(DoubleMap(), DoubleMap());
187 189
    CombMap map2 = combineMap(DoubleMap(), DoubleMap(), std::plus<double>());
188 190

	
189 191
    check(combineMap(constMap<B,int,2>(), identityMap<B>(), &binc)[B()] == 3,
190 192
          "Something is wrong with CombineMap");
191 193
  }
192 194

	
193 195
  // FunctorToMap, MapToFunctor
194 196
  {
195 197
    checkConcept<ReadMap<A,B>, FunctorToMap<F,A,B> >();
196 198
    checkConcept<ReadMap<A,B>, FunctorToMap<F> >();
197 199
    FunctorToMap<F> map1;
198 200
    FunctorToMap<F> map2 = FunctorToMap<F>(F());
199 201
    B b = functorToMap(F())[A()];
200 202

	
201 203
    checkConcept<ReadMap<A,B>, MapToFunctor<ReadMap<A,B> > >();
202
    MapToFunctor<ReadMap<A,B> > map = MapToFunctor<ReadMap<A,B> >(ReadMap<A,B>());
204
    MapToFunctor<ReadMap<A,B> > map =
205
      MapToFunctor<ReadMap<A,B> >(ReadMap<A,B>());
203 206

	
204 207
    check(functorToMap(&func)[A()] == 3,
205 208
          "Something is wrong with FunctorToMap");
206 209
    check(mapToFunctor(constMap<A,int>(2))(A()) == 2,
207 210
          "Something is wrong with MapToFunctor");
208 211
    check(mapToFunctor(functorToMap(&func))(A()) == 3 &&
209 212
          mapToFunctor(functorToMap(&func))[A()] == 3,
210 213
          "Something is wrong with FunctorToMap or MapToFunctor");
211 214
    check(functorToMap(mapToFunctor(constMap<A,int>(2)))[A()] == 2,
212 215
          "Something is wrong with FunctorToMap or MapToFunctor");
213 216
  }
214 217

	
215 218
  // ConvertMap
216 219
  {
217 220
    checkConcept<ReadMap<double,double>,
218 221
      ConvertMap<ReadMap<double, int>, double> >();
219 222
    ConvertMap<RangeMap<bool>, int> map1(rangeMap(1, true));
220 223
    ConvertMap<RangeMap<bool>, int> map2 = convertMap<int>(rangeMap(2, false));
221 224
  }
222 225

	
223 226
  // ForkMap
224 227
  {
225 228
    checkConcept<DoubleWriteMap, ForkMap<DoubleWriteMap, DoubleWriteMap> >();
226 229

	
227 230
    typedef RangeMap<double> RM;
228 231
    typedef SparseMap<int, double> SM;
229 232
    RM m1(10, -1);
230 233
    SM m2(-1);
231 234
    checkConcept<ReadWriteMap<int, double>, ForkMap<RM, SM> >();
232 235
    checkConcept<ReadWriteMap<int, double>, ForkMap<SM, RM> >();
233 236
    ForkMap<RM, SM> map1(m1,m2);
234 237
    ForkMap<SM, RM> map2 = forkMap(m2,m1);
235 238
    map2.set(5, 10);
236 239
    check(m1[1] == -1 && m1[5] == 10 && m2[1] == -1 &&
237 240
          m2[5] == 10 && map2[1] == -1 && map2[5] == 10,
238 241
          "Something is wrong with ForkMap");
239 242
  }
240 243

	
241 244
  // Arithmetic maps:
242 245
  // - AddMap, SubMap, MulMap, DivMap
243 246
  // - ShiftMap, ShiftWriteMap, ScaleMap, ScaleWriteMap
244 247
  // - NegMap, NegWriteMap, AbsMap
245 248
  {
246 249
    checkConcept<DoubleMap, AddMap<DoubleMap,DoubleMap> >();
247 250
    checkConcept<DoubleMap, SubMap<DoubleMap,DoubleMap> >();
248 251
    checkConcept<DoubleMap, MulMap<DoubleMap,DoubleMap> >();
249 252
    checkConcept<DoubleMap, DivMap<DoubleMap,DoubleMap> >();
250 253

	
0 comments (0 inline)