IBM ILOG Solver User's Manual > More on Solving > Searching for Optimal Solutions: Replanning Warehouses > Using embedded search |
Using embedded search |
INDEX
![]() |
Sometimes, it may be useful to search for the first solution of a given goal while you are searching for a solution to a set of goals.
For example, let's say that your problem can be decomposed into two subproblems A and B, but you are interested only in the first solution for A. In other words, you know by some means or other that the solutions of A and B are independent, and once you have a solution to A, you need not change it while you continue to search for solutions to B. Let's assume that the problem A is represented by the goal goalA
, and problem B by goalB
.
Then the following code find a solution to both problems:
solver.startNewSearch(goalA && goalB); solver.next(); solver.endSearch(); |
However, if problem B has no solutions, backtracking occurs, and Solver searches for another solution to problem A. In fact, as you have set things up in this preliminary model, all solutions of problem B are generated--useless computation in this case. Indeed, since you have already established that they are independent, you know that changing the solution for problem A will not help you find the solution of problem B.
Thus, the following code is better suited to the problem at hand:
You will end up have a solution to both problem A and B stored in solutionA
and solutionB
.
Furthermore, if problem A and problem B are not independent, you may still keep this way of solving the problem by committing to the first solution found for the problem A and then searching for a solution of problem B.
This is illustrated by the following code:
© Copyright IBM Corp. 1987, 2009. Legal terms. | PREVIOUS NEXT |