0 purchases
tsp route finder
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:
Ensure that you have the required dependencies listed in the pubspec.yaml file.
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);
}
}
copied to clipboard
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
copied to clipboard
For personal and professional use. You cannot resell or redistribute these repositories in their original state.
There are no reviews.