IBM ILOG Solver User's Manual > More on Modeling > Using the Distribute Constraint: Car Sequencing > Solve |
Solve |
INDEX
![]() |
After you have declared the decision variables and added the constraints to the model, you are ready to search for a solution. In this lesson, you use the predefined goal IloGenerate
to search for a solution, as you did in Chapter 4, Searching with Predefined Goals: Magic Square. The predefined goal IloGenerate
allows you to control a choice in the solution search: you choose which constrained variable Solver tries to bind first.
You start the solution search by creating an instance of the class IloSolver
to solve the problem expressed in the model.
Step 8 - | Create an instance of IloSolver |
Add the following code after the comment //Create an instance of IloSolver
IloSolver solver(model); |
You now use the member function IloSolver::solve
. In this lesson, you use the predefined goal IloGenerate
as a parameter of IloSolver::solve
. The predefined goal itself takes the following parameters: the environment, the array of variables cars
, and IloChooseMinSizeInt
. From the array of variables cars
, Solver will first choose the unbound variable with the smallest domain and select a value from that domain. Solver will propagate the effects of this decision and repeat the process, moving to the variable with the next smallest domain. If a decision leads to a situation where a constraint is not satisfied, it is undone and Solver backtracks to the last decision.
Step 9 - | Search for a solution |
Add the following code after the comment //Search for a solution
if (solver.solve(IloGenerate(env, cars, IloChooseMinSizeInt))) |
The member functions and streams IloAlgorithm::out
and IloSolver::getValue
are used to display the solution. When you print the solution, you associate each value with the name of a color using the array Names[]
, which is provided for you in the exercise code. As in Chapter 4, Searching with Predefined Goals: Magic Square, the member function IloSolver::printInformation
displays information about the solution search, including number of variables, number of constraints, elapsed time since creation of search, number of fails, and number of choice points.
The following code is provided for you:
Step 10 - | Compile and run the program |
Compile and run the program. You should get the following results, though the information displayed by IloSolver::printInformation
will vary depending on platform, machine, configuration, and so on.
As you can see, three cars are painted green; three cars are painted yellow; and two cars are painted blue. The first car off the assembly line is not painted green. This is obviously a very simple example with a very straightforward result. You will model and solve a more complex car sequencing problem, involving different options and configurations, in Chapter 18, Writing a Goal: Car Sequencing.
The complete program is listed in "Complete program". You can also view it online in the file YourSolverHome/examples/src/carseq_basic.cpp
.
© Copyright IBM Corp. 1987, 2009. Legal terms. | PREVIOUS NEXT |