Reputation: 21
it's quite a long time since I'm dealing with a problem of labeling in Sicstus prolog. I want to create an array of length 7, where each item is again an array of 4 integers. I tried following code, but it doesn't work and gives an instantiation error.
:- use_module(library(clpfd)).
schedule(Ss) :-
length(Ss, 7),
Ss = [[A, B, C, D]|T],
solve_days(Ss),
labeling([], Ss).
solve_days([]).
solve_days([[A, B, C, D]|T]):-
A in 1..3,
B in 4..7,
C in 7..9,
D in 6..10,
solve_days(T).
Can anyone give me an advice how to solve it? Thanks a lot!
Upvotes: 2
Views: 681
Reputation:
An approach often seen to solve this kind of annoyance, is to use the predicate term_variables/2
before calling labeling.
The predcate term_variables/2
is an ISO core predicate since Corr.2 and determines the list of variables in a term.
In the present case one would replace
labeling([], Ss)
by
term_variables(Ss, Vars), labeling([], Vars)
Upvotes: 1
Reputation: 6854
The argument for labeling must be a plain list. One way to fix this is use use append/3 to flatten A..D and T, e.g. append([A,B,C,D],T,Vars)
.
Upvotes: 1