Skip to content

Commit

Permalink
New start/end constraint system
Browse files Browse the repository at this point in the history
  • Loading branch information
leo848 committed May 31, 2024
1 parent a65299f commit 419ab6f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
27 changes: 24 additions & 3 deletions src/path/create/ilp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,20 @@ pub fn solve<C: CreateContext>(ctx: C) -> C::Path {
}
}

// Respektiere Start- und Ende
let ends = [pool.ilp_start, pool.ilp_end].into_iter().flatten();
for start in ends {
let constraint = model.add_row();
model.set_row_upper(constraint, 1.0);
for j in node_indices() {
if j == start {
continue;
}
model.set_weight(constraint, x[start][j], 1.0);
model.set_weight(constraint, x[j][start], 1.0);
}
}

// Jeder Knoten muss erreicht werden.
for i in node_indices() {
let mut pairs = Vec::new();
Expand Down Expand Up @@ -113,10 +127,10 @@ pub fn solve<C: CreateContext>(ctx: C) -> C::Path {
}
}

// Zyklen verhindern

model.solve();

// Zyklen verhindern

let mut paths = print_paths_solution(&mut model, &x);

let time_start = Instant::now();
Expand Down Expand Up @@ -147,10 +161,17 @@ pub fn solve<C: CreateContext>(ctx: C) -> C::Path {
paths = print_paths_solution(&mut model, &x);
}

let path = &paths[0];
let mut path = paths[0].clone();

// (matrix[(i, j)].into(), (0.0, 1.0));

if pool
.ilp_start
.is_some_and(|start| path.last() == Some(&start))
{
path.reverse();
}

ctx.path_from_indices(path.iter().copied())
}

Expand Down
4 changes: 4 additions & 0 deletions src/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,8 @@ pub struct OptionsPool {
pub milp_solver: Option<MilpSolver>,
#[serde(default)]
pub ilp_max_duration: Option<u64>,
#[serde(default)]
pub ilp_start: Option<usize>,
#[serde(default)]
pub ilp_end: Option<usize>,
}

0 comments on commit 419ab6f

Please sign in to comment.