Skip to content

Commit

Permalink
Avoid messages, store edges to send
Browse files Browse the repository at this point in the history
  • Loading branch information
leo848 committed Apr 6, 2024
1 parent aa86fed commit dee5678
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions src/path/create/ilp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ pub fn solve<C: CreateContext>(ctx: C) -> C::Path {
let node_indices = { || (0..size) };

let mut model = Model::default();
model.set_parameter("messages", "off");

model.set_obj_sense(Sense::Minimize);

let x: Vec<Vec<Col>> = {
Expand Down Expand Up @@ -96,24 +98,22 @@ pub fn solve<C: CreateContext>(ctx: C) -> C::Path {
let mut paths = print_paths_solution(&mut model, &x);

while paths.len() > 1 {
ctx.send_edges(
paths
.iter()
.flat_map(|path| {
path.iter().tuple_windows::<(_, _)>().chain(
if path[0] == path[path.len() - 1] {
vec![(&path[path.len() - 1], &path[0])]
} else {
vec![]
},
)
})
.map(|(&i, &j)| (i, j))
.filter(|(i, j)| i != j)
.sorted()
.dedup(),
None,
);
let edges_to_send = paths
.iter()
.flat_map(|path| {
path.iter()
.tuple_windows::<(_, _)>()
.chain(if path[0] == path[path.len() - 1] {
vec![(&path[path.len() - 1], &path[0])]
} else {
vec![]
})
})
.map(|(&i, &j)| (i, j))
.filter(|(i, j)| i != j)
.sorted()
.dedup();
ctx.send_edges(edges_to_send, None);
add_cycle_constraints(&mut model, &paths, &x);
paths = print_paths_solution(&mut model, &x);
}
Expand Down

0 comments on commit dee5678

Please sign in to comment.