### 8.10 Optimization constraints

- `fd_minimize/2`, `fd_maximize/2`

#### 8.10.1 `fd_minimize/2`, `fd_maximize/2`

Templates

  `fd_minimize(+callable_term, ?fd_variable)
  fd_maximize(+callable_term, ?fd_variable)`

Description

`fd_minimize(Goal, X)` repeatedly calls `Goal` to find a value that minimizes the variable `X`. `Goal` is a Prolog goal that should instantiate `X`, a common case being the use of `fd_labeling/2` (section 8.9.1). This predicate uses a branch-and-bound algorithm with restart: each time `call(Goal)` succeeds the computation restarts with a new constraint `X #< V` where `V` is the value of `X` at the end of the last call of `Goal`. When a failure occurs (either because there are no remaining choice-points for `Goal` or because the added constraint is inconsistent with the rest of the store) the last solution is recomputed since it is optimal.

`fd_maximize(Goal, X)` is similar to `fd_minimize/2` but `X` is maximized`.`

Errors

`Goal` is a variable |  | `instantiation_error`
`Goal` is neither a variable nor a callable term |  | `type_error(callable, Goal)`
The predicate indicator `Pred` of `Goal` does not correspond to an existing procedure and the value of the `unknown` Prolog flag is `error` (section 7.22.1) |  | `existence_error(procedure, Pred)`
`X` is neither a variable nor an FD variable nor an integer |  | `type_error(fd_variable, X)`

Portability

GNU Prolog predicates.

Copyright (C) 1999-2007 Daniel Diaz Verbatim copying and distribution of this entire article is permitted in any medium, provided this notice is preserved. More about the copyright