FICO
FICO Xpress Optimization Examples Repository
FICO Optimization Community FICO Xpress Optimization Home
Back to examples browserPrevious exampleNext example

Resource usage profiles

Description
Special cases of resource constraints:
  • residle.mos: Preemptive scheduling ('resource idle times'); definition of resource usage profiles.
  • resprofile.mos: Scheduling with resource usage profiles; 'requires' constraints with sets of 'resusage'
  • altresource.mos: Scheduling with resource choice; 'requires' constraints with sets of 'resusage'
Further explanation of this example: 'Xpress Kalis User Guide', Section 5.6 Extensions: setup times, resource choice, usage profiles

resprofidle.zip[download all files]

Source Files





resprofile.mos

(!****************************************************************
   CP example problems
   ===================
   
   file resprofile.mos
   ```````````````````
   Scheduling tasks with resource usage profiles.

   (c) 2008 Artelys S.A. and Fair Isaac Corporation
       Creation: 2008, rev. Sep. 2018        
*****************************************************************!)
model "Task resource usage profiles"
 uses "kalis"
 
 setparam("KALIS_DEFAULT_LB", 0)
 
 declarations
  TASKS = {"a","b","c","d"}           ! Index set of tasks
  Profile: array(TASKS) of list of integer   ! Task profiles
  DUR: array(TASKS) of integer        ! Durations of tasks
 
  T: array(TASKS) of cptask           ! Tasks
  R: cpresource                       ! Cumulative resource
 end-declarations 

 DUR::(["a","b","c","d"])[7, 9, 8, 5]
 Profile("a"):= [12, 12, 6, 2, 2, 2, 2]
 Profile("b"):= [12, 12, 6, 2, 2, 2, 2, 2, 2]
 Profile("c"):= [12, 12, 3, 3, 3, 3, 3, 3]
 Profile("d"):= [6, 6, 6, 6, 6]
 
! Define a discrete resource
 set_resource_attributes(R, KALIS_DISCRETE_RESOURCE, 18)
 R.name:="machine"
 
! Define tasks with profiled resource usage
 forall(t in TASKS) do
  T(t).duration:= DUR(t)
  T(t).name:= t
  requires(T(t), resusage(R, Profile(t)))   
 end-do

 cp_set_solution_callback("print_solution")   
 starttime:=timestamp
 
! Solve the problem
 if cp_schedule(getmakespan)=0 then
  writeln("No solution")
  exit(0)
 end-if

! Solution printing
 writeln("Schedule with makespan ", getsol(getmakespan), ":")
 forall(t in TASKS)
  writeln(t, ": ", getsol(getstart(T(t))), " - ", getsol(getend(T(t))))

! ****************************************************************

! Print solutions during enumeration at the node where they are found.
! 'getrequirement' can only be used here to access solution information,
! not after the enumeration (it returns a value corresponding to the
! current state, that is, 0 after the enumeration).
 public procedure print_solution    
  writeln(timestamp-starttime, "sec. Solution: ", getsol(getmakespan))

  forall(i in 0..getsol(getmakespan)-1) do
   write(strfmt(i,2), ": ")
   forall(t in TASKS | getrequirement(T(t), R, i)>0) 
    write(t, ":", getrequirement(T(t), R, i), "  " )
   writeln(" (total ", sum(t in TASKS) getrequirement(T(t), R, i), ")" )
  end-do   
 end-procedure

end-model

Back to examples browserPrevious exampleNext example