コード例 #1
0
ファイル: Demo10.php プロジェクト: EdenChan/Instances
 /**
  * Main program.
  *
  * @param array $args Command-line arguments.
  * @return integer Zero on succes; non-zero on failure.
  */
 public static function main($args)
 {
     printf("Demonstration program number 10.\n");
     $status = 0;
     GraphAsMatrix::main($args);
     GraphAsLists::main($args);
     DigraphAsMatrix::main($args);
     DigraphAsLists::main($args);
     return $status;
 }
コード例 #2
0
ファイル: Algorithms.php プロジェクト: EdenChan/Instances
 /**
  * Computes the critical path in an event-node graph.
  *
  * @param object IDigraph $g An edge-weighted, directed acylic graph.
  * It is assumed that the edge weights are <code>Int</code>s
  * @return object IDigraph A vertex-weighted, directed graph.
  * The events (vertices) on the critical path have zero weight.
  * The one edge that emantes from a vertex connects that vertex
  * to its predecessor on the critical path.
  */
 public static function criticalPathAnalysis(IDigraph $g)
 {
     $n = $g->getNumberOfVertices();
     $earliestTime = new BasicArray($n);
     $earliestTime[0] = 0;
     $g->topologicalOrderTraversal(new EarliestTimeVisitor($earliestTime));
     $latestTime = new BasicArray($n);
     $latestTime[$n - 1] = $earliestTime[$n - 1];
     $g->depthFirstTraversal(new PostOrder(new LatestTimeVisitor($latestTime)), 0);
     $slackGraph = new DigraphAsLists($n);
     for ($v = 0; $v < $n; ++$v) {
         $slackGraph->addVertex($v);
     }
     foreach ($g->getEdges() as $edge) {
         $n0 = $edge->getV0()->getNumber();
         $n1 = $edge->getV1()->getNumber();
         $wt = $edge->getWeight();
         $slack = $latestTime[$n1] - $earliestTime[$n0] - unbox($wt);
         $slackGraph->addEdge($n0, $n1, box($slack));
     }
     return Algorithms::dijkstrasAlgorithm($slackGraph, 0);
 }