% machine(M) - M is a machine % job(J) - J is a job % use lparse -c n=6 schedule.lp prob1 | smodels % to calculate one solution % n=8 for prob 2 % use lparse -c n=6 schedule.lp prob1 | smodels % to calculate one solution time(0..n). #domain machine(M1;M2). #domain job(J1;J2). #domain time(T1;T2;T3). % a job must be executed one 1 {do(J,M,T) : machine(M) : time(T) } 1 :- job(J). % we could use % 0 {do(J,M,T) : job(J) : machine(M) } :- time(T). % but we will need to make sure that the job is executed % at least one using the rules % % finished(J):- job(J), time(T), machine(M), do(J,M,T). % :- job(J), not finished(J). % % these two rules will make sure that there is at least % one pair of M and T such that do(J,M,T) belongs to the % stable model % a job can be executed only on the machine where it is % possibele to do it :- do(J1,M1,T1), not possible_on(J1,M1). % the above rule (constraint) removes all stable models % in which a job J1 is executed on machine M1 but the problem % specifies that it is not possible to execute J1 on M1 % (in the absence of possible_on(J1,M1) % a job needs to start before it is too late :- do(J1,M1,T1), start(J1,T2), T2 <= T1. % the above rule removes all stable models in which job J1 is % executed at a time later than it is supposed to start % a job can only start if all of its dependencies finished :- do(J1,M1,T1), do(J2,M2,T2), depend(J1,J2), duration(J2,T3), T1 T2. % and then states that if there is an overlap, then it is % not good :- overlap(T3). %% alternatively, the above two rules can be combined into %% one constraint: % :- do(J1,M1,T1), do(J2,M1,T2), neq(J1,J2), % T1 < T2, % duration(J1,T3), T1 + T3 > T2. % the following directives are used to remove (from the display) % those atoms that we are not interested in hide machine(_). hide job(_). hide time(_). hide depend(_,_). hide possible_on(_,_). hide duration(_,_). hide start(_,_).