SWI Prolog,CLP(R):我可以将约束绑定到变量吗?
SWI Prolog, CLP(R): Can I bind a constraint to a variable?
或者约束变量是否可以绑定到另一个变量(参见下面的示例)?
?- use_module(library(clpr)).
true.
% this works
?- {X >= 5.0, X =< 10.0}, minimize(X).
X = 5.0 .
% but I do not know why this fails
?- C = {X >= 5.0, X =< 10.0}, minimize(X).
false.
% and this also fails consequently
?- C = {X >= 5.0, X =< 10.0}, term_variables(C, [Var]), minimize(Var).
false.
Prolog 没有'assignment',所以要注意,一般来说你应该先了解它独特的编程模型。在这种特殊情况下,您可以 'invoke' 您的绑定,让 library(clpr) 有机会执行其复杂的职责:
?- use_module(library(clpr)).
true.
?- {X >= 5.0, X =< 10.0}, minimize(X).
X = 5.0 ;
false.
?- C = {X >= 5.0, X =< 10.0}, C, minimize(X).
C = {5.0>=5.0, 5.0=<10.0},
X = 5.0 ;
false.
但我认为将此技巧系统地应用于您的约束模型可能会导致应用程序变得脆弱。
或者约束变量是否可以绑定到另一个变量(参见下面的示例)?
?- use_module(library(clpr)).
true.
% this works
?- {X >= 5.0, X =< 10.0}, minimize(X).
X = 5.0 .
% but I do not know why this fails
?- C = {X >= 5.0, X =< 10.0}, minimize(X).
false.
% and this also fails consequently
?- C = {X >= 5.0, X =< 10.0}, term_variables(C, [Var]), minimize(Var).
false.
Prolog 没有'assignment',所以要注意,一般来说你应该先了解它独特的编程模型。在这种特殊情况下,您可以 'invoke' 您的绑定,让 library(clpr) 有机会执行其复杂的职责:
?- use_module(library(clpr)).
true.
?- {X >= 5.0, X =< 10.0}, minimize(X).
X = 5.0 ;
false.
?- C = {X >= 5.0, X =< 10.0}, C, minimize(X).
C = {5.0>=5.0, 5.0=<10.0},
X = 5.0 ;
false.
但我认为将此技巧系统地应用于您的约束模型可能会导致应用程序变得脆弱。