简体   繁体   English

SWI Prolog,CLP(R):我可以将约束绑定到变量吗?

[英]SWI Prolog, CLP(R): Can I bind a constraint to a variable?

Or can a constraint variable be bound to another variable (see the example below)? 还是可以将约束变量绑定到另一个变量(请参见下面的示例)?

?- 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 doesn't have 'assignment', so beware that generally you should first understand its peculiar programming model. Prolog没有“分配”,因此请注意,通常您应该首先了解其特殊的编程模型。 In this particular case, you can 'invoke' your bindings, giving to library(clpr) a chance to perform its complex duties: 在这种情况下,您可以“调用”您的绑定,使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.

but I think that applying systematically this trick to your constraints model could result in a brittle application. 但是我认为系统地将此技巧应用于约束模型可能会导致应用程序脆弱。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM