Crates.io | ibn_battuta |
lib.rs | ibn_battuta |
version | 0.1.1 |
source | src |
created_at | 2024-09-14 17:04:11.855184 |
updated_at | 2024-09-14 17:08:28.173804 |
description | A Rust Library for Solving the Travelling Salesman Problem (TSP) |
homepage | https://github.com//BIRSAx2/ibn-battuta |
repository | https://github.com//BIRSAx2/ibn-battuta |
max_upload_size | |
id | 1374935 |
size | 9,762,449 |
ibn-battuta
is a powerful, flexible, and extensible Rust library designed to solve the Travelling Salesman Problem (
TSP) using various algorithms, including exact, heuristic, and metaheuristic methods. The library is designed to handle
both small and large instances of TSP efficiently and is optimized for parallel processing, making it suitable for
performance benchmarking across multiple solvers.
Exact Algorithms:
Heuristic Algorithms:
Metaheuristic Algorithms:
TSP Parser:
.tsp
files (TSPLIB format) for loading TSP instances.Parallel Processing:
rayon
crate for multi-threaded execution, allowing for efficient benchmarking and parallel
computations.Add the following to your Cargo.toml
:
[dependencies]
ibn_battuta = "0.1.0"
Then, in your Rust code:
use ibn_battuta::algorithms::utils::Solver;
use ibn_battuta::parser::TspBuilder;
The following example demonstrates how to benchmark multiple TSP solvers in parallel:
use ibn_battuta::algorithms::utils::Solver;
use ibn_battuta::algorithms::*;
use ibn_battuta::parser::TspBuilder;
use rayon::prelude::*;
use std::sync::{Arc, Mutex};
use std::fs::OpenOptions;
use std::time::Duration;
fn main() {
// List of solvers to benchmark
let solvers = vec![
Solver::NearestNeighbor,
Solver::TwoOpt,
Solver::SimulatedAnnealing,
Solver::GeneticAlgorithm,
Solver::AntColonySystem,
Solver::RedBlackAntColonySystem,
];
// Parameters for each solver
let params = vec![
vec![], // NN
vec![], // 2-Opt
vec![1000.0, 0.999, 0.0001, 1000.0, 100.0], // SA
vec![100.0, 5.0, 0.7, 0.01, 500.0], // GA
vec![0.1, 2.0, 0.1, 0.9, 1000.0, 15.0], // ACS
vec![0.1, 2.0, 0.1, 0.2, 0.9, 1000.0, 15.0], // RB-ACS
];
// Number of threads to use
let num_threads = 8;
// TSP instances to benchmark
let instances = vec![
TspInstance { path: "data/tsplib/eil51.tsp".to_string(), best_known: 426.0 },
TspInstance { path: "data/tsplib/berlin52.tsp".to_string(), best_known: 7542.0 },
];
// CSV file to save results
let csv_file = Arc::new(Mutex::new(create_csv_file("Benchmark-Results.csv")));
run_parallel_benchmarks(&instances, &solvers, ¶ms, num_threads, csv_file);
}
fn create_csv_file(filename: &str) -> std::fs::File {
OpenOptions::new().write(true).create(true).truncate(true).open(filename).expect("Unable to create file")
}
These algorithms find the optimal solution but may take a long time for large instances:
These algorithms find good (but not necessarily optimal) solutions quickly:
These algorithms use more complex strategies to search the solution space:
Contributions to ibn-battuta
are welcome! Please submit issues or pull requests via GitHub.
This project is licensed under the MIT License.
This project is inspired by the work of various TSP solvers and metaheuristics, and is named after the famous explorer Ibn Battuta, representing the spirit of exploring optimal solutions in vast solution spaces.
Special thanks to the authors of the following libraries and tools:
Particular thanks to the authors of the following papers :