Skip to content
Extraits de code Groupes Projets
Valider 34f17c26 rédigé par hieda_kyuko@hpr's avatar hieda_kyuko@hpr
Parcourir les fichiers

fix: correctly parse branching lines

parent 2116da7c
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -50,13 +50,12 @@ sub is_train_route
return $frame->{'is_train'};
}
sub get_rosenmei
{
return (get_rosen_frame $_[0], $_[1])->{'rosenmei'};
}
sub get_eki_position
sub get_eki_indexes
{
my $master = $_[0];
my $rosen_id = $_[1];
......@@ -65,7 +64,18 @@ sub get_eki_position
my @ekis = @{ $rosen->{'eki'} };
my @pos;
return first { $ekis[$_] eq $id } 0..$#ekis;
my @refs;
foreach my $i (0 .. $#ekis)
{
if ($ekis[$i] eq $id) { push @refs, $i; }
}
return @refs;
}
sub get_eki_position
{
my @indexes = get_eki_indexes $_[0], $_[1], $_[2];
return $indexes[0];
}
sub get_patterns
......
......@@ -40,11 +40,14 @@ sub Raptor_simple
my %taustar;
my @marked;
# We add two more hashes:
# We also add some 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
# one to save the station used to board this last used service
my %from;
# one to keep the arrival / departure times from a station
# (this allows us to avoid having to use get_eki_indexes)
my %adt;
# 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.
......@@ -148,8 +151,9 @@ sub Raptor_simple
# We do two runs starting from $p, one towards each end of the route.
my @r_ekis = @{ (MasterUtils::get_rosen_frame $master, $r)->{'eki'} };
my $ekinum = $#r_ekis;
my $p_index = MasterUtils::get_eki_position $master, $r, $p;
my @p_indexes = MasterUtils::get_eki_indexes $master, $r, $p;
foreach my $p_index (@p_indexes)
{
# New idea: find the fastest service on a single route from $p to $index
for (my $dist = -$#r_ekis;
$dist <= $#r_ekis; # TODO optimization
......@@ -164,16 +168,22 @@ sub Raptor_simple
: $index;
my $pi = $r_ekis[$index];
$trip = NaviUtils::direct_trip $master, $r, $p, $pi, $taus{$p}[$k-1];
($trip, my $dt, my $at) = NaviUtils::direct_trip $master, $r, $p, $pi, $taus{$p}[$k-1];
# if (defined $trip
# && defined (Ressya::arr_time $trip, $index_rel)
# && (Ressya::arr_time $trip, $index_rel) < (min $taustar{$pi}, $taustar{$to_id}))
# {
if (defined $trip
&& defined (Ressya::arr_time $trip, $index_rel)
&& (Ressya::arr_time $trip, $index_rel) < (min $taustar{$pi}, $taustar{$to_id}))
{
my $trip_arrival = Ressya::arr_time $trip, $index_rel;
Log::d "Updating ETA($k) for $pi >> $trip_arrival";
$taus{$pi}->[$k] = $trip_arrival;
$taustar{$pi} = $trip_arrival;
&& defined $at
&& $at < (min $taustar{$pi}, $taustar{$to_id}))
{
# my $trip_arrival = Ressya::arr_time $trip, $index_rel;
Log::d "Updating ETA($k) for $pi >> $at using $dt from $p";
# $adt{$p}{'hatsu'} = $dt;
$adt{$pi}{'chaku'} = $at;
$taus{$pi}->[$k] = $at;
$taustar{$pi} = $at;
$earliest{$pi}{'rosen'} = $r;
$earliest{$pi}{'dir'} = $d;
$earliest{$pi}{'service'} = $trip;
......@@ -232,6 +242,7 @@ sub Raptor_simple
}
}
}
my @next_marked;
# Look at foot-paths
......@@ -307,30 +318,42 @@ sub Raptor_simple
}
# First crawl: build a list of arrival/departure times
# This does not apply for stations reached on foot
# (processed afterwards)
for (my $i = 0; $i <= $#path; $i++)
{
my %eki_jikoku = ( 'chaku' => undef, 'hatsu' => undef );
if ($i == 0) { $eki_jikoku{'chaku'} = $dep_time; }
if ($i != $#path and !defined $legs[$i]->{'time'})
{
my $next_frame = $earliest{$path[$i+1]};
my $next_eki_pos = $next_frame->{'dir'}
? $master->{'rosen'}->{$next_frame->{'rosen'}}->{'eki_num'} - (MasterUtils::get_eki_position $master, $next_frame->{'rosen'}, $path[$i]) - 1
: MasterUtils::get_eki_position $master, $next_frame->{'rosen'}, $path[$i];
my $dir = $next_frame->{'dir'};
my @next_indexes = MasterUtils::get_eki_indexes $master, $next_frame->{'rosen'}, $path[$i];
foreach my $next_index (@next_indexes)
{
my $next_eki_pos = $dir
? $master->{'rosen'}->{$next_frame->{'rosen'}}->{'eki_num'} - $next_index - 1
: $next_index;
my $dep = Ressya::dep_time $next_frame->{'service'}, $next_eki_pos;
$eki_jikoku{'hatsu'} = $dep;
if (defined $dep) { $eki_jikoku{'hatsu'} = $dep; }
}
}
if ($i != 0 and !defined $legs[$i-1]->{'time'})
{
my $previous_frame = $earliest{$path[$i]};
my $previous_eki_pos = $previous_frame->{'dir'}
? $master->{'rosen'}->{$previous_frame->{'rosen'}}->{'eki_num'} - (MasterUtils::get_eki_position $master, $previous_frame->{'rosen'}, $path[$i]) - 1
: MasterUtils::get_eki_position $master, $previous_frame->{'rosen'}, $path[$i];
my $dir = $previous_frame->{'dir'};
my @previous_indexes = MasterUtils::get_eki_indexes $master, $previous_frame->{'rosen'}, $path[$i];
foreach my $previous_index (@previous_indexes)
{
my $previous_eki_pos = $dir
? $master->{'rosen'}->{$previous_frame->{'rosen'}}->{'eki_num'} - $previous_index - 1
: $previous_index;
my $arr = Ressya::arr_time $previous_frame->{'service'}, $previous_eki_pos;
$eki_jikoku{'chaku'} = $arr;
if (defined $arr) { $eki_jikoku{'chaku'} = $arr; }
}
}
push @jikoku, \%eki_jikoku;
......@@ -346,9 +369,9 @@ sub Raptor_simple
my $m = (defined $u->{'meisyo'}) ? ' ' . $u->{'meisyo'} : '';
my $from_what = MasterUtils::get_ekimei $master, $path[$i];
my $from_dep = $jikoku[$i]->{'hatsu'};
my $from_dep = $jikoku[$i]{'hatsu'};
my $to_what = MasterUtils::get_ekimei $master, $path[$i+1];
my $to_arr = $jikoku[$i+1]->{'chaku'};
my $to_arr = $jikoku[$i+1]{'chaku'};
print( (TimeUtils::format_time $from_dep)
. "\t$from_what\n"
......@@ -369,7 +392,7 @@ sub Raptor_simple
if ($i != $#path - 1 && !defined $legs[$i+1]->{'time'})
{
my $to_dep = $jikoku[$i+1]->{'hatsu'};
my $to_dep = $jikoku[$i+1]{'hatsu'};
print( '('
. TimeUtils::format_time_simple (TimeUtils::subtract_from $to_arr, $to_dep)
. ")\tO\n"
......@@ -377,7 +400,7 @@ sub Raptor_simple
}
if ($i != $#path - 1 && defined $legs[$i+1]->{'time'})
{
my $to_dep = $jikoku[$i+2]->{'hatsu'};
my $to_dep = $jikoku[$i+2]{'hatsu'};
my $tt = $legs[$i+1]->{'time'};
my $total = TimeUtils::subtract_from $to_arr, $to_dep;
my $wait = TimeUtils::subtract_from $tt, $total;
......
......@@ -43,8 +43,18 @@ sub direct_trip
# Determine direction
# 0 down, 1 up
my $from_pos = MasterUtils::get_eki_position $master, $r, $from_id;
my $to_pos = MasterUtils::get_eki_position $master, $r, $to_id;
my $final;
# Departure time from the origin
my $final_from = ~0;
# Arrival time at the destination
my $final_to = ~0;
my @froms = MasterUtils::get_eki_indexes $master, $r, $from_id;
my @tos = MasterUtils::get_eki_indexes $master, $r, $to_id;
foreach my $from_pos (@froms)
{
foreach my $to_pos (@tos)
{
my $dir = $to_pos - $from_pos < 0 ? 1 : 0;
Log::d 'Direction is ' . ($dir ? 'up' : 'down');
my $dia = $dir
......@@ -59,7 +69,6 @@ sub direct_trip
# Only keep departures after $dep that stop at $from_id
my $final;
foreach my $u (@$dia)
{
my $udep = Ressya::dep_time $u, $from_corr;
......@@ -69,9 +78,13 @@ sub direct_trip
# TODO Times > 23:59 are currently not supported.
if ($uarr < $udep) { next; }
if (!defined $final ||
$uarr < Ressya::arr_time $final, $to_corr)
$uarr < $final_to)
{
$final = $u;
$final_from = $udep;
$final_to = $uarr;
}
}
}
}
......@@ -81,9 +94,8 @@ sub direct_trip
return;
}
my $display_dep = Ressya::dep_time $final, $from_corr;
Log::d "Found earliest departure from $from_id @ $display_dep";
return $final;
Log::d "Found earliest departure from $from_id @ $final_from > $final_to";
return ($final, $final_from, $final_to);
}
1;
......@@ -451,11 +451,11 @@ $master{'transfer_times'} = $transfers;
# FrameUtils::hassya_hyou \%master, 'sekihoku1_28';
my $d = MasterUtils::search_eki \%master, '帯広';
my $a = MasterUtils::search_eki \%master, '釧路';
my $d = MasterUtils::search_eki \%master, '春別';
my $a = MasterUtils::search_eki \%master, '五十嵐';
sub eki { return MasterUtils::search_eki \%master, $_[0]; }
Navi::Raptor_simple \%master, $d, $a, 525;
Navi::Raptor_simple \%master, $d, $a, 1000;
# FrameUtils::hassya_hyou \%master, (eki '古瀬');
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter