Skip to content

Commit 50167c5

Browse files
committed
add comp optimizer which does not use an ILP, use this optimizer as default to avoid bad optimization times or memory issues when only glpk is available as an ILP solver, see for example issue #26
1 parent 3510740 commit 50167c5

File tree

5 files changed

+115
-25
lines changed

5 files changed

+115
-25
lines changed

src/loom/LoomMain.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "loom/config/ConfigReader.cpp"
1212
#include "loom/config/LoomConfig.h"
1313
#include "loom/optim/CombOptimizer.h"
14+
#include "loom/optim/CombNoILPOptimizer.h"
1415
#include "loom/optim/GreedyOptimizer.h"
1516
#include "loom/optim/ILPEdgeOrderOptimizer.h"
1617
#include "shared/rendergraph/Penalties.h"
@@ -72,6 +73,9 @@ int main(int argc, char** argv) {
7273
} else if (cfg.optimMethod == "comb") {
7374
optim::CombOptimizer ilpCombiOptim(&cfg, pens);
7475
stats = ilpCombiOptim.optimize(&g);
76+
} else if (cfg.optimMethod == "comb-no-ilp") {
77+
optim::CombNoILPOptimizer noIlpCombiOptim(&cfg, pens);
78+
stats = noIlpCombiOptim.optimize(&g);
7579
} else if (cfg.optimMethod == "exhaust") {
7680
optim::ExhaustiveOptimizer exhausOptim(&cfg, pens);
7781
stats = exhausOptim.optimize(&g);

src/loom/config/ConfigReader.cpp

+24-24
Original file line numberDiff line numberDiff line change
@@ -35,52 +35,52 @@ void ConfigReader::help(const char* bin) const {
3535
<< "Usage: " << bin << " < graph.json\n\n"
3636
<< "Allowed options:\n\n"
3737
<< "General:\n"
38-
<< std::setw(41) << " -v [ --version ]"
38+
<< std::setw(43) << " -v [ --version ]"
3939
<< "print version\n"
40-
<< std::setw(41) << " -h [ --help ]"
40+
<< std::setw(43) << " -h [ --help ]"
4141
<< "show this help message\n"
42-
<< std::setw(41) << " --no-untangle"
42+
<< std::setw(43) << " --no-untangle"
4343
<< "Don't apply untangling rules\n"
44-
<< std::setw(41) << " --no-prune"
44+
<< std::setw(43) << " --no-prune"
4545
<< "Don't apply pruning rules\n"
46-
<< std::setw(41) << " -m [ --optim-method ] arg (=comb)"
46+
<< std::setw(43) << " -m [ --optim-method ] arg (=comb-no-ilp)"
4747
<< "Optimization method, one of ilp-naive, ilp,\n"
48-
<< std::setw(41) << " "
49-
<< " comb, exhaust, hillc, hillc-random, anneal,\n"
50-
<< std::setw(41) << " "
48+
<< std::setw(43) << " "
49+
<< " comb, comb-no-ilp, exhaust, hillc, hillc-random, anneal,\n"
50+
<< std::setw(43) << " "
5151
<< " anneal-random, greedy, greedy-lookahead, null\n"
52-
<< std::setw(41) << " --same-seg-cross-pen arg (=4)"
52+
<< std::setw(43) << " --same-seg-cross-pen arg (=4)"
5353
<< "Penalty for same-segment crossings\n"
54-
<< std::setw(41) << " --diff-seg-cross-pen arg (=1)"
54+
<< std::setw(43) << " --diff-seg-cross-pen arg (=1)"
5555
<< "Penalty for diff-segment crossings\n"
56-
<< std::setw(41) << " --in-stat-cross-pen-same-seg arg (=12)"
56+
<< std::setw(43) << " --in-stat-cross-pen-same-seg arg (=12)"
5757
<< "Penalty for same-segment crossings at stations\n"
58-
<< std::setw(41) << " --in-stat-cross-pen-diff-seg arg (=3)"
58+
<< std::setw(43) << " --in-stat-cross-pen-diff-seg arg (=3)"
5959
<< "Penalty for diff-segment crossings at stations\n"
60-
<< std::setw(41) << " --sep-pen arg (=3)"
60+
<< std::setw(43) << " --sep-pen arg (=3)"
6161
<< "Penalty for separations\n"
62-
<< std::setw(41) << " --in-stat-sep-pen arg (=9)"
62+
<< std::setw(43) << " --in-stat-sep-pen arg (=9)"
6363
<< "Penalty for separations at stations\n\n"
6464
<< "Misc:\n"
65-
<< std::setw(41) << " -D [ --from-dot ]"
65+
<< std::setw(43) << " -D [ --from-dot ]"
6666
<< "input is in dot format\n"
67-
<< std::setw(41) << " --output-stats"
67+
<< std::setw(43) << " --output-stats"
6868
<< "Print stats to stdout\n"
69-
<< std::setw(41) << " --write-stats"
69+
<< std::setw(43) << " --write-stats"
7070
<< "Write stats to output\n"
71-
<< std::setw(41) << " --ilp-solver arg (=gurobi)"
71+
<< std::setw(43) << " --ilp-solver arg (=gurobi)"
7272
<< "Preferred ILP solver, either glpk, cbc, or gurobi.\n"
73-
<< std::setw(41) << " "
73+
<< std::setw(43) << " "
7474
<< "Will fall back if not available.\n"
75-
<< std::setw(41) << " --ilp-num-threads arg (=0)"
75+
<< std::setw(43) << " --ilp-num-threads arg (=0)"
7676
<< "Number of threads to use by ILP solver,\n"
77-
<< std::setw(41) << " "
77+
<< std::setw(43) << " "
7878
<< " 0 means solver default\n"
79-
<< std::setw(41) << " --ilp-time-limit arg (=-1)"
79+
<< std::setw(43) << " --ilp-time-limit arg (=-1)"
8080
<< "ILP solve time limit (seconds), -1 for infinite\n"
81-
<< std::setw(41) << " --dbg-output-path arg (=.)"
81+
<< std::setw(43) << " --dbg-output-path arg (=.)"
8282
<< "Path used for debug output\n"
83-
<< std::setw(41) << " --output-optgraph"
83+
<< std::setw(43) << " --output-optgraph"
8484
<< "Output optimization graph to debug path\n";
8585
}
8686

src/loom/config/LoomConfig.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ struct Config {
1515
std::string outputPath;
1616
std::string dbgPath;
1717

18-
std::string optimMethod = "comb";
18+
std::string optimMethod = "comb-no-ilp";
1919
std::string MPSOutputPath;
2020

2121
size_t optimRuns = 1;

src/loom/optim/CombNoILPOptimizer.cpp

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Copyright 2016, University of Freiburg,
2+
// Chair of Algorithms and Data Structures.
3+
// Authors: Patrick Brosi <[email protected]>
4+
5+
#include <chrono>
6+
#include <cstdio>
7+
#include <fstream>
8+
#include <thread>
9+
10+
#include "loom/optim/CombNoILPOptimizer.h"
11+
#include "loom/optim/OptGraph.h"
12+
#include "shared/rendergraph/OrderCfg.h"
13+
#include "util/String.h"
14+
#include "util/geo/Geo.h"
15+
#include "util/geo/output/GeoGraphJsonOutput.h"
16+
#include "util/graph/Algorithm.h"
17+
#include "util/log/Log.h"
18+
19+
using loom::optim::CombNoILPOptimizer;
20+
using shared::rendergraph::HierarOrderCfg;
21+
22+
// _____________________________________________________________________________
23+
double CombNoILPOptimizer::optimizeComp(OptGraph* og, const std::set<OptNode*>& g,
24+
HierarOrderCfg* hc, size_t depth,
25+
OptResStats& stats) const {
26+
size_t maxC = maxCard(g);
27+
double solSp = solutionSpaceSize(g);
28+
29+
LOGTO(DEBUG, std::cerr) << prefix(depth)
30+
<< "(CombNoILPOptimizer) Optimizing comp with " << g.size()
31+
<< " nodes, max card " << maxC << ", sol space size "
32+
<< solSp;
33+
34+
if (maxC == 1) {
35+
return _nullOpt.optimizeComp(og, g, hc, depth + 1, stats);
36+
} else if (solSp < 500) {
37+
return _exhausOpt.optimizeComp(og, g, hc, depth + 1, stats);
38+
} else {
39+
return _hillcOpt.optimizeComp(og, g, hc, depth + 1, stats);
40+
}
41+
}

src/loom/optim/CombNoILPOptimizer.h

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// Copyright 2016, University of Freiburg,
2+
// Chair of Algorithms and Data Structures.
3+
// Authors: Patrick Brosi <[email protected]>
4+
5+
#ifndef LOOM_OPTIM_COMBNOILPOPTIMIZER_H_
6+
#define LOOM_OPTIM_COMBNOILPOPTIMIZER_H_
7+
8+
#include "loom/config/LoomConfig.h"
9+
#include "loom/optim/ExhaustiveOptimizer.h"
10+
#include "loom/optim/HillClimbOptimizer.h"
11+
#include "loom/optim/NullOptimizer.h"
12+
#include "loom/optim/OptGraph.h"
13+
#include "loom/optim/Optimizer.h"
14+
#include "loom/optim/SimulatedAnnealingOptimizer.h"
15+
#include "shared/rendergraph/OrderCfg.h"
16+
17+
namespace loom {
18+
namespace optim {
19+
20+
class CombNoILPOptimizer : public Optimizer {
21+
public:
22+
CombNoILPOptimizer(const config::Config* cfg,
23+
const shared::rendergraph::Penalties& pens)
24+
: Optimizer(cfg, pens),
25+
_nullOpt(cfg, pens),
26+
_exhausOpt(cfg, pens),
27+
_hillcOpt(cfg, pens, false),
28+
_annealOpt(cfg, pens, false){};
29+
30+
double optimizeComp(OptGraph* og, const std::set<OptNode*>& g,
31+
shared::rendergraph::HierarOrderCfg* c, size_t depth,
32+
OptResStats& stats) const;
33+
34+
virtual std::string getName() const { return "comb-no-ilp"; }
35+
36+
private:
37+
const NullOptimizer _nullOpt;
38+
const ExhaustiveOptimizer _exhausOpt;
39+
const HillClimbOptimizer _hillcOpt;
40+
const SimulatedAnnealingOptimizer _annealOpt;
41+
};
42+
} // namespace optim
43+
} // namespace loom
44+
45+
#endif // LOOM_OPTIM_COMBNOILPOPTIMIZER_H_

0 commit comments

Comments
 (0)