(!**************************************************************** CP example problems =================== file residle.mos ```````````````` Preemptive scheduling. (c) 2008 Artelys S.A. and Fair Isaac Corporation Creation: 2008, rev. Sep. 2018 *****************************************************************!) model "Preemption" uses "kalis" setparam("KALIS_DEFAULT_LB", 0) declarations aprofile,bprofile: list of integer a,b: cptask R: cpresource end-declarations ! Define a discrete resource set_resource_attributes(R, KALIS_DISCRETE_RESOURCE, 3) ! Create a 'hole' in the availability of the resource: ! Uncomment one of the following two lines to compare their effect ! setcapacity(R, 1, 2, 0); setcapacity(R, 7, 8, 0) setidletimes(R, (1..2)+(7..8)) ! Define two tasks (a: constant resource use, b: resource profile) a.duration >= 4 a.name:= "task_a" aprofile:= [1,1,1,1] b.duration >= 8 b.name:= "task_b" bprofile:= [1,1,1,2,2,2,1,1] ! Resource usage constraints requires(a, resusage(R,aprofile)) requires(b, resusage(R,bprofile)) cp_set_solution_callback("print_solution") ! Solve the problem if cp_schedule(getmakespan)<>0 then cp_show_sol else writeln("No solution") end-if ! **************************************************************** public procedure print_solution writeln("Solution: ", getsol(getmakespan)) writeln("Schedule: a: ", getsol(getstart(a)), "-", getsol(getend(a))-1, ", b: ", getsol(getstart(b)), "-", getsol(getend(b))-1) writeln("Resource usage:") forall(t in 0..getsol(getmakespan)-1) writeln(strfmt(t,5), ": Cap: ", getcapacity(R,t), ", a:", getrequirement(a, R, t), ", b:", getrequirement(b, R, t)) end-procedure end-model