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
10namespace cyclus {
11
12void Report(OsiSolverInterface* iface) {
13 std::cout << iface->getNumCols() << " total variables, "
14 << iface->getNumIntegers() << " integer.\n";
15 std::cout << iface->getNumRows() << " constraints\n";
16}
17
18ProgSolver::ProgSolver(std::string solver_t)
19 : solver_t_(solver_t),
20 tmax_(ProgSolver::kDefaultTimeout),
21 verbose_(false),
22 mps_(false),
24
25ProgSolver::ProgSolver(std::string solver_t, bool exclusive_orders)
26 : solver_t_(solver_t),
27 tmax_(ProgSolver::kDefaultTimeout),
28 verbose_(false),
29 mps_(false),
31
32ProgSolver::ProgSolver(std::string solver_t, double tmax)
33 : solver_t_(solver_t),
34 tmax_(tmax),
35 verbose_(false),
36 mps_(false),
38
39ProgSolver::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),
46
48
49void ProgSolver::WriteMPS() {
50 std::stringstream ss;
51 ss << "exchng_" << sim_ctx_->time();
52 iface_->writeMps(ss.str().c_str());
53}
54
56 SolverFactory sf(solver_t_, tmax_);
57 iface_ = sf.get();
58 try {
59 // get greedy solution
61 double greedy_obj = greedy.Solve(graph_);
63
64 // translate graph to iface_ instance
65 double pseudo_cost = PseudoCost(); // from ExchangeSolver API
67 xlator.ToProg();
68 if (mps_)
69 WriteMPS();
70
71 // set noise level
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
virtual int time()
Returns the current simulation timestep.
Definition context.cc:313
void ClearMatches()
clears all matches
a very simple interface for solving translated resource exchanges
double PseudoCost()
Calculates the ratio of the maximum objective coefficient to minimum unit capacity plus an added cost...
The GreedySolver provides the implementation for a "greedy" solution to a resource exchange graph.
The ProgSolver provides the implementation for a mathematical programming solution to a resource exch...
Definition prog_solver.h:19
virtual double SolveGraph()
the ProgSolver solves an ExchangeGraph...
ProgSolver(std::string solver_t)
virtual ~ProgSolver()
a helper class to translate a product exchange into a mathematical program.
A factory class that, given a configuration, returns a Coin::OsiSolverInterface for a solver.
taken directly from OsiSolverInterface.cpp on 2/17/14 from https://projects.coin-or....
Definition agent.cc:14
void Report(OsiSolverInterface *iface)
void SolveProg(OsiSolverInterface *si, double greedy_obj, bool verbose)
T OptionalQuery(InfileTree *tree, std::string query, T default_val)
a query method for optional parameters