我想创建一个包含三个元素A、B和C的列表L,并应用以下限制条件:
但是,它报错了 -
:- use_module(library(clpfd)).
L[A,B,C], L ins 1..3, A#=B+C.
但是,它报错了 -
语法错误:需要运算符。
只是回答一下,这样问题就不会成为未回答的问题了: 错误也可能是(:-)/2而不仅仅是丢失的(=)/2。所以以下会话可以工作:
Welcome to SWI-Prolog (Multi-threaded, 64 bits, Version 7.1.11)
Copyright (c) 1990-2014 University of Amsterdam, VU Amsterdam
?- use_module(library(clpfd)).
% library(occurs) compiled into occurs 0.00 sec, 14 clauses
% library(apply_macros) compiled into apply_macros 0.01 sec, 51 clauses
% library(assoc) compiled into assoc 0.01 sec, 103 clauses
% library(clpfd) compiled into clpfd 0.12 sec, 2,694 clauses
true.
?- L=[A,B,C], L ins 1..3, A#=B+C.
L = [A, B, C],
A in 2..3,
B+C#=A,
B in 1..2,
C in 1..2.
?- L=[A,B,C], L ins 1..3, A#=B+C, label(L).
L = [2, 1, 1],
A = 2,
B = C, C = 1
L = [3, 1, 2],
A = 3,
B = 1,
C = 2
L = [3, 2, 1],
A = 3,
B = 2,
C = 1.
再见