CYCLUS
Loading...
Searching...
No Matches
exchange_graph.cc
Go to the documentation of this file.
1#include "exchange_graph.h"
2
3#include <algorithm>
4#include <boost/math/special_functions/next.hpp>
5
6#include "cyc_limits.h"
7#include "error.h"
8#include "logger.h"
9
10namespace cyclus {
11
12ExchangeNode::ExchangeNode(double qty, bool exclusive, std::string commod,
13 int agent_id)
14 : qty(qty),
15 exclusive(exclusive),
16 commod(commod),
17 agent_id(agent_id),
18 group(NULL) {}
19
20ExchangeNode::ExchangeNode(double qty, bool exclusive)
21 : qty(qty),
22 exclusive(exclusive),
23 commod(""),
24 agent_id(-1),
25 group(NULL) {}
26
27ExchangeNode::ExchangeNode(double qty, bool exclusive, std::string commod)
28 : qty(qty),
29 exclusive(exclusive),
30 commod(commod),
31 agent_id(-1),
32 group(NULL) {}
33
35 : qty(qty),
36 exclusive(false),
37 commod(""),
38 agent_id(-1),
39 group(NULL) {}
40
42 : qty(std::numeric_limits<double>::max()),
43 exclusive(false),
44 commod(""),
45 agent_id(-1),
46 group(NULL) {}
47
48// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
50 return (lhs.unit_capacities == rhs.unit_capacities &&
51 lhs.qty == rhs.qty &&
52 lhs.exclusive == rhs.exclusive &&
53 lhs.group == rhs.group &&
54 lhs.commod == rhs.commod);
55}
56
57// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
58Arc::Arc(boost::shared_ptr<ExchangeNode> unode,
59 boost::shared_ptr<ExchangeNode> vnode)
60 : unode_(unode),
61 vnode_(vnode) {
62 exclusive_ = unode->exclusive || vnode->exclusive;
63 if (exclusive_) {
64 double fqty = unode->qty;
65 double sqty = vnode->qty;
66 // this careful float comparison is vital for preventing false positive
67 // constraint violations w.r.t. exclusivity-related capacity.
68 double dist = boost::math::float_distance(fqty, sqty);
69 if (unode->exclusive && vnode->exclusive) {
70 excl_val_ = (std::abs(dist) <= float_ulp_eq) ? fqty : 0;
71 } else if (unode->exclusive) {
72 excl_val_ = dist >= -float_ulp_eq ? fqty : 0;
73 } else {
74 excl_val_ = dist <= float_ulp_eq ? sqty : 0;
75 }
76 } else {
77 excl_val_ = 0;
78 }
79}
80
81// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
83 : unode_(other.unode()),
84 vnode_(other.vnode()),
85 pref_(other.pref()),
86 exclusive_(other.exclusive()),
87 excl_val_(other.excl_val()) {}
88
89// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
91 node->group = this;
92 nodes_.push_back(node);
93}
94
95// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
97 std::vector<ExchangeNode::Ptr> nodes;
98 nodes.push_back(node);
99 excl_node_groups_.push_back(nodes);
100}
101
102// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
103RequestGroup::RequestGroup(double qty) : qty_(qty) {}
104
105// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
112
113// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
114ExchangeGraph::ExchangeGraph() : next_arc_id_(0) { }
115
116// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
118 request_groups_.push_back(prs);
119}
120
121// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
123 supply_groups_.push_back(pss);
124}
125
126// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
128 arcs_.push_back(a);
129 int id = next_arc_id_++;
130 arc_ids_.insert(std::pair<Arc, int>(a, id));
131 arc_by_id_.insert(std::pair<int, Arc>(id, a));
132 node_arc_map_[a.unode()].push_back(a);
133 node_arc_map_[a.vnode()].push_back(a);
134}
135
136// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
137void ExchangeGraph::AddMatch(const Arc& a, double qty) {
138 matches_.push_back(std::make_pair(a, qty));
139}
140
141} // namespace cyclus
An arc represents a possible connection between two nodes in the bipartite resource exchange graph.
boost::shared_ptr< ExchangeNode > vnode() const
boost::shared_ptr< ExchangeNode > unode() const
Arc()
default required for usage in maps
void AddRequestGroup(RequestGroup::Ptr prs)
adds a request group to the graph
void AddSupplyGroup(ExchangeNodeGroup::Ptr prs)
adds a supply group to the graph
void AddMatch(const Arc &a, double qty)
adds a match for a quanity of flow along an arc
void AddArc(const Arc &a)
adds an arc to the graph
boost::shared_ptr< ExchangeNodeGroup > Ptr
virtual void AddExchangeNode(ExchangeNode::Ptr node)
Add the node to the ExchangeNodeGroup and informs the node it is a member of this ExchangeNodeGroup.
const std::vector< ExchangeNode::Ptr > & nodes() const
void AddExclNode(ExchangeNode::Ptr n)
adds a single node to the set of exclusive node groupings, in general this function is used for deman...
virtual void AddExchangeNode(ExchangeNode::Ptr node)
Add the node to the ExchangeNodeGroup and informs the node it is a member of this ExchangeNodeGroup,...
RequestGroup(double qty=0.0)
boost::shared_ptr< RequestGroup > Ptr
Code providing rudimentary logging capability for the Cyclus core.
taken directly from OsiSolverInterface.cpp on 2/17/14 from https://projects.coin-or....
Definition agent.cc:14
static const double float_ulp_eq
distance in ULP within which floating point numbers should be considered equal.
Definition cyc_limits.h:35
bool operator==(const CapacityConstraint< T > &lhs, const CapacityConstraint< T > &rhs)
CapacityConstraint-CapacityConstraint equality operator.
T OptionalQuery(InfileTree *tree, std::string query, T default_val)
a query method for optional parameters
ExchangeNodes are used in ExchangeGraphs to house information about a given translated Bid or Request...
boost::shared_ptr< ExchangeNode > Ptr