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
13 int agent_id)
14 : qty(qty),
18 group(NULL) {}
19
22
24 : qty(qty),
27 agent_id(-1),
28 group(NULL) {}
29
31 : qty(qty), exclusive(false), commod(""), agent_id(-1), group(NULL) {}
32
34 : qty(std::numeric_limits<double>::max()),
35 exclusive(false),
36 commod(""),
37 agent_id(-1),
38 group(NULL) {}
39
40// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
41bool operator==(const ExchangeNode& lhs, const ExchangeNode& rhs) {
42 return (lhs.unit_capacities == rhs.unit_capacities && lhs.qty == rhs.qty &&
43 lhs.exclusive == rhs.exclusive && lhs.group == rhs.group &&
44 lhs.commod == rhs.commod);
45}
46
47// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
48Arc::Arc(boost::shared_ptr<ExchangeNode> unode,
49 boost::shared_ptr<ExchangeNode>
50 vnode)
51 : unode_(unode), vnode_(vnode) {
52 exclusive_ = unode->exclusive || vnode->exclusive;
53 if (exclusive_) {
54 double fqty = unode->qty;
55 double sqty = vnode->qty;
56 // this careful float comparison is vital for preventing false positive
57 // constraint violations w.r.t. exclusivity-related capacity.
58 double dist = boost::math::float_distance(fqty, sqty);
59 if (unode->exclusive && vnode->exclusive) {
60 excl_val_ = (std::abs(dist) <= float_ulp_eq) ? fqty : 0;
61 } else if (unode->exclusive) {
62 excl_val_ = dist >= -float_ulp_eq ? fqty : 0;
63 } else {
64 excl_val_ = dist <= float_ulp_eq ? sqty : 0;
65 }
66 } else {
67 excl_val_ = 0;
68 }
69}
70
71// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
72Arc::Arc(const Arc& other)
73 : unode_(other.unode()),
74 vnode_(other.vnode()),
75 pref_(other.pref()),
76 exclusive_(other.exclusive()),
77 excl_val_(other.excl_val()) {}
78
79// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
81 node->group = this;
82 nodes_.push_back(node);
83}
84
85// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
87 std::vector<ExchangeNode::Ptr> nodes;
88 nodes.push_back(node);
89 excl_node_groups_.push_back(nodes);
90}
91
92// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
94
95// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
102
103// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
104ExchangeGraph::ExchangeGraph() : next_arc_id_(0) {}
105
106// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
108 request_groups_.push_back(prs);
109}
110
111// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
113 supply_groups_.push_back(pss);
114}
115
116// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
118 arcs_.push_back(a);
119 int id = next_arc_id_++;
120 arc_ids_.insert(std::pair<Arc, int>(a, id));
121 arc_by_id_.insert(std::pair<int, Arc>(id, a));
122 node_arc_map_[a.unode()].push_back(a);
123 node_arc_map_[a.vnode()].push_back(a);
124}
125
126// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
127void ExchangeGraph::AddMatch(const Arc& a, double qty) {
128 matches_.push_back(std::make_pair(a, qty));
129}
130
131} // namespace cyclus
An arc represents a possible connection between two nodes in the bipartite resource exchange graph.
boost::shared_ptr< ExchangeNode > vnode() const
double pref() const
boost::shared_ptr< ExchangeNode > unode() const
double excl_val() const
bool exclusive() 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.
ExchangeNodes are used in ExchangeGraphs to house information about a given translated Bid or Request...
int agent_id
the id of the agent associated with this node
bool exclusive
whether this node represents an exclusive request or offer
ExchangeNodeGroup * group
the parent ExchangeNodeGroup to which this ExchangeNode belongs
std::map< Arc, std::vector< double > > unit_capacities
unit values associated with this ExchangeNode corresponding to capacties of its parent ExchangeNodeGr...
double qty
the maximum amount of a resource that can be associated with this node
boost::shared_ptr< ExchangeNode > Ptr
std::string commod
the commodity associated with this exchange node