maximize
OPL keyword for the objective function
Purpose
OPL keyword to express the objective function.
context |
---|
Model files (.mod) |
Syntax
Objective: . "minimize" Expression | . "maximize" Expression
Description
OPL
instructions are responsible for stating the problem constraints and,
in optimization problems, the objective function. Constraints are
stated in OPL by an optimization instruction: maximize
or minimize
.
Note:
Optimization instructions require an objective function of type integer or float.
You cannot insert an execute block between a maximize or minimize statement and constraint definitions. If there are no constraints for an objective definition, use an empty one like “subject to {}” instead.
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];
}