reinterpretcat / vrp

A Vehicle Routing Problem solver
https://reinterpretcat.github.io/vrp/
Apache License 2.0
331 stars 68 forks source link

Save full solution after every Nth iteration or accept terminal signal #73

Open tdeenes opened 2 years ago

tdeenes commented 2 years ago

Would it be possible to save the full solution after every Nth iteration or gracefully handle a terminal signal and write out the solution at the iteration when the terminal signal was received?

This is also related to #72 . Use case: we want to let the user terminate the optimization process. Since I am not aware of any such termination criterion, what we wanted to do is to wrap vrp-cli in a loop, and pass the previous solution as the initial solution when starting the next run in the loop. When the user interrupts the process, we kill the actual vrp-cli run, but the user can still access the result of the previous run. However, 1) the initial solution file is not taken as the initial solution by vrp-cli (see #72), and 2) a SIGKILL termination criterion would be less hackish and way more ideal for us. Unfortunately I am an absolute newbie in Rust, otherwise I would try to implement this feature.

reinterpretcat commented 2 years ago

Just added: https://github.com/reinterpretcat/vrp/commit/40d531e8296d5900817dc6698ba9ba82ae8b1316

tdeenes commented 2 years ago

Great, thanks!

tdeenes commented 2 years ago

@reinterpretcat I had to re-open this issue because the ctrl+c termination does not work if vrp-cli is started with --config. The Ctrl+C signal itself is detected, but the program is not terminated. At least if I modify the corresponding part of the ctrlc handler so that it logs when the signal it receives, I get "Received Ctrl+C!" printed to the console both with and without --config, but the program is terminated only in the latter case.

    let _ = ctrlc::set_handler({
        let should_interrupt = should_interrupt.clone();
        move || {
            println!("Received Ctrl+C!");
            should_interrupt.store(true, Ordering::Relaxed);
        }
    });
reinterpretcat commented 2 years ago

ok, I will check it once I finish my current task