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.
- checksums.yaml +7 -0
- data/.yardopts +8 -0
- data/LICENSE +674 -0
- data/README.md +6 -0
- data/ext/lemon-1.3.1/AUTHORS +26 -0
- data/ext/lemon-1.3.1/CMakeLists.txt +371 -0
- data/ext/lemon-1.3.1/INSTALL +167 -0
- data/ext/lemon-1.3.1/LICENSE +32 -0
- data/ext/lemon-1.3.1/NEWS +337 -0
- data/ext/lemon-1.3.1/README +50 -0
- data/ext/lemon-1.3.1/cmake/FindCOIN.cmake +110 -0
- data/ext/lemon-1.3.1/cmake/FindGLPK.cmake +55 -0
- data/ext/lemon-1.3.1/cmake/FindGhostscript.cmake +10 -0
- data/ext/lemon-1.3.1/cmake/FindILOG.cmake +102 -0
- data/ext/lemon-1.3.1/cmake/FindSOPLEX.cmake +23 -0
- data/ext/lemon-1.3.1/cmake/LEMONConfig.cmake.in +13 -0
- data/ext/lemon-1.3.1/cmake/nsis/lemon.ico +0 -0
- data/ext/lemon-1.3.1/cmake/nsis/uninstall.ico +0 -0
- data/ext/lemon-1.3.1/cmake/version.cmake +1 -0
- data/ext/lemon-1.3.1/cmake/version.cmake.in +1 -0
- data/ext/lemon-1.3.1/contrib/CMakeLists.txt +19 -0
- data/ext/lemon-1.3.1/lemon/CMakeLists.txt +91 -0
- data/ext/lemon-1.3.1/lemon/adaptors.h +3638 -0
- data/ext/lemon-1.3.1/lemon/arg_parser.cc +474 -0
- data/ext/lemon-1.3.1/lemon/arg_parser.h +440 -0
- data/ext/lemon-1.3.1/lemon/assert.h +214 -0
- data/ext/lemon-1.3.1/lemon/base.cc +37 -0
- data/ext/lemon-1.3.1/lemon/bellman_ford.h +1116 -0
- data/ext/lemon-1.3.1/lemon/bfs.h +1754 -0
- data/ext/lemon-1.3.1/lemon/bin_heap.h +347 -0
- data/ext/lemon-1.3.1/lemon/binomial_heap.h +445 -0
- data/ext/lemon-1.3.1/lemon/bits/alteration_notifier.h +472 -0
- data/ext/lemon-1.3.1/lemon/bits/array_map.h +351 -0
- data/ext/lemon-1.3.1/lemon/bits/bezier.h +174 -0
- data/ext/lemon-1.3.1/lemon/bits/default_map.h +182 -0
- data/ext/lemon-1.3.1/lemon/bits/edge_set_extender.h +627 -0
- data/ext/lemon-1.3.1/lemon/bits/enable_if.h +131 -0
- data/ext/lemon-1.3.1/lemon/bits/graph_adaptor_extender.h +401 -0
- data/ext/lemon-1.3.1/lemon/bits/graph_extender.h +1332 -0
- data/ext/lemon-1.3.1/lemon/bits/lock.h +65 -0
- data/ext/lemon-1.3.1/lemon/bits/map_extender.h +332 -0
- data/ext/lemon-1.3.1/lemon/bits/path_dump.h +177 -0
- data/ext/lemon-1.3.1/lemon/bits/solver_bits.h +194 -0
- data/ext/lemon-1.3.1/lemon/bits/traits.h +388 -0
- data/ext/lemon-1.3.1/lemon/bits/variant.h +494 -0
- data/ext/lemon-1.3.1/lemon/bits/vector_map.h +244 -0
- data/ext/lemon-1.3.1/lemon/bits/windows.cc +166 -0
- data/ext/lemon-1.3.1/lemon/bits/windows.h +44 -0
- data/ext/lemon-1.3.1/lemon/bucket_heap.h +594 -0
- data/ext/lemon-1.3.1/lemon/capacity_scaling.h +1014 -0
- data/ext/lemon-1.3.1/lemon/cbc.cc +460 -0
- data/ext/lemon-1.3.1/lemon/cbc.h +129 -0
- data/ext/lemon-1.3.1/lemon/christofides_tsp.h +254 -0
- data/ext/lemon-1.3.1/lemon/circulation.h +807 -0
- data/ext/lemon-1.3.1/lemon/clp.cc +464 -0
- data/ext/lemon-1.3.1/lemon/clp.h +164 -0
- data/ext/lemon-1.3.1/lemon/color.cc +44 -0
- data/ext/lemon-1.3.1/lemon/color.h +204 -0
- data/ext/lemon-1.3.1/lemon/concept_check.h +77 -0
- data/ext/lemon-1.3.1/lemon/concepts/bpgraph.h +1029 -0
- data/ext/lemon-1.3.1/lemon/concepts/digraph.h +491 -0
- data/ext/lemon-1.3.1/lemon/concepts/graph.h +788 -0
- data/ext/lemon-1.3.1/lemon/concepts/graph_components.h +2134 -0
- data/ext/lemon-1.3.1/lemon/concepts/heap.h +324 -0
- data/ext/lemon-1.3.1/lemon/concepts/maps.h +223 -0
- data/ext/lemon-1.3.1/lemon/concepts/path.h +312 -0
- data/ext/lemon-1.3.1/lemon/config.h.in +22 -0
- data/ext/lemon-1.3.1/lemon/connectivity.h +1688 -0
- data/ext/lemon-1.3.1/lemon/core.h +2506 -0
- data/ext/lemon-1.3.1/lemon/cost_scaling.h +1607 -0
- data/ext/lemon-1.3.1/lemon/counter.h +249 -0
- data/ext/lemon-1.3.1/lemon/cplex.cc +994 -0
- data/ext/lemon-1.3.1/lemon/cplex.h +292 -0
- data/ext/lemon-1.3.1/lemon/cycle_canceling.h +1230 -0
- data/ext/lemon-1.3.1/lemon/dfs.h +1637 -0
- data/ext/lemon-1.3.1/lemon/dheap.h +352 -0
- data/ext/lemon-1.3.1/lemon/dijkstra.h +1303 -0
- data/ext/lemon-1.3.1/lemon/dim2.h +726 -0
- data/ext/lemon-1.3.1/lemon/dimacs.h +448 -0
- data/ext/lemon-1.3.1/lemon/edge_set.h +1420 -0
- data/ext/lemon-1.3.1/lemon/edmonds_karp.h +556 -0
- data/ext/lemon-1.3.1/lemon/elevator.h +982 -0
- data/ext/lemon-1.3.1/lemon/error.h +276 -0
- data/ext/lemon-1.3.1/lemon/euler.h +287 -0
- data/ext/lemon-1.3.1/lemon/fib_heap.h +475 -0
- data/ext/lemon-1.3.1/lemon/fractional_matching.h +2139 -0
- data/ext/lemon-1.3.1/lemon/full_graph.h +1082 -0
- data/ext/lemon-1.3.1/lemon/glpk.cc +1012 -0
- data/ext/lemon-1.3.1/lemon/glpk.h +263 -0
- data/ext/lemon-1.3.1/lemon/gomory_hu.h +568 -0
- data/ext/lemon-1.3.1/lemon/graph_to_eps.h +1186 -0
- data/ext/lemon-1.3.1/lemon/greedy_tsp.h +251 -0
- data/ext/lemon-1.3.1/lemon/grid_graph.h +699 -0
- data/ext/lemon-1.3.1/lemon/grosso_locatelli_pullan_mc.h +840 -0
- data/ext/lemon-1.3.1/lemon/hao_orlin.h +1015 -0
- data/ext/lemon-1.3.1/lemon/hartmann_orlin_mmc.h +654 -0
- data/ext/lemon-1.3.1/lemon/howard_mmc.h +651 -0
- data/ext/lemon-1.3.1/lemon/hypercube_graph.h +459 -0
- data/ext/lemon-1.3.1/lemon/insertion_tsp.h +533 -0
- data/ext/lemon-1.3.1/lemon/karp_mmc.h +590 -0
- data/ext/lemon-1.3.1/lemon/kruskal.h +324 -0
- data/ext/lemon-1.3.1/lemon/lemon.pc.in +10 -0
- data/ext/lemon-1.3.1/lemon/lgf_reader.h +3854 -0
- data/ext/lemon-1.3.1/lemon/lgf_writer.h +2687 -0
- data/ext/lemon-1.3.1/lemon/list_graph.h +2510 -0
- data/ext/lemon-1.3.1/lemon/lp.h +95 -0
- data/ext/lemon-1.3.1/lemon/lp_base.cc +30 -0
- data/ext/lemon-1.3.1/lemon/lp_base.h +2147 -0
- data/ext/lemon-1.3.1/lemon/lp_skeleton.cc +143 -0
- data/ext/lemon-1.3.1/lemon/lp_skeleton.h +234 -0
- data/ext/lemon-1.3.1/lemon/maps.h +4057 -0
- data/ext/lemon-1.3.1/lemon/matching.h +3505 -0
- data/ext/lemon-1.3.1/lemon/math.h +77 -0
- data/ext/lemon-1.3.1/lemon/max_cardinality_search.h +794 -0
- data/ext/lemon-1.3.1/lemon/min_cost_arborescence.h +808 -0
- data/ext/lemon-1.3.1/lemon/nagamochi_ibaraki.h +702 -0
- data/ext/lemon-1.3.1/lemon/nauty_reader.h +113 -0
- data/ext/lemon-1.3.1/lemon/nearest_neighbor_tsp.h +238 -0
- data/ext/lemon-1.3.1/lemon/network_simplex.h +1659 -0
- data/ext/lemon-1.3.1/lemon/opt2_tsp.h +367 -0
- data/ext/lemon-1.3.1/lemon/pairing_heap.h +474 -0
- data/ext/lemon-1.3.1/lemon/path.h +1164 -0
- data/ext/lemon-1.3.1/lemon/planarity.h +2754 -0
- data/ext/lemon-1.3.1/lemon/preflow.h +985 -0
- data/ext/lemon-1.3.1/lemon/quad_heap.h +343 -0
- data/ext/lemon-1.3.1/lemon/radix_heap.h +438 -0
- data/ext/lemon-1.3.1/lemon/radix_sort.h +487 -0
- data/ext/lemon-1.3.1/lemon/random.cc +29 -0
- data/ext/lemon-1.3.1/lemon/random.h +1005 -0
- data/ext/lemon-1.3.1/lemon/smart_graph.h +1344 -0
- data/ext/lemon-1.3.1/lemon/soplex.cc +465 -0
- data/ext/lemon-1.3.1/lemon/soplex.h +158 -0
- data/ext/lemon-1.3.1/lemon/static_graph.h +476 -0
- data/ext/lemon-1.3.1/lemon/suurballe.h +776 -0
- data/ext/lemon-1.3.1/lemon/time_measure.h +610 -0
- data/ext/lemon-1.3.1/lemon/tolerance.h +242 -0
- data/ext/lemon-1.3.1/lemon/unionfind.h +1824 -0
- data/ext/lemon-1.3.1/scripts/unify-sources.sh +390 -0
- data/ext/lemon-1.3.1/scripts/valgrind-wrapper.sh +22 -0
- data/ext/lemongraph/arc_map.cc +1007 -0
- data/ext/lemongraph/digraph.cc +282 -0
- data/ext/lemongraph/digraph_arc.cc +153 -0
- data/ext/lemongraph/digraph_node.cc +277 -0
- data/ext/lemongraph/edge_map.cc +770 -0
- data/ext/lemongraph/extconf.rb +53 -0
- data/ext/lemongraph/graph.cc +351 -0
- data/ext/lemongraph/graph_arc.cc +95 -0
- data/ext/lemongraph/graph_edge.cc +153 -0
- data/ext/lemongraph/graph_item.cc +76 -0
- data/ext/lemongraph/graph_node.cc +321 -0
- data/ext/lemongraph/lemongraph.cc +260 -0
- data/ext/lemongraph/lemongraph.hh +295 -0
- data/ext/lemongraph/lemongraph.map +6 -0
- data/ext/lemongraph/lemongraph_export.hh +31 -0
- data/ext/lemongraph/node_map.cc +1011 -0
- data/lemongraph.gemspec +176 -0
- data/lib/lemongraph/graphviz.rb +240 -0
- data/lib/lemongraph/version.rb +4 -0
- data/lib/lemongraph.rb +21 -0
- data/samples/lemondeps.rb +38 -0
- metadata +202 -0
|
@@ -0,0 +1,244 @@
|
|
|
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-2009
|
|
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_BITS_VECTOR_MAP_H
|
|
20
|
+
#define LEMON_BITS_VECTOR_MAP_H
|
|
21
|
+
|
|
22
|
+
#include <vector>
|
|
23
|
+
#include <algorithm>
|
|
24
|
+
|
|
25
|
+
#include <lemon/core.h>
|
|
26
|
+
#include <lemon/bits/alteration_notifier.h>
|
|
27
|
+
|
|
28
|
+
#include <lemon/concept_check.h>
|
|
29
|
+
#include <lemon/concepts/maps.h>
|
|
30
|
+
|
|
31
|
+
//\ingroup graphbits
|
|
32
|
+
//
|
|
33
|
+
//\file
|
|
34
|
+
//\brief Vector based graph maps.
|
|
35
|
+
namespace lemon {
|
|
36
|
+
|
|
37
|
+
// \ingroup graphbits
|
|
38
|
+
//
|
|
39
|
+
// \brief Graph map based on the std::vector storage.
|
|
40
|
+
//
|
|
41
|
+
// The VectorMap template class is graph map structure that automatically
|
|
42
|
+
// updates the map when a key is added to or erased from the graph.
|
|
43
|
+
// This map type uses std::vector to store the values.
|
|
44
|
+
//
|
|
45
|
+
// \tparam _Graph The graph this map is attached to.
|
|
46
|
+
// \tparam _Item The item type of the graph items.
|
|
47
|
+
// \tparam _Value The value type of the map.
|
|
48
|
+
template <typename _Graph, typename _Item, typename _Value>
|
|
49
|
+
class VectorMap
|
|
50
|
+
: public ItemSetTraits<_Graph, _Item>::ItemNotifier::ObserverBase {
|
|
51
|
+
private:
|
|
52
|
+
|
|
53
|
+
// The container type of the map.
|
|
54
|
+
typedef std::vector<_Value> Container;
|
|
55
|
+
|
|
56
|
+
public:
|
|
57
|
+
|
|
58
|
+
// The graph type of the map.
|
|
59
|
+
typedef _Graph GraphType;
|
|
60
|
+
// The item type of the map.
|
|
61
|
+
typedef _Item Item;
|
|
62
|
+
// The reference map tag.
|
|
63
|
+
typedef True ReferenceMapTag;
|
|
64
|
+
|
|
65
|
+
// The key type of the map.
|
|
66
|
+
typedef _Item Key;
|
|
67
|
+
// The value type of the map.
|
|
68
|
+
typedef _Value Value;
|
|
69
|
+
|
|
70
|
+
// The notifier type.
|
|
71
|
+
typedef typename ItemSetTraits<_Graph, _Item>::ItemNotifier Notifier;
|
|
72
|
+
|
|
73
|
+
// The map type.
|
|
74
|
+
typedef VectorMap Map;
|
|
75
|
+
|
|
76
|
+
// The reference type of the map;
|
|
77
|
+
typedef typename Container::reference Reference;
|
|
78
|
+
// The const reference type of the map;
|
|
79
|
+
typedef typename Container::const_reference ConstReference;
|
|
80
|
+
|
|
81
|
+
private:
|
|
82
|
+
|
|
83
|
+
// The base class of the map.
|
|
84
|
+
typedef typename Notifier::ObserverBase Parent;
|
|
85
|
+
|
|
86
|
+
public:
|
|
87
|
+
|
|
88
|
+
// \brief Constructor to attach the new map into the notifier.
|
|
89
|
+
//
|
|
90
|
+
// It constructs a map and attachs it into the notifier.
|
|
91
|
+
// It adds all the items of the graph to the map.
|
|
92
|
+
VectorMap(const GraphType& graph) {
|
|
93
|
+
Parent::attach(graph.notifier(Item()));
|
|
94
|
+
container.resize(Parent::notifier()->maxId() + 1);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// \brief Constructor uses given value to initialize the map.
|
|
98
|
+
//
|
|
99
|
+
// It constructs a map uses a given value to initialize the map.
|
|
100
|
+
// It adds all the items of the graph to the map.
|
|
101
|
+
VectorMap(const GraphType& graph, const Value& value) {
|
|
102
|
+
Parent::attach(graph.notifier(Item()));
|
|
103
|
+
container.resize(Parent::notifier()->maxId() + 1, value);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
private:
|
|
107
|
+
// \brief Copy constructor
|
|
108
|
+
//
|
|
109
|
+
// Copy constructor.
|
|
110
|
+
VectorMap(const VectorMap& _copy) : Parent() {
|
|
111
|
+
if (_copy.attached()) {
|
|
112
|
+
Parent::attach(*_copy.notifier());
|
|
113
|
+
container = _copy.container;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// \brief Assign operator.
|
|
118
|
+
//
|
|
119
|
+
// This operator assigns for each item in the map the
|
|
120
|
+
// value mapped to the same item in the copied map.
|
|
121
|
+
// The parameter map should be indiced with the same
|
|
122
|
+
// itemset because this assign operator does not change
|
|
123
|
+
// the container of the map.
|
|
124
|
+
VectorMap& operator=(const VectorMap& cmap) {
|
|
125
|
+
return operator=<VectorMap>(cmap);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
// \brief Template assign operator.
|
|
130
|
+
//
|
|
131
|
+
// The given parameter should conform to the ReadMap
|
|
132
|
+
// concecpt and could be indiced by the current item set of
|
|
133
|
+
// the NodeMap. In this case the value for each item
|
|
134
|
+
// is assigned by the value of the given ReadMap.
|
|
135
|
+
template <typename CMap>
|
|
136
|
+
VectorMap& operator=(const CMap& cmap) {
|
|
137
|
+
checkConcept<concepts::ReadMap<Key, _Value>, CMap>();
|
|
138
|
+
const typename Parent::Notifier* nf = Parent::notifier();
|
|
139
|
+
Item it;
|
|
140
|
+
for (nf->first(it); it != INVALID; nf->next(it)) {
|
|
141
|
+
set(it, cmap[it]);
|
|
142
|
+
}
|
|
143
|
+
return *this;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
public:
|
|
147
|
+
|
|
148
|
+
// \brief The subcript operator.
|
|
149
|
+
//
|
|
150
|
+
// The subscript operator. The map can be subscripted by the
|
|
151
|
+
// actual items of the graph.
|
|
152
|
+
Reference operator[](const Key& key) {
|
|
153
|
+
return container[Parent::notifier()->id(key)];
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// \brief The const subcript operator.
|
|
157
|
+
//
|
|
158
|
+
// The const subscript operator. The map can be subscripted by the
|
|
159
|
+
// actual items of the graph.
|
|
160
|
+
ConstReference operator[](const Key& key) const {
|
|
161
|
+
return container[Parent::notifier()->id(key)];
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
// \brief The setter function of the map.
|
|
166
|
+
//
|
|
167
|
+
// It the same as operator[](key) = value expression.
|
|
168
|
+
void set(const Key& key, const Value& value) {
|
|
169
|
+
(*this)[key] = value;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
protected:
|
|
173
|
+
|
|
174
|
+
// \brief Adds a new key to the map.
|
|
175
|
+
//
|
|
176
|
+
// It adds a new key to the map. It is called by the observer notifier
|
|
177
|
+
// and it overrides the add() member function of the observer base.
|
|
178
|
+
virtual void add(const Key& key) {
|
|
179
|
+
int id = Parent::notifier()->id(key);
|
|
180
|
+
if (id >= int(container.size())) {
|
|
181
|
+
container.resize(id + 1);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
// \brief Adds more new keys to the map.
|
|
186
|
+
//
|
|
187
|
+
// It adds more new keys to the map. It is called by the observer notifier
|
|
188
|
+
// and it overrides the add() member function of the observer base.
|
|
189
|
+
virtual void add(const std::vector<Key>& keys) {
|
|
190
|
+
int max = container.size() - 1;
|
|
191
|
+
for (int i = 0; i < int(keys.size()); ++i) {
|
|
192
|
+
int id = Parent::notifier()->id(keys[i]);
|
|
193
|
+
if (id >= max) {
|
|
194
|
+
max = id;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
container.resize(max + 1);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
// \brief Erase a key from the map.
|
|
201
|
+
//
|
|
202
|
+
// Erase a key from the map. It is called by the observer notifier
|
|
203
|
+
// and it overrides the erase() member function of the observer base.
|
|
204
|
+
virtual void erase(const Key& key) {
|
|
205
|
+
container[Parent::notifier()->id(key)] = Value();
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
// \brief Erase more keys from the map.
|
|
209
|
+
//
|
|
210
|
+
// It erases more keys from the map. It is called by the observer notifier
|
|
211
|
+
// and it overrides the erase() member function of the observer base.
|
|
212
|
+
virtual void erase(const std::vector<Key>& keys) {
|
|
213
|
+
for (int i = 0; i < int(keys.size()); ++i) {
|
|
214
|
+
container[Parent::notifier()->id(keys[i])] = Value();
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
// \brief Build the map.
|
|
219
|
+
//
|
|
220
|
+
// It builds the map. It is called by the observer notifier
|
|
221
|
+
// and it overrides the build() member function of the observer base.
|
|
222
|
+
virtual void build() {
|
|
223
|
+
int size = Parent::notifier()->maxId() + 1;
|
|
224
|
+
container.reserve(size);
|
|
225
|
+
container.resize(size);
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
// \brief Clear the map.
|
|
229
|
+
//
|
|
230
|
+
// It erases all items from the map. It is called by the observer notifier
|
|
231
|
+
// and it overrides the clear() member function of the observer base.
|
|
232
|
+
virtual void clear() {
|
|
233
|
+
container.clear();
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
private:
|
|
237
|
+
|
|
238
|
+
Container container;
|
|
239
|
+
|
|
240
|
+
};
|
|
241
|
+
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
#endif
|
|
@@ -0,0 +1,166 @@
|
|
|
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/bits/windows.h>
|
|
23
|
+
|
|
24
|
+
#ifdef WIN32
|
|
25
|
+
#ifndef WIN32_LEAN_AND_MEAN
|
|
26
|
+
#define WIN32_LEAN_AND_MEAN
|
|
27
|
+
#endif
|
|
28
|
+
#ifndef NOMINMAX
|
|
29
|
+
#define NOMINMAX
|
|
30
|
+
#endif
|
|
31
|
+
#ifdef UNICODE
|
|
32
|
+
#undef UNICODE
|
|
33
|
+
#endif
|
|
34
|
+
#include <windows.h>
|
|
35
|
+
#ifdef LOCALE_INVARIANT
|
|
36
|
+
#define MY_LOCALE LOCALE_INVARIANT
|
|
37
|
+
#else
|
|
38
|
+
#define MY_LOCALE LOCALE_NEUTRAL
|
|
39
|
+
#endif
|
|
40
|
+
#else
|
|
41
|
+
#include <unistd.h>
|
|
42
|
+
#include <ctime>
|
|
43
|
+
#ifndef WIN32
|
|
44
|
+
#include <sys/times.h>
|
|
45
|
+
#endif
|
|
46
|
+
#include <sys/time.h>
|
|
47
|
+
#endif
|
|
48
|
+
|
|
49
|
+
#include <cmath>
|
|
50
|
+
#include <sstream>
|
|
51
|
+
|
|
52
|
+
namespace lemon {
|
|
53
|
+
namespace bits {
|
|
54
|
+
void getWinProcTimes(double &rtime,
|
|
55
|
+
double &utime, double &stime,
|
|
56
|
+
double &cutime, double &cstime)
|
|
57
|
+
{
|
|
58
|
+
#ifdef WIN32
|
|
59
|
+
static const double ch = 4294967296.0e-7;
|
|
60
|
+
static const double cl = 1.0e-7;
|
|
61
|
+
|
|
62
|
+
FILETIME system;
|
|
63
|
+
GetSystemTimeAsFileTime(&system);
|
|
64
|
+
rtime = ch * system.dwHighDateTime + cl * system.dwLowDateTime;
|
|
65
|
+
|
|
66
|
+
FILETIME create, exit, kernel, user;
|
|
67
|
+
if (GetProcessTimes(GetCurrentProcess(),&create, &exit, &kernel, &user)) {
|
|
68
|
+
utime = ch * user.dwHighDateTime + cl * user.dwLowDateTime;
|
|
69
|
+
stime = ch * kernel.dwHighDateTime + cl * kernel.dwLowDateTime;
|
|
70
|
+
cutime = 0;
|
|
71
|
+
cstime = 0;
|
|
72
|
+
} else {
|
|
73
|
+
rtime = 0;
|
|
74
|
+
utime = 0;
|
|
75
|
+
stime = 0;
|
|
76
|
+
cutime = 0;
|
|
77
|
+
cstime = 0;
|
|
78
|
+
}
|
|
79
|
+
#else
|
|
80
|
+
timeval tv;
|
|
81
|
+
gettimeofday(&tv, 0);
|
|
82
|
+
rtime=tv.tv_sec+double(tv.tv_usec)/1e6;
|
|
83
|
+
|
|
84
|
+
tms ts;
|
|
85
|
+
double tck=sysconf(_SC_CLK_TCK);
|
|
86
|
+
times(&ts);
|
|
87
|
+
utime=ts.tms_utime/tck;
|
|
88
|
+
stime=ts.tms_stime/tck;
|
|
89
|
+
cutime=ts.tms_cutime/tck;
|
|
90
|
+
cstime=ts.tms_cstime/tck;
|
|
91
|
+
#endif
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
std::string getWinFormattedDate()
|
|
95
|
+
{
|
|
96
|
+
std::ostringstream os;
|
|
97
|
+
#ifdef WIN32
|
|
98
|
+
SYSTEMTIME time;
|
|
99
|
+
GetSystemTime(&time);
|
|
100
|
+
char buf1[11], buf2[9], buf3[5];
|
|
101
|
+
if (GetDateFormat(MY_LOCALE, 0, &time,
|
|
102
|
+
("ddd MMM dd"), buf1, 11) &&
|
|
103
|
+
GetTimeFormat(MY_LOCALE, 0, &time,
|
|
104
|
+
("HH':'mm':'ss"), buf2, 9) &&
|
|
105
|
+
GetDateFormat(MY_LOCALE, 0, &time,
|
|
106
|
+
("yyyy"), buf3, 5)) {
|
|
107
|
+
os << buf1 << ' ' << buf2 << ' ' << buf3;
|
|
108
|
+
}
|
|
109
|
+
else os << "unknown";
|
|
110
|
+
#else
|
|
111
|
+
timeval tv;
|
|
112
|
+
gettimeofday(&tv, 0);
|
|
113
|
+
|
|
114
|
+
char cbuf[26];
|
|
115
|
+
ctime_r(&tv.tv_sec,cbuf);
|
|
116
|
+
os << cbuf;
|
|
117
|
+
#endif
|
|
118
|
+
return os.str();
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
int getWinRndSeed()
|
|
122
|
+
{
|
|
123
|
+
#ifdef WIN32
|
|
124
|
+
FILETIME time;
|
|
125
|
+
GetSystemTimeAsFileTime(&time);
|
|
126
|
+
return GetCurrentProcessId() + time.dwHighDateTime + time.dwLowDateTime;
|
|
127
|
+
#else
|
|
128
|
+
timeval tv;
|
|
129
|
+
gettimeofday(&tv, 0);
|
|
130
|
+
return getpid() + tv.tv_sec + tv.tv_usec;
|
|
131
|
+
#endif
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
WinLock::WinLock() {
|
|
135
|
+
#ifdef WIN32
|
|
136
|
+
CRITICAL_SECTION *lock = new CRITICAL_SECTION;
|
|
137
|
+
InitializeCriticalSection(lock);
|
|
138
|
+
_repr = lock;
|
|
139
|
+
#else
|
|
140
|
+
_repr = 0; //Just to avoid 'unused variable' warning with clang
|
|
141
|
+
#endif
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
WinLock::~WinLock() {
|
|
145
|
+
#ifdef WIN32
|
|
146
|
+
CRITICAL_SECTION *lock = static_cast<CRITICAL_SECTION*>(_repr);
|
|
147
|
+
DeleteCriticalSection(lock);
|
|
148
|
+
delete lock;
|
|
149
|
+
#endif
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
void WinLock::lock() {
|
|
153
|
+
#ifdef WIN32
|
|
154
|
+
CRITICAL_SECTION *lock = static_cast<CRITICAL_SECTION*>(_repr);
|
|
155
|
+
EnterCriticalSection(lock);
|
|
156
|
+
#endif
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
void WinLock::unlock() {
|
|
160
|
+
#ifdef WIN32
|
|
161
|
+
CRITICAL_SECTION *lock = static_cast<CRITICAL_SECTION*>(_repr);
|
|
162
|
+
LeaveCriticalSection(lock);
|
|
163
|
+
#endif
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
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_BITS_WINDOWS_H
|
|
20
|
+
#define LEMON_BITS_WINDOWS_H
|
|
21
|
+
|
|
22
|
+
#include <string>
|
|
23
|
+
|
|
24
|
+
namespace lemon {
|
|
25
|
+
namespace bits {
|
|
26
|
+
void getWinProcTimes(double &rtime,
|
|
27
|
+
double &utime, double &stime,
|
|
28
|
+
double &cutime, double &cstime);
|
|
29
|
+
std::string getWinFormattedDate();
|
|
30
|
+
int getWinRndSeed();
|
|
31
|
+
|
|
32
|
+
class WinLock {
|
|
33
|
+
public:
|
|
34
|
+
WinLock();
|
|
35
|
+
~WinLock();
|
|
36
|
+
void lock();
|
|
37
|
+
void unlock();
|
|
38
|
+
private:
|
|
39
|
+
void *_repr;
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
#endif
|