两个目标函数

时间:2019-05-19 12:59:14

标签: prolog eclipse-clp

如果我们在Eclipse CLP中有两个目标函数,即Cost1Cost2更重要,那么是否正确?

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

1 个答案:

答案 0 :(得分:1)

是的,只要您告诉内部最小化函数来计算所有最优解,而不仅仅是第一个解(使用minimize的{​​{3}}变体),就可以了:

:- 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}
    ).

操作行为是首先最小化Cost1(忽略Cost2),然后最小化Cost2(最小固定Cost1):

?- 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)