0

我已经使用 ECLiPSe 解决了有关在会议中分配文章的问题。目标是:相似的文章应该在同一个会话中。这是适用于 ECLiPSe 的解决方案:

:- lib(fd).

    paper(1, 'An Empirical Study on Using Stereotypes to Improve Understanding of UML Models').
    paper(2, 'Tool-Supported Customization of UML Class Diagrams for Learning Complex System Models').
    paper(3, 'Understanding Class Evolution in Object-Oriented Software').

    paper(4, 'A Simple Static Model for Understanding the Dynamic Behavior of Programs').
    paper(5, 'Reuse in Reverse Engineering').
    paper(6, 'Working in Pairs as a Means for Design Knowledge Building: An Empirical Study').

like(X, Y) :-
    element(I, [1, 1, 2, 4, 4, 5], X),
    element(I, [2, 3, 3, 5, 6, 6], Y).

conference([T1, T2, T3], [T4, T5, T6]) :-
    % --- domains
    L = [1, 2, 3, 4, 5, 6],
    X1::L, X2::L, X3::L, X4::L, X5::L, X6::L,
    % --- constraints
    alldifferent([X1, X2, X3, X4, X5, X6]),
    like(X1, X2), like(X1, X3), like(X2, X3), like(X4, X5), like(X4, X6), like(X5, X6), 
    % --- searching
    labeling([X1, X2, X3, X4, X5, X6]),
    % --- converting ids to titles
    paper(X1, T1), paper(X2, T2), paper(X3, T3), paper(X4, T4), paper(X5, T5), paper(X6, T6).

在 prolog 中,问题是约束的定义和标签。我知道 ECLiPSe 使用传播算法,但在序言中我必须使用回溯策略。

如何在 prolog 中移植此代码?

4

1 回答 1

3

SWI-Prolog 有一个CLP(FD)实现,它支持 ECLiPSe 版本中的大部分功能,但语法略有不同。这是conference

:- use_module(library(clpfd)).

conference([T1, T2, T3], [T4, T5, T6]) :-
    Domain = 1..6,
    [X1, X2, X3, X4, X5, X6] ins Domain,

    all_different([X1, X2, X3, X4, X5, X6]),
    like(X1, X2), like(X1, X3), like(X2, X3),
    like(X4, X5), like(X4, X6), like(X5, X6), 

    label([X1, X2, X3, X4, X5, X6]),

    paper(X1, T1), paper(X2, T2),
    paper(X3, T3), paper(X4, T4),
    paper(X5, T5), paper(X6, T6).

其他谓词按原样工作。除了label/1,您还可以使用labeling/2,它提供了对约束搜索算法的额外控制。

于 2013-06-11T19:11:29.083 回答