% Job-shop scheduling program. % Query this program with: aclp_solve(allocate_jobs(N)) where % N = 1..20 (the number of jobs to be scheduled) :- dynamic job/4, task/3. :- compile("j10t50_17.pl"). :- dynamic allocate_jobs/1, allocate_all/4, allocate_one/5, ic/0, append1/3, previous/4, ostart/4, decoupled/4, related/2, cheaper/2, idle/2, working/2, select_task/3, already_started/4. % MODULE-1 PROBLEM MODEL allocate_jobs(N) :- allocate_all(0, N, [], AllStartVars). allocate_all(N, N, AllStartVars, AllStartVars). allocate_all(I, N, IntStartVars, AllStartVars) :- I < N, job(I, Deadline, ReleaseTime, TaskList), allocate_one(TaskList, I, ReleaseTime, Deadline, StartVars), append1(IntStartVars, StartVars, NewIntStartVars), I1 is I + 1, allocate_all(I1, N, NewIntStartVars, AllStartVars). allocate_one([], _, _, _, []). allocate_one([TaskName | RestTasks], JobName, ReleaseTime, Deadline, [StartTime | RestStart]) :- task(TaskName, Duration, Resource), StartTime :: ReleaseTime..(Deadline - Duration), start(JobName, TaskName, Resource, StartTime), allocate_one(RestTasks, JobName, ReleaseTime, Deadline, RestStart). % MODULE-2 DECLARATION OF ABDUCIBLE PREDICATES abducible_predicate(start/4). % MODULE-3 INTEGRITY CONSTRAINTS : PROPERTIES OF THE SOLUTION % Precedence constraints ic :- start(J, T1,R1,S1), previous(J, T1, T2, S2), task(T2,D2,_), S1 #< (S2 + D2). % Capacity constraints ic :- start(J1,T1,R,S1),ostart(J2,T2,R,S2),T1=\=T2, not decoupled(T1,S1,T2,S2). % Auxiliary Predicates decoupled(T1,S1,T2,S2) :- task(T1,D1,_), S1 #<= S2, S2 #>= (S1 + D1). decoupled(T1,S1,T2,S2) :- task(T2,D2,_), S2 #<= S1, S1 #>= (S2 + D2). previous(J, T1,T2,S2) :- T2 is T1 - 1, start(J, T2,R2,S2). ostart(J2,T2,R,S2) :- start(J2,T2,R,S2). append1(L1,L2,L3) :- call(append(L1,L2,L3)).