31 #ifndef __adevs_digraph_h_
32 #define __adevs_digraph_h_
46 template <
class VALUE,
class PORT=
int>
class PortValue
88 template <
class VALUE,
class PORT=
int,
class T =
double>
class Digraph:
89 public Network<PortValue<VALUE,PORT>,T>
129 const node& operator=(
const node& src)
139 bool operator<(
const node& other)
const
141 if (model == other.model)
return port < other.port;
142 return model < other.model;
146 Set<Component*> models;
148 std::map<node,Bag<node> > graph;
151 template <
class VALUE,
class PORT,
class T>
154 assert(model !=
this);
155 models.insert(model);
159 template <
class VALUE,
class PORT,
class T>
163 if (src !=
this) add(src);
164 if (dst !=
this) add(dst);
165 node src_node(src,srcPort);
166 node dst_node(dst,dstPort);
167 graph[src_node].insert(dst_node);
170 template <
class VALUE,
class PORT,
class T>
176 template <
class VALUE,
class PORT,
class T>
182 node src_node(model,x.
port);
183 typename std::map<node,Bag<node> >::iterator graph_iter;
184 graph_iter = graph.find(src_node);
186 if (graph_iter == graph.end())
return;
190 for (node_iter = (*graph_iter).second.begin();
191 node_iter != (*graph_iter).second.end(); node_iter++)
193 event.model = (*node_iter).model;
194 event.value.port = (*node_iter).port;
195 event.value.value = x.
value;
199 template <
class VALUE,
class PORT,
class T>
203 for (i = models.begin(); i != models.end(); i++)
Definition: adevs_set.h:42
const PortValue< VALUE, PORT > & operator=(const PortValue< VALUE, PORT > &src)
Assignment operator.
Definition: adevs_digraph.h:68
Digraph()
Construct a network with no components.
Definition: adevs_digraph.h:98
Definition: adevs_digraph.h:46
PortValue(const PortValue &src)
Copy constructor.
Definition: adevs_digraph.h:56
PortValue()
Constructor.
Definition: adevs_digraph.h:50
void route(const IO_Type &x, Component *model, Bag< Event< IO_Type, T > > &r)
Route an event based on the coupling information.
Definition: adevs_digraph.h:178
Definition: adevs_models.h:46
PORT port
The port on which the value appears.
Definition: adevs_digraph.h:79
void setParent(Network< X, T > *parent)
Definition: adevs_models.h:96
Devs< IO_Type, T > Component
A component of the Digraph model.
Definition: adevs_digraph.h:95
~PortValue()
Destructor.
Definition: adevs_digraph.h:75
void couple(Component *src, PORT srcPort, Component *dst, PORT dstPort)
Couple the source model to the destination model.
Definition: adevs_digraph.h:160
PortValue< VALUE, PORT > IO_Type
An input or output to a component model.
Definition: adevs_digraph.h:93
A bidirectional iterator for the Bag.
Definition: adevs_bag.h:49
PortValue(PORT port, const VALUE &value)
Create an object with the specified port and value.
Definition: adevs_digraph.h:62
~Digraph()
Destructor. Destroys all of the component models.
Definition: adevs_digraph.h:200
VALUE value
The value appearing on the port.
Definition: adevs_digraph.h:81
Definition: adevs_models.h:63
Definition: adevs_digraph.h:88
Definition: adevs_models.h:142
void getComponents(Set< Component * > &c)
Puts the network's components into to c.
Definition: adevs_digraph.h:171
void add(Component *model)
Add a model to the network.
Definition: adevs_digraph.h:152
Definition: adevs_bag.h:45