welcome: please sign in
location: attachment:Incremental-Scheduling-ENCODING.txt of OfficialProblemSuite

Attachment 'Incremental-Scheduling-ENCODING.txt'

Download

   1 %
   2 % ******GRINGO 3.x REQUIRED******
   3 %
   4 %
   5 
   6 time(0).
   7 time(T+1) :- time(T), T < MT, max_value(MT).
   8 %time(0..MT) :- max_value(MT).
   9 
  10 pen_value(T) :- time(T).
  11 td_value(T) :- time(T).
  12 
  13 instance_of(D,1) :- device(D).
  14 instance_of(D,I+1) :- device(D), instance_of(D,I), instances(D,N), I < N.
  15 
  16 % Pick a unique start time and instance for each job
  17 1 <= { start(J,S) : time(S) } <= 1 :- job(J), not checking_solution.
  18 1 <= { on_instance(J,I) : instance_of(D,I) } <= 1 :- job(J), job_device(J,D), not checking_solution.
  19 
  20 
  21 %----------------------
  22 % - overlap
  23 %----------------------
  24 :- on_instance(J1,I), on_instance(J2,I), J1 != J2,
  25    job_device(J1,D), job_device(J2,D),
  26    start(J1,S1), job_len(J1,L1),
  27    start(J2,S2),
  28    S1 <= S2, S2 < S1 + L1.
  29 
  30 
  31 %----------------------
  32 %     - order
  33 %----------------------
  34 :- precedes(J1,J2),
  35    start(J1,S1), job_len(J1,L1),
  36    start(J2,S2),
  37    S2 < S1 + L1.
  38 
  39 
  40 %-------------------------------------
  41 %     - completion -- total-tardiness
  42 %-------------------------------------
  43 td(J,S + L - D) :-
  44 	job(J),
  45 	start(J,S), job_len(J,L),
  46 	deadline(J,D),
  47 	S + L > D.
  48 
  49 td(J,0) :-
  50 	job(J),
  51 	start(J,S), job_len(J,L),
  52 	deadline(J,D),
  53 	S + L <= D.
  54 
  55 %-------------------------------------
  56 %     - completion -- penalty
  57 %-------------------------------------
  58 
  59 penalty(J,TD * I) :-
  60 	job(J),
  61 	td(J,TD),
  62 	importance(J,I).
  63 
  64 :- penalty(J,P),
  65    max_value(MV),
  66    P > MV.
  67 
  68 tot_penalty(TP) :-
  69 	pen_value(TP),
  70 	TP = #sum{ P,J :  penalty(J,P) }.
  71 
  72 %
  73 % If the value of the total penalty would be greater than the
  74 % maximum allowed value of pen_value(_), the above rule
  75 % does not define tot_penalty(_).
  76 % In that case, the solution is not acceptable.
  77 %
  78 has_tot_penalty :-
  79 	tot_penalty(TP).
  80 -has_tot_penalty :-
  81 	not has_tot_penalty.
  82 :- -has_tot_penalty.
  83 
  84 :- pen_value(TP), tot_penalty(TP), max_total_penalty(K),
  85    TP > K.
  86 
  87 
  88 %----------------------
  89 %     - instance assignment
  90 %----------------------
  91 
  92 
  93 :- on_instance(J1,I), on_instance(J2,I),
  94    job_device(J1,D), job_device(J2,D),
  95    instances(D,N), N > 1,
  96    J1 != J2,
  97    start(J1,S1), start(J2,S2),
  98    job_len(J1,L1),
  99    S1 <= S2, S2 < S1 + L1.
 100 
 101 :- on_instance(J,I),
 102    device(D),
 103    job(J), job_device(J,D),
 104    offline_instance(D,I),
 105    must_schedule(J).
 106 
 107 
 108 %----------------------
 109 % - current schedule
 110 %----------------------
 111 
 112 already_started(J) :-
 113 	curr_job_start(J,S),
 114 	curr_time(CT),
 115 	CT > S.
 116 
 117 already_finished(J) :-
 118 	curr_job_start(J,S),
 119 	job_len(J,L),
 120 	curr_time(CT),
 121 	CT >= S + L.
 122 
 123 must_schedule(J) :-
 124 	job(J),
 125 	not must_not_schedule(J).
 126 
 127 must_not_schedule(J) :-
 128 	already_started(J),
 129 	not rescheduled(J).
 130 
 131 rescheduled(J) :-
 132 	already_started(J),
 133 	not already_finished(J),
 134 	job_device(J,D),
 135 	curr_on_instance(J,I),
 136 	offline_instance(D,I).
 137 
 138 :- start(J,S),
 139    curr_time(CT),
 140    S < CT,
 141    device(D),
 142    job_device(J,D),
 143    time(S),
 144    must_schedule(J).
 145 
 146 :- start(J,S),
 147    curr_job_start(J,CS),
 148    S != CS,
 149    job_device(J,D),
 150    must_not_schedule(J).
 151 
 152 :- on_instance(J,I),
 153    curr_on_instance(J,CI),
 154    I != CI,
 155    must_not_schedule(J).

Attached Files

You are not allowed to attach a file to this page.