[ library(fd) | The ECLiPSe Libraries | Reference Manual | Alphabetic Index ]

# minimize(+Goal, ?Template, ?Solution, ?C, +Lower, +Upper, +Percent, +Timeout)

Find the solution of Goal that minimizes the maximum of elements of C, within the bounds set by Lower,Upper and Percent in time not longer than Timeout.
+Goal
A callable term.
?Template
A term containing all or some of Goal's variables
?Solution
Term to be unified with the minimized Template
?C
A linear term or a list of linear terms.
+Lower
An integer.
+Upper
An integer.
+Percent
An integer.
+Timeout
A number.

## Description

This is the most general version of the minimize predicate with all options.

A solution of the goal Goal is found that minimizes the value of C. The solution is found using the branch and bound method. Whenever a better solution is found, the upper cost bound is tightened and the search for a better solution continues.

The starting assumption is that the value to minimize is less than Upper and that any value less than Lower can be considered as a final solution. Moreover, solutions whose minimized values are closer than Percent % are considered equal. Every time a new better solution is found, the event 280 is raised, its default handler prints the current cost.

Solutions will be unified with a copy of Template where the variables are replaced with their minimized values. Typically, the Template will contain all or a subset of Goal's variables.

If Timeout is not zero, the predicate will stop after Timeout seconds and report the best solution it has found so far. Calls with specified Timeout cannot be nested.

All other variants of minimize can be written in terms of minimize/9, eg.

```	minimize(Goal, Cost) :-
minint(Min), maxint(Max),
minimize(Goal, Goal, Goal, Cost, Min, Max, 0, 0).
```

### Modules

This predicate is sensitive to its module context (tool predicate, see @/2).

### Fail Conditions

Fails if there is no solution to Goal.

No.

## Examples

```    % Find the minimal C and bind X to the corresponding value
[eclipse]: X::1..3, C #= 3-X, minimize(indomain(X), X, X, C).
Found a solution with cost 2
Found a solution with cost 1
Found a solution with cost 0
X = 3
C = 0
yes.

% Find the minimal C and don't bind anything
[eclipse]: X::1..3, C #= 3-X, minimize(indomain(X), [], [], C).
Found a solution with cost 2
Found a solution with cost 1
Found a solution with cost 0
X = X{[1..3]}
C = C{[0..2]}

Delayed goals:
-3 + X{[1..3]} + C{[0..2]}#=0
yes.

% Find the minimal C and return it in MinC. Don't bind X or C.
[eclipse]: X::1..3, C #= 3-X, minimize(indomain(X), C, MinC, C).
Found a solution with cost 2
Found a solution with cost 1
Found a solution with cost 0
X = X{[1..3]}
MinC = 0
C = C{[0..2]}

Delayed goals:
-3 + X{[1..3]} + C{[0..2]}#=0
yes.

```