The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Map::Metro::Graph - An entire graph

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($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 exposes 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.

full_graph()

This is the other Graph related method. This returns the complete Graph object created from parsing the map.

AUTHOR

Erik Carlsson <info@code301.com>

COPYRIGHT

Copyright 2014 - Erik Carlsson

LICENSE

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.