Hello,

there is a start place and a destination place. In the middle there are 22 other places. I want to find a short way (not the shortest because I know that this would consume too much time to calculate it) from the start place to the destination place considering all places between. The goal is that all 24 places were visited exactly once.

My input is the distance in km between all places.

My idea was to take the Graph::Simple module. I tried it with 4 places.

Here my code snippet:

use strict; use warnings; use Graph::Simple; use Data::Dumper; my $g = Graph::Simple->new ( is_directed => 0, is_weighted => 1); $g->add_edge( 'A', 'B', 200 ); $g->add_edge( 'A', 'C', 700 ); $g->add_edge( 'A', 'D', 700 ); $g->add_edge( 'B', 'C', 500 ); $g->add_edge( 'B', 'D', 500 ); $g->add_edge( 'C', 'D', 600 ); my @path = $g->shortest_path('A', 'D'); print Dumper (\@path);

The result is

$VAR1 = [ 'A', 'B', 'D' ];

But why is my point "C" not considered? I would need a route from "A" to "D" which visits also "B" and "C".

What is your suggestion to solve this problem? Is it a good idea to take a graph module to solve it?

Thank you very much.

Greetings,

Dirk


In reply to Travelling problem by Dirk80

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.