(!****************************************************** Mosel Example Problems ====================== file d4backup3c_ka.mos `````````````````````` Bin packing: backup of files onto floppy disks - Alternative formulation using tasks, selecting the propagation algorithm - *** This model cannot be run with a Community Licence for the provided data instance *** (c) 2008 Artelys S.A. and Fair Isaac Corporation *******************************************************!) model "D-4 Bin packing (CP)" uses "kalis", "mmsystem" parameters ALG = KALIS_TASK_INTERVALS ! or: KALIS_TIMETABLING end-parameters declarations ND: integer ! Number of floppy disks FILES = 1..16 ! Set of files DISKS: range ! Set of disks CAP: integer ! Floppy disk size SIZE: array(FILES) of integer ! Size of files to be saved file: array(FILES) of cptask ! Tasks (= files to be saved) disks: cpresource ! Resource representing disks L: cpvarlist diskuse: cpvar ! Number of disks used end-declarations initializations from 'Data/d4backup.dat' CAP SIZE end-initializations ! Provide a sufficiently large number of disks ND:= ceil((sum(f in FILES) SIZE(f))/CAP) DISKS:= 1..ND ! Setting up the resource (capacity limit of disks) set_resource_attributes(disks, KALIS_DISCRETE_RESOURCE, CAP, ALG) ! Setting up the tasks forall(f in FILES) do setdomain(getstart(file(f)), DISKS) ! Start time (= choice of disk) set_task_attributes(file(f), disks, SIZE(f)) ! Resource (disk space) req. set_task_attributes(file(f), 1) ! Duration (= number of disks used) end-do ! Limit the number of disks used forall(f in FILES) L += getstart(file(f)) diskuse = maximum(L) ! Minimize the total number of disks used starttime:=gettime if cp_schedule(diskuse) = 0 then writeln("Problem infeasible") end-if ! Solution printing writeln("Number of disks used: ", getsol(diskuse)) forall(d in 1..getsol(diskuse)) do write(d, ":") forall(f in FILES) write( if(getsol(getstart(file(f)))=d , " "+SIZE(f), "")) writeln(" space used: ", sum(f in FILES | getsol(getstart(file(f)))=d) SIZE(f)) end-do writeln("Total time: ", gettime-starttime, "sec") end-model