HOG2
Graph.cpp
Go to the documentation of this file.
1 /*
2  * $Id: Graph.cpp
3  * hog2
4  *
5  * Created by Nathan Sturtevant on 10/24/06.
6  * Modified by Nathan Sturtevant on 02/29/20.
7  *
8  * This file is part of HOG2. See https://github.com/nathansttt/hog2 for licensing information.
9  *
10  */
11 
12 // HOG File
13 
14 #include <cstdlib>
15 #include "Graph.h"
16 #include <cstring>
17 
18 #include <vector>
19 
20 using namespace std;
21 
22 void graph_object::Print(ostream& /*out*/) const
23 {
24  // out << val;
25 }
26 
27 ostream& operator <<(ostream & out, const graph_object &_Obj)
28 {
29  _Obj.Print(out);
30  return out;
31 }
32 
34 :_nodes(), _edges()
35 {
36  //node_index = edge_index = 0;
37 }
38 
40 {
41  // cout << "destructor got called" << endl;
42  Reset();
43 }
44 
46 {
47  node_iterator ni;
48  edge_iterator ei;
49  ni = getNodeIter();
50  while (1)
51  {
52  node *n = nodeIterNext(ni);
53  if (n)
54  {
55  delete n;
56  n = 0;
57  }
58  else
59  break;
60  }
61 
62  ei = getEdgeIter();
63  while (1)
64  {
65  edge *e = edgeIterNext(ei);
66  if (e)
67  {
68  delete e;
69  e = 0;
70  } else
71  break;
72  }
73  _nodes.clear();
74  _edges.clear();
75 }
76 
78 {
79  Graph *g = new Graph();
81  while (1)
82  {
83  node *n = (node *)nodeIterNext(it);
84  if (n)
85  g->AddNode((node*)n->Clone());
86  else
87  break;
88  }
89  return g;
90 }
91 
93 {
94  Graph *g = new Graph();
96  while (1)
97  {
98  node *n = (node *)nodeIterNext(it);
99  if (n)
100  g->AddNode((node*)n->Clone());
101  else
102  break;
103  }
104  edge_iterator ei = getEdgeIter();
105  while (1)
106  {
107  edge *e = (edge *)edgeIterNext(ei);
108  if (e)
109  g->AddEdge((edge*)e->Clone());
110  else
111  break;
112  }
113  return g;
114 }
115 
116 void Graph::Export(const char *fname)
117 {
118  FILE *f = fopen(fname, "w+");
119  if (f)
120  {
121  fprintf(f, "d\n%d %d\n", GetNumNodes(), GetNumEdges());
122  edge_iterator ei = getEdgeIter();
123  while (1)
124  {
125  edge *e = (edge *)edgeIterNext(ei);
126  if (e)
127  fprintf(f, "%d %d %d 1\n", e->getFrom(), e->getTo(), (int)(100.0*e->GetWeight()));
128  else
129  break;
130  }
131  fclose(f);
132  }
133 }
134 
135 
137 {
138  if (n)
139  {
140  _nodes.push_back(n);
141  n->nodeNum = _nodes.size()-1;
142  //n->uniqueID = uniqueCounter++;
143  //node_index;
144  return n->nodeNum;
145  //node_index++;
146  //return node_index-1;
147  }
148  cerr << "ERRROR ERRROR ERRROR ERRROR ERRROR" << endl;
149  return -1;
150 }
151 
152 node *Graph::GetNode(unsigned long num)
153 {
154  if (num < _nodes.size()) return _nodes[num];
155  return 0;
156 }
157 
158 const node *Graph::GetNode(unsigned long num) const
159 {
160  if (num < _nodes.size()) return _nodes[num];
161  return 0;
162 }
163 
164 edge *Graph::GetEdge(unsigned long num)
165 {
166  if (num < _edges.size()) return _edges[num];
167  return 0;
168 }
169 
171 {
172  if (e)
173  {
174  _edges.push_back(e);
175  e->edgeNum = _edges.size()-1;
176  //_edges[edge_index] = e;
177  if (e->getFrom() < _nodes.size())
178  _nodes[e->getFrom()]->AddEdge(e);
179  else
180  cerr << "Adding edge from illegal index" << endl;
181  if (e->getTo() < _nodes.size())
182  _nodes[e->getTo()]->AddEdge(e);
183  else
184  cerr << "Adding edge to illegal index" << endl;
185  //edge_index++;
186  }
187 }
188 
189 edge *Graph::findDirectedEdge(unsigned int from, unsigned int to)
190 {
191  node *n = GetNode(from);
193  while (1)
194  {
195  edge *e = n->edgeIterNextOutgoing(ei);
196  if (e == 0)
197  break;
198  if (e->getTo() == to)
199  return e;
200  }
201  return 0;
202 }
203 
204 const edge *Graph::FindEdge(unsigned int from, unsigned int to) const
205 {
206  const node *n = GetNode(from);
207  const node *t = GetNode(to);
208  if (n->_allEdges.size() > t->_allEdges.size())
209  n = t;
210  if (n)
211  {
212  edge_iterator ei = n->getEdgeIter();
213  while (1)
214  {
215  edge *e = n->edgeIterNext(ei);
216  if (e == 0) break;
217  if (((e->getTo() == to) && (e->getFrom() == from)) ||
218  ((e->getFrom() == to) && (e->getTo() == from)))
219  return e;
220  }
221  }
222  return 0;
223 }
224 
230 edge *Graph::FindEdge(unsigned int from, unsigned int to)
231 {
232  node *n = GetNode(from);
233  node *t = GetNode(to);
234  if (n->_allEdges.size() > t->_allEdges.size())
235  n = t;
236  if (n)
237  {
238  edge_iterator ei = n->getEdgeIter();
239  while (1)
240  {
241  edge *e = n->edgeIterNext(ei);
242  if (e == 0) break;
243  if (((e->getTo() == to) && (e->getFrom() == from)) ||
244  ((e->getFrom() == to) && (e->getTo() == from)))
245  return e;
246  }
247  }
248  return 0;
249 }
250 
251 bool Graph::relax(edge *e, int weightIndex)
252 {
253  int from = e->getFrom();
254  int to = e->getTo();
255  if (e == 0) return false;
256  double newCost = GetNode(from)->GetLabelF(weightIndex)+e->GetWeight();
257  if (newCost < GetNode(to)->GetLabelF(weightIndex))
258  {
259  //cout << "re-weighting" << endl << *GetNode(to) << endl;
260  GetNode(to)->SetLabelF(weightIndex, newCost);
261  //cout << *GetNode(to) << endl;
262  return true;
263  }
264  return false;
265 }
266 
267 bool Graph::relaxReverseEdge(edge *e, int weightIndex)
268 {
269  int from = e->getFrom();
270  int to = e->getTo();
271  if (e == 0) return false;
272  double newCost = GetNode(to)->GetLabelF(weightIndex)+e->GetWeight();
273  if (newCost < GetNode(from)->GetLabelF(weightIndex))
274  {
275  GetNode(from)->SetLabelF(weightIndex, newCost);
276  return true;
277  }
278  return false;
279 }
280 
282 {
283  if (_nodes.size() == 0) return 0;
284  int rand_val = (int)(((double)random()/RAND_MAX)*_nodes.size());
285  return _nodes[rand_val];
286 }
287 
289 {
290  if (_edges.size() == 0) return 0;
291  // int rand_val = random()%edge_index;
292  int rand_val = (int)(((double)random()/RAND_MAX)*_edges.size());
293  return _edges[rand_val];
294  //return 0;
295 }
296 
297 // fixme: should be inlined
299 {
300  return _nodes.begin();
301 }
302 
304 {
305  if (node_iter != _nodes.end())
306  {
307  node *v = *node_iter;
308  node_iter++;
309  return v;
310  }
311  return 0;
312 }
313 
314 // fixme: should be inlined
316 {
317  return _edges.begin();
318 }
319 
321 {
322  if (edge_iter != _edges.end())
323  {
324  edge *v = *edge_iter;
325  edge_iter++;
326  return v;
327  }
328  return 0;
329 }
330 
332 {
333  //cout << "Removing edge " << e->edgeNum << " from " << e->from << " to " << e->to << endl;
334  GetNode(e->from)->RemoveEdge(e);
335  GetNode(e->to)->RemoveEdge(e);
336  unsigned int oldLoc = e->edgeNum;
337  edge *replacement = _edges.back();
338  //cout << "Removing edge at " << oldLoc << " and putting " << replacement->edgeNum << " in its place" << endl;
339  if (_edges[oldLoc] == e)
340  {
341  _edges[oldLoc] = replacement;
342  replacement->edgeNum = oldLoc;
343  _edges.pop_back();
344  }
345  else {
346  cerr << "ERROR removing edge at " << oldLoc << endl;
347  // for (unsigned int x = 0; x < _edges.size(); x++)
348  // {
349  // if (_edges[x] == e)
350  // cout << "We found it at " << x << endl;
351  // }
352  }
353 }
354 
355 // returns the node that had it's node number changed, if any
356 node *Graph::RemoveNode(node *n, unsigned int &oldID)
357 {
358  if (!n) return 0;
359 
360  while (n->_allEdges.size() > 0)
361  {
362  edge *e = n->_allEdges.back();
363  // cout << "All edges contain " << n->_allEdges.size() << " edges." << endl;
364  // cout << "incoming has " << n->_edgesIncoming.size() << " and outgoing has "
365  // << n->_edgesOutgoing.size() << " edges" << endl;
366  // cout << "Going to remove " << e << " " << *e << endl;
367  if (e) RemoveEdge(e);
368  else break;
369  }
370  //printf("_nodes size is %u\n", _nodes.size());
371  node *tmp = _nodes.back();
372  _nodes.pop_back();
373  if (_nodes.size() > 0)
374  {
375  _nodes[n->GetNum()] = tmp;
376  oldID = tmp->nodeNum;
377  tmp->nodeNum = n->GetNum();
378  }
379 
380  if (n == tmp) return 0;
381 
382  // repair edges to and from this node...
384  for (edge *e = tmp->edgeIterNextIncoming(ei); e; e = tmp->edgeIterNextIncoming(ei))
385  {
386  e->to = tmp->nodeNum;
387  }
388  ei = tmp->getOutgoingEdgeIter();
389  for (edge *e = tmp->edgeIterNextOutgoing(ei); e; e = tmp->edgeIterNextOutgoing(ei))
390  {
391  e->from = tmp->nodeNum;
392  }
393  return tmp;
394 }
395 
396 // fixme: should be inlined
398 {
399  return _edges.size();
400 }
401 
402 // fixme: should be inlined
404 {
405  return _nodes.size();
406 }
407 
408 // BFS from start node
409 vector<node*>* Graph::getReachableNodes(node* start)
410 {
411  // Non-const array size trick in new compiler; appears as though
412  // an initializer is not allowed
413  std::vector<int> visitedList(_nodes.size());
414  for (unsigned int i = 0; i < _nodes.size(); i++)
415  {
416  visitedList[i] = 0;
417  }
418  // Preallocation estimate
419  vector<node*> *nodeList = new vector<node*>();
420  nodeList->reserve(_nodes.size() * 3 / 4);
421  unsigned int index = 0;
422  int neighborNum = 0;
423  node *n;
424 
425  nodeList->push_back(start);
426  visitedList[start->GetNum()] = 1;
427  while (index < nodeList->size())
428  {
429  n = (*nodeList)[index];
431  while ((neighborNum = n->nodeNeighborNext(ni)) >= 0)
432  {
433  //cout << neighborNum << endl;
434  if (visitedList[neighborNum] <= 0)
435  {
436  visitedList[neighborNum] = 1;
437  nodeList->push_back(_nodes[neighborNum]);
438  }
439  }
440  index++;
441  }
442 
443  return nodeList;
444 }
445 
446 void Graph::Print(ostream &out) const
447 {
448  node_iterator ni = getNodeIter();
449  edge_iterator ei = getEdgeIter();
450 
451  out << "Nodes:" << endl;
452  while (1)
453  {
454  node *n = nodeIterNext(ni);
455  if (!n) break;
456  out << *n << endl;
457  }
458  out << "Edges:" << endl;
459  while (1)
460  {
461  edge *e = edgeIterNext(ei);
462  if (!e) break;
463  out << *e << endl;
464  }
465 }
466 
468 {
469  cout << GetNumEdges() << " total edges; " << GetNumNodes() << " total nodes." << endl;
470  int minEdges = GetNumEdges();
471  int maxEdges[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
472  node_iterator ni = getNodeIter();
473  while (1)
474  {
475  node *n = nodeIterNext(ni);
476  if (!n) break;
477  minEdges = min(minEdges, n->GetNumEdges());
478  for (int x = 0; x < 10; x++)
479  {
480  if (n->GetNumEdges() > maxEdges[x])
481  {
482  for (int y = x; y < 9; y++)
483  maxEdges[y+1] = maxEdges[y];
484  maxEdges[x] = n->GetNumEdges();
485  break;
486  }
487  }
488  //maxEdges = max(maxEdges, n->GetNumEdges());
489  }
490  cout << "Min edges: " << minEdges << ", max edges: ";
491  for (int x = 0; x < 10; x++)
492  cout << maxEdges[x] << ", ";
493  cout << endl;
494 }
495 
496 bool Graph::verifyGraph() const
497 {
498  bool verified = true;
499  int totalEdges1 = 0, totalEdges2 = 0;
500  node_iterator ni = getNodeIter();
501  edge_iterator ei;
502 
503  // if (node_index != _nodes.size())
504  // {
505  // cerr << "Error: our node count doesn't match the size of nodes stored" << endl;
506  // verified = false;
507  // }
508  // if (edge_index != _edges.size())
509  // {
510  // cerr << "Error: our edge count doesn't match the size of edges stored" << endl;
511  // verified = false;
512  // }
513 
514  for (node *n = nodeIterNext(ni); n; n = nodeIterNext(ni))
515  {
516  if (!n)
517  {
518  cerr << "Error; we've stored null node" << endl;
519  verified = false;
520  continue;
521  }
522  else {
523  //cout << "Testing node " << n->GetNum() << endl;
524  }
525  if (_nodes[n->nodeNum] != n)
526  {
527  cerr << "Error; node " << n->nodeNum << "'s node number is off." << endl;
528  verified = false;
529  }
530 
531  ei = n->getEdgeIter();
532  int supposedCount = n->getNumIncomingEdges()+n->getNumOutgoingEdges();
533  int realCount = 0;
534  for (edge *e = n->edgeIterNext(ei); e; e = n->edgeIterNext(ei))
535  {
536  totalEdges1++;
537  realCount++;
538  if ((e->getFrom() != n->GetNum()) && (e->getTo() != n->GetNum()))
539  {
540  cerr << "At node " << n->GetNum() << " found edge between " << e->getFrom() << " and " << e->getTo() << endl;
541  verified = false;
542  }
543  }
544  if (realCount != supposedCount)
545  {
546  cerr << "At node " << n->GetNum() << " supposed count is " << supposedCount << " but only found " << realCount << endl;
547  verified = false;
548  }
549  }
550 
551  ei = getEdgeIter();
552  for (edge *e = edgeIterNext(ei); e; e = edgeIterNext(ei))
553  {
554  if (_edges[e->edgeNum] != e)
555  {
556  cerr << "Error; edge " << e->edgeNum << "'s edge number is off." << endl;
557  verified = false;
558  }
559 
560  totalEdges2++;
561  }
562  if (totalEdges1/2 != totalEdges2)
563  {
564  cerr << "Edge counts don't match - from nodes " << totalEdges1 << ", from edges " << totalEdges2 << endl;
565  verified = false;
566  }
567  return verified;
568 }
569 
570 edge::edge(unsigned int f, unsigned int t, double w)
571 : mark(false), from(f), to(t), label()
572 {
574  // if ((from == -1) || (to == -1))
575  // cerr << "Error - " << from << "->" << to << endl;
576 }
577 
578 void edge::Print(ostream& out) const
579 {
580  out << from << "->" << to << " (" << GetLabelF(kEdgeWeight) << ")";
581 }
582 
583 void edge::SetLabelF(unsigned int index, double val)
584 {
585  if (index < label.size())
586  label[index].fval = val;
587  else {
588  while (index > label.size())
589  {
590  labelValue v; v.fval = (double)MAXINT;
591  label.push_back(v);
592  }
593  labelValue v; v.fval = val;
594  label.push_back(v);
595  }
596 }
597 
598 void edge::SetLabelL(unsigned int index, long val)
599 {
600  if (index < label.size())
601  label[index].lval = val;
602  else {
603  while (index > label.size())
604  {
605  labelValue v; v.lval = MAXINT;
606  label.push_back(v);
607  }
608  labelValue v; v.lval = val;
609  label.push_back(v);
610  }
611 }
612 
613 
614 unsigned node::uniqueIDCounter = 0;
615 
616 node::node(const char *n)
617 :label(), _edgesOutgoing(), _edgesIncoming(), _allEdges()
618 {
619  // fixme: unsafe, 30?
620  strncpy(name, n, 30);
621  // for (int x = 0; x < MAXLABELS; x++)
622  // label[x] = MAXINT;
623  keyLabel = 0;
624  markedEdge = 0;
626 }
627 
629 {
630  node *n = new node(name);
631  for (unsigned int x = 0; x < label.size(); x++) n->label.push_back(label[x]);
632  n->keyLabel = keyLabel;
633  return n;
634 }
635 
637 {
638  if (e)
639  {
640  _allEdges.push_back(e);
641  if (e->getFrom() == nodeNum)
642  _edgesOutgoing.push_back(e);
643  else if (e->getTo() == nodeNum)
644  _edgesIncoming.push_back(e);
645  else
646  cerr << "Added an adge that doesn't belong to this node (" << nodeNum << ")" << endl;
647  }
648 }
649 
651 {
652  if (nodeNum == e->getTo())
653  {
654  for (unsigned int x = 0; x < _edgesIncoming.size(); x++)
655  {
656  if (_edgesIncoming[x] == e)
657  {
658  _edgesIncoming[x] = _edgesIncoming.back();
659  _edgesIncoming.pop_back();
660  break;
661  }
662  }
663  }
664  else {
665  for (unsigned int x = 0; x < _edgesOutgoing.size(); x++)
666  {
667  if (_edgesOutgoing[x] == e)
668  {
669  _edgesOutgoing[x] = _edgesOutgoing.back();
670  _edgesOutgoing.pop_back();
671  break;
672  }
673  }
674  }
675  for (unsigned int x = 0; x < _allEdges.size(); x++)
676  {
677  if (_allEdges[x] == e)
678  {
679  _allEdges[x] = _allEdges.back();
680  _allEdges.pop_back();
681  break;
682  }
683  }
684  if (markedEdge == e) markedEdge = 0;
685 }
686 
687 void node::SetLabelF(unsigned int index, double val) const
688 {
689  if (index < label.size())
690  label[index].fval = val;
691  else {
692  while (index > label.size())
693  {
694  labelValue v; v.fval = (double)MAXINT;
695  label.push_back(v);
696  }
697  labelValue v; v.fval = val;
698  label.push_back(v);
699  }
700 }
701 
702 void node::SetLabelL(unsigned int index, long val) const
703 {
704  if (index < label.size())
705  label[index].lval = val;
706  else {
707  while (index > label.size())
708  {
709  labelValue v; v.lval = MAXINT;
710  label.push_back(v);
711  }
712  labelValue v; v.lval = val;
713  label.push_back(v);
714  }
715 }
716 
718 {
719  return _edgesIncoming.begin();
720 }
721 
723 {
724  if (iterIncoming != _edgesIncoming.end())
725  {
726  edge *v = *iterIncoming;
727  iterIncoming++;
728  return v;
729  }
730  return 0;
731 }
732 
734 {
735  return _edgesOutgoing.begin();
736 }
737 
739 {
740  if (iterOutgoing != _edgesOutgoing.end())
741  {
742  edge *v = *iterOutgoing;
743  iterOutgoing++;
744  return v;
745  }
746  return 0;
747 }
748 
750 {
751  return _allEdges.begin();
752 }
753 
755 {
756  if (iter != _allEdges.end())
757  {
758  edge *v = *iter;
759  iter++;
760  return v;
761  }
762  return 0;
763 }
764 
766 {
767  int rand_val = random()%_edgesIncoming.size();
768  return _edgesIncoming[rand_val];
769 }
770 
772 {
773  int rand_val = random()%_edgesOutgoing.size();
774  return _edgesOutgoing[rand_val];
775 }
776 
778 {
779  int rand_val = random()%_allEdges.size();
780  return _allEdges[rand_val];
781 }
782 
783 // fixme: should be inlined
785 {
786  return _edgesOutgoing.size();
787 }
788 
790 {
791  return _edgesIncoming.size();
792 }
793 
794 edge *node::getEdge(unsigned int which)
795 {
796  if (which > _allEdges.size())
797  return 0;
798  return _allEdges[which];
799 }
800 
801 
803 {
804  return 0;
805 }
806 
808 {
809  int result = -1;
810  unsigned int os = _edgesOutgoing.size();
811  if (ni < os)
812  result = _edgesOutgoing[ni]->getTo();
813  else if (ni - os < _edgesIncoming.size())
814  result = _edgesIncoming[ni-os]->getFrom();
815  ni++;
816  return result;
817 }
818 
819 
820 void node::Print(ostream& out) const
821 {
822  out << "\"" << name << "\"" << " (" << nodeNum << ")";
823  for (unsigned int x = 0; x < label.size(); x++)
824  {
825  out << " - " << label[x].lval;
826  }
827 }
828 
829 ostream& operator <<(ostream & out, const Graph &_Graph)
830 {
831  _Graph.Print(out);
832  return out;
833 }
834 
835 ostream& operator <<(ostream & out, const node &_Node)
836 {
837  _Node.Print(out);
838  return out;
839 }
840 
841 ostream& operator <<(ostream & out, const edge &_Edge)
842 {
843  _Edge.Print(out);
844  return out;
845 }
node::_allEdges
std::vector< edge * > _allEdges
Definition: Graph.h:238
Graph::AddNode
int AddNode(node *)
Definition: Graph.cpp:136
operator<<
ostream & operator<<(ostream &out, const graph_object &_Obj)
Definition: Graph.cpp:27
node::SetLabelL
void SetLabelL(unsigned int index, long val) const
Definition: Graph.cpp:702
edge::GetWeight
double GetWeight()
Definition: Graph.h:140
Graph.h
node::SetLabelF
void SetLabelF(unsigned int index, double val) const
Definition: Graph.cpp:687
edge::getFrom
unsigned int getFrom() const
Definition: Graph.h:146
edge::getTo
unsigned int getTo() const
Definition: Graph.h:147
Graph::RemoveNode
node * RemoveNode(node *, unsigned int &)
Definition: Graph.cpp:356
Graph::FindEdge
edge * FindEdge(unsigned int from, unsigned int to)
Finds an edge between nodes with ids from and to, no matter which direction.
Definition: Graph.cpp:230
neighbor_iterator
unsigned int neighbor_iterator
Definition: Graph.h:34
min
double min(double a, double b)
Definition: FPUtil.h:35
node::getOutgoingEdgeIter
edge_iterator getOutgoingEdgeIter() const
Definition: Graph.cpp:733
edge::from
unsigned int from
Definition: Graph.h:158
labelValue
Definition: Graph.h:36
node::edgeIterNextIncoming
edge * edgeIterNextIncoming(edge_iterator &) const
Definition: Graph.cpp:722
node::RemoveEdge
void RemoveEdge(edge *)
Definition: Graph.cpp:650
node::node
node(const char *)
Definition: Graph.cpp:616
node::name
char name[30]
Definition: Graph.h:239
graph_object::Print
virtual void Print(std::ostream &) const
Definition: Graph.cpp:22
Graph::AddEdge
void AddEdge(edge *)
Definition: Graph.cpp:170
Graph::nodeIterNext
node * nodeIterNext(node_iterator &) const
Definition: Graph.cpp:303
Graph::verifyGraph
bool verifyGraph() const
Definition: Graph.cpp:496
edge_iterator
std::vector< edge * >::const_iterator edge_iterator
Definition: Graph.h:30
node::uniqueIDCounter
static unsigned int uniqueIDCounter
Definition: Graph.h:243
node::edgeIterNextOutgoing
edge * edgeIterNextOutgoing(edge_iterator &) const
Definition: Graph.cpp:738
edge::label
std::vector< labelValue > label
Definition: Graph.h:163
Graph::RemoveEdge
void RemoveEdge(edge *)
Definition: Graph.cpp:331
node::Print
void Print(std::ostream &) const
Definition: Graph.cpp:820
Graph
A generic Graph class.
Definition: Graph.h:66
Graph::Reset
void Reset()
Definition: Graph.cpp:45
Graph::GetNode
node * GetNode(unsigned long num)
Definition: Graph.cpp:152
edge::edge
edge(unsigned int, unsigned int, double)
Definition: Graph.cpp:570
node::getEdge
edge * getEdge(unsigned int which)
Definition: Graph.cpp:794
Graph::edgeIterNext
edge * edgeIterNext(edge_iterator &) const
Definition: Graph.cpp:320
Graph::_nodes
std::vector< node * > _nodes
Definition: Graph.h:114
Graph::Print
void Print(std::ostream &) const
Definition: Graph.cpp:446
graph_object
Parent class for nodes and edges allowing them to be stored in a Heap or manipulated with other data ...
Definition: Graph.h:47
node_iterator
std::vector< node * >::const_iterator node_iterator
Definition: Graph.h:33
edge::edgeNum
unsigned int edgeNum
Definition: Graph.h:161
node::getEdgeIter
edge_iterator getEdgeIter() const
Definition: Graph.cpp:749
Graph::cloneAll
Graph * cloneAll() const
Definition: Graph.cpp:92
node::_edgesOutgoing
std::vector< edge * > _edgesOutgoing
Definition: Graph.h:236
edge::Clone
graph_object * Clone() const
Definition: Graph.h:132
edge::SetLabelF
void SetLabelF(unsigned int index, double val)
Definition: Graph.cpp:583
node::AddEdge
void AddEdge(edge *)
Definition: Graph.cpp:636
Graph::Clone
graph_object * Clone() const
Definition: Graph.cpp:77
Graph::getEdgeIter
edge_iterator getEdgeIter() const
Definition: Graph.cpp:315
Graph::Export
void Export(const char *fname)
Definition: Graph.cpp:116
node::keyLabel
int keyLabel
Definition: Graph.h:240
Graph::GetNumEdges
int GetNumEdges()
Definition: Graph.cpp:397
node::GetRandomEdge
edge * GetRandomEdge()
Definition: Graph.cpp:777
edge::SetLabelL
void SetLabelL(unsigned int index, long val)
Definition: Graph.cpp:598
node::getRandomIncomingEdge
edge * getRandomIncomingEdge()
Definition: Graph.cpp:765
node::getRandomOutgoingEdge
edge * getRandomOutgoingEdge()
Definition: Graph.cpp:771
node::getIncomingEdgeIter
edge_iterator getIncomingEdgeIter() const
Definition: Graph.cpp:717
Graph::Graph
Graph()
Definition: Graph.cpp:33
Graph::GetRandomEdge
edge * GetRandomEdge()
Definition: Graph.cpp:288
labelValue::fval
double fval
Definition: Graph.h:36
Graph::GetNumNodes
int GetNumNodes()
Definition: Graph.cpp:403
Graph::getNodeIter
node_iterator getNodeIter() const
Definition: Graph.cpp:298
node::nodeNeighborNext
int nodeNeighborNext(neighbor_iterator &) const
Definition: Graph.cpp:807
edge::Print
void Print(std::ostream &) const
Definition: Graph.cpp:578
node::nodeNum
unsigned int nodeNum
Definition: Graph.h:233
node::label
std::vector< labelValue > label
Definition: Graph.h:234
node::GetLabelF
double GetLabelF(unsigned int index) const
Definition: Graph.h:215
Graph::relaxReverseEdge
bool relaxReverseEdge(edge *e, int weightIndex)
Definition: Graph.cpp:267
Graph::printStats
void printStats()
Definition: Graph.cpp:467
std
Definition: CanonicalGraphEnvironment.h:26
Graph::GetRandomNode
node * GetRandomNode()
Definition: Graph.cpp:281
Graph::~Graph
~Graph()
Definition: Graph.cpp:39
node::GetNum
unsigned int GetNum() const
Definition: Graph.h:176
MAXINT
#define MAXINT
Definition: Graph.h:24
edge::GetLabelF
double GetLabelF(unsigned int index) const
Definition: Graph.h:137
node::Clone
graph_object * Clone() const
Definition: Graph.cpp:628
node::uniqueID
int uniqueID
Definition: Graph.h:242
Graph::getReachableNodes
std::vector< node * > * getReachableNodes(node *start)
Definition: Graph.cpp:409
kEdgeWeight
@ kEdgeWeight
Definition: Graph.h:40
node::getNeighborIter
neighbor_iterator getNeighborIter() const
Definition: Graph.cpp:802
Graph::_edges
std::vector< edge * > _edges
Definition: Graph.h:116
node::_edgesIncoming
std::vector< edge * > _edgesIncoming
Definition: Graph.h:237
Graph::findDirectedEdge
edge * findDirectedEdge(unsigned int from, unsigned int to)
Definition: Graph.cpp:189
node::edgeIterNext
edge * edgeIterNext(edge_iterator &) const
Definition: Graph.cpp:754
labelValue::lval
long lval
Definition: Graph.h:36
node::getNumIncomingEdges
int getNumIncomingEdges()
Definition: Graph.cpp:789
node::GetNumEdges
int GetNumEdges()
Definition: Graph.h:204
nodeList
std::vector< node * > nodeList
Definition: FringeSearch.h:21
node
Nodes to be stored within a Graph.
Definition: Graph.h:170
edge::to
unsigned int to
Definition: Graph.h:158
node::markedEdge
edge * markedEdge
Definition: Graph.h:235
node::getNumOutgoingEdges
int getNumOutgoingEdges()
Definition: Graph.cpp:784
Graph::GetEdge
edge * GetEdge(unsigned long num)
Definition: Graph.cpp:164
edge
Edge class for connections between node in a Graph.
Definition: Graph.h:129
Graph::relax
bool relax(edge *e, int weightIndex)
Definition: Graph.cpp:251