tsp_route_finder 0.0.3 copy "tsp_route_finder: ^0.0.3" to clipboard
tsp_route_finder: ^0.0.3 copied to clipboard

A package for solving the Traveling Salesman Problem (TSP)

TSP Package #

TSP Package is a Dart package that provides a solution for the Traveling Salesman Problem (TSP). It includes an implementation of the Nearest Neighbor algorithm to find an approximate solution for the TSP route based on a list of locations.

Features #

  • Calculate the Traveling Salesman Problem (TSP) route using the Nearest Neighbor algorithm.
  • Support for calculating routes based on latitude and longitude coordinates using the google_maps_flutter package.

Example #

This package includes an example that demonstrates how to use the main features of the package.

To run the example, follow these steps:

  1. Ensure that you have the required dependencies listed in the pubspec.yaml file.
  2. Run the code to see the output in the console.
import 'package:flutter/material.dart';
import 'package:tsp_route_finder/tsp_route_finder.dart';

class FindTspRoute extends StatefulWidget {
  const FindTspRoute({super.key});

  @override
  State<FindTspRoute> createState() => _FindTspRouteState();
}

class _FindTspRouteState extends State<FindTspRoute> {
  List<int> tspRoute = [];
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text("TSP Route Finder"),
        centerTitle: true,
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            MaterialButton(
              onPressed: (){
                findTSP();
                setState(() {});
              },
              color: Colors.deepPurpleAccent,
              child: const Text("Find",style: TextStyle(color: Colors.white)),
            ),
            if(tspRoute.isNotEmpty)
              Text(tspRoute.toString()),
          ],
        ),
      ),
    );
  }

  void findTSP() async {
    // Define a list locations
    final List<CitiesLocations> locations = [
      CitiesLocations(cityName: "Cairo",latitude: 30.04536650078621,longitude: 31.233230917179828),
      CitiesLocations(cityName: "Tanta",latitude: 30.78654967266781,longitude: 31.001245021237708),
      CitiesLocations(cityName: "Mansoura",latitude: 31.040718440307945,longitude: 31.380351843023824),
      CitiesLocations(cityName: "Aswan",latitude: 24.089512449946742,longitude: 32.89933393026378),
      CitiesLocations(cityName: "Alexandria",latitude: 31.200888037065972,longitude: 29.927766526114013),
    ];

    // Calculate the TSP route
    tspRoute = await TspPackage.calculateTspRoute(locations: locations,startingLocationIndex: 0);
  }
}

Getting Started #

To start using the TSP Package, make sure you have added it as a dependency in your Dart project's pubspec.yaml file. For example:

dependencies:
  tsp_route_finder: ^0.0.3
24
likes
140
points
9
downloads

Publisher

unverified uploader

Weekly Downloads

A package for solving the Traveling Salesman Problem (TSP)

Homepage

Documentation

API reference

License

MIT (license)

Dependencies

flutter

More

Packages that depend on tsp_route_finder