CYCLUS
Loading...
Searching...
No Matches
prog_solver.cc
Go to the documentation of this file.
1
#include "
prog_solver.h
"
2
3
#include <sstream>
4
5
#include "
context.h
"
6
#include "
prog_translator.h
"
7
#include "
greedy_solver.h
"
8
#include "
solver_factory.h
"
9
10
namespace
cyclus
{
11
12
void
Report
(OsiSolverInterface*
iface
) {
13
std::cout <<
iface
->getNumCols() <<
" total variables, "
14
<<
iface
->getNumIntegers() <<
" integer.\n"
;
15
std::cout <<
iface
->getNumRows() <<
" constraints\n"
;
16
}
17
18
ProgSolver::ProgSolver
(std::string solver_t)
19
: solver_t_(solver_t),
20
tmax_(
ProgSolver
::kDefaultTimeout),
21
verbose_(
false
),
22
mps_(
false
),
23
ExchangeSolver
(
false
) {}
24
25
ProgSolver::ProgSolver
(std::string solver_t,
bool
exclusive_orders
)
26
: solver_t_(solver_t),
27
tmax_(
ProgSolver
::kDefaultTimeout),
28
verbose_(
false
),
29
mps_(
false
),
30
ExchangeSolver
(
exclusive_orders
) {}
31
32
ProgSolver::ProgSolver
(std::string solver_t,
double
tmax
)
33
: solver_t_(solver_t),
34
tmax_(
tmax
),
35
verbose_(
false
),
36
mps_(
false
),
37
ExchangeSolver
(
false
) {}
38
39
ProgSolver::ProgSolver
(std::string solver_t,
double
tmax
,
bool
exclusive_orders
,
40
bool
verbose,
bool
mps
)
41
: solver_t_(solver_t),
42
tmax_(
tmax
),
43
verbose_(verbose),
44
mps_(
mps
),
45
ExchangeSolver
(
exclusive_orders
) {}
46
47
ProgSolver::~ProgSolver
() {}
48
49
void
ProgSolver::WriteMPS() {
50
std::stringstream
ss
;
51
ss
<<
"exchng_"
<<
sim_ctx_
->
time
();
52
iface_->writeMps(
ss
.str().c_str());
53
}
54
55
double
ProgSolver::SolveGraph
() {
56
SolverFactory
sf
(solver_t_, tmax_);
57
iface_ =
sf
.get();
58
try
{
59
// get greedy solution
60
GreedySolver
greedy
(
exclusive_orders_
);
61
double
greedy_obj
=
greedy
.Solve(
graph_
);
62
graph_
->
ClearMatches
();
63
64
// translate graph to iface_ instance
65
double
pseudo_cost
=
PseudoCost
();
// from ExchangeSolver API
66
ProgTranslator
xlator
(
graph_
, iface_,
exclusive_orders_
,
pseudo_cost
);
67
xlator
.ToProg();
68
if
(mps_)
69
WriteMPS();
70
71
// set noise level
72
CoinMessageHandler
h
;
73
h
.setLogLevel(0);
74
if
(verbose_) {
75
Report
(iface_);
76
h
.setLogLevel(4);
77
}
78
iface_->passInMessageHandler(&
h
);
79
if
(verbose_) {
80
std::cout <<
"Solving problem, message handler has log level of "
81
<< iface_->messageHandler()->logLevel() <<
"\n"
;
82
}
83
84
// solve and back translate
85
SolveProg
(iface_,
greedy_obj
, verbose_);
86
87
xlator
.FromProg();
88
}
catch
(...) {
89
delete
iface_;
90
throw
;
91
}
92
double
ret
= iface_->getObjValue();
93
delete
iface_;
94
return
ret
;
95
}
96
97
}
// namespace cyclus
cyclus::Context::time
virtual int time()
Returns the current simulation timestep.
Definition
context.cc:313
cyclus::ExchangeGraph::ClearMatches
void ClearMatches()
clears all matches
Definition
exchange_graph.h:229
cyclus::ExchangeSolver
a very simple interface for solving translated resource exchanges
Definition
exchange_solver.h:15
cyclus::ExchangeSolver::graph_
ExchangeGraph * graph_
Definition
exchange_solver.h:68
cyclus::ExchangeSolver::exclusive_orders_
bool exclusive_orders_
Definition
exchange_solver.h:69
cyclus::ExchangeSolver::PseudoCost
double PseudoCost()
Calculates the ratio of the maximum objective coefficient to minimum unit capacity plus an added cost...
Definition
exchange_solver.cc:16
cyclus::ExchangeSolver::sim_ctx_
Context * sim_ctx_
Definition
exchange_solver.h:71
cyclus::GreedySolver
The GreedySolver provides the implementation for a "greedy" solution to a resource exchange graph.
Definition
greedy_solver.h:64
cyclus::ProgSolver
The ProgSolver provides the implementation for a mathematical programming solution to a resource exch...
Definition
prog_solver.h:19
cyclus::ProgSolver::SolveGraph
virtual double SolveGraph()
the ProgSolver solves an ExchangeGraph...
Definition
prog_solver.cc:55
cyclus::ProgSolver::ProgSolver
ProgSolver(std::string solver_t)
Definition
prog_solver.cc:18
cyclus::ProgSolver::~ProgSolver
virtual ~ProgSolver()
Definition
prog_solver.cc:47
cyclus::ProgTranslator
a helper class to translate a product exchange into a mathematical program.
Definition
prog_translator.h:38
cyclus::SolverFactory
A factory class that, given a configuration, returns a Coin::OsiSolverInterface for a solver.
Definition
solver_factory.h:41
context.h
greedy_solver.h
cyclus
taken directly from OsiSolverInterface.cpp on 2/17/14 from https://projects.coin-or....
Definition
agent.cc:14
cyclus::Report
void Report(OsiSolverInterface *iface)
Definition
prog_solver.cc:12
cyclus::SolveProg
void SolveProg(OsiSolverInterface *si, double greedy_obj, bool verbose)
Definition
solver_factory.cc:122
cyclus::OptionalQuery
T OptionalQuery(InfileTree *tree, std::string query, T default_val)
a query method for optional parameters
Definition
infile_tree.h:121
prog_solver.h
prog_translator.h
solver_factory.h
src
prog_solver.cc
Generated by
1.10.0