TAAFT
Free mode
100% free
Freemium
Free Trial
Deals

Hamiltonian Path Problem

BaseMax / HamiltonianPathProblemPHP

Implement a Hamiltonian path algorithm, and Design a tour for visiting all cities of a country. (PHP)

1 0 Language: PHP License: GPL-3.0 Updated: 3y ago

README

Hamiltonian Path Problem

Find a Hamiltonian path in a graph.

Implement a Hamiltonian path algorithm, and Design a tour for visiting all cities of a country. (PHP)

Using

$ php hamiltonian-path-problem.php

Example

If your start city is Kashan and you want to visit all cities only once and again back to Kashan.

$cities = [];
$cities[] = ["name" => "kashan", "points" => [0, 0]];
$cities[] = ["name" => "tehran", "points" => [1, 1]];
$cities[] = ["name" => "mashhad", "points" => [2, 2]];
$cities[] = ["name" => "tabriz", "points" => [3, 3]];
$cities[] = ["name" => "qom", "points" => [4, 4]];
$cities[] = ["name" => "shiraz", "points" => [5, 5]];
$cities[] = ["name" => "ahvaz", "points" => [6, 6]];
$cities[] = ["name" => "qazvin", "points" => [7, 7]];
$cities[] = ["name" => "khoramabad", "points" => [8, 8]];
$cities[] = ["name" => "yazd", "points" => [9, 9]];
$cities[] = ["name" => "sari", "points" => [10, 10]];

$res = HamiltonianPath($cities, $cities[0]);

So it's the output of the program:

  • Kashan
  • Tehran
  • Mashhad
  • Tabriz
  • Qom
  • Shiraz
  • Ahvaz
  • Qazvin
  • Khoramabad
  • Yazd
  • Sari
  • Kashan
0 AIs selected
Clear selection
#
Name
Task