|
:- lib(ic). overlap(Start,Duration,Time,Bool) :- % Bool is 1 if the task with start time Start and duration % Duration overlaps time point Time and 0 otherwise ic: (Bool #= ((Time $>= Start) and (Time $=< Start+Duration-1))). |
:- lib(eplex). before(Start,Duration,Time) :- % the task with start time Start and duration Duration is % completed before time point Time eplex: (Start+Duration $=< Time). |
ic_constraints(Time,S1,S2,B1,B2) :- % exactly one of task 1 with duration 3 and task 2 with % duration 5 overlaps time point Time ic: ([S1,S2]::1..20), overlap(S1,3,Time,B1), overlap(S2,5,Time,B2), ic: (B1+B2 #= 1). eplex_constraints(S1,S2,S3) :- % task 1 with duration 3 and task 2 with duration 5 are both % completed before the start time of task 3 before(S1,3,S3), before(S2,5,S3). hybrid1(Time, [S1,S2,S3], End) :- % give the eplex cost variable some default bounds ic:(End $:: -1.0Inf..1.0Inf), % we must give the start time of task 3 ic bounds in order to % suspend on changes to them ic: (S3::1..20), % setup the problem constraints ic_constraints(Time,S1,S2,B1,B2), % setup the eplex solver eplex_constraints(S1,S2,S3), eplex:eplex_solver_setup(min(S3),End,[sync_bounds(yes)],[ic:min,ic:max]), % label the variables occurring in ic constraints labeling([B1,B2,S1,S2]). |
:- lib(branch_and_bound). hybrid2(Time, [S1,S2,S3], End) :- % give the eplex cost variable some default bounds ic:(End $:: -1.0Inf..1.0Inf), % we must give the start time of task 3 ic bounds in order to % suspend on changes to them ic: (S3::1..20), % setup the problem constraints ic_constraints(Time,S1,S2,B1,B2), eplex_constraints(S1,S2,S3), % perform the optimisation both_opt(labeling([B1,B2,S1,S2]),min(S3),End). both_opt(Search,Obj,Cost) :- % setup the eplex solver eplex:eplex_solver_setup(Obj,Cost,[sync_bounds(yes)],[ic:min,ic:max]), % minimize Cost by branch-and-bound minimize((Search,eplex_get(cost,Cost)),Cost). |
A simple way to combine eplex and ic is to send the linear constraints to eplex and the other constraints to ic. The optimisation primitives must also be combined.
Figure 17.2: A Simple Example