7#include <boost/math/special_functions/next.hpp>
37 if (conditioner_ !=
NULL)
42 if (conditioner_ !=
NULL)
50 &GreedySolver::GetCaps,
52 std::placeholders::_1));
57 &GreedySolver::GetCaps,
59 std::placeholders::_1));
74 &GreedySolver::GreedilySatisfySet,
76 std::placeholders::_1));
98 if (n->group ==
NULL) {
102 if (n->unit_capacities[
a].size() == 0) {
106 std::vector<double>&
unit_caps = n->unit_capacities[
a];
107 const std::vector<double>&
group_caps = grp_caps_[n->group];
108 std::vector<double>
caps;
111 for (
int i = 0; i <
unit_caps.size(); i++) {
121 if (
grp_cap == std::numeric_limits<double>::max()) {
122 caps.push_back(std::numeric_limits<double>::max());
137 for (
int i = 0; i != g->nodes().size(); i++) {
138 n_qty_[g->nodes()[i]] = 0;
140 grp_caps_[g.get()] = g->capacities();
144 std::vector<ExchangeNode::Ptr>& nodes =
prs->nodes();
145 std::stable_sort(nodes.begin(), nodes.end(),
AvgPrefComp);
147 std::vector<ExchangeNode::Ptr>::iterator
req_it = nodes.begin();
148 double target =
prs->qty();
152 std::vector<Arc>::const_iterator
arc_it;
157 <<
" amount of a resource.";
159 while ((match <= target) && (
req_it != nodes.end())) {
165 sorted = std::vector<Arc>(arcs);
178 if (
arc_it->exclusive()) {
179 excl_val =
a.excl_val();
183 double dist = boost::math::float_distance(
tomatch, excl_val);
193 <<
" amount of a resource.";
209 unmatched_ += target - match;
212void GreedySolver::UpdateObj(
double qty,
double pref) {
223 std::vector<double>&
unit_caps = n->unit_capacities[
a];
224 std::vector<double>&
caps = grp_caps_[n->group];
226 for (
int i = 0; i <
caps.size(); i++) {
231 caps[i] = (
prev == std::numeric_limits<double>::max()) ?
232 std::numeric_limits<double>::max() :
239 std::stringstream
ss;
240 ss <<
"A bid for " << n->commod <<
" was set at " << n->qty
241 <<
" but has been matched to a higher value " << qty
242 <<
". This could be due to a problem with your "
243 <<
"bid portfolio constraints.";
244 throw ValueError(
ss.str());
An arc represents a possible connection between two nodes in the bipartite resource exchange graph.
const std::vector< ExchangeNodeGroup::Ptr > & supply_groups() const
const std::map< ExchangeNode::Ptr, std::vector< Arc > > & node_arc_map() 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
boost::shared_ptr< ExchangeNodeGroup > Ptr
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...
A GreedyPreconditioner conditions an ExchangeGraph for a GreedySolver by ordering the RequestGroups a...
void Condition(ExchangeGraph *graph)
conditions the graph as described above
virtual double SolveGraph()
the GreedySolver solves an ExchangeGraph by iterating over each RequestGroup and matching requests wi...
GreedySolver()
GreedySolver constructor.
double Capacity(const Arc &a, double u_curr_qty, double v_curr_qty)
the capacity of the arc
void Condition()
Uses the provided (or a default) GreedyPreconditioner to condition the solver's ExchangeGraph so that...
void Init()
Initialize member values based on the given graph.
boost::shared_ptr< RequestGroup > Ptr
For failed object state expectations.
For values that are too big, too small, etc.
Code providing rudimentary logging capability for the Cyclus core.
taken directly from OsiSolverInterface.cpp on 2/17/14 from https://projects.coin-or....
void Capacity(cyclus::Arc const &, double, double)
bool IsNegative(double d)
returns true if a double is less than 0 - eps()
bool AvgPrefComp(ExchangeNode::Ptr l, ExchangeNode::Ptr r)
A comparison function for sorting a container of Nodes by the nodes preference in decensing order (i....
bool ReqPrefComp(const Arc &l, const Arc &r)
double Capacity(const Arc& a, double u_curr_qty, double v_curr_qty) { return 0; }
@ LEV_DEBUG1
debugging information - least verbose
double eps()
a generic epsilon value
static const double float_ulp_eq
distance in ULP within which floating point numbers should be considered equal.
T OptionalQuery(InfileTree *tree, std::string query, T default_val)
a query method for optional parameters
boost::shared_ptr< ExchangeNode > Ptr