subject to
OPL keyword to express constraints
Purpose
OPL keyword.
An alias for constraints
context |
---|
Model files (.mod) |
Syntax
InModelDeclaration: . LocalVar ';' | . TypeDeclaration ';' | . Objective ';' | . "subject to" '{' Constraints_opt '}' | . ';' | . "assert" Expression ';' | . Scripting
Description
The
keywords subject
to
are
associated with an optimization instruction and followed by a block
of constraints. These keywords are an alias for the OPL keyword constraints
.
Example
{string} Products = { "Car", "Truck"};
{string} Components = { "Wheel", "Tyre"};
float demand[Products][Components] = [[ 100, 200] ,[300 ,400]];
float profit[Products] = [20 ,50];
float stock[Components] = [2000 ,4000];
dvar float+ production[Products];
maximize
sum (p in Products) profit[p] * production[p];
subject to {
forall (c in Components)
sum (p in Products) demand[p, c] * production[p] <= stock[c];
}