Commit 45775cd8 authored by rmrf's avatar rmrf
Browse files

Formatting should be consistent

parent 97dfc63f
...@@ -4,92 +4,57 @@ using namespace scpar; ...@@ -4,92 +4,57 @@ using namespace scpar;
/// Node class. /// Node class.
Node::Node ():_id (-1) Node::Node() : _id(-1) {}
{
} Node::Node(int i) : _id(i) {}
Node::Node (int i
):
_id (i
)
{
}
int int Node::getId() { return _id; }
Node::getId (
)
{
return _id;
}
void void Node::addSuccessor(Node *s) {
Node::addSuccessor (Node * s _succs.insert(Node::connectPairType(s->getId(), s));
) s->addPredecessor(this);
{
_succs.insert (Node::connectPairType (s->getId (), s));
s->addPredecessor (this);
} }
void void Node::addPredecessor(Node *p) {
Node::addPredecessor (Node * p _preds.insert(Node::connectPairType(p->getId(), p));
)
{
_preds.insert (Node::connectPairType (p->getId (), p));
} }
vector < int > vector<int> Node::getSuccessors(int fromId) {
Node::getSuccessors (int fromId
)
{
vector < int >tmpSuccs; vector<int> tmpSuccs;
for (Node::connectMapType::iterator it = _succs.begin (), eit = for (Node::connectMapType::iterator it = _succs.begin(), eit = _succs.end();
_succs.end (); it != eit; it++) it != eit; it++) {
{
// if(it->first == fromId) { // if(it->first == fromId) {
tmpSuccs.push_back (it->first); tmpSuccs.push_back(it->first);
// } // }
} }
return tmpSuccs; return tmpSuccs;
} }
vector < int > vector<int> Node::getPredecessors(int toId) {
Node::getPredecessors (int toId
)
{
vector < int >tmpPreds; vector<int> tmpPreds;
for (Node::connectMapType::iterator it = _preds.begin (), eit = for (Node::connectMapType::iterator it = _preds.begin(), eit = _preds.end();
_preds.end (); it != eit; it++) it != eit; it++) {
{
// if(it->first == fromId) { // if(it->first == fromId) {
tmpPreds.push_back (it->first); tmpPreds.push_back(it->first);
// } // }
} }
return tmpPreds; return tmpPreds;
} }
void void Node::dump(raw_ostream &os, int tabn) {
Node::dump (raw_ostream & os, int tabn os << "Node " << getId() << "\n";
)
{
os << "Node " << getId () << "\n";
os << " preds: "; os << " preds: ";
for (Node::connectMapType::iterator it = _preds.begin (), eit = for (Node::connectMapType::iterator it = _preds.begin(), eit = _preds.end();
_preds.end (); it != eit; it++) it != eit; it++) {
{
os << it->first << " "; os << it->first << " ";
} }
os << "\n succs: "; os << "\n succs: ";
for (Node::connectMapType::iterator it = _succs.begin (), eit = for (Node::connectMapType::iterator it = _succs.begin(), eit = _succs.end();
_succs.end (); it != eit; it++) it != eit; it++) {
{
os << it->first << " "; os << it->first << " ";
} }
os << "\n"; os << "\n";
...@@ -97,380 +62,262 @@ void ...@@ -97,380 +62,262 @@ void
//////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////
/// Edge class. /// Edge class.
Edge::Edge (Node * f, Node * t):_id (-1), _from (f), _to (t) Edge::Edge(Node *f, Node *t) : _id(-1), _from(f), _to(t) {}
{
}
Edge::Edge (Node * f, Node * t, int i
):
_id (i
),
_from (f
),
_to (t
)
{
} Edge::Edge(Node *f, Node *t, int i) : _id(i), _from(f), _to(t) {}
void void Edge::updateSuspensionTime(timePairType timePair) {
Edge::updateSuspensionTime (timePairType timePair _timeAdvanceVector.push_back(timePair);
)
{
_timeAdvanceVector.push_back (timePair);
} }
int int Edge::getId() { return _id; }
Edge::getId (
)
{
return _id;
}
void void Edge::dump(raw_ostream &os, int tabn) {
Edge::dump (raw_ostream & os, int tabn os << "Edge (" << _from->getId() << "," << _to->getId() << ")\n";
)
{
os << "Edge (" << _from->getId () << "," << _to->getId () << ")\n";
} }
int int Edge::getToId() { return _to->getId(); }
Edge::getToId (
)
{
return _to->getId ();
}
int int Edge::getFromId() { return _from->getId(); }
Edge::getFromId (
)
{
return _from->getId ();
}
Edge::timeAdvanceVectorType Edge::getTimeAdvanceVector () Edge::timeAdvanceVectorType Edge::getTimeAdvanceVector() {
{
return _timeAdvanceVector; return _timeAdvanceVector;
} }
//////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////
/// Graph class /// Graph class
Graph::Graph ():_nNodes (0), _nEdges (0) Graph::Graph() : _nNodes(0), _nEdges(0) {}
{
}
Node * Node *Graph::addNode() {
Graph::addNode ( Node *n = new Node(_nNodes);
)
{
Node *n = new Node (_nNodes);
_nodeMap.insert (Graph::nodePairType (_nNodes, n)); _nodeMap.insert(Graph::nodePairType(_nNodes, n));
_nodeVector.push_back (n); _nodeVector.push_back(n);
_nodeIDVector.push_back (_nNodes); _nodeIDVector.push_back(_nNodes);
++_nNodes; ++_nNodes;
return n; return n;
} }
Node * Node *Graph::addNode(int id) {
Graph::addNode (int id Node *n = new Node(id);
)
{
Node *n = new Node (id);
_nodeMap.insert (Graph::nodePairType (id, n)); _nodeMap.insert(Graph::nodePairType(id, n));
_nodeVector.push_back (n); _nodeVector.push_back(n);
_nodeIDVector.push_back (id); _nodeIDVector.push_back(id);
++_nNodes; ++_nNodes;
return n; return n;
} }
Edge * Edge *Graph::addEdge(Node *f, Node *t) {
Graph::addEdge (Node * f, Node * t Edge *e = new Edge(f, t, _nEdges);
)
{
Edge *e = new Edge (f, t, _nEdges);
_edgeMap.insert (Graph::edgePairType (_nEdges, e)); _edgeMap.insert(Graph::edgePairType(_nEdges, e));
// Update preds and succs in nodes. // Update preds and succs in nodes.
f->addSuccessor (t); f->addSuccessor(t);
++_nEdges; ++_nEdges;
// Insert in adjacency list. // Insert in adjacency list.
_adjList.insert (Graph::adjPairType _adjList.insert(
(Graph::twoNodePairType (f->getId (), t->getId ()), e)); Graph::adjPairType(Graph::twoNodePairType(f->getId(), t->getId()), e));
return e; return e;
} }
Edge * Edge *Graph::addEdge(int fID, int tID) {
Graph::addEdge (int fID, int tID
)
{
Node *f, *t; Node *f, *t;
if (_nodeMap.find (fID) != _nodeMap.end ()) if (_nodeMap.find(fID) != _nodeMap.end()) {
{ nodeMapType::iterator nodeFound = _nodeMap.find(fID);
nodeMapType::iterator nodeFound = _nodeMap.find (fID);
f = nodeFound->second; f = nodeFound->second;
} } else {
else f = new Node(fID);
{ _nodeMap.insert(nodePairType(fID, f));
f = new Node (fID); _nodeVector.push_back(f);
_nodeMap.insert (nodePairType (fID, f)); _nodeIDVector.push_back(fID);
_nodeVector.push_back (f);
_nodeIDVector.push_back (fID);
_nNodes++; _nNodes++;
} }
if (_nodeMap.find (tID) != _nodeMap.end ()) if (_nodeMap.find(tID) != _nodeMap.end()) {
{ nodeMapType::iterator nodeFound = _nodeMap.find(tID);
nodeMapType::iterator nodeFound = _nodeMap.find (tID);
t = nodeFound->second; t = nodeFound->second;
} } else {
else t = new Node(tID);
{ _nodeMap.insert(nodePairType(tID, t));
t = new Node (tID); _nodeVector.push_back(t);
_nodeMap.insert (nodePairType (tID, t)); _nodeIDVector.push_back(tID);
_nodeVector.push_back (t);
_nodeIDVector.push_back (tID);
_nNodes++; _nNodes++;
} }
Edge *e = new Edge (f, t, _nEdges); Edge *e = new Edge(f, t, _nEdges);
_edgeMap.insert (Graph::edgePairType (_nEdges, e)); _edgeMap.insert(Graph::edgePairType(_nEdges, e));
// Update preds and succs in nodes. // Update preds and succs in nodes.
f->addSuccessor (t); f->addSuccessor(t);
++_nEdges; ++_nEdges;
// Insert in adjacency list. // Insert in adjacency list.
_adjList.insert (Graph::adjPairType _adjList.insert(
(Graph::twoNodePairType (f->getId (), t->getId ()), e)); Graph::adjPairType(Graph::twoNodePairType(f->getId(), t->getId()), e));
return e; return e;
} }
int int Graph::getNodeID(Node *n) {
Graph::getNodeID (Node * n for (nodeMapType::iterator it = _nodeMap.begin(), eit = _nodeMap.end();
) it != eit; it++) {
{ if (n == it->second) {
for (nodeMapType::iterator it = _nodeMap.begin (), eit = _nodeMap.end ();
it != eit; it++)
{
if (n == it->second)
{
return it->first; return it->first;
} }
} }
return -1; return -1;
} }
int int Graph::getEdgeID(Edge *e) {
Graph::getEdgeID (Edge * e for (edgeMapType::iterator it = _edgeMap.begin(), eit = _edgeMap.end();
) it != eit; it++) {
{ if (it->second == e) {
for (edgeMapType::iterator it = _edgeMap.begin (), eit = _edgeMap.end ();
it != eit; it++)
{
if (it->second == e)
{
return it->first; return it->first;
} }
} }
return -1; return -1;
} }
int int Graph::getEdgeID(Node *f, Node *t) {
Graph::getEdgeID (Node * f, Node * t if (_adjList.find(twoNodePairType(f->getId(), t->getId())) !=
) _adjList.end()) {
{
if (_adjList.find (twoNodePairType (f->getId (), t->getId ())) !=
_adjList.end ())
{
adjMapType::iterator edgeFound = adjMapType::iterator edgeFound =
_adjList.find (twoNodePairType (f->getId (), t->getId ())); _adjList.find(twoNodePairType(f->getId(), t->getId()));
return getEdgeID (edgeFound->second); return getEdgeID(edgeFound->second);
} }
return -1; return -1;
} }
int int Graph::getEdgeID(int fID, int tID) {
Graph::getEdgeID (int fID, int tID if (_adjList.find(twoNodePairType(fID, tID)) != _adjList.end()) {
) adjMapType::iterator edgeFound = _adjList.find(twoNodePairType(fID, tID));
{ return getEdgeID(edgeFound->second);
if (_adjList.find (twoNodePairType (fID, tID)) != _adjList.end ())
{
adjMapType::iterator edgeFound =
_adjList.find (twoNodePairType (fID, tID));
return getEdgeID (edgeFound->second);
} }
return -1; return -1;
} }
Edge * Edge *Graph::getEdge(int f, int t) {
Graph::getEdge (int f, int t Graph::adjMapType::iterator fit = _adjList.find(Graph::twoNodePairType(f, t));
) if (fit == _adjList.end()) {
{
Graph::adjMapType::iterator fit =
_adjList.find (Graph::twoNodePairType (f, t));
if (fit == _adjList.end ())
{
return NULL; return NULL;
} }
return fit->second; return fit->second;
} }
Edge * Edge *Graph::getEdge(Node *f, Node *t) {
Graph::getEdge (Node * f, Node * t
)
{
Graph::adjMapType::iterator fit = Graph::adjMapType::iterator fit =
_adjList.find (Graph::twoNodePairType (f->getId (), t->getId ())); _adjList.find(Graph::twoNodePairType(f->getId(), t->getId()));
if (fit == _adjList.end ()) if (fit == _adjList.end()) {
{
return NULL; return NULL;
} }
return fit->second; return fit->second;
} }
Node * Node *Graph::getNode(int nodeID) {
Graph::getNode (int nodeID if (_nodeMap.find(nodeID) != _nodeMap.end()) {
) nodeMapType::iterator nodeFound = _nodeMap.find(nodeID);
{
if (_nodeMap.find (nodeID) != _nodeMap.end ())
{
nodeMapType::iterator nodeFound = _nodeMap.find (nodeID);
return nodeFound->second; return nodeFound->second;
} }
return NULL; return NULL;
} }
vector < Edge * >Graph::getEdgesFromSource (int sourceID) vector<Edge *> Graph::getEdgesFromSource(int sourceID) {
{ vector<Edge *> edges;
vector < Edge * >edges; for (adjMapType::iterator it = _adjList.begin(), eit = _adjList.end();
for (adjMapType::iterator it = _adjList.begin (), eit = _adjList.end (); it != eit; it++) {
it != eit; it++)
{
twoNodePairType nodePair = it->first; twoNodePairType nodePair = it->first;
if (nodePair.first == sourceID) if (nodePair.first == sourceID) {
{ edges.push_back(it->second);
edges.push_back (it->second);
} }
} }
return edges; return edges;
} }
vector < Edge * >Graph::getEdgesFromDest (int destID) vector<Edge *> Graph::getEdgesFromDest(int destID) {
{ vector<Edge *> edges;
vector < Edge * >edges; for (adjMapType::iterator it = _adjList.begin(), eit = _adjList.end();
for (adjMapType::iterator it = _adjList.begin (), eit = _adjList.end (); it != eit; it++) {
it != eit; it++)
{
twoNodePairType nodePair = it->first; twoNodePairType nodePair = it->first;
if (nodePair.second == destID) if (nodePair.second == destID) {
{ edges.push_back(it->second);
edges.push_back (it->second);
} }
} }
return edges; return edges;
} }
vector < Edge * >Graph::getEdgesFromSource (Node * sourceNode) vector<Edge *> Graph::getEdgesFromSource(Node *sourceNode) {
{ for (nodeMapType::iterator it = _nodeMap.begin(), eit = _nodeMap.end();
for (nodeMapType::iterator it = _nodeMap.begin (), eit = _nodeMap.end (); it != eit; it++) {
it != eit; it++) if (it->second == sourceNode) {
{ getEdgesFromSource(it->first);
if (it->second == sourceNode)
{
getEdgesFromSource (it->first);
} }
} }
} }
vector<Edge *> Graph::getEdgesFromDest(Node *destNode) {
vector < Edge * >Graph::getEdgesFromDest (Node * destNode) for (nodeMapType::iterator it = _nodeMap.begin(), eit = _nodeMap.end();
{ it != eit; it++) {
for (nodeMapType::iterator it = _nodeMap.begin (), eit = _nodeMap.end (); if (it->second == destNode) {
it != eit; it++) getEdgesFromDest(it->first);
{
if (it->second == destNode)
{
getEdgesFromDest (it->first);
} }
} }
} }
void void Graph::dump(raw_ostream &os, int tabn) {
Graph::dump (raw_ostream & os, int tabn