Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resetting the solver after finding optimal solutions #444

Closed
JLiangWaterloo opened this issue Aug 14, 2016 · 4 comments
Closed

Resetting the solver after finding optimal solutions #444

JLiangWaterloo opened this issue Aug 14, 2016 · 4 comments

Comments

@JLiangWaterloo
Copy link
Contributor

Consider the following example:

        Model m = new Model();
        IntVar i = m.intVar("i", 0, 5);
        Solver s = m.getSolver();
        System.out.println(s.findOptimalSolution(i, true));
        s.reset();
        System.out.println(s.findOptimalSolution(i, false));
        s.reset();
        System.out.println(s.findSolution());

This will print

Solution: i=5, 
Solution: i=0, 
null

The findSolution call failed even though the solver was reset?

@jgFages
Copy link
Contributor

jgFages commented Aug 14, 2016

I will add a model.clearObjective() at the beginning of findSolution()
Thanks

@JLiangWaterloo
Copy link
Contributor Author

I think reset should be calling model.clearObjective?

@jgFages
Copy link
Contributor

jgFages commented Aug 14, 2016

I would say that this is a different debate.

As findOptimalSolution sets the objective, it makes sense to me that findSolution and findAllSolutions make an objective clearance. As said in my commit post: For step-by-step
optimization, I recommend to use a while(solver.solve()) or to introduce a method called
findImprovingSolution(). In particular, calling solver.findAllSolutions() with an objective variable makes no sense : should we compute all solutions or all optimal ones?

solver.reset is supposed to focus on the solver object / the solving process.
The objective function is part of the model (although it also concerns the solver).
Changing the objective function is changing the problem to be solved in a sense, which is something that I would not expect when calling the reset function of the solver.

Does it make sense to you? I am open to discussion :-)

@JLiangWaterloo
Copy link
Contributor Author

Makes sense. Thanks for the clarification.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants