Ejemplo n.º 1
0
/**
    For each segment, the first marker and the second marker of the same segment will have the same lines. We check the line used. If it does not exist in second segment's second marker, then we know that the first marker is a junction point and needs to have a transfer.
    
    @param $path[]<Segment> the list of path segments
    @param $type<String> the type of connection (s2s,dir)
*/
function consolidatePath($path, $type)
{
    $cpath = array();
    $debug = false;
    $path_array = $path->path;
    $count = count($path_array);
    if ($debug) {
        echo "// algorithm2.php:consolidatePath()<br/>";
    }
    // this is a direction path and there is only one or two paths.
    // that means it either goes from loc->station->loc or just loc->loc
    if (($type == "dir" || $type == "dir_alt") && $count <= 2) {
        if ($debug) {
            echo "// end algorithm2.php:consolidatePath()<br/>";
        }
        return "walk";
    }
    //set up the first segment
    $segment = $path_array[0];
    if ($type == "s2s") {
        $i = 1;
    } else {
        $cpath[] = $segment;
        $segment = $path_array[1];
        $i = 2;
    }
    $marker1 = $segment->m1;
    $current_lines = $segment->m1->getOverlapLines($segment->m2);
    $connection = $segment->connection;
    $total_time = $segment->t;
    $segment2 = $path_array[$i];
    // loop through the path, starting at the next segment.
    for (; $i < $count; $i++) {
        // grab the segment
        $segment2 = $path_array[$i];
        if ($debug) {
            echo "[{$i}/{$count}]@" . $segment2->m1->name . "<br/>";
            echo "lines = ";
            foreach ($current_lines as $line) {
                echo $line->name . " ";
            }
            echo "<br/>";
        }
        if ($connection == "transfer") {
            // we know this segment is a transfer, so they will have to get off the train
            if ($debug) {
                echo "transfer<br/>";
            }
            $lines = $marker1->getOverlapLines($segment2->m1);
            $lines = getCorrectLines($lines, "transfer");
            if ($debug) {
                echo "lines: ";
                foreach ($lines as $line) {
                    echo $line->name . " ";
                }
                echo "<br/>";
            }
            // create the transfer segment
            $new_segment = new Segment($marker1, $segment2->m1, $lines, $total_time, $connection);
            if ($debug) {
                echo "adding segment = " . $new_segment->toString() . "<br/>";
            }
            $cpath[] = $new_segment;
            $segment = $path_array[$i];
            if ($debug) {
                echo "new segment = " . $segment->toString() . "<br/>";
            }
            $marker1 = $segment->m1;
            $current_lines = $marker1->getOverlapLines($segment->m2);
            $connection = $segment->connection;
            $total_time = $segment->t;
            if ($i < $count) {
                // more segments available
                if ($debug) {
                    echo "more segments {$i}/{$count}<br/>";
                }
                continue;
            }
            // we end here with this segment
            if ($debug) {
                echo "ending after transfer<br/>";
            }
            //$current_lines = getCorrectLines($current_lines, $connection);
            //$new_segment = new Segment($segment->m1, $segment->m2, $current_lines, $total_time, $connection);
            //$cpath[] = $new_segment;
            return $cpath;
        }
        // not a transfer
        $segment_lines = array();
        // find out which lines fit the segment
        foreach ($segment2->m1->lines as $line) {
            if ($debug) {
                echo "looking @ line: " . $line->name . "<br/>";
            }
            // check the connections and find which one to go to
            foreach ($line->connections as $line_connection) {
                if ($debug) {
                    echo "looking @ connection: " . $line_connection->id . "<br/>";
                }
                if ($line_connection->id == $segment2->m2->id) {
                    $line_name = $line->name;
                    if ($debug) {
                        echo "adding line {$line_name}<br/>";
                    }
                    $segment_lines["{$line_name}"] = $line;
                    break;
                }
            }
        }
        if ($debug) {
            echo "lines that fit the segment: ";
            foreach ($segment_lines as $line) {
                echo $line->name . " ";
            }
            echo "<br/>";
        }
        // we found all the lines that go to the marker that is next
        // now compare them to the current lines we have
        $new_lines = linesIntersect($current_lines, $segment_lines);
        if ($debug) {
            echo "lines that intersect the old: ";
            foreach ($new_lines as $line) {
                echo $line->name . " ";
            }
            echo "<br/>";
        }
        if (count($new_lines) == 0) {
            // no overlapping lines
            // end the old segment and add to the path
            $new_segment = new Segment($marker1, $segment2->m1, $current_lines, $total_time, $connection);
            if ($debug) {
                echo "adding segment = " . $new_segment->toString() . "<br/>";
            }
            $cpath[] = $new_segment;
            // reset our variables for the next segment
            $segment = $segment2;
            $marker1 = $segment2->m1;
            $current_lines = $segment2->m1->getOverlapLines($segment2->m2);
            $connection = $segment2->connection;
            $total_time = $segment2->t;
            continue;
        }
        // we move forward
        if ($debug) {
            echo "# current_lines: " . count($new_lines) . "<br/>";
            foreach ($new_lines as $line) {
                echo $line->name . " ";
            }
            echo "<br/>";
        }
        $current_lines = $new_lines;
        $connection = $segment2->connection;
        $total_time += $segment2->t;
    }
    // for
    // add the last segment
    if ($marker1->id != $segment2->m2->id) {
        $current_lines = getCorrectLines($current_lines, $connection);
        $new_segment = new Segment($marker1, $segment2->m2, $current_lines, $total_time, $connection);
        $cpath[] = $new_segment;
    }
    return $cpath;
}
Ejemplo n.º 2
0
 function constructor4($path, $station, $line, $connection)
 {
     $this->constructor1($path);
     $currentStation = $this->getCurrentStation();
     $lines = $currentStation->getConnectingLines($station, $connection->type);
     //$lines = $currentStation->getOverlapLines($station);
     $currentLines = $this->getCurrentLines();
     $intersect = linesIntersect($currentLines, $lines);
     if (count($intersect) == 0) {
         $this->addSegment(new Segment($currentStation, $currentStation, $intersect, 60, "transfer"), $this->bounding_box);
     }
     $box = new Box($station->getPoint(), $this->destination->getPoint());
     $this->addSegment(new Segment($currentStation, $station, $lines, $connection->duration, $connection->type), $box);
 }
Ejemplo n.º 3
0
function updateLines($segment, $current_lines)
{
    $segment_lines = $segment->m1->getOverlapLines($segment->m2);
    $current_lines = linesIntersect($current_lines, $segment_lines);
    return $current_lines;
}
Ejemplo n.º 4
0
function isSelfIntersecting($points)
{
    global $debug;
    $n_coords = count($points);
    $edges = array();
    for ($j = 0, $i = $n_coords - 1; $j < $n_coords; $i = $j++) {
        $edges[] = array($points[$i], $points[$j]);
    }
    for ($i = 0; $i <= $n_coords - 2; $i++) {
        for ($j = $i + 2; $j < $n_coords + min(0, $i - 1); $j++) {
            if ($debug) {
                echo "Checking {$i} and {$j}<br>";
            }
            if (linesIntersect($edges[$i], $edges[$j])) {
                if ($debug) {
                    echo "Lines {$i} and {$j} intersect<br>";
                }
                return true;
            }
        }
    }
    return false;
}
Ejemplo n.º 5
0
function isSelfIntersecting( $points )
{
    global $debug;

    $n_coords = count($points);
    $edges = array();
    for ( $j = 0, $i = $n_coords-1; $j < $n_coords; $i = $j++ )
    {
        $edges[] = array( $points[$i], $points[$j] );
    }

    for ( $i = 0; $i <= ($n_coords-2); $i++ )
    {
        for ( $j = $i+2; $j < $n_coords+min(0,$i-1); $j++ )
        {
            if ( $debug ) echo "Checking $i and $j<br>";
            if ( linesIntersect( $edges[$i], $edges[$j] ) )
            {
                if ( $debug ) echo "Lines $i and $j intersect<br>";
                return( true );
            }
        }
    }
    return( false );
}