Compare commits
28 Commits
6a0cfbc7cd
...
main
Author | SHA1 | Date | |
---|---|---|---|
e9486290d1 | |||
64e1df272f | |||
ec9652499c | |||
f34bc05741 | |||
a1da5a5e7c | |||
a05b615693 | |||
0317fb08cb | |||
0c111f4548 | |||
45f2a0d601 | |||
d5d0d32c2e | |||
7ee280d222 | |||
2ac1cb4c8a | |||
499ac62dbe | |||
6aed675ecc | |||
b42b8f5ced | |||
63d0dfb84a | |||
4d0a236e7c | |||
0aa50aad1c | |||
69d1ed02e2 | |||
872c42381b | |||
33c9bba8be | |||
60aecf6a17 | |||
aa3759b287 | |||
6db8bf1781 | |||
df5755d9ae | |||
e905c4263e | |||
7f36bb2abd | |||
09f412391d |
8
.gitea/workflows/config.js
Normal file
8
.gitea/workflows/config.js
Normal file
@@ -0,0 +1,8 @@
|
||||
module.exports = {
|
||||
"endpoint": "https://git.dev-null.rocks/api/v1", // replace it with your actual endpoint
|
||||
"gitAuthor": "Renovate Bot <renovate-bot@dev-null.rocks>",
|
||||
"platform": "gitea",
|
||||
"onboardingConfigFileName": "renovate.json",
|
||||
"autodiscover": true,
|
||||
"optimizeForDisabled": true,
|
||||
};
|
20
.gitea/workflows/renovate.yaml
Normal file
20
.gitea/workflows/renovate.yaml
Normal file
@@ -0,0 +1,20 @@
|
||||
name: renovate
|
||||
|
||||
on:
|
||||
schedule:
|
||||
- cron: "@daily"
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
|
||||
jobs:
|
||||
renovate:
|
||||
runs-on: ubuntu-latest
|
||||
container: ghcr.io/renovatebot/renovate:39.264.0
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- run: renovate
|
||||
env:
|
||||
RENOVATE_CONFIG_FILE: ".gitea/workflows/config.js" # replace it with your config.js path
|
||||
LOG_LEVEL: "debug"
|
||||
RENOVATE_TOKEN: ${{ secrets.RENOVATE_TOKEN }} # your Revonate bot token
|
46
.gitea/workflows/rust.yaml
Normal file
46
.gitea/workflows/rust.yaml
Normal file
@@ -0,0 +1,46 @@
|
||||
on: [push, pull_request]
|
||||
|
||||
name: Continuous integration
|
||||
|
||||
jobs:
|
||||
check:
|
||||
name: Check
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||
- run: cargo check
|
||||
|
||||
test:
|
||||
name: Test Suite
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||
- run: cargo test
|
||||
|
||||
fmt:
|
||||
name: Rustfmt
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||
- run: rustup component add rustfmt
|
||||
- run: cargo fmt --all -- --check
|
||||
|
||||
clippy:
|
||||
name: Clippy
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||
- run: rustup component add clippy
|
||||
- run: cargo clippy -- -D warnings
|
||||
|
||||
build:
|
||||
name: build
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||
- run: cargo build
|
5
.gitignore
vendored
5
.gitignore
vendored
@@ -20,3 +20,8 @@ Cargo.lock
|
||||
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
||||
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
||||
#.idea/
|
||||
|
||||
|
||||
# Added by cargo
|
||||
|
||||
/target
|
||||
|
16
Cargo.toml
Normal file
16
Cargo.toml
Normal file
@@ -0,0 +1,16 @@
|
||||
[package]
|
||||
name = "tsp-rs"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
rand = "0.9.0"
|
||||
rocket = "0.5.1"
|
||||
|
||||
[profile.release]
|
||||
opt-level = 'z' # Optimize for size
|
||||
lto = true # Enable link-time optimization
|
||||
codegen-units = 1 # Reduce number of codegen units to increase optimizations
|
||||
panic = 'abort' # Abort on panic
|
||||
strip = true # Strip symbols from binary*
|
||||
|
@@ -1,2 +1,6 @@
|
||||
# tsp-rs
|
||||
<p align="center">
|
||||
<a href="https://git.dev-null.rocks/alexohneander/tsp-rs/actions">
|
||||
<img src="https://git.dev-null.rocks/alexohneander/tsp-rs/actions/workflows/rust.yaml/badge.svg?branch=main" alt="Build status"></a>
|
||||
</p>
|
||||
|
||||
# tsp-rs
|
||||
|
9
renovate.json
Normal file
9
renovate.json
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"extends": ["config:recommended", ":dependencyDashboard"],
|
||||
"packageRules": [
|
||||
{
|
||||
"matchUpdateTypes": ["minor", "patch", "pin", "digest"],
|
||||
"automerge": true
|
||||
}
|
||||
]
|
||||
}
|
76
src/main.rs
Normal file
76
src/main.rs
Normal file
@@ -0,0 +1,76 @@
|
||||
//use rand::rng;
|
||||
//use rand::seq::SliceRandom;
|
||||
|
||||
#[macro_use]
|
||||
extern crate rocket;
|
||||
|
||||
fn calculate_distance(city1: &(f64, f64), city2: &(f64, f64)) -> f64 {
|
||||
let dx = city1.0 - city2.0;
|
||||
let dy = city1.1 - city2.1;
|
||||
(dx * dx + dy * dy).sqrt()
|
||||
}
|
||||
|
||||
fn calculate_tour_length(tour: &[usize], cities: &[(f64, f64)]) -> f64 {
|
||||
let mut length = 0.0;
|
||||
for i in 0..tour.len() {
|
||||
let city1 = &cities[tour[i]];
|
||||
let city2 = &cities[tour[(i + 1) % tour.len()]];
|
||||
length += calculate_distance(city1, city2);
|
||||
}
|
||||
length
|
||||
}
|
||||
|
||||
fn lin_kernighan(mut tour: Vec<usize>, cities: &[(f64, f64)]) -> Vec<usize> {
|
||||
// let rng = rng();
|
||||
let n = cities.len();
|
||||
let mut improved = true;
|
||||
|
||||
while improved {
|
||||
improved = false;
|
||||
for i in 0..n {
|
||||
for j in (i + 2)..n {
|
||||
if i == 0 && j == n - 1 {
|
||||
continue;
|
||||
}
|
||||
let mut new_tour = tour.clone();
|
||||
new_tour[i + 1..=j].reverse();
|
||||
if calculate_tour_length(&new_tour, cities) < calculate_tour_length(&tour, cities) {
|
||||
tour = new_tour;
|
||||
improved = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
tour
|
||||
}
|
||||
|
||||
#[get("/")]
|
||||
fn index() -> String {
|
||||
let cities = vec![
|
||||
(50.03317681689108, 7.630692594382566),
|
||||
(50.0511467529328, 7.610264891874095),
|
||||
(50.07417811821386, 7.637215727783678),
|
||||
(50.10154844328665, 7.683642662673185),
|
||||
(50.070237512738046, 7.697022868469907),
|
||||
(50.052876354261926, 7.6108551506699955),
|
||||
];
|
||||
|
||||
let tour: Vec<usize> = (0..cities.len()).collect();
|
||||
//tour.shuffle(&mut rng());
|
||||
|
||||
let best_tour = lin_kernighan(tour, &cities);
|
||||
|
||||
// println!("Beste Tour: {:?}", best_tour);
|
||||
println!(
|
||||
"Länge der besten Tour: {}",
|
||||
calculate_tour_length(&best_tour, &cities)
|
||||
);
|
||||
|
||||
let tour_str = format!("Beste Tour: {:?}", best_tour);
|
||||
tour_str
|
||||
}
|
||||
|
||||
#[launch]
|
||||
fn rocket() -> _ {
|
||||
rocket::build().mount("/", routes![index])
|
||||
}
|
Reference in New Issue
Block a user