PHPackages                             ahmedtaha/travelling-salesman-path - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. ahmedtaha/travelling-salesman-path

ActiveLibrary

ahmedtaha/travelling-salesman-path
==================================

The travelling salesman problem asks the following question: "Given a list of cities and the distances between each pair of cities, what is the shortest possible route that visits each city exactly once and returns to the origin city

127PHP

Since Jun 14Pushed 3y ago1 watchersCompare

[ Source](https://github.com/devTaha94/laravel-travelling-salesman-problem)[ Packagist](https://packagist.org/packages/ahmedtaha/travelling-salesman-path)[ RSS](/packages/ahmedtaha-travelling-salesman-path/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

Laravel travelling salesman problem algorithm
=============================================

[](#laravel-travelling-salesman-problem-algorithm)

Installation
------------

[](#installation)

You can install the package via [Composer](https://getcomposer.org).

```
composer require ahmedtaha/travelling-salesman-path
```

Publish your oto config file with

```
php artisan vendor:publish --provider="Ahmedtaha\TravellingSalesman\TravellingSalesmanServiceProvider" --tag="tsp"
```

If you want to calculate distance using google places driving distance change your tsp config from config/tsp.php file or i will calculate direct distance automatically

```
    "google_api_key"     => "", // google places paid key
```

Usage
-----

[](#usage)

- The problem is to find the shorter route for desired locations. let’s consider some cities you’ve to visit. you should be visit all cities once with a least cost.

```
       use Ahmedtaha\TravellingSalesman\Services\Concrete\TspBranchBound;

       $instance        = TspBranchBound::getInstance();

       #add starting point coordination
       $instance->addLocation([
        'id'            => 'Mansoura',
        'latitude'      => 31.0409,
        'longitude'     => 31.3785
      ]);

       #add array of another points coordination
      $instance->addLocation([
       [
            'id'        => 'Tanta',
            'latitude'  => 30.7865,
            'longitude' => 31.0004
        ],
        [
            'id'        => 'Ismailia',
            'latitude'  => 30.5965,
            'longitude' => 32.2715
        ],
        [
            'id'        => 'Damietta',
            'latitude'  => 31.4175,
            'longitude' => 31.8144
        ]
    ]);

     return $instance->solve();
```

Result
------

[](#result)

```
{
  "cost": 495.6299999999999,
  "locations": [
    {
      "latitude" : 31.0409,
      "longitude": 31.3785,
      "id"       : "Mansoura"
    },
    {
      "latitude" : 31.4175,
      "longitude": 31.8144,
      "id"       : "Damietta"
    },
    {
      "latitude" : 30.7865,
      "longitude": 31.0004,
      "id"       : "Tanta"
    },
    {
      "latitude" : 30.5965,
      "longitude": 32.2715,
      "id"       : "Ismailia"
    }
  ],
  "path": "Mansoura -> Damietta , Damietta -> Tanta , Tanta -> Ismailia , Ismailia -> Mansoura"
}
```

\#Follow me

[![github](https://camo.githubusercontent.com/90acd5ba6c6c0ec39271ebbe48af895142316c2f143f57b891b38f90447504bc/68747470733a2f2f63646e2e6a7364656c6976722e6e65742f6e706d2f73696d706c652d69636f6e7340332e302e312f69636f6e732f6769746875622e737667)](https://github.com/https://gitlab.com/devTaha) [![linkedin](https://camo.githubusercontent.com/3ba91dddae1fc709b104f6a0111263add9b431ccb4abf900e9ed1503aab2c0cd/68747470733a2f2f63646e2e6a7364656c6976722e6e65742f6e706d2f73696d706c652d69636f6e7340332e302e312f69636f6e732f6c696e6b6564696e2e737667)](https://www.linkedin.com/in/https://www.linkedin.com/in/devahmed94//) [![facebook](https://camo.githubusercontent.com/0da5c2a4957ac2c5e71c69d40b463c490f44b7f32d06d1e2c9afff3d888ee411/68747470733a2f2f63646e2e6a7364656c6976722e6e65742f6e706d2f73696d706c652d69636f6e7340332e302e312f69636f6e732f66616365626f6f6b2e737667)](https://www.facebook.com/https://www.facebook.com/engahmedtaha94/) [![twitter](https://camo.githubusercontent.com/985e2fd7680bb844827bf89c61eae41b82b6d6d834ea82ffaefc513fcb58b96b/68747470733a2f2f63646e2e6a7364656c6976722e6e65742f6e706d2f73696d706c652d69636f6e7340332e302e312f69636f6e732f747769747465722e737667)](https://twitter.com/https://twitter.com/a7med_sh3ish3) [![stackoverflow](https://camo.githubusercontent.com/2c4e1a60c09e43d86b54e47fc37b5cd6db26f813cbe311103f70c6ce72bd6f99/68747470733a2f2f63646e2e6a7364656c6976722e6e65742f6e706d2f73696d706c652d69636f6e7340332e302e312f69636f6e732f737461636b6f766572666c6f772e737667)](https://stackoverflow.com/users/https://stackoverflow.com/users/6555104/ahmed-taha)\#References

- [https://en.wikipedia.org/wiki/Travelling\_salesman\_problem](https://en.wikipedia.org/wiki/Travelling_salesman_problem)
-

###  Health Score

16

—

LowBetter than 5% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity25

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/8f6d5c195e9e832a7e268042b16ba2878d002f6acb2abb08b0ed2ae14027a20a?d=identicon)[devTaha94](/maintainers/devTaha94)

---

Top Contributors

[![AhmedShaisha](https://avatars.githubusercontent.com/u/9000460?v=4)](https://github.com/AhmedShaisha "AhmedShaisha (15 commits)")

### Embed Badge

![Health badge](/badges/ahmedtaha-travelling-salesman-path/health.svg)

```
[![Health](https://phpackages.com/badges/ahmedtaha-travelling-salesman-path/health.svg)](https://phpackages.com/packages/ahmedtaha-travelling-salesman-path)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
