Example #1
0
 /**
  * Weighted graph test program.
  *
  * @param object IGraph $g The weighted graph to test.
  */
 public static function weightedGraphTest(IGraph $g)
 {
     printf("Weighted graph test program.\n");
     $g->addVertex(0, box(123));
     $g->addVertex(1, box(234));
     $g->addVertex(2, box(345));
     $g->addEdge(0, 1, box(3));
     $g->addEdge(0, 2, box(1));
     $g->addEdge(1, 2, box(4));
     printf("%s\n", str($g));
     printf("Prim's Algorithm\n");
     $g2 = Algorithms::primsAlgorithm($g, 0);
     printf("%s\n", str($g2));
     printf("Kruskal's Algorithm\n");
     $g2 = Algorithms::kruskalsAlgorithm($g);
     printf("%s\n", str($g2));
 }
Example #2
0
 /**
  * Weighted graph test method.
  *
  * @param object IGraph $g The weighted graph to test.
  */
 public static function testWeighted(IGraph $g)
 {
     printf("Weighted graph test program.\n");
     $g->addVertex(0, box(123));
     $g->addVertex(1, box(234));
     $g->addVertex(2, box(345));
     $g->addEdge(0, 1, box(3));
     $g->addEdge(0, 2, box(1));
     $g->addEdge(1, 2, box(4));
     printf("%s\n", str($g));
     printf("Using vertex iterator\n");
     foreach ($g->getVertices() as $v) {
         printf("%s\n", str($v));
     }
     printf("Using edge iterator\n");
     foreach ($g->getEdges() as $e) {
         printf("%s\n", str($e));
     }
 }