Skip to content

keyboard interrupt #67

Open
Open

Description

@hadipourh

Hello all,

I would just like to report that we can not get the intermediate solution after a keyboard interruption.
However, this feature is available when we use Minizinc through the terminal to solve an optimization problem.
The current Python interface outputs the intermediate solution when the time limit reaches. So, is it possible to add this feature for the keyboard interruptions as well?

Activity

  1. Dekker1 commented on Nov 10, 2022

    @Dekker1
    Member

    This is slightly tricky. The simple workaround to do this is to actually capture the intermediate solutions, and keep (only) the incumbent. You can then trap the keyboard interrupt in your Python script, and then outputting the captured incumbent before exiting.

    The problem is that this pays the overhead of output/parsing for all the intermediate solutions. Depending on the amount of solutions (read: if there are thousands), this might be a large overhead to pay (especially in Python).

    Instead, we would have to use MiniZinc behaviour, and, when the solutions() function is interrupted, output the last solution that is given when the terminate() method is completed on the process. This was part of the initial design of the solutions() function, but I found that Python would throw an error if you yielded values after the async generator was already cancelled. This means we would have to provide our own terminate method for the solution() generator. This is not impossible, but might be a lot of work.

    I'm not sure if it's worth it . Especially since it should be noted that MiniZinc Python is currently set to always output and parse intermediate solutions since there are still various solvers that cannot be trusted to output their final solutions when reaching the time limit or when interrupted.

    Hopefully the workaround works for you. Otherwise, maybe we can investigate what is possible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions