2
1과 0의 목록에서 연속적인 1의 수를 제한하는 매우 간단한 자동 연산을 구현하고 싶습니다 (예 : [0,1,1,0,1,1,1]).clpfd : automaton을 사용하여 SICStus Prolog에서 카운터 값을 제한하는 방법?
내 자동 장치는 다음과 같습니다
% 'Day' is a list of clpfd variables
% 'Allowed' is an integer
%
% consecutiveOnes(+Day, +Allowed)
consecutiveOnes(Day, Allowed) :-
automaton(Day, _, Day,
[source(n)],
[
arc(n, 0, n, [0] ),
arc(n, 1, n, [C+1])
],
[C],
[0],
[_N]
).
% example 1:
% consecutiveOnes([0,0,0,1,1,1], 2) -> there are three consecutive 1s and we allow only 2 -> Fail.
% example 2:
% consecutiveOnes([0,1,1,1,0,0], 2) -> there are three consecutive 1s and we allow only 2 -> Fail.
% example 3:
% consecutiveOnes([0,1,1,0,0,0], 2) -> there are only two consecutive 1s and we allow 2 -> OK
어떻게 위의 프롤로그 코드에 C <= Allowed
를 지정 카운터 C
에 대한 제약 조건을 추가 할 수 있습니까?