Prolog 列表上的序言限制

Prolog 列表上的序言限制,prolog,clpfd,Prolog,Clpfd,我试图通过Sicstus Prolog使用限制编程 问题是:我有一套插槽和一套可以使用一两个插槽的电视系列。我必须最大化插槽的规格数量 % slots(SlotID) slots([17, 18, 24, 58, 59, 109, 184, 185, 202]). % serie(Name, Cost, Duration, Other restriction) serie(1, 1000, 60, 1). serie(2, 1500, 30, 0). ... 如果持续时间为60,则该系列需要

我试图通过Sicstus Prolog使用限制编程

问题是:我有一套插槽和一套可以使用一两个插槽的电视系列。我必须最大化插槽的规格数量

% slots(SlotID)
slots([17, 18, 24, 58, 59, 109, 184, 185, 202]).

% serie(Name, Cost, Duration, Other restriction)
serie(1, 1000, 60, 1).
serie(2, 1500, 30, 0).
...
如果持续时间为60,则该系列需要两个连续的赛段;如果持续时间为30,则该系列只需要一个赛段。系列数大于插槽数,因此无法显示某些系列

问题是,我需要说的是,持续时间为60分钟的序列必须是连续的,例如,在前面的示例中,id为1的序列可以显示在[17,18]或[58,59]或[184,185]中,但我不知道如何做到这一点

我使用了
全局基数(编程,值)
,因此编程中的域变量的编号为0或1(如果持续时间为30)和0或2(如果持续时间为60)。这样,程序中出现的id为1的série必须有2个插槽。但我想做到连续,但我不知道怎么做

这是我们的代码,但它不起作用:

conseqNumber(_, _, 0, _, _).        
conseqNumber(Programation, SlotIndex, SlotsNumber, Size, SerieId):-
        SlotIndex #=< Size, 
        element(SlotIndex, Programation, SerieId2),
        SerieId2 #= SerieId,
        SlotIndexAux #= SlotIndex +1,
        SlotsNumberAux #= SlotsNumber - 1,
        conseqNumber(Programation, SlotIndexAux, SlotsNumberAux, Size, SerieId).    


checkIfConsecutiveAux(Programation, DurationList, Size, SlotIndex, IndexCounter):- 
        element(SlotIndex, Programation, SerieId),
        element(SerieId, DurationList, SerieDuration),
        SlotsNumber #= (SerieDuration / 30) - 1,
        SlotIndexAux #= SlotIndex + 1,
        conseqNumber(Programation, SlotIndexAux, SlotsNumber, Size, SerieId),
        IndexCounter #= SlotIndexAux + SlotsNumber. 


checkIfConsecutive(_, _, Size, SlotIndex):- SlotIndex #> Size.
checkIfConsecutive(Programation, DurationList, Size, SlotIndex):- 
        checkIfConsecutiveAux(Programation, DurationList, Size, SlotIndex, IndexCounter),
        checkIfConsecutive(Programation, DurationList, Size, IndexCounter).
conseqNumber(u,u,0,u,uq)。
conseqNumber(编程、插槽索引、插槽编号、大小、序列号):-
SlotIndex#=大小。
CheckIfContinuous(编程、持续时间列表、大小、时隙索引):-
检查连续性(编程、持续时间列表、大小、时隙索引、索引计数器),
检查是否连续(编程、持续时间列表、大小、索引计数器)。
对不起,英语不好