1

或者可以将约束变量绑定到另一个变量(参见下面的示例)?

?- 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.
4

1 回答 1

2

Prolog doesn't have 'assignment', so beware that generally you should first understand its peculiar programming model. In this particular case, you can 'invoke' your bindings, giving to library(clpr) a chance to perform its complex duties:

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

于 2019-06-26T16:11:17.283 回答