IBM ILOG Solver User's Manual > The Basics > Constraint Programming with IBM ILOG Solver > Compile and test

This first lesson is designed to help you understand the basic concepts in constraint programming. In future lessons, you will work through problems by describing, modeling, and solving problems using IBM® ILOG® Concert Technology and IBM ILOG Solver classes. In this lesson, you are provided with the completed example code so that you can test your installation of Solver.

In Chapter 2, Modeling and Solving a Simple Problem: Map Coloring, you will learn about the classes and member functions used in this program.

The following code models and solves the problem introduced in this lesson:

#include <ilsolver/ilosolverint.h>
ILOSTLBEGIN

int main(){
  IloEnv env;
  try {
    IloModel model(env);
    IloIntVar x(env, 5, 12);
    IloIntVar y(env, 2, 17);
    model.add(x + y == 17);
    model.add(x - y == 5);
    IloSolver solver(model);
    if (solver.solve()){
      solver.out() << "x = " << solver.getValue(x) << endl;
      solver.out() << "y = " << solver.getValue(y) << endl;
    }
  }
  catch (IloException& ex) {
    cout << "Error: " << ex << endl;
  }
  env.end();
  return 0;
}

Open the example file YourSolverHome/examples/src/intro.cpp in your development environment. To test your installation of Solver, compile and run the program. If you have questions, see Installing IBM ILOG Solver in the Preface of this manual. When you run the program, you should get the following results:

x = 11
y = 6