Getting multiple optimal solutions using MS Solver Foundation

Proposed Answer Getting multiple optimal solutions using MS Solver Foundation

  • Sunday, June 24, 2012 7:06 PM
     
      Has Code

    Hi everyone, i'm working on a small project to learn MS Solver Foundation. I've got an application that's supposed to accept some constraints and a goal, then display ALL the optimal solutions. This is the call that i make in order to get a solution: 

    var solution = solver.Solve(new ConstraintProgrammingDirective());

    However, i get the following exception (an UnsolvableModelException): "No solver could be found that can accept the model given the model type and directive(s)".

    However, if i just write the code as follows i don't get an exception:

    var solution = solver.Solve();

    But then in this case i don't get ALL the optimal solutions, i just get one. I would like to display ALL the optimal solutions to the user.

    Thanks.

All Replies

  • Sunday, July 22, 2012 7:48 PM
     
     Proposed Answer Has Code

    Hi Arlvin,

    Sorry to see that nobody has answered your question. For solvers that support returning more than one solution you need to call the GetNext method on the solution object:

    var nextSolution = solution.GetNext();

    Not all solvers support this method - in fact, the ConstraintProgramming solver might be the only one. In order to use the ConstraintProgramming solver, make sure that your model does not contain any real-valued parameters or decisions. Here is more documentation on the GetNext method:

    http://msdn.microsoft.com/en-us/library/microsoft.solverfoundation.services.solution.getnext(v=vs.93)

    Hope this helps, Nate

    • Proposed As Answer by Nate Brixius Sunday, July 22, 2012 7:49 PM
    •