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 Mosel User Guide', Section 5.6 Extensions: setup times, resource choice, usage profiles

resprofidle.zip[download all files]

Source Files





altresource.mos

(!****************************************************************
   CP example problems
   ===================
   
   file altresource.mos
   ````````````````````
   Scheduling tasks with resource choice.

   (c) 2008 Artelys S.A. and Fair Isaac Corporation
       Creation: 2008, rev. Apr. 2022       
*****************************************************************!)
model "Alternative resources"
 uses "kalis", "mmsystem"
 
 setparam("KALIS_DEFAULT_LB", 0)
 
 forward procedure print_solution

 declarations
  TASKS = {"a","b","c","d"}           ! Index set of tasks
  MACH = {"M1", "M2"}                 ! Index set of resources
  USE: array(TASKS,MACH) of integer   ! Machine-dependent res. requirement
  DUR: array(TASKS) of integer        ! Durations of tasks
 
  task: array(TASKS) of cptask        ! Tasks
  res: array(MACH) of cpresource      ! Resources
 end-declarations 

 DUR::(["a","b","c","d"])[7, 9, 8, 5]
 USE::(["a","b","c","d"],["M1","M2"])[
      4, 3,
      2, 3,
      2, 1,
      4, 5]

! Define discrete resources
 forall(m in MACH)
  set_resource_attributes(res(m), KALIS_DISCRETE_RESOURCE, 5) 

! Define tasks with machine-dependent resource usages
 forall(j in TASKS) do
  task(j).duration:= DUR(j)
  task(j).name:= j
  requires(task(j), union(m in MACH) {resusage(res(m), USE(j,m))})   
 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
 forall(j in TASKS)
  writeln(j, ": ", getsol(getstart(task(j))), " - ", getsol(getend(task(j))))
 forall(t in 1..getsol(getmakespan)) do
  write(strfmt(t-1,2), ": ")

  ! We cannot use 'getrequirement' here to access solution information
  ! (it returns a value corresponding to the current state, that is 0)
  forall(j in TASKS | t>getsol(task(j).start) and t<=getsol(getend(task(j)))) 
   write(formattext("%s:%d  ",j,  
         sum(m in MACH) USE(j,m)*getsol(getassignment(task(j),res(m)))) )
  writeln
 end-do   

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

! Print solutions during enumeration at the node where they are found
 procedure print_solution    
  writeln(timestamp-starttime, "sec. Solution: ", getsol(getmakespan))

  forall(m in MACH) do
   writeln(m, ":")

   forall(t in 0..getsol(getmakespan)-1) do
    write(strfmt(t,2), ": ")
    forall(j in TASKS | getrequirement(task(j), res(m), t)>0) 
     write(j, ":", getrequirement(task(j), res(m), t), "  " )
    writeln("(total ", sum(j in TASKS) getrequirement(task(j), res(m), t), ")")
   end-do

  end-do 
 end-procedure

end-model

Back to examples browserPrevious exampleNext example