CYCLUS
Loading...
Searching...
No Matches
building_manager.cc
Go to the documentation of this file.
1#include "building_manager.h"
2
3#include "prog_translator.h"
4#include "CoinPackedVector.hpp"
5
7
8namespace cyclus {
9namespace toolkit {
10
13
14std::vector<BuildOrder> BuildingManager::MakeBuildDecision(Commodity& commodity,
15 double demand) {
16 std::vector<BuildOrder> orders;
17 if (demand > 0) {
20 std::map<CommodityProducer*, Builder*> p_to_b;
21 std::map<int, CommodityProducer*> idx_to_p;
22 SetUp_(iface, ctx, p_to_b, idx_to_p, commodity, demand);
23 Solve_(iface, ctx, p_to_b, idx_to_p, orders);
24 }
25 return orders;
26}
27
28void BuildingManager::SetUp_(OsiCbcSolverInterface& iface,
30 std::map<CommodityProducer*, Builder*>& p_to_b,
31 std::map<int, CommodityProducer*>& idx_to_p,
32 Commodity& commodity,
33 double demand) {
34 CoinPackedVector caps;
35 std::set<Builder*>::iterator bit;
36 std::set<CommodityProducer*>::iterator pit;
38 Builder* b;
39 int idx = 0;
40 double inf = iface.getInfinity();
41 for (bit = builders_.begin(); bit != builders_.end(); ++bit) {
42 b = *bit;
43 for (pit = b->producers().begin(); pit != b->producers().end(); ++pit) {
44 p = *pit;
45 if (p->Produces(commodity)) {
46 ctx.obj_coeffs.push_back(p->Cost(commodity));
47 caps.insert(idx, p->Capacity(commodity));
48 ctx.col_lbs.push_back(0);
49 ctx.col_ubs.push_back(inf);
50 p_to_b[p] = b;
51 idx_to_p[idx] = p;
52 idx++;
53 }
54 }
55 }
56 ctx.row_ubs.push_back(inf);
57 ctx.row_lbs.push_back(demand);
58 ctx.m.setDimensions(0, ctx.col_ubs.size());
59 ctx.m.appendRow(caps);
60}
61
62void BuildingManager::Solve_(OsiCbcSolverInterface& iface,
63 ProgTranslatorContext& ctx,
64 std::map<CommodityProducer*, Builder*>& p_to_b,
65 std::map<int, CommodityProducer*>& idx_to_p,
66 std::vector<BuildOrder>& orders) {
67 int nvar = ctx.col_ubs.size();
68 iface.setObjSense(1.0); // minimize
69 iface.loadProblem(ctx.m, &ctx.col_lbs[0], &ctx.col_ubs[0], &ctx.obj_coeffs[0],
70 &ctx.row_lbs[0], &ctx.row_ubs[0]);
71 for (int i = 0; i != nvar; i++) {
72 iface.setInteger(i);
73 }
74 iface.initialSolve();
75 iface.branchAndBound();
76
77 const double* sol = iface.getColSolution();
78 int n;
79 CommodityProducer* p;
80 Builder* b;
81 for (int i = 0; i != nvar; i++) {
82 n = static_cast<int>(sol[i]);
83 if (n > 0) {
84 p = idx_to_p[i];
85 b = p_to_b[p];
86 orders.push_back(BuildOrder(n, b, p));
87 }
88 }
89}
90
91} // namespace toolkit
92} // namespace cyclus
virtual void setInteger(int index)
Set the index-th variable to be an integer variable.
virtual void initialSolve()
Solve initial LP relaxation.
virtual void loadProblem(const CoinPackedMatrix &matrix, const double *collb, const double *colub, const double *obj, const double *rowlb, const double *rowub)
Load in an problem by copying the arguments (the constraints on the rows are given by lower and upper...
virtual void branchAndBound()
Invoke solver's built-in enumeration algorithm.
virtual void setObjSense(double s)
Set objective function sense (1 for min (default), -1 for max,)
virtual const double * getColSolution() const
Get pointer to array[getNumCols()] of primal solution vector.
virtual double getInfinity() const
Get solver's value for infinity.
A mixin to provide information about commodity producers that can be built.
Definition builder.h:14
std::vector< BuildOrder > MakeBuildDecision(Commodity &commodity, double demand)
Given a certain commodity and demand, a decision is made as to how many producers of each available t...
A mixin to provide information about produced commodities.
double Capacity(const Commodity &commodity)
double Cost(const Commodity &commodity)
bool Produces(const Commodity &commodity) const
A simple class defining a commodity; it is currently super simple.
Definition commodity.h:12
taken directly from OsiSolverInterface.cpp on 2/17/14 from https://projects.coin-or....
Definition agent.cc:14
double b(int nuc)
Computes the scattering length [cm] from the coherent and incoherent components.
Definition pyne.cc:8819
struct to hold all problem instance state
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
CommodityProducer * producer
BuildOrder(int n, Builder *b, CommodityProducer *cp)