Search code examples
prologeclipse-clp

Two objective functions


If we have two objective functions in Eclipse CLP that Cost1 is more important than Cost2, is the following true?

minimize(minimize(labeling(Vars), Cost1), Costs2).

Solution

  • Yes, this works, provided you tell the inner minimize to compute all optimal solutions, rather than just the first one (use the bb_min/3 variant of minimize):

    :- lib(ic).
    :- lib(branch_and_bound).
    
    minmin(X, Y) :-
        [X,Y] #:: 1..4,
        Cost1 #= -2*X,
        Cost2 #= -Y,
        bb_min(
            bb_min(
                labeling([X,Y]),
                Cost1,
                bb_options{solutions:all}
            ),
            Cost2,
            bb_options{solutions:one}
        ).
    

    The operational behaviour is that first Cost1 is minimized (ignoring Cost2), then Cost2 is minimized (with Cost1 fixed at its minimum):

    ?- minmin(X, Y).
    Found a solution with cost -2
    Found a solution with cost -4
    Found a solution with cost -6
    Found a solution with cost -8
    Found a solution with cost -1
    Found a solution with cost -2
    Found a solution with cost -3
    Found a solution with cost -4
    X = 4
    Y = 4
    Yes (0.00s cpu)