Go to the documentation of this file.
118 FILE *f = fopen(fname,
"w+");
148 cerr <<
"ERRROR ERRROR ERRROR ERRROR ERRROR" << endl;
180 cerr <<
"Adding edge from illegal index" << endl;
184 cerr <<
"Adding edge to illegal index" << endl;
198 if (e->
getTo() == to)
255 if (e == 0)
return false;
257 if (newCost <
GetNode(to)->GetLabelF(weightIndex))
271 if (e == 0)
return false;
273 if (newCost <
GetNode(from)->GetLabelF(weightIndex))
283 if (
_nodes.size() == 0)
return 0;
284 int rand_val = (int)(((
double)random()/RAND_MAX)*
_nodes.size());
290 if (
_edges.size() == 0)
return 0;
292 int rand_val = (int)(((
double)random()/RAND_MAX)*
_edges.size());
305 if (node_iter !=
_nodes.end())
307 node *v = *node_iter;
322 if (edge_iter !=
_edges.end())
324 edge *v = *edge_iter;
336 unsigned int oldLoc = e->
edgeNum;
341 _edges[oldLoc] = replacement;
346 cerr <<
"ERROR removing edge at " << oldLoc << endl;
380 if (n == tmp)
return 0;
413 std::vector<int> visitedList(
_nodes.size());
414 for (
unsigned int i = 0; i <
_nodes.size(); i++)
419 vector<node*> *
nodeList =
new vector<node*>();
421 unsigned int index = 0;
426 visitedList[start->
GetNum()] = 1;
427 while (index < nodeList->size())
429 n = (*nodeList)[index];
434 if (visitedList[neighborNum] <= 0)
436 visitedList[neighborNum] = 1;
451 out <<
"Nodes:" << endl;
458 out <<
"Edges:" << endl;
471 int maxEdges[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
478 for (
int x = 0; x < 10; x++)
482 for (
int y = x; y < 9; y++)
483 maxEdges[y+1] = maxEdges[y];
490 cout <<
"Min edges: " << minEdges <<
", max edges: ";
491 for (
int x = 0; x < 10; x++)
492 cout << maxEdges[x] <<
", ";
498 bool verified =
true;
499 int totalEdges1 = 0, totalEdges2 = 0;
518 cerr <<
"Error; we've stored null node" << endl;
525 if (
_nodes[n->nodeNum] != n)
527 cerr <<
"Error; node " << n->nodeNum <<
"'s node number is off." << endl;
531 ei = n->getEdgeIter();
532 int supposedCount = n->getNumIncomingEdges()+n->getNumOutgoingEdges();
534 for (
edge *e = n->edgeIterNext(ei); e; e = n->edgeIterNext(ei))
538 if ((e->getFrom() != n->GetNum()) && (e->getTo() != n->GetNum()))
540 cerr <<
"At node " << n->GetNum() <<
" found edge between " << e->getFrom() <<
" and " << e->getTo() << endl;
544 if (realCount != supposedCount)
546 cerr <<
"At node " << n->GetNum() <<
" supposed count is " << supposedCount <<
" but only found " << realCount << endl;
554 if (
_edges[e->edgeNum] != e)
556 cerr <<
"Error; edge " << e->edgeNum <<
"'s edge number is off." << endl;
562 if (totalEdges1/2 != totalEdges2)
564 cerr <<
"Edge counts don't match - from nodes " << totalEdges1 <<
", from edges " << totalEdges2 << endl;
571 : mark(false), from(f), to(t), label()
585 if (index <
label.size())
586 label[index].fval = val;
588 while (index >
label.size())
600 if (index <
label.size())
601 label[index].lval = val;
603 while (index >
label.size())
617 :label(), _edgesOutgoing(), _edgesIncoming(), _allEdges()
620 strncpy(
name, n, 30);
631 for (
unsigned int x = 0; x <
label.size(); x++) n->
label.push_back(
label[x]);
646 cerr <<
"Added an adge that doesn't belong to this node (" <<
nodeNum <<
")" << endl;
675 for (
unsigned int x = 0; x <
_allEdges.size(); x++)
689 if (index <
label.size())
690 label[index].fval = val;
692 while (index >
label.size())
704 if (index <
label.size())
705 label[index].lval = val;
707 while (index >
label.size())
726 edge *v = *iterIncoming;
742 edge *v = *iterOutgoing;
779 int rand_val = random()%
_allEdges.size();
822 out <<
"\"" <<
name <<
"\"" <<
" (" <<
nodeNum <<
")";
823 for (
unsigned int x = 0; x <
label.size(); x++)
825 out <<
" - " <<
label[x].lval;
std::vector< edge * > _allEdges
ostream & operator<<(ostream &out, const graph_object &_Obj)
void SetLabelL(unsigned int index, long val) const
void SetLabelF(unsigned int index, double val) const
unsigned int getFrom() const
unsigned int getTo() const
node * RemoveNode(node *, unsigned int &)
edge * FindEdge(unsigned int from, unsigned int to)
Finds an edge between nodes with ids from and to, no matter which direction.
unsigned int neighbor_iterator
double min(double a, double b)
edge_iterator getOutgoingEdgeIter() const
edge * edgeIterNextIncoming(edge_iterator &) const
virtual void Print(std::ostream &) const
node * nodeIterNext(node_iterator &) const
std::vector< edge * >::const_iterator edge_iterator
static unsigned int uniqueIDCounter
edge * edgeIterNextOutgoing(edge_iterator &) const
std::vector< labelValue > label
void Print(std::ostream &) const
node * GetNode(unsigned long num)
edge(unsigned int, unsigned int, double)
edge * getEdge(unsigned int which)
edge * edgeIterNext(edge_iterator &) const
std::vector< node * > _nodes
void Print(std::ostream &) const
Parent class for nodes and edges allowing them to be stored in a Heap or manipulated with other data ...
std::vector< node * >::const_iterator node_iterator
edge_iterator getEdgeIter() const
std::vector< edge * > _edgesOutgoing
graph_object * Clone() const
void SetLabelF(unsigned int index, double val)
graph_object * Clone() const
edge_iterator getEdgeIter() const
void Export(const char *fname)
void SetLabelL(unsigned int index, long val)
edge * getRandomIncomingEdge()
edge * getRandomOutgoingEdge()
edge_iterator getIncomingEdgeIter() const
node_iterator getNodeIter() const
int nodeNeighborNext(neighbor_iterator &) const
void Print(std::ostream &) const
std::vector< labelValue > label
double GetLabelF(unsigned int index) const
bool relaxReverseEdge(edge *e, int weightIndex)
unsigned int GetNum() const
double GetLabelF(unsigned int index) const
graph_object * Clone() const
std::vector< node * > * getReachableNodes(node *start)
neighbor_iterator getNeighborIter() const
std::vector< edge * > _edges
std::vector< edge * > _edgesIncoming
edge * findDirectedEdge(unsigned int from, unsigned int to)
edge * edgeIterNext(edge_iterator &) const
int getNumIncomingEdges()
std::vector< node * > nodeList
Nodes to be stored within a Graph.
int getNumOutgoingEdges()
edge * GetEdge(unsigned long num)
Edge class for connections between node in a Graph.
bool relax(edge *e, int weightIndex)