5#include "CoinPackedVector.hpp"
6#include "OsiSolverInterface.hpp"
20 pseudo_cost_(
std::numeric_limits<double>::max()) {
29 pseudo_cost_(
std::numeric_limits<double>::max()) {
38 pseudo_cost_(pseudo_cost) {
43 bool exclusive,
double pseudo_cost)
47 pseudo_cost_(pseudo_cost) {
51void ProgTranslator::Init() {
52 arc_offset_ = g_->
arcs().size();
57 ctx_.
m = CoinPackedMatrix(
false, 0, 0);
60void ProgTranslator::CheckPref(
double pref) {
63 ss <<
"Preference value found to be nonpositive (" << pref
64 <<
"). Preferences must be positive when using an optimization solver."
65 <<
" If using Cyclus in simulation mode (e.g., from the command line),"
66 <<
" this error is likely a bug in Cyclus. Please report it to the developer's "
67 <<
"list (https://groups.google.com/forum/#!forum/cyclus-dev).";
68 throw ValueError(ss.str());
77 nfalse += rgs[i].get()->HasArcs() ? 1 : 0;
78 int n_cols = g_->
arcs().size() + nfalse;
79 ctx_.
m.setDimensions(0, n_cols);
82 std::vector<ExchangeNodeGroup::Ptr>& sgs = g_->
supply_groups();
83 for (
int i = 0; i != sgs.size(); i++) {
85 XlateGrp_(sgs[i].get(), request);
88 for (
int i = 0; i != rgs.size(); i++) {
90 XlateGrp_(rgs[i].get(), request);
96 double inf = iface_->getInfinity();
97 for (
int i = g_->
arcs().size(); i != arc_offset_; i++) {
105 iface_->setObjSense(1.0);
113 std::vector<Arc>& arcs = g_->
arcs();
114 for (
int i = 0; i != arcs.size(); i++) {
117 iface_->setInteger(g_->
arc_ids()[a]);
130 double inf = iface_->getInfinity();
131 std::vector<double>& caps = grp->
capacities();
133 if (request && !grp->
HasArcs())
136 std::vector<CoinPackedVector> cap_rows;
137 std::vector<CoinPackedVector> excl_rows;
138 for (
int i = 0; i != caps.size(); i++) {
139 cap_rows.push_back(CoinPackedVector());
142 std::vector<ExchangeNode::Ptr>& nodes = grp->
nodes();
143 for (
int i = 0; i != nodes.size(); i++) {
144 std::map<Arc, std::vector<double> >& ucap_map = nodes[i]->unit_capacities;
145 std::map<Arc, std::vector<double> >::iterator cap_it;
148 for (cap_it = ucap_map.begin(); cap_it != ucap_map.end(); ++cap_it) {
149 const Arc& a = cap_it->first;
150 std::vector<double>& ucaps = cap_it->second;
154 for (
int j = 0; j != ucaps.size(); j++) {
155 double coeff = ucaps[j];
156 if (excl_ && a.exclusive()) {
157 coeff *= a.excl_val();
160 cap_rows[j].insert(arc_id, coeff);
167 ctx_.
col_ubs[arc_id] = (excl_ && a.exclusive()) ? 1 :
168 std::min(nodes[i]->qty, inf);
175 faux_id = arc_offset_++;
179 for (
int i = 0; i != cap_rows.size(); i++) {
181 cap_rows[i].insert(faux_id, 1.0);
186 double rlb = std::min(caps[i], 1e15);
187 ctx_.
row_lbs.push_back(request ? rlb : 0);
188 ctx_.
row_ubs.push_back(request ? inf : caps[i]);
189 ctx_.
m.appendRow(cap_rows[i]);
194 std::vector< std::vector<ExchangeNode::Ptr> >& exngs =
196 for (
int i = 0; i != exngs.size(); i++) {
197 CoinPackedVector excl_row;
198 std::vector<ExchangeNode::Ptr>& nodes = exngs[i];
199 for (
int j = 0; j != nodes.size(); j++) {
201 for (
int k = 0; k != arcs.size(); k++) {
202 excl_row.insert(g_->
arc_ids()[arcs[k]], 1.0);
205 if (excl_row.getNumElements() > 0) {
206 excl_rows.push_back(excl_row);
211 for (
int i = 0; i != excl_rows.size(); i++) {
214 ctx_.
m.appendRow(excl_rows[i]);
220 const double* sol = iface_->getColSolution();
221 std::vector<Arc>& arcs = g_->
arcs();
223 for (
int i = 0; i < arcs.size(); i++) {
An arc represents a possible connection between two nodes in the bipartite resource exchange graph.
An ExchangeGraph is a resource-neutral representation of a ResourceExchange.
const std::vector< Arc > & arcs() const
const std::vector< ExchangeNodeGroup::Ptr > & supply_groups() const
const std::map< ExchangeNode::Ptr, std::vector< Arc > > & node_arc_map() const
const std::map< Arc, int > & arc_ids() const
const std::vector< RequestGroup::Ptr > & request_groups() const
void AddMatch(const Arc &a, double qty)
adds a match for a quanity of flow along an arc
const std::map< int, Arc > & arc_by_id() const
A ExchangeNodeGroup is a collection of ExchangeNodes, and is the ExchangeGraph representation of a Bi...
const std::vector< double > & capacities() const
the flow capacities assocaited with this group
const std::vector< ExchangeNode::Ptr > & nodes() const
const std::vector< std::vector< ExchangeNode::Ptr > > & excl_node_groups() const
exclusive node groups represent nodes over whose combined arcs flow can only exist on one arc
static double Cost(const Arc &a, bool exclusive_orders=kDefaultExclusive)
return the cost of an arc
ProgTranslator(ExchangeGraph *g, OsiSolverInterface *iface)
constructor
void FromProg()
translates solution from iface back into graph matches
void Populate()
populates the solver interface with values from the translators Context
void ToProg()
translates graph into mathematic program via iface.
void Translate()
translates the graph, filling the translators Context
Code providing rudimentary logging capability for the Cyclus core.
taken directly from OsiSolverInterface.cpp on 2/17/14 from https://projects.coin-or....
@ LEV_DEBUG1
debugging information - least verbose
double eps()
a generic epsilon value
std::vector< double > col_lbs
std::vector< double > col_ubs
std::vector< double > obj_coeffs
std::vector< double > row_ubs
std::vector< double > row_lbs