1#ifndef CYCLUS_SRC_EXCHANGE_GRAPH_H_
2#define CYCLUS_SRC_EXCHANGE_GRAPH_H_
10#include <boost/weak_ptr.hpp>
11#include <boost/shared_ptr.hpp>
15class ExchangeNodeGroup;
29 typedef boost::shared_ptr<ExchangeNode>
Ptr;
74 Arc(boost::shared_ptr<ExchangeNode>
unode,
75 boost::shared_ptr<ExchangeNode>
vnode);
79 unode_ =
other.unode();
80 vnode_ =
other.vnode();
81 exclusive_ =
other.exclusive();
82 excl_val_ =
other.excl_val();
87 return unode_ <
rhs.unode_ ||
88 (!(
rhs.unode_ < unode_) && vnode_ <
rhs.vnode_);
95 inline boost::shared_ptr<ExchangeNode>
unode()
const {
return unode_.lock(); }
96 inline boost::shared_ptr<ExchangeNode>
vnode()
const {
return vnode_.lock(); }
97 inline bool exclusive()
const {
return exclusive_; }
98 inline double excl_val()
const {
return excl_val_; }
99 inline double pref()
const {
return pref_; }
103 boost::weak_ptr<ExchangeNode> unode_;
104 boost::weak_ptr<ExchangeNode> vnode_;
106 double excl_val_, pref_;
120 typedef boost::shared_ptr<ExchangeNodeGroup>
Ptr;
122 const std::vector<ExchangeNode::Ptr>&
nodes()
const {
return nodes_; }
123 std::vector<ExchangeNode::Ptr>&
nodes() {
return nodes_; }
127 const std::vector< std::vector<ExchangeNode::Ptr> >&
129 return excl_node_groups_;
132 return excl_node_groups_;
136 const std::vector<double>&
capacities()
const {
return capacities_; }
149 excl_node_groups_.push_back(
nodes);
154 for (std::vector<ExchangeNode::Ptr>::iterator
it = nodes_.begin();
157 if (
it->get()->prefs.size() > 0)
171 std::vector<ExchangeNode::Ptr> nodes_;
172 std::vector< std::vector<ExchangeNode::Ptr> > excl_node_groups_;
173 std::vector<double> capacities_;
182 typedef boost::shared_ptr<RequestGroup>
Ptr;
186 double qty() {
return qty_; }
197typedef std::pair<Arc, double>
Match;
209 typedef boost::shared_ptr<ExchangeGraph>
Ptr;
232 return request_groups_;
235 return request_groups_;
239 return supply_groups_;
242 return supply_groups_;
245 inline const std::map<ExchangeNode::Ptr, std::vector<Arc> >&
247 return node_arc_map_;
249 inline std::map<ExchangeNode::Ptr, std::vector<Arc> >&
node_arc_map() {
250 return node_arc_map_;
253 inline const std::vector<Match>&
matches() {
return matches_; }
255 inline const std::vector<Arc>&
arcs()
const {
return arcs_; }
256 inline std::vector<Arc>&
arcs() {
return arcs_; }
258 inline const std::map<Arc, int>&
arc_ids()
const {
return arc_ids_; }
259 inline std::map<Arc, int>&
arc_ids() {
return arc_ids_; }
261 inline const std::map<int, Arc>&
arc_by_id()
const {
return arc_by_id_; }
262 inline std::map<int, Arc>&
arc_by_id() {
return arc_by_id_; }
265 std::vector<RequestGroup::Ptr> request_groups_;
266 std::vector<ExchangeNodeGroup::Ptr> supply_groups_;
267 std::map<ExchangeNode::Ptr, std::vector<Arc> > node_arc_map_;
268 std::vector<Match> matches_;
269 std::vector<Arc> arcs_;
270 std::map<Arc, int> arc_ids_;
271 std::map<int, Arc> arc_by_id_;
An arc represents a possible connection between two nodes in the bipartite resource exchange graph.
Arc & operator=(const Arc &other)
boost::shared_ptr< ExchangeNode > vnode() const
bool operator<(const Arc &rhs) const
bool operator==(const Arc &rhs) const
boost::shared_ptr< ExchangeNode > unode() const
Arc()
default required for usage in maps
An ExchangeGraph is a resource-neutral representation of a ResourceExchange.
const std::vector< Arc > & arcs() const
std::vector< ExchangeNodeGroup::Ptr > & supply_groups()
const std::vector< ExchangeNodeGroup::Ptr > & supply_groups() const
const std::map< ExchangeNode::Ptr, std::vector< Arc > > & node_arc_map() const
void AddRequestGroup(RequestGroup::Ptr prs)
adds a request group to the graph
const std::vector< Match > & matches()
std::map< Arc, int > & arc_ids()
const std::map< Arc, int > & arc_ids() const
std::vector< Arc > & arcs()
void AddSupplyGroup(ExchangeNodeGroup::Ptr prs)
adds a supply group to the graph
void ClearMatches()
clears all matches
const std::vector< RequestGroup::Ptr > & request_groups() const
std::map< int, Arc > & arc_by_id()
void AddMatch(const Arc &a, double qty)
adds a match for a quanity of flow along an arc
std::vector< RequestGroup::Ptr > & request_groups()
const std::map< int, Arc > & arc_by_id() const
void AddArc(const Arc &a)
adds an arc to the graph
std::map< ExchangeNode::Ptr, std::vector< Arc > > & node_arc_map()
boost::shared_ptr< ExchangeGraph > Ptr
A ExchangeNodeGroup is a collection of ExchangeNodes, and is the ExchangeGraph representation of a Bi...
const std::vector< double > & capacities() const
the flow capacities assocaited with this group
void AddCapacity(double c)
Add a flow capacity to the group.
boost::shared_ptr< ExchangeNodeGroup > Ptr
std::vector< ExchangeNode::Ptr > & nodes()
std::vector< std::vector< ExchangeNode::Ptr > > & excl_node_groups()
void AddExclGroup(std::vector< ExchangeNode::Ptr > &nodes)
Adds a node grouping to the set of exclusive node groups, in general this function is used for bid ex...
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
const std::vector< std::vector< ExchangeNode::Ptr > > & excl_node_groups() const
exclusive node groups represent nodes over whose combined arcs flow can only exist on one arc
void AddExclNode(ExchangeNode::Ptr n)
adds a single node to the set of exclusive node groupings, in general this function is used for deman...
std::vector< double > & capacities()
A RequestGroup is a specific ExchangeNodeGroup with a notion of an total requested quantity.
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
taken directly from OsiSolverInterface.cpp on 2/17/14 from https://projects.coin-or....
std::pair< Arc, double > Match
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...
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
std::map< Arc, double > prefs
preference values for arcs
boost::shared_ptr< ExchangeNode > Ptr
std::string commod
the commodity associated with this exchange node