[ library(fd) | Reference Manual | Alphabetic Index ]

min_max(+Goal, ?Template, ?Solution, ?C)

Find the solution of Goal that minimizes the maximum of elements of C, and unify the minimized Template with Solution.
+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.

Description

If C is a linear term, a solution of the goal Goal is found that minimizes the value of C. If C is a list of linear terms, the returned solution minimizes the maximum value of terms in the list. The solution is found using the branch and bound method; as soon as a partial solution is found that is worse than a previous solution, the search is abandoned and a new solution is searched for. 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.

min_max/2 can be written in terms of min_max/4 as follows:

	min_max(Goal, Cost) :-
	    min_max(Goal, Goal, Goal, Cost).

Fail Conditions

Fails if there is no solution to Goal.

Resatisfiable

No.

Examples

    % Find the minimal C and bind X to the corresponding value
    [eclipse]: X::1..3, C #= 3-X, min_max(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, min_max(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, min_max(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.




See Also

min_max / 2, min_max / 5, min_max / 6, min_max / 8, minimize / 2, minimize / 4, minimize / 5, minimize / 6, minimize / 8