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,460 @@
|
|
|
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 Implementation of the CBC MIP solver interface.
|
|
21
|
+
|
|
22
|
+
#include "cbc.h"
|
|
23
|
+
|
|
24
|
+
#include <coin/CoinModel.hpp>
|
|
25
|
+
#include <coin/CbcModel.hpp>
|
|
26
|
+
#include <coin/OsiSolverInterface.hpp>
|
|
27
|
+
|
|
28
|
+
#include "coin/OsiClpSolverInterface.hpp"
|
|
29
|
+
|
|
30
|
+
#include "coin/CbcCutGenerator.hpp"
|
|
31
|
+
#include "coin/CbcHeuristicLocal.hpp"
|
|
32
|
+
#include "coin/CbcHeuristicGreedy.hpp"
|
|
33
|
+
#include "coin/CbcHeuristicFPump.hpp"
|
|
34
|
+
#include "coin/CbcHeuristicRINS.hpp"
|
|
35
|
+
|
|
36
|
+
#include "coin/CglGomory.hpp"
|
|
37
|
+
#include "coin/CglProbing.hpp"
|
|
38
|
+
#include "coin/CglKnapsackCover.hpp"
|
|
39
|
+
#include "coin/CglOddHole.hpp"
|
|
40
|
+
#include "coin/CglClique.hpp"
|
|
41
|
+
#include "coin/CglFlowCover.hpp"
|
|
42
|
+
#include "coin/CglMixedIntegerRounding.hpp"
|
|
43
|
+
|
|
44
|
+
#include "coin/CbcHeuristic.hpp"
|
|
45
|
+
|
|
46
|
+
namespace lemon {
|
|
47
|
+
|
|
48
|
+
CbcMip::CbcMip() {
|
|
49
|
+
_prob = new CoinModel();
|
|
50
|
+
_prob->setProblemName("LEMON");
|
|
51
|
+
_osi_solver = 0;
|
|
52
|
+
_cbc_model = 0;
|
|
53
|
+
messageLevel(MESSAGE_NOTHING);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
CbcMip::CbcMip(const CbcMip& other) {
|
|
57
|
+
_prob = new CoinModel(*other._prob);
|
|
58
|
+
_prob->setProblemName("LEMON");
|
|
59
|
+
_osi_solver = 0;
|
|
60
|
+
_cbc_model = 0;
|
|
61
|
+
messageLevel(MESSAGE_NOTHING);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
CbcMip::~CbcMip() {
|
|
65
|
+
delete _prob;
|
|
66
|
+
if (_osi_solver) delete _osi_solver;
|
|
67
|
+
if (_cbc_model) delete _cbc_model;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const char* CbcMip::_solverName() const { return "CbcMip"; }
|
|
71
|
+
|
|
72
|
+
int CbcMip::_addCol() {
|
|
73
|
+
_prob->addColumn(0, 0, 0, -COIN_DBL_MAX, COIN_DBL_MAX, 0.0, 0, false);
|
|
74
|
+
return _prob->numberColumns() - 1;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
CbcMip* CbcMip::newSolver() const {
|
|
78
|
+
CbcMip* newlp = new CbcMip;
|
|
79
|
+
return newlp;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
CbcMip* CbcMip::cloneSolver() const {
|
|
83
|
+
CbcMip* copylp = new CbcMip(*this);
|
|
84
|
+
return copylp;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
int CbcMip::_addRow() {
|
|
88
|
+
_prob->addRow(0, 0, 0, -COIN_DBL_MAX, COIN_DBL_MAX);
|
|
89
|
+
return _prob->numberRows() - 1;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
int CbcMip::_addRow(Value l, ExprIterator b, ExprIterator e, Value u) {
|
|
93
|
+
std::vector<int> indexes;
|
|
94
|
+
std::vector<Value> values;
|
|
95
|
+
|
|
96
|
+
for(ExprIterator it = b; it != e; ++it) {
|
|
97
|
+
indexes.push_back(it->first);
|
|
98
|
+
values.push_back(it->second);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
_prob->addRow(values.size(), &indexes.front(), &values.front(), l, u);
|
|
102
|
+
return _prob->numberRows() - 1;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
void CbcMip::_eraseCol(int i) {
|
|
106
|
+
_prob->deleteColumn(i);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
void CbcMip::_eraseRow(int i) {
|
|
110
|
+
_prob->deleteRow(i);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
void CbcMip::_eraseColId(int i) {
|
|
114
|
+
cols.eraseIndex(i);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
void CbcMip::_eraseRowId(int i) {
|
|
118
|
+
rows.eraseIndex(i);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
void CbcMip::_getColName(int c, std::string& name) const {
|
|
122
|
+
name = _prob->getColumnName(c);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
void CbcMip::_setColName(int c, const std::string& name) {
|
|
126
|
+
_prob->setColumnName(c, name.c_str());
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
int CbcMip::_colByName(const std::string& name) const {
|
|
130
|
+
return _prob->column(name.c_str());
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
void CbcMip::_getRowName(int r, std::string& name) const {
|
|
134
|
+
name = _prob->getRowName(r);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
void CbcMip::_setRowName(int r, const std::string& name) {
|
|
138
|
+
_prob->setRowName(r, name.c_str());
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
int CbcMip::_rowByName(const std::string& name) const {
|
|
142
|
+
return _prob->row(name.c_str());
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
void CbcMip::_setRowCoeffs(int i, ExprIterator b, ExprIterator e) {
|
|
146
|
+
for (ExprIterator it = b; it != e; ++it) {
|
|
147
|
+
_prob->setElement(i, it->first, it->second);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
void CbcMip::_getRowCoeffs(int ix, InsertIterator b) const {
|
|
152
|
+
int length = _prob->numberRows();
|
|
153
|
+
|
|
154
|
+
std::vector<int> indices(length);
|
|
155
|
+
std::vector<Value> values(length);
|
|
156
|
+
|
|
157
|
+
length = _prob->getRow(ix, &indices[0], &values[0]);
|
|
158
|
+
|
|
159
|
+
for (int i = 0; i < length; ++i) {
|
|
160
|
+
*b = std::make_pair(indices[i], values[i]);
|
|
161
|
+
++b;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
void CbcMip::_setColCoeffs(int ix, ExprIterator b, ExprIterator e) {
|
|
166
|
+
for (ExprIterator it = b; it != e; ++it) {
|
|
167
|
+
_prob->setElement(it->first, ix, it->second);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
void CbcMip::_getColCoeffs(int ix, InsertIterator b) const {
|
|
172
|
+
int length = _prob->numberColumns();
|
|
173
|
+
|
|
174
|
+
std::vector<int> indices(length);
|
|
175
|
+
std::vector<Value> values(length);
|
|
176
|
+
|
|
177
|
+
length = _prob->getColumn(ix, &indices[0], &values[0]);
|
|
178
|
+
|
|
179
|
+
for (int i = 0; i < length; ++i) {
|
|
180
|
+
*b = std::make_pair(indices[i], values[i]);
|
|
181
|
+
++b;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
void CbcMip::_setCoeff(int ix, int jx, Value value) {
|
|
186
|
+
_prob->setElement(ix, jx, value);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
CbcMip::Value CbcMip::_getCoeff(int ix, int jx) const {
|
|
190
|
+
return _prob->getElement(ix, jx);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
void CbcMip::_setColLowerBound(int i, Value lo) {
|
|
195
|
+
LEMON_ASSERT(lo != INF, "Invalid bound");
|
|
196
|
+
_prob->setColumnLower(i, lo == - INF ? - COIN_DBL_MAX : lo);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
CbcMip::Value CbcMip::_getColLowerBound(int i) const {
|
|
200
|
+
double val = _prob->getColumnLower(i);
|
|
201
|
+
return val == - COIN_DBL_MAX ? - INF : val;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
void CbcMip::_setColUpperBound(int i, Value up) {
|
|
205
|
+
LEMON_ASSERT(up != -INF, "Invalid bound");
|
|
206
|
+
_prob->setColumnUpper(i, up == INF ? COIN_DBL_MAX : up);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
CbcMip::Value CbcMip::_getColUpperBound(int i) const {
|
|
210
|
+
double val = _prob->getColumnUpper(i);
|
|
211
|
+
return val == COIN_DBL_MAX ? INF : val;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
void CbcMip::_setRowLowerBound(int i, Value lo) {
|
|
215
|
+
LEMON_ASSERT(lo != INF, "Invalid bound");
|
|
216
|
+
_prob->setRowLower(i, lo == - INF ? - COIN_DBL_MAX : lo);
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
CbcMip::Value CbcMip::_getRowLowerBound(int i) const {
|
|
220
|
+
double val = _prob->getRowLower(i);
|
|
221
|
+
return val == - COIN_DBL_MAX ? - INF : val;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
void CbcMip::_setRowUpperBound(int i, Value up) {
|
|
225
|
+
LEMON_ASSERT(up != -INF, "Invalid bound");
|
|
226
|
+
_prob->setRowUpper(i, up == INF ? COIN_DBL_MAX : up);
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
CbcMip::Value CbcMip::_getRowUpperBound(int i) const {
|
|
230
|
+
double val = _prob->getRowUpper(i);
|
|
231
|
+
return val == COIN_DBL_MAX ? INF : val;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
void CbcMip::_setObjCoeffs(ExprIterator b, ExprIterator e) {
|
|
235
|
+
int num = _prob->numberColumns();
|
|
236
|
+
for (int i = 0; i < num; ++i) {
|
|
237
|
+
_prob->setColumnObjective(i, 0.0);
|
|
238
|
+
}
|
|
239
|
+
for (ExprIterator it = b; it != e; ++it) {
|
|
240
|
+
_prob->setColumnObjective(it->first, it->second);
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
void CbcMip::_getObjCoeffs(InsertIterator b) const {
|
|
245
|
+
int num = _prob->numberColumns();
|
|
246
|
+
for (int i = 0; i < num; ++i) {
|
|
247
|
+
Value coef = _prob->getColumnObjective(i);
|
|
248
|
+
if (coef != 0.0) {
|
|
249
|
+
*b = std::make_pair(i, coef);
|
|
250
|
+
++b;
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
void CbcMip::_setObjCoeff(int i, Value obj_coef) {
|
|
256
|
+
_prob->setColumnObjective(i, obj_coef);
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
CbcMip::Value CbcMip::_getObjCoeff(int i) const {
|
|
260
|
+
return _prob->getColumnObjective(i);
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
CbcMip::SolveExitStatus CbcMip::_solve() {
|
|
264
|
+
|
|
265
|
+
if (_osi_solver) {
|
|
266
|
+
delete _osi_solver;
|
|
267
|
+
}
|
|
268
|
+
_osi_solver = new OsiClpSolverInterface();
|
|
269
|
+
|
|
270
|
+
_osi_solver->loadFromCoinModel(*_prob);
|
|
271
|
+
|
|
272
|
+
if (_cbc_model) {
|
|
273
|
+
delete _cbc_model;
|
|
274
|
+
}
|
|
275
|
+
_cbc_model= new CbcModel(*_osi_solver);
|
|
276
|
+
|
|
277
|
+
_osi_solver->messageHandler()->setLogLevel(_message_level);
|
|
278
|
+
_cbc_model->setLogLevel(_message_level);
|
|
279
|
+
|
|
280
|
+
_cbc_model->initialSolve();
|
|
281
|
+
_cbc_model->solver()->setHintParam(OsiDoReducePrint, true, OsiHintTry);
|
|
282
|
+
|
|
283
|
+
if (!_cbc_model->isInitialSolveAbandoned() &&
|
|
284
|
+
_cbc_model->isInitialSolveProvenOptimal() &&
|
|
285
|
+
!_cbc_model->isInitialSolveProvenPrimalInfeasible() &&
|
|
286
|
+
!_cbc_model->isInitialSolveProvenDualInfeasible()) {
|
|
287
|
+
|
|
288
|
+
CglProbing generator1;
|
|
289
|
+
generator1.setUsingObjective(true);
|
|
290
|
+
generator1.setMaxPass(3);
|
|
291
|
+
generator1.setMaxProbe(100);
|
|
292
|
+
generator1.setMaxLook(50);
|
|
293
|
+
generator1.setRowCuts(3);
|
|
294
|
+
_cbc_model->addCutGenerator(&generator1, -1, "Probing");
|
|
295
|
+
|
|
296
|
+
CglGomory generator2;
|
|
297
|
+
generator2.setLimit(300);
|
|
298
|
+
_cbc_model->addCutGenerator(&generator2, -1, "Gomory");
|
|
299
|
+
|
|
300
|
+
CglKnapsackCover generator3;
|
|
301
|
+
_cbc_model->addCutGenerator(&generator3, -1, "Knapsack");
|
|
302
|
+
|
|
303
|
+
CglOddHole generator4;
|
|
304
|
+
generator4.setMinimumViolation(0.005);
|
|
305
|
+
generator4.setMinimumViolationPer(0.00002);
|
|
306
|
+
generator4.setMaximumEntries(200);
|
|
307
|
+
_cbc_model->addCutGenerator(&generator4, -1, "OddHole");
|
|
308
|
+
|
|
309
|
+
CglClique generator5;
|
|
310
|
+
generator5.setStarCliqueReport(false);
|
|
311
|
+
generator5.setRowCliqueReport(false);
|
|
312
|
+
_cbc_model->addCutGenerator(&generator5, -1, "Clique");
|
|
313
|
+
|
|
314
|
+
CglMixedIntegerRounding mixedGen;
|
|
315
|
+
_cbc_model->addCutGenerator(&mixedGen, -1, "MixedIntegerRounding");
|
|
316
|
+
|
|
317
|
+
CglFlowCover flowGen;
|
|
318
|
+
_cbc_model->addCutGenerator(&flowGen, -1, "FlowCover");
|
|
319
|
+
|
|
320
|
+
OsiClpSolverInterface* osiclp =
|
|
321
|
+
dynamic_cast<OsiClpSolverInterface*>(_cbc_model->solver());
|
|
322
|
+
if (osiclp->getNumRows() < 300 && osiclp->getNumCols() < 500) {
|
|
323
|
+
osiclp->setupForRepeatedUse(2, 0);
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
CbcRounding heuristic1(*_cbc_model);
|
|
327
|
+
heuristic1.setWhen(3);
|
|
328
|
+
_cbc_model->addHeuristic(&heuristic1);
|
|
329
|
+
|
|
330
|
+
CbcHeuristicLocal heuristic2(*_cbc_model);
|
|
331
|
+
heuristic2.setWhen(3);
|
|
332
|
+
_cbc_model->addHeuristic(&heuristic2);
|
|
333
|
+
|
|
334
|
+
CbcHeuristicGreedyCover heuristic3(*_cbc_model);
|
|
335
|
+
heuristic3.setAlgorithm(11);
|
|
336
|
+
heuristic3.setWhen(3);
|
|
337
|
+
_cbc_model->addHeuristic(&heuristic3);
|
|
338
|
+
|
|
339
|
+
CbcHeuristicFPump heuristic4(*_cbc_model);
|
|
340
|
+
heuristic4.setWhen(3);
|
|
341
|
+
_cbc_model->addHeuristic(&heuristic4);
|
|
342
|
+
|
|
343
|
+
CbcHeuristicRINS heuristic5(*_cbc_model);
|
|
344
|
+
heuristic5.setWhen(3);
|
|
345
|
+
_cbc_model->addHeuristic(&heuristic5);
|
|
346
|
+
|
|
347
|
+
if (_cbc_model->getNumCols() < 500) {
|
|
348
|
+
_cbc_model->setMaximumCutPassesAtRoot(-100);
|
|
349
|
+
} else if (_cbc_model->getNumCols() < 5000) {
|
|
350
|
+
_cbc_model->setMaximumCutPassesAtRoot(100);
|
|
351
|
+
} else {
|
|
352
|
+
_cbc_model->setMaximumCutPassesAtRoot(20);
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
if (_cbc_model->getNumCols() < 5000) {
|
|
356
|
+
_cbc_model->setNumberStrong(10);
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
_cbc_model->solver()->setIntParam(OsiMaxNumIterationHotStart, 100);
|
|
360
|
+
_cbc_model->branchAndBound();
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
if (_cbc_model->isAbandoned()) {
|
|
364
|
+
return UNSOLVED;
|
|
365
|
+
} else {
|
|
366
|
+
return SOLVED;
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
CbcMip::Value CbcMip::_getSol(int i) const {
|
|
371
|
+
return _cbc_model->getColSolution()[i];
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
CbcMip::Value CbcMip::_getSolValue() const {
|
|
375
|
+
return _cbc_model->getObjValue();
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
CbcMip::ProblemType CbcMip::_getType() const {
|
|
379
|
+
if (_cbc_model->isProvenOptimal()) {
|
|
380
|
+
return OPTIMAL;
|
|
381
|
+
} else if (_cbc_model->isContinuousUnbounded()) {
|
|
382
|
+
return UNBOUNDED;
|
|
383
|
+
}
|
|
384
|
+
return FEASIBLE;
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
void CbcMip::_setSense(Sense sense) {
|
|
388
|
+
switch (sense) {
|
|
389
|
+
case MIN:
|
|
390
|
+
_prob->setOptimizationDirection(1.0);
|
|
391
|
+
break;
|
|
392
|
+
case MAX:
|
|
393
|
+
_prob->setOptimizationDirection(- 1.0);
|
|
394
|
+
break;
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
CbcMip::Sense CbcMip::_getSense() const {
|
|
399
|
+
if (_prob->optimizationDirection() > 0.0) {
|
|
400
|
+
return MIN;
|
|
401
|
+
} else if (_prob->optimizationDirection() < 0.0) {
|
|
402
|
+
return MAX;
|
|
403
|
+
} else {
|
|
404
|
+
LEMON_ASSERT(false, "Wrong sense");
|
|
405
|
+
return CbcMip::Sense();
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
void CbcMip::_setColType(int i, CbcMip::ColTypes col_type) {
|
|
410
|
+
switch (col_type){
|
|
411
|
+
case INTEGER:
|
|
412
|
+
_prob->setInteger(i);
|
|
413
|
+
break;
|
|
414
|
+
case REAL:
|
|
415
|
+
_prob->setContinuous(i);
|
|
416
|
+
break;
|
|
417
|
+
default:;
|
|
418
|
+
LEMON_ASSERT(false, "Wrong sense");
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
CbcMip::ColTypes CbcMip::_getColType(int i) const {
|
|
423
|
+
return _prob->getColumnIsInteger(i) ? INTEGER : REAL;
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
void CbcMip::_clear() {
|
|
427
|
+
delete _prob;
|
|
428
|
+
if (_osi_solver) {
|
|
429
|
+
delete _osi_solver;
|
|
430
|
+
_osi_solver = 0;
|
|
431
|
+
}
|
|
432
|
+
if (_cbc_model) {
|
|
433
|
+
delete _cbc_model;
|
|
434
|
+
_cbc_model = 0;
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
_prob = new CoinModel();
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
void CbcMip::_messageLevel(MessageLevel level) {
|
|
441
|
+
switch (level) {
|
|
442
|
+
case MESSAGE_NOTHING:
|
|
443
|
+
_message_level = 0;
|
|
444
|
+
break;
|
|
445
|
+
case MESSAGE_ERROR:
|
|
446
|
+
_message_level = 1;
|
|
447
|
+
break;
|
|
448
|
+
case MESSAGE_WARNING:
|
|
449
|
+
_message_level = 1;
|
|
450
|
+
break;
|
|
451
|
+
case MESSAGE_NORMAL:
|
|
452
|
+
_message_level = 2;
|
|
453
|
+
break;
|
|
454
|
+
case MESSAGE_VERBOSE:
|
|
455
|
+
_message_level = 3;
|
|
456
|
+
break;
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
} //END OF NAMESPACE LEMON
|
|
@@ -0,0 +1,129 @@
|
|
|
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_CBC_H
|
|
20
|
+
#define LEMON_CBC_H
|
|
21
|
+
|
|
22
|
+
///\file
|
|
23
|
+
///\brief Header of the LEMON-CBC mip solver interface.
|
|
24
|
+
///\ingroup lp_group
|
|
25
|
+
|
|
26
|
+
#include <lemon/lp_base.h>
|
|
27
|
+
|
|
28
|
+
class CoinModel;
|
|
29
|
+
class OsiSolverInterface;
|
|
30
|
+
class CbcModel;
|
|
31
|
+
|
|
32
|
+
namespace lemon {
|
|
33
|
+
|
|
34
|
+
/// \brief Interface for the CBC MIP solver
|
|
35
|
+
///
|
|
36
|
+
/// This class implements an interface for the CBC MIP solver.
|
|
37
|
+
///\ingroup lp_group
|
|
38
|
+
class CbcMip : public MipSolver {
|
|
39
|
+
protected:
|
|
40
|
+
|
|
41
|
+
CoinModel *_prob;
|
|
42
|
+
OsiSolverInterface *_osi_solver;
|
|
43
|
+
CbcModel *_cbc_model;
|
|
44
|
+
|
|
45
|
+
public:
|
|
46
|
+
|
|
47
|
+
/// \e
|
|
48
|
+
CbcMip();
|
|
49
|
+
/// \e
|
|
50
|
+
CbcMip(const CbcMip&);
|
|
51
|
+
/// \e
|
|
52
|
+
~CbcMip();
|
|
53
|
+
/// \e
|
|
54
|
+
virtual CbcMip* newSolver() const;
|
|
55
|
+
/// \e
|
|
56
|
+
virtual CbcMip* cloneSolver() const;
|
|
57
|
+
|
|
58
|
+
protected:
|
|
59
|
+
|
|
60
|
+
virtual const char* _solverName() const;
|
|
61
|
+
|
|
62
|
+
virtual int _addCol();
|
|
63
|
+
virtual int _addRow();
|
|
64
|
+
virtual int _addRow(Value l, ExprIterator b, ExprIterator e, Value u);
|
|
65
|
+
|
|
66
|
+
virtual void _eraseCol(int i);
|
|
67
|
+
virtual void _eraseRow(int i);
|
|
68
|
+
|
|
69
|
+
virtual void _eraseColId(int i);
|
|
70
|
+
virtual void _eraseRowId(int i);
|
|
71
|
+
|
|
72
|
+
virtual void _getColName(int col, std::string& name) const;
|
|
73
|
+
virtual void _setColName(int col, const std::string& name);
|
|
74
|
+
virtual int _colByName(const std::string& name) const;
|
|
75
|
+
|
|
76
|
+
virtual void _getRowName(int row, std::string& name) const;
|
|
77
|
+
virtual void _setRowName(int row, const std::string& name);
|
|
78
|
+
virtual int _rowByName(const std::string& name) const;
|
|
79
|
+
|
|
80
|
+
virtual void _setRowCoeffs(int i, ExprIterator b, ExprIterator e);
|
|
81
|
+
virtual void _getRowCoeffs(int i, InsertIterator b) const;
|
|
82
|
+
|
|
83
|
+
virtual void _setColCoeffs(int i, ExprIterator b, ExprIterator e);
|
|
84
|
+
virtual void _getColCoeffs(int i, InsertIterator b) const;
|
|
85
|
+
|
|
86
|
+
virtual void _setCoeff(int row, int col, Value value);
|
|
87
|
+
virtual Value _getCoeff(int row, int col) const;
|
|
88
|
+
|
|
89
|
+
virtual void _setColLowerBound(int i, Value value);
|
|
90
|
+
virtual Value _getColLowerBound(int i) const;
|
|
91
|
+
virtual void _setColUpperBound(int i, Value value);
|
|
92
|
+
virtual Value _getColUpperBound(int i) const;
|
|
93
|
+
|
|
94
|
+
virtual void _setRowLowerBound(int i, Value value);
|
|
95
|
+
virtual Value _getRowLowerBound(int i) const;
|
|
96
|
+
virtual void _setRowUpperBound(int i, Value value);
|
|
97
|
+
virtual Value _getRowUpperBound(int i) const;
|
|
98
|
+
|
|
99
|
+
virtual void _setObjCoeffs(ExprIterator b, ExprIterator e);
|
|
100
|
+
virtual void _getObjCoeffs(InsertIterator b) const;
|
|
101
|
+
|
|
102
|
+
virtual void _setObjCoeff(int i, Value obj_coef);
|
|
103
|
+
virtual Value _getObjCoeff(int i) const;
|
|
104
|
+
|
|
105
|
+
virtual void _setSense(Sense sense);
|
|
106
|
+
virtual Sense _getSense() const;
|
|
107
|
+
|
|
108
|
+
virtual ColTypes _getColType(int col) const;
|
|
109
|
+
virtual void _setColType(int col, ColTypes col_type);
|
|
110
|
+
|
|
111
|
+
virtual SolveExitStatus _solve();
|
|
112
|
+
virtual ProblemType _getType() const;
|
|
113
|
+
virtual Value _getSol(int i) const;
|
|
114
|
+
virtual Value _getSolValue() const;
|
|
115
|
+
|
|
116
|
+
virtual void _clear();
|
|
117
|
+
|
|
118
|
+
virtual void _messageLevel(MessageLevel level);
|
|
119
|
+
void _applyMessageLevel();
|
|
120
|
+
|
|
121
|
+
int _message_level;
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
#endif
|