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

Formatting should be consistent

parent 97dfc63f
...@@ -4,497 +4,342 @@ using namespace scpar; ...@@ -4,497 +4,342 @@ 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;
for (Node::connectMapType::iterator it = _succs.begin (), eit = vector<int> tmpSuccs;
_succs.end (); it != eit; it++)
{
// if(it->first == fromId) {
tmpSuccs.push_back (it->first);
// }
}
return tmpSuccs;
for (Node::connectMapType::iterator it = _succs.begin(), eit = _succs.end();
it != eit; it++) {
// if(it->first == fromId) {
tmpSuccs.push_back(it->first);
// }
}
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 =
_preds.end (); it != eit; it++)
{
// if(it->first == fromId) {
tmpPreds.push_back (it->first);
// }
}
return tmpPreds;
for (Node::connectMapType::iterator it = _preds.begin(), eit = _preds.end();
it != eit; it++) {
// if(it->first == fromId) {
tmpPreds.push_back(it->first);
// }
}
return tmpPreds;
} }
void void Node::dump(raw_ostream &os, int tabn) {
Node::dump (raw_ostream & os, int tabn os << "Node " << getId() << "\n";
) os << " preds: ";
{ for (Node::connectMapType::iterator it = _preds.begin(), eit = _preds.end();
os << "Node " << getId () << "\n"; it != eit; it++) {
os << " preds: "; os << it->first << " ";
for (Node::connectMapType::iterator it = _preds.begin (), eit = }
_preds.end (); it != eit; it++) os << "\n succs: ";
{ for (Node::connectMapType::iterator it = _succs.begin(), eit = _succs.end();
os << it->first << " "; it != eit; it++) {
} os << it->first << " ";
os << "\n succs: "; }
for (Node::connectMapType::iterator it = _succs.begin (), eit = os << "\n";
_succs.end (); it != eit; it++)
{
os << it->first << " ";
}
os << "\n";
} }
//////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////
/// 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 Edge::updateSuspensionTime(timePairType timePair) {
_timeAdvanceVector.push_back(timePair);
} }
void int Edge::getId() { return _id; }
Edge::updateSuspensionTime (timePairType timePair
)
{
_timeAdvanceVector.push_back (timePair);
}
int void Edge::dump(raw_ostream &os, int tabn) {
Edge::getId ( os << "Edge (" << _from->getId() << "," << _to->getId() << ")\n";
)
{
return _id;
} }
void int Edge::getToId() { return _to->getId(); }
Edge::dump (raw_ostream & os, int tabn
)
{
os << "Edge (" << _from->getId () << "," << _to->getId () << ")\n";
}
int int Edge::getFromId() { return _from->getId(); }
Edge::getToId (
)
{
return _to->getId ();
}
int Edge::timeAdvanceVectorType Edge::getTimeAdvanceVector() {
Edge::getFromId ( return _timeAdvanceVector;
)
{
return _from->getId ();
}
Edge::timeAdvanceVectorType Edge::getTimeAdvanceVector ()
{
return _timeAdvanceVector;
} }
//////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////
/// Graph class /// Graph class
Graph::Graph ():_nNodes (0), _nEdges (0) Graph::Graph() : _nNodes(0), _nEdges(0) {}
{
Node *Graph::addNode() {
} Node *n = new Node(_nNodes);
Node * _nodeMap.insert(Graph::nodePairType(_nNodes, n));
Graph::addNode ( _nodeVector.push_back(n);
) _nodeIDVector.push_back(_nNodes);
{ ++_nNodes;
Node *n = new Node (_nNodes); return n;
}
_nodeMap.insert (Graph::nodePairType (_nNodes, n));
_nodeVector.push_back (n); Node *Graph::addNode(int id) {
_nodeIDVector.push_back (_nNodes); Node *n = new Node(id);
++_nNodes;
return n; _nodeMap.insert(Graph::nodePairType(id, n));
} _nodeVector.push_back(n);
_nodeIDVector.push_back(id);
Node * ++_nNodes;
Graph::addNode (int id return n;
) }
{
Node *n = new Node (id); Edge *Graph::addEdge(Node *f, Node *t) {
Edge *e = new Edge(f, t, _nEdges);
_nodeMap.insert (Graph::nodePairType (id, n));
_nodeVector.push_back (n); _edgeMap.insert(Graph::edgePairType(_nEdges, e));
_nodeIDVector.push_back (id);
++_nNodes; // Update preds and succs in nodes.
return n; f->addSuccessor(t);
} ++_nEdges;
Edge * // Insert in adjacency list.
Graph::addEdge (Node * f, Node * t _adjList.insert(
) Graph::adjPairType(Graph::twoNodePairType(f->getId(), t->getId()), e));
{ return e;
Edge *e = new Edge (f, t, _nEdges); }
_edgeMap.insert (Graph::edgePairType (_nEdges, e)); Edge *Graph::addEdge(int fID, int tID) {
Node *f, *t;
// Update preds and succs in nodes.
f->addSuccessor (t); if (_nodeMap.find(fID) != _nodeMap.end()) {
++_nEdges; nodeMapType::iterator nodeFound = _nodeMap.find(fID);
f = nodeFound->second;
// Insert in adjacency list. } else {
_adjList.insert (Graph::adjPairType f = new Node(fID);
(Graph::twoNodePairType (f->getId (), t->getId ()), e)); _nodeMap.insert(nodePairType(fID, f));
return e; _nodeVector.push_back(f);
} _nodeIDVector.push_back(fID);
_nNodes++;
Edge * }
Graph::addEdge (int fID, int tID if (_nodeMap.find(tID) != _nodeMap.end()) {
) nodeMapType::iterator nodeFound = _nodeMap.find(tID);
{ t = nodeFound->second;
Node *f, *t; } else {
t = new Node(tID);
if (_nodeMap.find (fID) != _nodeMap.end ()) _nodeMap.insert(nodePairType(tID, t));
{ _nodeVector.push_back(t);
nodeMapType::iterator nodeFound = _nodeMap.find (fID); _nodeIDVector.push_back(tID);
f = nodeFound->second; _nNodes++;
} }
else Edge *e = new Edge(f, t, _nEdges);
{
f = new Node (fID); _edgeMap.insert(Graph::edgePairType(_nEdges, e));
_nodeMap.insert (nodePairType (fID, f));
_nodeVector.push_back (f); // Update preds and succs in nodes.
_nodeIDVector.push_back (fID); f->addSuccessor(t);
_nNodes++; ++_nEdges;
}
if (_nodeMap.find (tID) != _nodeMap.end ()) // Insert in adjacency list.
{ _adjList.insert(
nodeMapType::iterator nodeFound = _nodeMap.find (tID); Graph::adjPairType(Graph::twoNodePairType(f->getId(), t->getId()), e));
t = nodeFound->second; return e;
} }
else
{ int Graph::getNodeID(Node *n) {
t = new Node (tID); for (nodeMapType::iterator it = _nodeMap.begin(), eit = _nodeMap.end();
_nodeMap.insert (nodePairType (tID, t)); it != eit; it++) {
_nodeVector.push_back (t); if (n == it->second) {
_nodeIDVector.push_back (tID); return it->first;
_nNodes++; }
} }
Edge *e = new Edge (f, t, _nEdges); return -1;
}
_edgeMap.insert (Graph::edgePairType (_nEdges, e));
int Graph::getEdgeID(Edge *e) {
// Update preds and succs in nodes. for (edgeMapType::iterator it = _edgeMap.begin(), eit = _edgeMap.end();
f->addSuccessor (t); it != eit; it++) {
++_nEdges; if (it->second == e) {
return it->first;
// Insert in adjacency list. }
_adjList.insert (Graph::adjPairType }
(Graph::twoNodePairType (f->getId (), t->getId ()), e)); return -1;
return e; }
}
int Graph::getEdgeID(Node *f, Node *t) {
int if (_adjList.find(twoNodePairType(f->getId(), t->getId())) !=
Graph::getNodeID (Node * n _adjList.end()) {
) adjMapType::iterator edgeFound =
{ _adjList.find(twoNodePairType(f->getId(), t->getId()));
for (nodeMapType::iterator it = _nodeMap.begin (), eit = _nodeMap.end (); return getEdgeID(edgeFound->second);
it != eit; it++) }
{ return -1;
if (n == it->second) }
{
return it->first; int Graph::getEdgeID(int fID, int tID) {
} if (_adjList.find(twoNodePairType(fID, tID)) != _adjList.end()) {
} adjMapType::iterator edgeFound = _adjList.find(twoNodePairType(fID, tID));
return -1; return getEdgeID(edgeFound->second);
} }
return -1;
int }
Graph::getEdgeID (Edge * e
) Edge *Graph::getEdge(int f, int t) {
{ Graph::adjMapType::iterator fit = _adjList.find(Graph::twoNodePairType(f, t));
for (edgeMapType::iterator it = _edgeMap.begin (), eit = _edgeMap.end (); if (fit == _adjList.end()) {
it != eit; it++) return NULL;
{ }
if (it->second == e) return fit->second;
{ }
return it->first;
} Edge *Graph::getEdge(Node *f, Node *t) {
} Graph::adjMapType::iterator fit =
return -1; _adjList.find(Graph::twoNodePairType(f->getId(), t->getId()));
} if (fit == _adjList.end()) {
return NULL;
int }
Graph::getEdgeID (Node * f, Node * t
) return fit->second;
{ }
if (_adjList.find (twoNodePairType (f->getId (), t->getId ())) !=
_adjList.end ()) Node *Graph::getNode(int nodeID) {
{ if (_nodeMap.find(nodeID) != _nodeMap.end()) {
adjMapType::iterator edgeFound = nodeMapType::iterator nodeFound = _nodeMap.find(nodeID);
_adjList.find (twoNodePairType (f->getId (), t->getId ())); return nodeFound->second;
return getEdgeID (edgeFound->second); }
} return NULL;
return -1; }
}
vector<Edge *> Graph::getEdgesFromSource(int sourceID) {
vector<Edge *> edges;
for (adjMapType::iterator it = _adjList.begin(), eit = _adjList.end();
it != eit; it++) {
twoNodePairType nodePair = it->first;
if (nodePair.first == sourceID) {
edges.push_back(it->second);
}
}
return edges;
}
vector<Edge *> Graph::getEdgesFromDest(int destID) {
vector<Edge *> edges;
for (adjMapType::iterator it = _adjList.begin(), eit = _adjList.end();
it != eit; it++) {
twoNodePairType nodePair = it->first;
if (nodePair.second == destID) {
edges.push_back(it->second);
}
}
return edges;
}
vector<Edge *> Graph::getEdgesFromSource(Node *sourceNode) {
for (nodeMapType::iterator it = _nodeMap.begin(), eit = _nodeMap.end();
it != eit; it++) {
if (it->second == sourceNode) {
getEdgesFromSource(it->first);
}
}
}
vector<Edge *> Graph::getEdgesFromDest(Node *destNode) {
for (nodeMapType::iterator it = _nodeMap.begin(), eit = _nodeMap.end();
it != eit; it++) {
if (it->second == destNode) {
getEdgesFromDest(it->first);
}
}
}
void Graph::dump(raw_ostream &os, int tabn) {
// Print all nodes.
os << "Node map: " << _nNodes << "\n";
for (Graph::nodeMapType::iterator it = _nodeMap.begin(), eit = _nodeMap.end();
it != eit; it++) {
os << it->first << " " << it->second << " ";
it->second->dump(os, tabn++);
}
int // Print all Edges.
Graph::getEdgeID (int fID, int tID os << "Edge map: " << _nEdges << "\n";
) for (Graph::edgeMapType::iterator it = _edgeMap.begin(), eit = _edgeMap.end();
{ it != eit; it++) {
if (_adjList.find (twoNodePairType (fID, tID)) != _adjList.end ())
{ os << it->first << " " << it->second << " ";
adjMapType::iterator edgeFound = // it->second->dump(os, tabn++);
_adjList.find (twoNodePairType (fID, tID)); }
return getEdgeID (edgeFound->second);
}
return -1;
}
Edge * os << "Adjacency list: " << _adjList.size() << "\n";
Graph::getEdge (int f, int t for (Graph::adjMapType::iterator it = _adjList.begin(), eit = _adjList.end();
) it != eit; it++) {
{ Graph::twoNodePairType p = it->first;
Graph::adjMapType::iterator fit = Edge *e = it->second;
_adjList.find (Graph::twoNodePairType (f, t));
if (fit == _adjList.end ())
{
return NULL;
}
return fit->second;
}
Edge * os << "Edge (" << p.first << "," << p.second << ") \n";
Graph::getEdge (Node * f, Node * t os << "TimeAdvance : \n";
) Edge::timeAdvanceVectorType timeAdvanceVector = e->getTimeAdvanceVector();
{ os << "\n Size of timeAdvanceVector : " << timeAdvanceVector.size();
Graph::adjMapType::iterator fit = for (unsigned int i = 0; i < timeAdvanceVector.size(); i++) {
_adjList.find (Graph::twoNodePairType (f->getId (), t->getId ())); Edge::timePairType timePair = timeAdvanceVector.at(i);
if (fit == _adjList.end ()) os << " " << timePair.first << " " << timePair.second << "\n";
{ }
return NULL; // e->dump(os,tabn++);
} }
return fit->second;
} }
Node * void Graph::dumpSauto(raw_ostream &os, int tabn) {
Graph::getNode (int nodeID
)
{
if (_nodeMap.find (nodeID) != _nodeMap.end ())
{
nodeMapType::iterator nodeFound = _nodeMap.find (nodeID);
return nodeFound->second;
}
return NULL;
}
vector < Edge * >Graph::getEdgesFromSource (int sourceID) LangOptions LO;
{
vector < Edge * >edges;
for (adjMapType::iterator it = _adjList.begin (), eit = _adjList.end ();
it != eit; it++)
{
twoNodePairType nodePair = it->first;
if (nodePair.first == sourceID)
{
edges.push_back (it->second);
}
}
return edges;