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_graph.mos

(!****************************************************************
   CP example problems
   ===================
   
   file resprofile_graph.mos
   `````````````````````````
   Scheduling tasks with resource usage profiles.
   - Graphical solution representation -

   (c) 2008 Artelys S.A. and Fair Isaac Corporation
       Creation: 2008, rev. Sep. 2017        
*****************************************************************!)
model "Task resource usage profiles"
 uses "kalis", "mmsvg"
 
 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

! Solve the problem
 if cp_schedule(getmakespan)=0 then
  writeln("No solution")
  exit(0)
 end-if

 writeln("Solution: ", getsol(getmakespan))

! ************ Drawing a resource usage diagram ************

 declarations
  AProfile: array(TASKS) of array(S:range) of integer   ! Task profile arrays
 end-declarations 

 forall(t in TASKS) do
  ct:=1
  forall(l in Profile(t), ct as counter) AProfile(t,ct):=l
 end-do  

 L:=getsol(getmakespan)

 svgaddgroup("Res", "Resource capacity", SVG_RED)
 forall(i in 2..L)
  svgaddline([i-1, getcapacity(R,i-1), i-1, getcapacity(R,i), i, getcapacity(R,i)]) 

 declarations
  TLIST: list of string
 end-declarations 	

 ! Task graph colors
 ct:= 0
 forall(t in TASKS, ct as counter) do
  svgaddgroup(t, "Task "+t, svgcolor(25+ct*25, 25+ct*25, 50+ct*50))
  svgsetstyle(SVG_FILL,SVG_CURRENT)
 end-do 

 ! Order tasks by start times to obtain a nicer graph
 TCopy:= TASKS
 while (TCopy<>{}) do
  val:=L
  forall(t in TCopy)
   if getsol(getstart(T(t)))<val then
    val:=getsol(getstart(T(t)))
    ind:=t
   end-if 
  TLIST += [ind]
  TCopy-= {ind}
 end-do 

 ! Drawing task graphs
 forall(i in 1..L) do
  CUM:=0

  ! We cannot use 'getrequirement' here to access solution information
  ! if this graph is not drawn directly at the solution node
  forall(t in TLIST | i>getsol(getstart(T(t))) and i<=getsol(getend(T(t))) ) do
   REQ:= AProfile(t,i-getsol(getstart(T(t))))
   svgaddrectangle(t, i-1, CUM, 1, REQ)
   CUM+= REQ
  end-do 
 end-do 
 
 svgsetgraphscale(10)
 svgsetgraphviewbox(svggetgraphviewbox)
 svgsetgraphlabels("Time","Resource usage")

 svgsave("resprof.svg")
 svgrefresh
 svgwaitclose("Close browser window to terminate model execution.", 1)
end-model

Back to examples browserPrevious exampleNext example