Skip to content
Extraits de code Groupes Projets
Sélectionner une révision Git
  • f9c61514a8250aecf347398c7e3a2cfca457a7a8
  • main par défaut protégée
2 résultats

Navi.pm

Blame
  • Navi.pm 10,24 Kio
    package Navi;
    
    use strict;
    use warnings;
    
    BEGIN
    {
        unshift @INC, '.';
    }
    
    use App::NaviUtils;
    use App::FrameUtils;
    use App::MasterUtils;
    use App::Log;
    use App::Ressya;
    use App::TimeUtils;
    
    use List::Util qw(min);
    use Data::Printer;
    
    our $MAX_LEGS = 9;
    
    sub Raptor_simple
    {
        my $master = $_[0];
        my $from_id = $_[1];
        my $to_id = $_[2];
        my $dep_time = $_[3];
    
        my $from = MasterUtils::sta_from_id $master, $from_id;
        my $to = MasterUtils::sta_from_id $master, $to_id;
    
        Log::i "Calculating fastest routes from $from->{'ekimei'} to $to->{'ekimei'} leaving at $dep_time with $MAX_LEGS maximum legs\n";
    
        # From now on we are just blindly following the algorithm from the paper...
        # Use ~0 as a substitute to infty, not that travel times would exceed this anyway
        my %taus;
        my %taustar;
        my @marked;    
    
        # We add two more hashes:
        # one to keep track of the last used service to arrive at a station
        my %earliest;
        # and one to save the station used to board this last used service
        my %from;
    
        # We also save the number of times a station was visited
        # This may need a demonstration but we consider that the minimal time is already reached if the station is processed two times the number of routes it is served by.
        my %visited;
    
        my sub earliest_trip
        {
    	my $k = $_[0];
    	my $r = $_[1];
    	my $r_frame = MasterUtils::get_rosen_frame $master, $r;
    	my $pi = $_[2];
    	my $pos = MasterUtils::get_eki_position $master, $r, $pi;
    	# 0 is down, 1 is up
    	my $way = $_[3];
    	$pos = $way
    	    ? $r_frame->{'eki_num'} - $pos - 1
    	    : $pos;
    	Log::d "Finding the earliest trip on $r starting from $pi @ $taus{$pi}[$k - 1], direction is " . ($way ? 'up' : 'down');
    
    	my $services = $way
    	    ? $r_frame->{'dia'}{'nobori'} : $r_frame->{'dia'}{'kudari'};
    	my $final;
    	foreach my $unten (@$services)
    	{
    	    my $dt = Ressya::dep_time $unten, $pos;