lemongraph 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (161) hide show
  1. checksums.yaml +7 -0
  2. data/.yardopts +8 -0
  3. data/LICENSE +674 -0
  4. data/README.md +6 -0
  5. data/ext/lemon-1.3.1/AUTHORS +26 -0
  6. data/ext/lemon-1.3.1/CMakeLists.txt +371 -0
  7. data/ext/lemon-1.3.1/INSTALL +167 -0
  8. data/ext/lemon-1.3.1/LICENSE +32 -0
  9. data/ext/lemon-1.3.1/NEWS +337 -0
  10. data/ext/lemon-1.3.1/README +50 -0
  11. data/ext/lemon-1.3.1/cmake/FindCOIN.cmake +110 -0
  12. data/ext/lemon-1.3.1/cmake/FindGLPK.cmake +55 -0
  13. data/ext/lemon-1.3.1/cmake/FindGhostscript.cmake +10 -0
  14. data/ext/lemon-1.3.1/cmake/FindILOG.cmake +102 -0
  15. data/ext/lemon-1.3.1/cmake/FindSOPLEX.cmake +23 -0
  16. data/ext/lemon-1.3.1/cmake/LEMONConfig.cmake.in +13 -0
  17. data/ext/lemon-1.3.1/cmake/nsis/lemon.ico +0 -0
  18. data/ext/lemon-1.3.1/cmake/nsis/uninstall.ico +0 -0
  19. data/ext/lemon-1.3.1/cmake/version.cmake +1 -0
  20. data/ext/lemon-1.3.1/cmake/version.cmake.in +1 -0
  21. data/ext/lemon-1.3.1/contrib/CMakeLists.txt +19 -0
  22. data/ext/lemon-1.3.1/lemon/CMakeLists.txt +91 -0
  23. data/ext/lemon-1.3.1/lemon/adaptors.h +3638 -0
  24. data/ext/lemon-1.3.1/lemon/arg_parser.cc +474 -0
  25. data/ext/lemon-1.3.1/lemon/arg_parser.h +440 -0
  26. data/ext/lemon-1.3.1/lemon/assert.h +214 -0
  27. data/ext/lemon-1.3.1/lemon/base.cc +37 -0
  28. data/ext/lemon-1.3.1/lemon/bellman_ford.h +1116 -0
  29. data/ext/lemon-1.3.1/lemon/bfs.h +1754 -0
  30. data/ext/lemon-1.3.1/lemon/bin_heap.h +347 -0
  31. data/ext/lemon-1.3.1/lemon/binomial_heap.h +445 -0
  32. data/ext/lemon-1.3.1/lemon/bits/alteration_notifier.h +472 -0
  33. data/ext/lemon-1.3.1/lemon/bits/array_map.h +351 -0
  34. data/ext/lemon-1.3.1/lemon/bits/bezier.h +174 -0
  35. data/ext/lemon-1.3.1/lemon/bits/default_map.h +182 -0
  36. data/ext/lemon-1.3.1/lemon/bits/edge_set_extender.h +627 -0
  37. data/ext/lemon-1.3.1/lemon/bits/enable_if.h +131 -0
  38. data/ext/lemon-1.3.1/lemon/bits/graph_adaptor_extender.h +401 -0
  39. data/ext/lemon-1.3.1/lemon/bits/graph_extender.h +1332 -0
  40. data/ext/lemon-1.3.1/lemon/bits/lock.h +65 -0
  41. data/ext/lemon-1.3.1/lemon/bits/map_extender.h +332 -0
  42. data/ext/lemon-1.3.1/lemon/bits/path_dump.h +177 -0
  43. data/ext/lemon-1.3.1/lemon/bits/solver_bits.h +194 -0
  44. data/ext/lemon-1.3.1/lemon/bits/traits.h +388 -0
  45. data/ext/lemon-1.3.1/lemon/bits/variant.h +494 -0
  46. data/ext/lemon-1.3.1/lemon/bits/vector_map.h +244 -0
  47. data/ext/lemon-1.3.1/lemon/bits/windows.cc +166 -0
  48. data/ext/lemon-1.3.1/lemon/bits/windows.h +44 -0
  49. data/ext/lemon-1.3.1/lemon/bucket_heap.h +594 -0
  50. data/ext/lemon-1.3.1/lemon/capacity_scaling.h +1014 -0
  51. data/ext/lemon-1.3.1/lemon/cbc.cc +460 -0
  52. data/ext/lemon-1.3.1/lemon/cbc.h +129 -0
  53. data/ext/lemon-1.3.1/lemon/christofides_tsp.h +254 -0
  54. data/ext/lemon-1.3.1/lemon/circulation.h +807 -0
  55. data/ext/lemon-1.3.1/lemon/clp.cc +464 -0
  56. data/ext/lemon-1.3.1/lemon/clp.h +164 -0
  57. data/ext/lemon-1.3.1/lemon/color.cc +44 -0
  58. data/ext/lemon-1.3.1/lemon/color.h +204 -0
  59. data/ext/lemon-1.3.1/lemon/concept_check.h +77 -0
  60. data/ext/lemon-1.3.1/lemon/concepts/bpgraph.h +1029 -0
  61. data/ext/lemon-1.3.1/lemon/concepts/digraph.h +491 -0
  62. data/ext/lemon-1.3.1/lemon/concepts/graph.h +788 -0
  63. data/ext/lemon-1.3.1/lemon/concepts/graph_components.h +2134 -0
  64. data/ext/lemon-1.3.1/lemon/concepts/heap.h +324 -0
  65. data/ext/lemon-1.3.1/lemon/concepts/maps.h +223 -0
  66. data/ext/lemon-1.3.1/lemon/concepts/path.h +312 -0
  67. data/ext/lemon-1.3.1/lemon/config.h.in +22 -0
  68. data/ext/lemon-1.3.1/lemon/connectivity.h +1688 -0
  69. data/ext/lemon-1.3.1/lemon/core.h +2506 -0
  70. data/ext/lemon-1.3.1/lemon/cost_scaling.h +1607 -0
  71. data/ext/lemon-1.3.1/lemon/counter.h +249 -0
  72. data/ext/lemon-1.3.1/lemon/cplex.cc +994 -0
  73. data/ext/lemon-1.3.1/lemon/cplex.h +292 -0
  74. data/ext/lemon-1.3.1/lemon/cycle_canceling.h +1230 -0
  75. data/ext/lemon-1.3.1/lemon/dfs.h +1637 -0
  76. data/ext/lemon-1.3.1/lemon/dheap.h +352 -0
  77. data/ext/lemon-1.3.1/lemon/dijkstra.h +1303 -0
  78. data/ext/lemon-1.3.1/lemon/dim2.h +726 -0
  79. data/ext/lemon-1.3.1/lemon/dimacs.h +448 -0
  80. data/ext/lemon-1.3.1/lemon/edge_set.h +1420 -0
  81. data/ext/lemon-1.3.1/lemon/edmonds_karp.h +556 -0
  82. data/ext/lemon-1.3.1/lemon/elevator.h +982 -0
  83. data/ext/lemon-1.3.1/lemon/error.h +276 -0
  84. data/ext/lemon-1.3.1/lemon/euler.h +287 -0
  85. data/ext/lemon-1.3.1/lemon/fib_heap.h +475 -0
  86. data/ext/lemon-1.3.1/lemon/fractional_matching.h +2139 -0
  87. data/ext/lemon-1.3.1/lemon/full_graph.h +1082 -0
  88. data/ext/lemon-1.3.1/lemon/glpk.cc +1012 -0
  89. data/ext/lemon-1.3.1/lemon/glpk.h +263 -0
  90. data/ext/lemon-1.3.1/lemon/gomory_hu.h +568 -0
  91. data/ext/lemon-1.3.1/lemon/graph_to_eps.h +1186 -0
  92. data/ext/lemon-1.3.1/lemon/greedy_tsp.h +251 -0
  93. data/ext/lemon-1.3.1/lemon/grid_graph.h +699 -0
  94. data/ext/lemon-1.3.1/lemon/grosso_locatelli_pullan_mc.h +840 -0
  95. data/ext/lemon-1.3.1/lemon/hao_orlin.h +1015 -0
  96. data/ext/lemon-1.3.1/lemon/hartmann_orlin_mmc.h +654 -0
  97. data/ext/lemon-1.3.1/lemon/howard_mmc.h +651 -0
  98. data/ext/lemon-1.3.1/lemon/hypercube_graph.h +459 -0
  99. data/ext/lemon-1.3.1/lemon/insertion_tsp.h +533 -0
  100. data/ext/lemon-1.3.1/lemon/karp_mmc.h +590 -0
  101. data/ext/lemon-1.3.1/lemon/kruskal.h +324 -0
  102. data/ext/lemon-1.3.1/lemon/lemon.pc.in +10 -0
  103. data/ext/lemon-1.3.1/lemon/lgf_reader.h +3854 -0
  104. data/ext/lemon-1.3.1/lemon/lgf_writer.h +2687 -0
  105. data/ext/lemon-1.3.1/lemon/list_graph.h +2510 -0
  106. data/ext/lemon-1.3.1/lemon/lp.h +95 -0
  107. data/ext/lemon-1.3.1/lemon/lp_base.cc +30 -0
  108. data/ext/lemon-1.3.1/lemon/lp_base.h +2147 -0
  109. data/ext/lemon-1.3.1/lemon/lp_skeleton.cc +143 -0
  110. data/ext/lemon-1.3.1/lemon/lp_skeleton.h +234 -0
  111. data/ext/lemon-1.3.1/lemon/maps.h +4057 -0
  112. data/ext/lemon-1.3.1/lemon/matching.h +3505 -0
  113. data/ext/lemon-1.3.1/lemon/math.h +77 -0
  114. data/ext/lemon-1.3.1/lemon/max_cardinality_search.h +794 -0
  115. data/ext/lemon-1.3.1/lemon/min_cost_arborescence.h +808 -0
  116. data/ext/lemon-1.3.1/lemon/nagamochi_ibaraki.h +702 -0
  117. data/ext/lemon-1.3.1/lemon/nauty_reader.h +113 -0
  118. data/ext/lemon-1.3.1/lemon/nearest_neighbor_tsp.h +238 -0
  119. data/ext/lemon-1.3.1/lemon/network_simplex.h +1659 -0
  120. data/ext/lemon-1.3.1/lemon/opt2_tsp.h +367 -0
  121. data/ext/lemon-1.3.1/lemon/pairing_heap.h +474 -0
  122. data/ext/lemon-1.3.1/lemon/path.h +1164 -0
  123. data/ext/lemon-1.3.1/lemon/planarity.h +2754 -0
  124. data/ext/lemon-1.3.1/lemon/preflow.h +985 -0
  125. data/ext/lemon-1.3.1/lemon/quad_heap.h +343 -0
  126. data/ext/lemon-1.3.1/lemon/radix_heap.h +438 -0
  127. data/ext/lemon-1.3.1/lemon/radix_sort.h +487 -0
  128. data/ext/lemon-1.3.1/lemon/random.cc +29 -0
  129. data/ext/lemon-1.3.1/lemon/random.h +1005 -0
  130. data/ext/lemon-1.3.1/lemon/smart_graph.h +1344 -0
  131. data/ext/lemon-1.3.1/lemon/soplex.cc +465 -0
  132. data/ext/lemon-1.3.1/lemon/soplex.h +158 -0
  133. data/ext/lemon-1.3.1/lemon/static_graph.h +476 -0
  134. data/ext/lemon-1.3.1/lemon/suurballe.h +776 -0
  135. data/ext/lemon-1.3.1/lemon/time_measure.h +610 -0
  136. data/ext/lemon-1.3.1/lemon/tolerance.h +242 -0
  137. data/ext/lemon-1.3.1/lemon/unionfind.h +1824 -0
  138. data/ext/lemon-1.3.1/scripts/unify-sources.sh +390 -0
  139. data/ext/lemon-1.3.1/scripts/valgrind-wrapper.sh +22 -0
  140. data/ext/lemongraph/arc_map.cc +1007 -0
  141. data/ext/lemongraph/digraph.cc +282 -0
  142. data/ext/lemongraph/digraph_arc.cc +153 -0
  143. data/ext/lemongraph/digraph_node.cc +277 -0
  144. data/ext/lemongraph/edge_map.cc +770 -0
  145. data/ext/lemongraph/extconf.rb +53 -0
  146. data/ext/lemongraph/graph.cc +351 -0
  147. data/ext/lemongraph/graph_arc.cc +95 -0
  148. data/ext/lemongraph/graph_edge.cc +153 -0
  149. data/ext/lemongraph/graph_item.cc +76 -0
  150. data/ext/lemongraph/graph_node.cc +321 -0
  151. data/ext/lemongraph/lemongraph.cc +260 -0
  152. data/ext/lemongraph/lemongraph.hh +295 -0
  153. data/ext/lemongraph/lemongraph.map +6 -0
  154. data/ext/lemongraph/lemongraph_export.hh +31 -0
  155. data/ext/lemongraph/node_map.cc +1011 -0
  156. data/lemongraph.gemspec +176 -0
  157. data/lib/lemongraph/graphviz.rb +240 -0
  158. data/lib/lemongraph/version.rb +4 -0
  159. data/lib/lemongraph.rb +21 -0
  160. data/samples/lemondeps.rb +38 -0
  161. metadata +202 -0
@@ -0,0 +1,440 @@
1
+ /* -*- mode: C++; indent-tabs-mode: nil; -*-
2
+ *
3
+ * This file is a part of LEMON, a generic C++ optimization library.
4
+ *
5
+ * Copyright (C) 2003-2010
6
+ * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7
+ * (Egervary Research Group on Combinatorial Optimization, EGRES).
8
+ *
9
+ * Permission to use, modify and distribute this software is granted
10
+ * provided that this copyright notice appears in all copies. For
11
+ * precise terms see the accompanying LICENSE file.
12
+ *
13
+ * This software is provided "AS IS" with no warranty of any kind,
14
+ * express or implied, and with no claim as to its suitability for any
15
+ * purpose.
16
+ *
17
+ */
18
+
19
+ #ifndef LEMON_ARG_PARSER_H
20
+ #define LEMON_ARG_PARSER_H
21
+
22
+ #include <vector>
23
+ #include <map>
24
+ #include <list>
25
+ #include <string>
26
+ #include <iostream>
27
+ #include <sstream>
28
+ #include <algorithm>
29
+ #include <lemon/assert.h>
30
+
31
+ ///\ingroup misc
32
+ ///\file
33
+ ///\brief A tool to parse command line arguments.
34
+
35
+ namespace lemon {
36
+
37
+ ///Exception used by ArgParser
38
+
39
+ ///Exception used by ArgParser.
40
+ ///
41
+ class ArgParserException : public Exception {
42
+ public:
43
+ /// Reasons for failure
44
+
45
+ /// Reasons for failure.
46
+ ///
47
+ enum Reason {
48
+ HELP, ///< <tt>--help</tt> option was given.
49
+ UNKNOWN_OPT, ///< Unknown option was given.
50
+ INVALID_OPT ///< Invalid combination of options.
51
+ };
52
+
53
+ private:
54
+ Reason _reason;
55
+
56
+ public:
57
+ ///Constructor
58
+ ArgParserException(Reason r) throw() : _reason(r) {}
59
+ ///Virtual destructor
60
+ virtual ~ArgParserException() throw() {}
61
+ ///A short description of the exception
62
+ virtual const char* what() const throw() {
63
+ switch(_reason)
64
+ {
65
+ case HELP:
66
+ return "lemon::ArgParseException: ask for help";
67
+ break;
68
+ case UNKNOWN_OPT:
69
+ return "lemon::ArgParseException: unknown option";
70
+ break;
71
+ case INVALID_OPT:
72
+ return "lemon::ArgParseException: invalid combination of options";
73
+ break;
74
+ }
75
+ return "";
76
+ }
77
+ ///Return the reason for the failure
78
+ Reason reason() const {return _reason; }
79
+ };
80
+
81
+
82
+ ///Command line arguments parser
83
+
84
+ ///\ingroup misc
85
+ ///Command line arguments parser.
86
+ ///
87
+ ///For a complete example see the \ref arg_parser_demo.cc demo file.
88
+ class ArgParser {
89
+
90
+ static void _showHelp(void *p);
91
+ protected:
92
+
93
+ int _argc;
94
+ const char * const *_argv;
95
+
96
+ enum OptType { UNKNOWN=0, BOOL=1, STRING=2, DOUBLE=3, INTEGER=4, FUNC=5 };
97
+
98
+ class ParData {
99
+ public:
100
+ union {
101
+ bool *bool_p;
102
+ int *int_p;
103
+ double *double_p;
104
+ std::string *string_p;
105
+ struct {
106
+ void (*p)(void *);
107
+ void *data;
108
+ } func_p;
109
+
110
+ };
111
+ std::string help;
112
+ bool mandatory;
113
+ OptType type;
114
+ bool set;
115
+ bool ingroup;
116
+ bool has_syn;
117
+ bool syn;
118
+ bool self_delete;
119
+ ParData() : mandatory(false), type(UNKNOWN), set(false), ingroup(false),
120
+ has_syn(false), syn(false), self_delete(false) {}
121
+ };
122
+
123
+ typedef std::map<std::string,ParData> Opts;
124
+ Opts _opts;
125
+
126
+ class GroupData
127
+ {
128
+ public:
129
+ typedef std::list<std::string> Opts;
130
+ Opts opts;
131
+ bool only_one;
132
+ bool mandatory;
133
+ GroupData() :only_one(false), mandatory(false) {}
134
+ };
135
+
136
+ typedef std::map<std::string,GroupData> Groups;
137
+ Groups _groups;
138
+
139
+ struct OtherArg
140
+ {
141
+ std::string name;
142
+ std::string help;
143
+ OtherArg(std::string n, std::string h) :name(n), help(h) {}
144
+
145
+ };
146
+
147
+ std::vector<OtherArg> _others_help;
148
+ std::vector<std::string> _file_args;
149
+ std::string _command_name;
150
+
151
+
152
+ private:
153
+ //Bind a function to an option.
154
+
155
+ //\param name The name of the option. The leading '-' must be omitted.
156
+ //\param help A help string.
157
+ //\retval func The function to be called when the option is given. It
158
+ // must be of type "void f(void *)"
159
+ //\param data Data to be passed to \c func
160
+ ArgParser &funcOption(const std::string &name,
161
+ const std::string &help,
162
+ void (*func)(void *),void *data);
163
+
164
+ bool _exit_on_problems;
165
+
166
+ void _terminate(ArgParserException::Reason reason) const;
167
+
168
+ public:
169
+
170
+ ///Constructor
171
+ ArgParser(int argc, const char * const *argv);
172
+
173
+ ~ArgParser();
174
+
175
+ ///\name Options
176
+ ///
177
+
178
+ ///@{
179
+
180
+ ///Add a new integer type option
181
+
182
+ ///Add a new integer type option.
183
+ ///\param name The name of the option. The leading '-' must be omitted.
184
+ ///\param help A help string.
185
+ ///\param value A default value for the option.
186
+ ///\param obl Indicate if the option is mandatory.
187
+ ArgParser &intOption(const std::string &name,
188
+ const std::string &help,
189
+ int value=0, bool obl=false);
190
+
191
+ ///Add a new floating point type option
192
+
193
+ ///Add a new floating point type option.
194
+ ///\param name The name of the option. The leading '-' must be omitted.
195
+ ///\param help A help string.
196
+ ///\param value A default value for the option.
197
+ ///\param obl Indicate if the option is mandatory.
198
+ ArgParser &doubleOption(const std::string &name,
199
+ const std::string &help,
200
+ double value=0, bool obl=false);
201
+
202
+ ///Add a new bool type option
203
+
204
+ ///Add a new bool type option.
205
+ ///\param name The name of the option. The leading '-' must be omitted.
206
+ ///\param help A help string.
207
+ ///\param value A default value for the option.
208
+ ///\param obl Indicate if the option is mandatory.
209
+ ///\note A mandatory bool obtion is of very little use.
210
+ ArgParser &boolOption(const std::string &name,
211
+ const std::string &help,
212
+ bool value=false, bool obl=false);
213
+
214
+ ///Add a new string type option
215
+
216
+ ///Add a new string type option.
217
+ ///\param name The name of the option. The leading '-' must be omitted.
218
+ ///\param help A help string.
219
+ ///\param value A default value for the option.
220
+ ///\param obl Indicate if the option is mandatory.
221
+ ArgParser &stringOption(const std::string &name,
222
+ const std::string &help,
223
+ std::string value="", bool obl=false);
224
+
225
+ ///Give help string for non-parsed arguments.
226
+
227
+ ///With this function you can give help string for non-parsed arguments.
228
+ ///The parameter \c name will be printed in the short usage line, while
229
+ ///\c help gives a more detailed description.
230
+ ArgParser &other(const std::string &name,
231
+ const std::string &help="");
232
+
233
+ ///@}
234
+
235
+ ///\name Options with External Storage
236
+ ///Using this functions, the value of the option will be directly written
237
+ ///into a variable once the option appears in the command line.
238
+
239
+ ///@{
240
+
241
+ ///Add a new integer type option with a storage reference
242
+
243
+ ///Add a new integer type option with a storage reference.
244
+ ///\param name The name of the option. The leading '-' must be omitted.
245
+ ///\param help A help string.
246
+ ///\param obl Indicate if the option is mandatory.
247
+ ///\retval ref The value of the argument will be written to this variable.
248
+ ArgParser &refOption(const std::string &name,
249
+ const std::string &help,
250
+ int &ref, bool obl=false);
251
+
252
+ ///Add a new floating type option with a storage reference
253
+
254
+ ///Add a new floating type option with a storage reference.
255
+ ///\param name The name of the option. The leading '-' must be omitted.
256
+ ///\param help A help string.
257
+ ///\param obl Indicate if the option is mandatory.
258
+ ///\retval ref The value of the argument will be written to this variable.
259
+ ArgParser &refOption(const std::string &name,
260
+ const std::string &help,
261
+ double &ref, bool obl=false);
262
+
263
+ ///Add a new bool type option with a storage reference
264
+
265
+ ///Add a new bool type option with a storage reference.
266
+ ///\param name The name of the option. The leading '-' must be omitted.
267
+ ///\param help A help string.
268
+ ///\param obl Indicate if the option is mandatory.
269
+ ///\retval ref The value of the argument will be written to this variable.
270
+ ///\note A mandatory bool obtion is of very little use.
271
+ ArgParser &refOption(const std::string &name,
272
+ const std::string &help,
273
+ bool &ref, bool obl=false);
274
+
275
+ ///Add a new string type option with a storage reference
276
+
277
+ ///Add a new string type option with a storage reference.
278
+ ///\param name The name of the option. The leading '-' must be omitted.
279
+ ///\param help A help string.
280
+ ///\param obl Indicate if the option is mandatory.
281
+ ///\retval ref The value of the argument will be written to this variable.
282
+ ArgParser &refOption(const std::string &name,
283
+ const std::string &help,
284
+ std::string &ref, bool obl=false);
285
+
286
+ ///@}
287
+
288
+ ///\name Option Groups and Synonyms
289
+ ///
290
+
291
+ ///@{
292
+
293
+ ///Bundle some options into a group
294
+
295
+ /// You can group some option by calling this function repeatedly for each
296
+ /// option to be grouped with the same groupname.
297
+ ///\param group The group name.
298
+ ///\param opt The option name.
299
+ ArgParser &optionGroup(const std::string &group,
300
+ const std::string &opt);
301
+
302
+ ///Make the members of a group exclusive
303
+
304
+ ///If you call this function for a group, than at most one of them can be
305
+ ///given at the same time.
306
+ ArgParser &onlyOneGroup(const std::string &group);
307
+
308
+ ///Make a group mandatory
309
+
310
+ ///Using this function, at least one of the members of \c group
311
+ ///must be given.
312
+ ArgParser &mandatoryGroup(const std::string &group);
313
+
314
+ ///Create synonym to an option
315
+
316
+ ///With this function you can create a synonym \c syn of the
317
+ ///option \c opt.
318
+ ArgParser &synonym(const std::string &syn,
319
+ const std::string &opt);
320
+
321
+ ///@}
322
+
323
+ private:
324
+ void show(std::ostream &os,Opts::const_iterator i) const;
325
+ void show(std::ostream &os,Groups::const_iterator i) const;
326
+ void showHelp(Opts::const_iterator i) const;
327
+ void showHelp(std::vector<OtherArg>::const_iterator i) const;
328
+
329
+ void unknownOpt(std::string arg) const;
330
+
331
+ void requiresValue(std::string arg, OptType t) const;
332
+ void checkMandatories() const;
333
+
334
+ void shortHelp() const;
335
+ void showHelp() const;
336
+ public:
337
+
338
+ ///Start the parsing process
339
+ ArgParser &parse();
340
+
341
+ /// Synonym for parse()
342
+ ArgParser &run()
343
+ {
344
+ return parse();
345
+ }
346
+
347
+ ///Give back the command name (the 0th argument)
348
+ const std::string &commandName() const { return _command_name; }
349
+
350
+ ///Check if an opion has been given to the command.
351
+ bool given(std::string op) const
352
+ {
353
+ Opts::const_iterator i = _opts.find(op);
354
+ return i!=_opts.end()?i->second.set:false;
355
+ }
356
+
357
+
358
+ ///Magic type for operator[]
359
+
360
+ ///This is the type of the return value of ArgParser::operator[]().
361
+ ///It automatically converts to \c int, \c double, \c bool or
362
+ ///\c std::string if the type of the option matches, which is checked
363
+ ///with an \ref LEMON_ASSERT "assertion" (i.e. it performs runtime
364
+ ///type checking).
365
+ class RefType
366
+ {
367
+ const ArgParser &_parser;
368
+ std::string _name;
369
+ public:
370
+ ///\e
371
+ RefType(const ArgParser &p,const std::string &n) :_parser(p),_name(n) {}
372
+ ///\e
373
+ operator bool()
374
+ {
375
+ Opts::const_iterator i = _parser._opts.find(_name);
376
+ LEMON_ASSERT(i!=_parser._opts.end(),
377
+ std::string()+"Unkown option: '"+_name+"'");
378
+ LEMON_ASSERT(i->second.type==ArgParser::BOOL,
379
+ std::string()+"'"+_name+"' is a bool option");
380
+ return *(i->second.bool_p);
381
+ }
382
+ ///\e
383
+ operator std::string()
384
+ {
385
+ Opts::const_iterator i = _parser._opts.find(_name);
386
+ LEMON_ASSERT(i!=_parser._opts.end(),
387
+ std::string()+"Unkown option: '"+_name+"'");
388
+ LEMON_ASSERT(i->second.type==ArgParser::STRING,
389
+ std::string()+"'"+_name+"' is a string option");
390
+ return *(i->second.string_p);
391
+ }
392
+ ///\e
393
+ operator double()
394
+ {
395
+ Opts::const_iterator i = _parser._opts.find(_name);
396
+ LEMON_ASSERT(i!=_parser._opts.end(),
397
+ std::string()+"Unkown option: '"+_name+"'");
398
+ LEMON_ASSERT(i->second.type==ArgParser::DOUBLE ||
399
+ i->second.type==ArgParser::INTEGER,
400
+ std::string()+"'"+_name+"' is a floating point option");
401
+ return i->second.type==ArgParser::DOUBLE ?
402
+ *(i->second.double_p) : *(i->second.int_p);
403
+ }
404
+ ///\e
405
+ operator int()
406
+ {
407
+ Opts::const_iterator i = _parser._opts.find(_name);
408
+ LEMON_ASSERT(i!=_parser._opts.end(),
409
+ std::string()+"Unkown option: '"+_name+"'");
410
+ LEMON_ASSERT(i->second.type==ArgParser::INTEGER,
411
+ std::string()+"'"+_name+"' is an integer option");
412
+ return *(i->second.int_p);
413
+ }
414
+
415
+ };
416
+
417
+ ///Give back the value of an option
418
+
419
+ ///Give back the value of an option.
420
+ ///\sa RefType
421
+ RefType operator[](const std::string &n) const
422
+ {
423
+ return RefType(*this, n);
424
+ }
425
+
426
+ ///Give back the non-option type arguments.
427
+
428
+ ///Give back a reference to a vector consisting of the program arguments
429
+ ///not starting with a '-' character.
430
+ const std::vector<std::string> &files() const { return _file_args; }
431
+
432
+ ///Throw instead of exit in case of problems
433
+ void throwOnProblems()
434
+ {
435
+ _exit_on_problems=false;
436
+ }
437
+ };
438
+ }
439
+
440
+ #endif // LEMON_ARG_PARSER_H
@@ -0,0 +1,214 @@
1
+ /* -*- mode: C++; indent-tabs-mode: nil; -*-
2
+ *
3
+ * This file is a part of LEMON, a generic C++ optimization library.
4
+ *
5
+ * Copyright (C) 2003-2013
6
+ * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7
+ * (Egervary Research Group on Combinatorial Optimization, EGRES).
8
+ *
9
+ * Permission to use, modify and distribute this software is granted
10
+ * provided that this copyright notice appears in all copies. For
11
+ * precise terms see the accompanying LICENSE file.
12
+ *
13
+ * This software is provided "AS IS" with no warranty of any kind,
14
+ * express or implied, and with no claim as to its suitability for any
15
+ * purpose.
16
+ *
17
+ */
18
+
19
+ #ifndef LEMON_ASSERT_H
20
+ #define LEMON_ASSERT_H
21
+
22
+ /// \ingroup exceptions
23
+ /// \file
24
+ /// \brief Extended assertion handling
25
+
26
+ #include <lemon/error.h>
27
+
28
+ namespace lemon {
29
+
30
+ inline void assert_fail_abort(const char *file, int line,
31
+ const char *function, const char* message,
32
+ const char *assertion)
33
+ {
34
+ std::cerr << file << ":" << line << ": ";
35
+ if (function)
36
+ std::cerr << function << ": ";
37
+ std::cerr << message;
38
+ if (assertion)
39
+ std::cerr << " (assertion '" << assertion << "' failed)";
40
+ std::cerr << std::endl;
41
+ std::abort();
42
+ }
43
+
44
+ namespace _assert_bits {
45
+
46
+
47
+ inline const char* cstringify(const std::string& str) {
48
+ return str.c_str();
49
+ }
50
+
51
+ inline const char* cstringify(const char* str) {
52
+ return str;
53
+ }
54
+ }
55
+ }
56
+
57
+ #endif // LEMON_ASSERT_H
58
+
59
+ #undef LEMON_ASSERT
60
+ #undef LEMON_DEBUG
61
+
62
+ #if (defined(LEMON_ASSERT_ABORT) ? 1 : 0) + \
63
+ (defined(LEMON_ASSERT_CUSTOM) ? 1 : 0) > 1
64
+ #error "LEMON assertion system is not set properly"
65
+ #endif
66
+
67
+ #if ((defined(LEMON_ASSERT_ABORT) ? 1 : 0) + \
68
+ (defined(LEMON_ASSERT_CUSTOM) ? 1 : 0) == 1 || \
69
+ defined(LEMON_ENABLE_ASSERTS)) && \
70
+ (defined(LEMON_DISABLE_ASSERTS) || \
71
+ defined(NDEBUG))
72
+ #error "LEMON assertion system is not set properly"
73
+ #endif
74
+
75
+
76
+ #if defined LEMON_ASSERT_ABORT
77
+ # undef LEMON_ASSERT_HANDLER
78
+ # define LEMON_ASSERT_HANDLER ::lemon::assert_fail_abort
79
+ #elif defined LEMON_ASSERT_CUSTOM
80
+ # undef LEMON_ASSERT_HANDLER
81
+ # ifndef LEMON_CUSTOM_ASSERT_HANDLER
82
+ # error "LEMON_CUSTOM_ASSERT_HANDLER is not set"
83
+ # endif
84
+ # define LEMON_ASSERT_HANDLER LEMON_CUSTOM_ASSERT_HANDLER
85
+ #elif defined LEMON_DISABLE_ASSERTS
86
+ # undef LEMON_ASSERT_HANDLER
87
+ #elif defined NDEBUG
88
+ # undef LEMON_ASSERT_HANDLER
89
+ #else
90
+ # define LEMON_ASSERT_HANDLER ::lemon::assert_fail_abort
91
+ #endif
92
+
93
+ #ifndef LEMON_FUNCTION_NAME
94
+ # if defined __GNUC__
95
+ # define LEMON_FUNCTION_NAME (__PRETTY_FUNCTION__)
96
+ # elif defined _MSC_VER
97
+ # define LEMON_FUNCTION_NAME (__FUNCSIG__)
98
+ # elif __STDC_VERSION__ >= 199901L
99
+ # define LEMON_FUNCTION_NAME (__func__)
100
+ # else
101
+ # define LEMON_FUNCTION_NAME ("<unknown>")
102
+ # endif
103
+ #endif
104
+
105
+ #ifdef DOXYGEN
106
+
107
+ /// \ingroup exceptions
108
+ ///
109
+ /// \brief Macro for assertion with customizable message
110
+ ///
111
+ /// Macro for assertion with customizable message.
112
+ /// \param exp An expression that must be convertible to \c bool. If it is \c
113
+ /// false, then an assertion is raised. The concrete behaviour depends on the
114
+ /// settings of the assertion system.
115
+ /// \param msg A <tt>const char*</tt> parameter, which can be used to provide
116
+ /// information about the circumstances of the failed assertion.
117
+ ///
118
+ /// The assertions are enabled in the default behaviour.
119
+ /// You can disable them with the following code:
120
+ /// \code
121
+ /// #define LEMON_DISABLE_ASSERTS
122
+ /// \endcode
123
+ /// or with compilation parameters:
124
+ /// \code
125
+ /// g++ -DLEMON_DISABLE_ASSERTS
126
+ /// make CXXFLAGS='-DLEMON_DISABLE_ASSERTS'
127
+ /// \endcode
128
+ /// The checking is also disabled when the standard macro \c NDEBUG is defined.
129
+ ///
130
+ /// As a default behaviour the failed assertion prints a short log message to
131
+ /// the standard error and aborts the execution.
132
+ ///
133
+ /// However, the following modes can be used in the assertion system:
134
+ /// - \c LEMON_ASSERT_ABORT The failed assertion prints a short log message to
135
+ /// the standard error and aborts the program. It is the default behaviour.
136
+ /// - \c LEMON_ASSERT_CUSTOM The user can define own assertion handler
137
+ /// function.
138
+ /// \code
139
+ /// void custom_assert_handler(const char* file, int line,
140
+ /// const char* function, const char* message,
141
+ /// const char* assertion);
142
+ /// \endcode
143
+ /// The name of the function should be defined as the \c
144
+ /// LEMON_CUSTOM_ASSERT_HANDLER macro name.
145
+ /// \code
146
+ /// #define LEMON_CUSTOM_ASSERT_HANDLER custom_assert_handler
147
+ /// \endcode
148
+ /// Whenever an assertion is occured, the custom assertion
149
+ /// handler is called with appropiate parameters.
150
+ ///
151
+ /// The assertion mode can also be changed within one compilation unit.
152
+ /// If the macros are redefined with other settings and the
153
+ /// \ref lemon/assert.h "assert.h" file is reincluded, then the
154
+ /// behaviour is changed appropiately to the new settings.
155
+ # define LEMON_ASSERT(exp, msg) \
156
+ (static_cast<void> (!!(exp) ? 0 : ( \
157
+ LEMON_ASSERT_HANDLER(__FILE__, __LINE__, \
158
+ LEMON_FUNCTION_NAME, \
159
+ ::lemon::_assert_bits::cstringify(msg), #exp), 0)))
160
+
161
+ /// \ingroup exceptions
162
+ ///
163
+ /// \brief Macro for internal assertions
164
+ ///
165
+ /// Macro for internal assertions, it is used in the library to check
166
+ /// the consistency of results of algorithms, several pre- and
167
+ /// postconditions and invariants. The checking is disabled by
168
+ /// default, but it can be turned on with the macro \c
169
+ /// LEMON_ENABLE_DEBUG.
170
+ /// \code
171
+ /// #define LEMON_ENABLE_DEBUG
172
+ /// \endcode
173
+ /// or with compilation parameters:
174
+ /// \code
175
+ /// g++ -DLEMON_ENABLE_DEBUG
176
+ /// make CXXFLAGS='-DLEMON_ENABLE_DEBUG'
177
+ /// \endcode
178
+ ///
179
+ /// This macro works like the \c LEMON_ASSERT macro, therefore the
180
+ /// current behaviour depends on the settings of \c LEMON_ASSERT
181
+ /// macro.
182
+ ///
183
+ /// \see LEMON_ASSERT
184
+ # define LEMON_DEBUG(exp, msg) \
185
+ (static_cast<void> (!!(exp) ? 0 : ( \
186
+ LEMON_ASSERT_HANDLER(__FILE__, __LINE__, \
187
+ LEMON_FUNCTION_NAME, \
188
+ ::lemon::_assert_bits::cstringify(msg), #exp), 0)))
189
+
190
+ #else
191
+
192
+ # ifndef LEMON_ASSERT_HANDLER
193
+ # define LEMON_ASSERT(exp, msg) (static_cast<void>(0))
194
+ # define LEMON_DEBUG(exp, msg) (static_cast<void>(0))
195
+ # else
196
+ # define LEMON_ASSERT(exp, msg) \
197
+ (static_cast<void> (!!(exp) ? 0 : ( \
198
+ LEMON_ASSERT_HANDLER(__FILE__, __LINE__, \
199
+ LEMON_FUNCTION_NAME, \
200
+ ::lemon::_assert_bits::cstringify(msg), \
201
+ #exp), 0)))
202
+ # if defined LEMON_ENABLE_DEBUG
203
+ # define LEMON_DEBUG(exp, msg) \
204
+ (static_cast<void> (!!(exp) ? 0 : ( \
205
+ LEMON_ASSERT_HANDLER(__FILE__, __LINE__, \
206
+ LEMON_FUNCTION_NAME, \
207
+ ::lemon::_assert_bits::cstringify(msg), \
208
+ #exp), 0)))
209
+ # else
210
+ # define LEMON_DEBUG(exp, msg) (static_cast<void>(0))
211
+ # endif
212
+ # endif
213
+
214
+ #endif
@@ -0,0 +1,37 @@
1
+ /* -*- mode: C++; indent-tabs-mode: nil; -*-
2
+ *
3
+ * This file is a part of LEMON, a generic C++ optimization library.
4
+ *
5
+ * Copyright (C) 2003-2013
6
+ * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7
+ * (Egervary Research Group on Combinatorial Optimization, EGRES).
8
+ *
9
+ * Permission to use, modify and distribute this software is granted
10
+ * provided that this copyright notice appears in all copies. For
11
+ * precise terms see the accompanying LICENSE file.
12
+ *
13
+ * This software is provided "AS IS" with no warranty of any kind,
14
+ * express or implied, and with no claim as to its suitability for any
15
+ * purpose.
16
+ *
17
+ */
18
+
19
+ ///\file
20
+ ///\brief Some basic non-inline functions and static global data.
21
+
22
+ #include<lemon/tolerance.h>
23
+ #include<lemon/core.h>
24
+ #include<lemon/time_measure.h>
25
+ namespace lemon {
26
+
27
+ float Tolerance<float>::def_epsilon = static_cast<float>(1e-4);
28
+ double Tolerance<double>::def_epsilon = 1e-10;
29
+ long double Tolerance<long double>::def_epsilon = 1e-14;
30
+
31
+ #ifndef LEMON_ONLY_TEMPLATES
32
+ const Invalid INVALID = Invalid();
33
+ #endif
34
+
35
+ TimeStamp::Format TimeStamp::_format = TimeStamp::NORMAL;
36
+
37
+ } //namespace lemon