I'm working on a scheduling problem which I have used cumulatives/3 to model.

Ex:

s1(Ss, Es, Ms ) :-
    Ss = [S1,S2,S3,S4,S5,S6,S7],
    Es = [E1,E2,E3,E4,E5,E6,E7],
    Ms = [M1,M2,M3,M4,M5,M6,M7],

    domain(Ss, 1, 30),
    domain(Es, 1, 30),
    domain(Ms, 1, 3),

    %task( StartTime, Duration, EndTime, ResourceCons, MachineId)
    Tasks = [
        task(S1, 6,E1, 1,M1),
        task(S2, 6,E2, 1,M2),
        task(S3, 3,E3, 1,M3),
        task(S4, 7,E4, 1,M4),
        task(S5, 5,E5, 1,M5),
        task(S6, 8,E6, 1,M6),
        task(S7, 4,E7, 1,M7)
    ],

    %machine( Id, ResourceBound ),
    Machines = [
        machine( 1, 1),
        machine( 2, 1),
        machine( 3, 1)
    ],

    cumulatives(Tasks, Machines, [bound(upper)] ),
    append([Ss,Es,Ms], Vars),
    labeling([], Vars). 

If I run the predicate s1/3 I get:

| ?- s1(Ss, Es, Ms ).
Es = [7,7,4,11,12,15,15],
Ms = [1,2,3,3,1,2,3],
Ss = [1,1,1,4,7,7,11] ? 
yes
| ?-

This example shows that m1 is done at 12, m2 at 15, and m3 at 15.

But what is the 'optimal' or best way to express when each machine is done with all its tasks? I would like to add some additional constraints to the end-time for a machine. Is there any global constraints which fits well to express this?

有帮助吗?

解决方案

Here is one way of expressing it. The only relevant global constraint that comes to mind is maximum/2.

| ?- makespans([1,2,3,3,1,2,3], [7,7,4,11,12,15,15], [M1,M2,M3]).
M1 = 12,
M2 = 15,
M3 = 15 ? 

% makespans(+Machines, +EndTimes, +MakeSpans) :-
%   given N tasks assigned to Machines and finishing at EndTimes,
%   the ith element of MakeSpans is unified with the max finish time for task i
%   MakeSpans should be a list of the right length
makespans(Machines, EndTimes, MakeSpans) :-
(   foreach(Make,MakeSpans),
    count(I,1,_),
    param(Machines,EndTimes)
do  (   foreach(E,EndTimes),
    foreach(M,Machines),
    foreach(T,Terms),
    param(I)
    do  T #= (M#=I)*E
    ),
    maximum(Make, Terms)
).
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top