CYCLUS
Loading...
Searching...
No Matches
exchange_solver.cc
Go to the documentation of this file.
1#include "exchange_solver.h"
2
3#include <vector>
4#include <map>
5
6#include "context.h"
7#include "exchange_graph.h"
8
9namespace cyclus {
10
11double ExchangeSolver::Cost(const Arc& a, bool exclusive_orders) {
12 return (exclusive_orders && a.exclusive()) ? a.excl_val() / a.pref()
13 : 1.0 / a.pref();
14}
15
17 return PseudoCost(1e-1);
18}
19
20double ExchangeSolver::PseudoCost(double cost_factor) {
21 return PseudoCostByPref(cost_factor);
22}
23
24double ExchangeSolver::PseudoCostByCap(double cost_factor) {
25 std::vector<ExchangeNode::Ptr>::iterator n_it;
26 std::map<Arc, std::vector<double>>::iterator c_it;
27 std::map<Arc, double>::iterator p_it;
28 std::vector<RequestGroup::Ptr>::iterator rg_it;
29 std::vector<ExchangeNodeGroup::Ptr>::iterator sg_it;
30 double min_cap, pref, coeff;
31
32 double max_coeff = std::numeric_limits<double>::min();
33 double min_unit_cap = std::numeric_limits<double>::max();
34
35 for (sg_it = graph_->supply_groups().begin();
36 sg_it != graph_->supply_groups().end();
37 ++sg_it) {
38 std::vector<ExchangeNode::Ptr>& nodes = (*sg_it)->nodes();
39 for (n_it = nodes.begin(); n_it != nodes.end(); ++n_it) {
40 // update min_unit_cap
41 std::map<Arc, std::vector<double>>::iterator c_it;
42 std::map<Arc, std::vector<double>>& caps = (*n_it)->unit_capacities;
43 for (c_it = caps.begin(); c_it != caps.end(); ++c_it) {
44 std::vector<double>& ucaps = c_it->second;
45 if (!ucaps.empty()) {
46 min_cap = *std::min_element(ucaps.begin(), ucaps.end());
47 if (min_cap < min_unit_cap) min_unit_cap = min_cap;
48 }
49 }
50 }
51 }
52
53 for (rg_it = graph_->request_groups().begin();
54 rg_it != graph_->request_groups().end();
55 ++rg_it) {
56 std::vector<ExchangeNode::Ptr>& nodes = (*rg_it)->nodes();
57 for (n_it = nodes.begin(); n_it != nodes.end(); ++n_it) {
58 // update min_unit_cap
59 std::map<Arc, std::vector<double>>::iterator c_it;
60 std::map<Arc, std::vector<double>>& caps = (*n_it)->unit_capacities;
61 for (c_it = caps.begin(); c_it != caps.end(); ++c_it) {
62 std::vector<double>& ucaps = c_it->second;
63 if (!ucaps.empty()) {
64 min_cap = *std::min_element(ucaps.begin(), ucaps.end());
65 if (min_cap < min_unit_cap) min_unit_cap = min_cap;
66 }
67 }
68
69 // update max_pref_
70 std::map<Arc, double>& prefs = (*n_it)->prefs;
71 for (p_it = prefs.begin(); p_it != prefs.end(); ++p_it) {
72 pref = p_it->second;
73 const Arc& a = p_it->first;
74 coeff = ArcCost(a);
75 if (coeff > max_coeff) max_coeff = coeff;
76 }
77 }
78 }
79
80 return max_coeff / min_unit_cap * (1 + cost_factor);
81}
82
83double ExchangeSolver::PseudoCostByPref(double cost_factor) {
84 double max_cost = 0;
85 std::vector<Arc>& arcs = graph_->arcs();
86 for (int i = 0; i != arcs.size(); i++) {
87 const Arc& a = arcs[i];
88 // remove exclusive value factor from costs for preferences that are less
89 // than unity. otherwise they can artificially raise the maximum cost.
90 double factor =
91 (a.exclusive() && a.excl_val() < 1) ? 1 / a.excl_val() : 1.0;
92 max_cost = std::max(max_cost, ArcCost(a) * factor);
93 }
94 return max_cost * (1 + cost_factor);
95}
96
97} // namespace cyclus
An arc represents a possible connection between two nodes in the bipartite resource exchange graph.
double pref() const
double excl_val() const
bool exclusive() const
double PseudoCostByCap(double cost_factor)
double PseudoCostByPref(double cost_factor)
double PseudoCost()
Calculates the ratio of the maximum objective coefficient to minimum unit capacity plus an added cost...
double ArcCost(const Arc &a)
return the cost of an arc
static double Cost(const Arc &a, bool exclusive_orders=kDefaultExclusive)
return the cost of an arc
taken directly from OsiSolverInterface.cpp on 2/17/14 from https://projects.coin-or....
Definition agent.cc:14