Prolog Restrictions on a list

192 views Asked by At

I am trying to use restrictions programming through Sicstus Prolog.

The problem is: I have a set of slots and a set of tv séries that can use one or two slots. I have to maximize the number of specs for the slots.

% 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).
...

If the duration is 60 the serie needs 2 consecutive slots, if the duration is 30 the serie only needs one. The number of series is bigger then the slots, so some series cannot be displayed.

The problem is that, i need to say that the series with 60min duration have to be consecutive, e.g. in the previous example the serie with id 1, can be displayed in [17, 18] or [58, 59] or [184, 185], but i dont know how to do that.

I used global_cardinality(Programation, Values), so that the domain variables in Programation has the number of series 0 or 1 (if the duration is 30) and 0 or 2 (if the duration is 60). This way the série with id 1, if appears in the programation has to have 2 slots. But i want to make then to be consecutive, but i dont know how to do it.

This code is what we have but it's not working:

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

Sorry for the bad english

0

There are 0 answers