1 #ifndef __DIADES__AUTOMATA__TOPOLOGY__HH 2 #define __DIADES__AUTOMATA__TOPOLOGY__HH 5 #include <unordered_set> 12 using std::unordered_set;
52 static string typeName() {
return "AutModel::Topology"; }
61 while((!found) && (nodeIt!=
nodeEnd()))
63 found = _labels[*nodeIt] == name;
77 throw Exception(
"getNodeOfName(): the operation did not succeed", e);
88 require(Exception,node.valid(),
"setNodeName(): the node is not valid");
89 require(Exception,&node.owner() == &
graph(),
"setNodeName(): the node does not belong to the topology");
94 throw Exception(
"setNodeName(): the operation did not succeed", e);
102 require(Exception,node.valid(),
"getNodeName(): the node is not valid");
103 require(Exception,&node.owner() == &
graph(),
"getNodeName(): the node does not belong to the topology");
104 return _labels[node];
108 throw Exception(
"getNodeName(): the operation did not succeed", e);
110 return _labels[node];
118 require(Exception,connection.valid(),
"getConnectionLabel(): the connection is not valid");
119 require(Exception,&connection.owner() == &
graph(),
"getConnectionLabel(): the connection does not belong to the topology");
120 return _labels[connection];
124 throw Exception(
"setConnectionEventLabel(): the operation did not succeed", e);
126 return _labels[connection];
133 require(Exception,connection.valid(),
"setConnectionEventLabel(): the connection is not valid");
134 require(Exception,&connection.owner() == &
graph(),
"setConnectionEventLabel(): the connection does not belong to the topology");
135 _labels[connection]=label;
139 throw Exception(
"setConnectionEventLabel(): the operation did not succeed", e);
157 reference
operator*()
const {
return _it->targetRef(); }
161 bool operator==(
const self & it)
const {
return _it == it._it; }
162 bool operator !=(
const self & it)
const {
return !(*
this == it); }
179 return _nodes.size();
190 return _connections.size();
204 require(Exception, connection.valid() && (&connection.owner() == &
graph()),
"isSimple(): the connection is invalid");
207 return connection.outDeg() == 2;
211 throw Exception(
"isSimple(): the operation did not succeed", e);
236 Connection
addConnection(Node n1, Node n2,
const Identifier & label);
245 return connection.outDeg();
262 require(Exception, connection.valid() && (&connection.owner() == &
graph()),
"cliqueBegin(): the connection is invalid");
267 throw Exception(
"cliqueBegin(): the operation did not succeed", e);
283 require(Exception, connection.valid() && (&connection.owner() == &
graph()),
"cliqueEnd: the connection is invalid");
290 throw Exception(
"cliqueEnd(): the operation did not succeed", e);
306 return _connections.begin();
316 return _connections.end();
323 Topology():_graph(),_connections(),_nodes(),_labels()
325 _labels.
init(_graph);
344 unsigned nbConnections(
const Node & n1,
const Node & n2)
const;
373 bool isConnected(
const Node & n1,
const Node & n2)
const;
380 void getConnections(
const Node & n1,
const Node & n2, list<Connection> & connections)
const;
390 Connection
addClique(
const set<Node> & clique);
403 result = _graph.newNode();
404 _nodes.insert(result);
406 stream <<
"n" << result.id();
408 ensure(Exception, result.valid() && (&result.owner() == &
graph()),
"addNode: the returned node is invalid");
412 throw Exception(
"addNode: cannot add a new node to the topology");
429 result = _graph.newNode();
430 _nodes.insert(result);
431 _labels[result] = name;
432 ensure(Exception, result.valid() && (&result.owner() == &
graph()),
"addNode: the returned node is invalid");
436 throw Exception(
"addNode: cannot add a new node to the topology");
449 return _nodes.begin();
473 require(Exception, n.valid() && (&n.owner() == &
graph()),
"nodeConnectionBegin: the node is invalid");
478 throw Exception(
"nodeConnectionBegin(): cannot get an iterator about the connection of a node",e);
493 require(Exception, n.valid() && (&n.owner() == &
graph()),
"nodeConnectionEnd: the node is invalid");
498 throw Exception(
"nodeConnectionEnd(): cannot get an iterator about the connection of a node",e);
509 require(Exception, connection.valid() && (&connection.owner() == &
graph()),
"removeConnection: the connection is invalid");
510 _connections.erase(connection);
511 _graph.deleteNode(connection);
547 void import(
const string & fileName);
562 void save(
const string & fileName);
577 return this == &topology;
583 require(Exception, node.valid(),
"contains(): invalid node");
586 return &node.owner() == &
graph();
590 throw Exception(
"contains(): the operation did not succeed",e);
619 const Identifier & connectionEventLabel);
unordered_set< Node >::const_iterator NodeIterator
Connection addConnection(Node n1, Node n2)
An Identifier is a reference to a string (IdentifierData) that only contains alpha-numeric characters...
CliqueIterator cliqueBegin(Connection connection) const
ConnectionIterator connectionBegin() const
ptrdiff_t difference_type
unsigned structuralConnectivity(const Node &n) const
Node addNode(const Identifier &name)
NodeIterator nodeEnd() const
Diades::Graph::Node Connection
Diades::Graph::Graph Graph
void init(Graph &g, SizeType capacity=0, ValueType dflt=ValueType())
Diades::Utils::Exception< Topology > Exception
unsigned cliqueSize(Connection connection) const
#define ensure(Exception, expr, message)
Node getNodeOfName(const Identifier &name) const
NodeConnectionIterator nodeConnectionEnd(Node n) const
void topology2dot(const string &fileName)
void removeConnection(Connection connection)
unordered_set< Connection > _connections
void setNodeName(Node node, const Identifier &name)
const Graph & graph() const
CliqueIterator(SupportIterator it)
NodeConnectionIterator nodeConnectionBegin(Node n) const
unordered_set< Connection >::const_iterator ConnectionIterator
NodeIterator nodeBegin() const
const Diades::Graph::Node * pointer
bool operator==(const Topology &topology) const
bool isSimple(const Connection &connection) const
#define require(Exception, expr, message)
Namespace of the Diades project.
pointer operator->() const
void setConnectionLabel(Connection connection, const Identifier &label)
void save(const string &fileName)
reference operator*() const
const Identifier & getNodeName(Node node) const
const Diades::Graph::Node & reference
list< Edge >::iterator OutEdgeIterator
unordered_set< Node > _nodes
Connection addClique(const set< Node > &clique)
const Identifier & getConnectionLabel(Connection connection) const
bool contains(Node node) const
CliqueIterator NodeConnectionIterator
unsigned numberOfConnections() const
unsigned numberOfNodes() const
bool operator==(const self &it) const
Diades::Utils::Identifier Identifier
Topology::Connection getConnection(const Topology &topology, const set< Topology::Node > &clique, const Identifier &connectionEventLabel)
unsigned nbConnections(const Node &n1, const Node &n2) const
ConnectionIterator connectionEnd() const
std::forward_iterator_tag iterator_category
Diades::Graph::NodeMap< Identifier > _labels
bool operator!=(const self &it) const
bool isConnected(const Node &n1, const Node &n2) const
void getConnections(const Node &n1, const Node &n2, list< Connection > &connections) const
Diades::Graph::Node value_type
unsigned connectivity(const Node &n) const
CliqueIterator cliqueEnd(Connection connection) const
Diades::Graph::OutEdgeIterator SupportIterator