boolean

OPL keyword.

Purpose

OPL keyword. A domain shortcut. Also a reserved word in IBM ILOG Script.

context
Model files (.mod)

Syntax

LiteralType: "int"
           | "float"
           | "boolean"
           | "int+"
           | "float+"
           | "string"
           | "range"
           | "range" "float"
           | "constraint"

Description

This keyword, which is a domain shortcut, is used only with decision variables (dvar). float+ and int+ are also domain shortcuts for dvar.


dvar boolean x;

is the same as


dvar int x in 0..1;

Example

dvar boolean weightInKnapsack1; // Is the object1 in the knapsack ?
dvar boolean weightInKnapsack2;
dvar boolean weightInKnapsack3;

int maxWeight=10; // The total weight should be less than maxWeight

int weight1=3;
int weight2=9;
int weight3=2;

// Let us try to take as many objects as we can
maximize (weightInKnapsack1+weightInKnapsack2+weightInKnapsack3);

subject to
{
   
   weightInKnapsack1*weight1+
   weightInKnapsack2*weight2+
   weightInKnapsack3*weight3<=maxWeight;
}