NAME
Map::Metro::Graph - An entire graph
VERSION
Version 0.2207, released 2015-03-03.
SYNOPSIS
my $graph = Map::Metro->new('Stockholm')->parse;
my $routing = $graph->routing_for('Universitetet', 'Kista');
# And then it's traversing time. Also see the
# Map::Metro::Plugin::Hook::PrettyPrinter hook
say $routing->origin_station->name;
say $routing->destination_station->name;
foreach my $route ($routing->all_routes) {
foreach my $step ($route->all_steps) {
say 'Transfer!' if $step->was_line_transfer;
say $step->origin_line_station->line->id;
say $step->origin_line_station->station->name;
}
say '----';
}
#* The constructed Graph object is also available
my $full_graph = $graph->full_graph;
DESCRIPTION
This class is at the core of Map::Metro. After a map has been parsed the returned instance of this class contains the entire network (graph) in a hierarchy of objects.
Methods
routing_for
Positional parameters | |||||
$origin
|
Int | Str | Station | required | The first station. Station id, name or object. |
||
$destination
|
Int | Str | Station | required | The final station. Station id, name or object. |
||
Returns | |||||
Routing |
routing_for($from, $to)
$from
Mandatory. The starting station; can be either a station id (integer), or a station name (string, case insensitive). Must be of the same type as $to
.
$to
Mandatory. The finishing station; can be either a station id (integer), or a station name (string, case insensitive). Must be of the same type as $from
.
Returns a Map::Metro::Graph::Routing object.
all_routes()
Returns an array reference of Map::Metro::Graph::Routing objects containing every unique route in the network.
asps()
This class uses Graph under the hood. This method returns the "All-Pairs Shortest Paths (APSP)" in Graph object returned by the APSP_Floyd_Warshall() method. If you prefer to traverse the graph via this object, observe that the vertices is identified by their line_station_id
in Map::Metro::Graph::LineStation.
Call this method after creation if you prefer long startup times but faster searches.
full_graph()
This returns the complete Graph object created from parsing the map.
SOURCE
https://github.com/Csson/p5-Map-Metro
HOMEPAGE
https://metacpan.org/release/Map-Metro
AUTHOR
Erik Carlsson <info@code301.com>
COPYRIGHT AND LICENSE
This software is copyright (c) 2015 by Erik Carlsson <info@code301.com>.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.