/* Next learn to solve minimization problems. */ :- lib(ic). :- lib(ic_sets). :- lib(ic_global). :- lib(branch_and_bound). :- import alldifferent/1 from ic_global. request(1, X) :- X in [0, 1, 2]. request(2, X) :- X in [0, 2, 3]. cost(1, 0, 1). cost(1, 1, 0). cost(1, 2, 0). cost(2, 0, 0). cost(2, 2, 1). cost(2, 3, 1). schedule(Allocation) :- NCouples is 2, length(Allocation, NCouples), alldifferent(Allocation), ( for(I, 1, NCouples), foreach(Lesson, Allocation) do request(I, Lesson) ) % bb_min(labeling(Allocation), Cost, bb_options{strategy:step}) % labeling(Allocation) . find(Allocation) :- % schedule(Allocation), length(Allocation, NCouples), ( for(I, 1, NCouples), foreach(Lesson, Allocation), fromto(0, In, Out, Cost) do request(I, Lesson), cost(I, Lesson, C), Out is In + C ), minimize(schedule(Allocation), Cost) .