There is the predicate indomain/1 in manual that assigns values to a variable (let's call it X) in increasing order via backtracking.

I would like to change the order of values that are assigned to the variable X as I try writing a custom labeling predicate. I've come up with this code:

fd_set(X, X_as_set),
fdset_to_list(X_as_set, X_as_list), % now I have domain of the variable X in form of a list
% sort X_as_list in some way and return the changed list as X_as_list2
member(Val, X_as_list2), 
X = Val   % assign value to CLPFD variable

But I don't really know if it is correct or not. Moreover, I'm not sure if it is a proper way how to do it.

有帮助吗?

解决方案

That's a perfectly fine way of doing it.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top