IBM ILOG Solver User's Manual > More on Modeling > Using Constrained Floating-Point Variables: Modeling Equations > Factored and canonical forms of expressions > Factored and canonical forms: Example 2

Now suppose that x and y are two constrained variables, and you want to express the following relation: y = (x - 1)*(x + 2). If you write it in a factored form, like this:

#include <ilsolver/ilosolverfloat.h>

ILOSTLBEGIN

int main() {

  IloEnv env;
  try {
  IloModel model(env);

  IloNumVar x(env, -2, 2), y(env, -100, 100);
  model.add((x - 1)*(x + 2) == y );
  IloSolver solver(model);
  solver.propagate();
  cout << "y = " << solver.getFloatVar(y) << endl;
}
  catch (IloException& ex) {
          cerr << "Error:" << ex << endl;
  }
  env.end();
  return 0;
}

The propagation reduces the domain of y:

y = [-12, 4]

However, if you write it this way:

#include <ilsolver/ilosolverfloat.h>

ILOSTLBEGIN

int main() {

  IloEnv env;
  try {
  IloModel model(env);

  IloNumVar x(env, -2, 2), y(env, -100, 100);
  model.add(x*x + x - 2 == y);
  IloSolver solver(model);
  solver.propagate();
  cout << "y = " << solver.getFloatVar(y) << endl;
}
  catch (IloException& ex) {
          cerr << "Error:" << ex << endl;
  }
  env.end();
  return 0;
}

Then, the domain of y is:

y = [-4, 4]

In short, there are situations where the canonical form of an arithmetic expression leads to greater domain reduction than does the factored form of the same expression.


Privacy Policy