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
12 : number(n),
13 builder(b),
14 producer(cp) {}
15
16std::vector<BuildOrder> BuildingManager::MakeBuildDecision(Commodity& commodity,
17 double demand) {
18 std::vector<BuildOrder> orders;
19 if (demand > 0) {
22 std::map<CommodityProducer*, Builder*> p_to_b;
23 std::map<int, CommodityProducer*> idx_to_p;
24 SetUp_(iface, ctx, p_to_b, idx_to_p, commodity, demand);
25 Solve_(iface, ctx, p_to_b, idx_to_p, orders);
26 }
27 return orders;
28}
29
30void BuildingManager::SetUp_(OsiCbcSolverInterface& iface,
32 std::map<CommodityProducer*, Builder*>& p_to_b,
33 std::map<int, CommodityProducer*>& idx_to_p,
34 Commodity& commodity,
35 double demand) {
37 std::set<Builder*>::iterator bit;
38 std::set<CommodityProducer*>::iterator pit;
40 Builder* b;
41 int idx = 0;
42 double inf = iface.getInfinity();
43 for (bit = builders_.begin(); bit != builders_.end(); ++bit) {
44 b = *bit;
45 for (pit = b->producers().begin(); pit != b->producers().end(); ++pit) {
46 p = *pit;
47 if (p->Produces(commodity)) {
48 ctx.obj_coeffs.push_back(p->Cost(commodity));
49 caps.insert(idx, p->Capacity(commodity));
50 ctx.col_lbs.push_back(0);
51 ctx.col_ubs.push_back(inf);
52 p_to_b[p] = b;
53 idx_to_p[idx] = p;
54 idx++;
55 }
56 }
57 }
58 ctx.row_ubs.push_back(inf);
59 ctx.row_lbs.push_back(demand);
60 ctx.m.setDimensions(0, ctx.col_ubs.size());
61 ctx.m.appendRow(caps);
62}
63
64void BuildingManager::Solve_(OsiCbcSolverInterface& iface,
65 ProgTranslatorContext& ctx,
66 std::map<CommodityProducer*, Builder*>& p_to_b,
67 std::map<int, CommodityProducer*>& idx_to_p,
68 std::vector<BuildOrder>& orders) {
69 int nvar = ctx.col_ubs.size();
70 iface.setObjSense(1.0); // minimize
71 iface.loadProblem(ctx.m, &ctx.col_lbs[0], &ctx.col_ubs[0],
72 &ctx.obj_coeffs[0], &ctx.row_lbs[0], &ctx.row_ubs[0]);
73 for (int i = 0; i != nvar; i++) {
74 iface.setInteger(i);
75 }
76 iface.initialSolve();
77 iface.branchAndBound();
78
79 const double* sol = iface.getColSolution();
80 int n;
81 CommodityProducer* p;
82 Builder* b;
83 for (int i = 0; i != nvar; i++) {
84 n = static_cast<int>(sol[i]);
85 if (n > 0) {
86 p = idx_to_p[i];
87 b = p_to_b[p];
88 orders.push_back(BuildOrder(n, b, p));
89 }
90 }
91}
92
93} // namespace toolkit
94} // namespace cyclus
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.
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
T OptionalQuery(InfileTree *tree, std::string query, T default_val)
a query method for optional parameters
double b(int nuc)
Computes the scattering length [cm] from the coherent and incoherent components.
Definition pyne.cc:11180
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
BuildOrder(int n, Builder *b, CommodityProducer *cp)