Пример #1
0
function continuePath($path, $destination, $lineName)
{
    $debug = true;
    outputDebug("algorithm.continuePath()", $debug);
    $currentStation = $path->getCurrentStation();
    $currentLine = $currentStation->getLine($lineName);
    $connections = $currentLine->getConnections();
    if ($debug) {
        echo "currentStation = " . $currentStation->getName() . " (" . $currentStation->getID() . ")<br/>\n";
        echo "currentLine = " . $currentLine->name . "<br/>\n";
        echo "continuePath() :: found " . count($connections) . " connections.<br/>\n";
    }
    $newPaths = array();
    foreach ($connections as $connection) {
        if ($connection->id == $path->getLastStation()->getID()) {
            continue;
        }
        // create a new segment from the connection
        outputDebug("connection->id = " . $connection->id, $debug);
        $nextStation = retrieveStation($connection->id);
        $visited = isVisited($nextStation, $path->visited);
        if ($visited) {
            if (count($connections) == 1) {
                // end of the line. no match.
                outputDebug("end of line.", $debug);
                $newPaths[] = new MetaPath("EOL", $path);
                return $newPaths;
            } else {
                // we only care to go in the forward direction
                outputDebug("continuePath() :: already visited.", $debug);
                continue;
            }
        }
        $lines = $currentStation->getOverlapLines($nextStation);
        $newPath = new Path($path, $nextStation, $currentLine, $connection);
        $pathDestination = $path->getDestination();
        if ($destination instanceof Station2 && $nextStation->getID() == $destination->getID()) {
            outputDebug("found match, creating completed path", $debug);
            $newPaths[] = new MetaPath("match", $newPath);
            continue;
        }
        if ($pathDestination instanceof Station2 && $nextStation->getID() == $pathDestination->getID()) {
            outputDebug("found path destination, creating completed path", $debug);
            $newPaths[] = new MetaPath("found", $newPath);
            continue;
        }
        outputDebug("adding path to list = " . $newPath->toString(), $debug);
        $newPaths[] = new MetaPath("continue", $newPath);
    }
    outputDebug("algorithm.continuePath() : DONE", $debug);
    return $newPaths;
}
Пример #2
0
 public function testCreateFromParts()
 {
     $parts = ['foo', 'bar/baz', 'taz'];
     $phlibPath = new Path($parts);
     $this->assertEquals('foo/bar\\/baz/taz', $phlibPath->toString());
 }