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

Resource profiles

Description
  • resource_altern.mos - Alternative resources and non-constant resource usage profiles
  • resource_altern_graph.mos - Graphical repesentation of solutions as user graph.
  • resource_profile.mos - Scheduling tasks with non-constant resource usage profiles.
  • resource_profile_graph.mos - Graphical repesentation of solutions as user graph.
Further explanation of this example: 'Xpress Kalis Mosel Reference Manual'

resprofile.zip[download all files]

Source Files





resource_altern_graph.mos

(!****************************************************************
   CP example problems
   ===================
   
   file resource_altern_graph.mos
   ````````````````````````````
   Scheduling tasks with non-constant resource usage profiles.

   (c) 2008 Artelys S.A. and Fair Isaac Corporation
       rev. Sep. 2017
*****************************************************************!)
model "Alternative resources and non constant resource usage"
 uses "kalis", "mmsvg"
 
 forward procedure draw_solution(tasks: set of cptask, resources:set of cpresource)

 declarations  
  res1,res2   : cpresource
  taska,taskb : cptask 
  arr1,arr2   : list of integer
 end-declarations
 
! Fix start times and durations
 taska.start    = 3
 taska.duration = 4
 taskb.start    = 3
 taskb.duration = 4
 
! Define 2 cumulative resources
 set_resource_attributes(res1, KALIS_DISCRETE_RESOURCE, 4)
 set_resource_attributes(res2, KALIS_DISCRETE_RESOURCE, 4)
 
 setname(taska,"taska"); setname(taskb,"taskb")
 setname(res1,"R1"); setname(res2,"R2")
 
! Define alternative resources for both tasks
 arr1 := [1,3,2,3]
 arr2 := [2,4,1,3]
 requires(taska, {resusage(res1,arr1),resusage(res2,arr2)}, 1, 1)
 requires(taskb, {resusage(res1,1,1),resusage(res2,1,1)}, 1, 1)

! Find all solutions
 while (cp_find_next_sol) do
  cp_show_sol
  draw_solution({taska,taskb},{res1,res2})
  if svgclosing then break; end-if
 end-do
 
 svgwaitclose("Close browser window to terminate model execution.", 1)

!-------------------------------------------------------------
!**** Display results ****
 procedure draw_solution(tasks: set of cptask, resources: set of cpresource)
  svgerase 
  
  ires := 0    
  RESHEIGHT := 0   
  forall(res in resources, ires as counter) do      
   forall(timeindex in 0..getub(getmakespan)) do
    ub1 := getcapacity(res,timeindex)    
    forall(t in tasks)
     ub1 += getproduction(t,res,timeindex) + getprovision(t,res,timeindex)    
    if RESHEIGHT < ub1 then
     RESHEIGHT := ub1
    end-if   
   end-do
  end-do

  ires := 0
  forall(res in resources, ires as counter) do     
   svgaddgroup(getname(res),getname(res),
     if(ires mod 2 = 0, svgcolor(235,235,235), svgcolor(215,215,215))) 
   svgsetstyle(SVG_FILL,SVG_CURRENT)
   svgaddrectangle(-1,ires * RESHEIGHT, 
                    getub(getmakespan)+2, 1 * RESHEIGHT)
   svgaddtext(-1, ires * RESHEIGHT, getname(res))
  end-do

  forall(t in tasks) do    
   svgaddgroup(getname(t), getname(t))    
   svgsetstyle(SVG_FILL,SVG_CURRENT)
  end-do

  svgaddgroup("back", "",SVG_RED)    
  ires := 0
  forall(res in resources, ires as counter) do  
   forall(timeindex in 0..getub(getmakespan)) cumul(timeindex) := 0   
   forall(timeindex in 0..getub(getmakespan), t in tasks) do
    rnd := getrequirement(t,res,timeindex) + getconsumption(t,res,timeindex)
    svgaddrectangle(getname(t), timeindex, ires * RESHEIGHT +
     cumul(timeindex), 1, rnd) 
    cumul(timeindex) += rnd      
   end-do

   forall(timeindex in 0..getub(getmakespan)) do
    ub1 := ires * RESHEIGHT + getcapacity(res,timeindex) 
    ub2 := ires * RESHEIGHT + getcapacity(res,timeindex+1) 
    forall(t in tasks) do
     ub1 += getproduction(t,res,timeindex) + getprovision(t,res,timeindex)
     ub2 += getproduction(t,res,timeindex+1) + getprovision(t,res,timeindex+1)
    end-do
    svgaddline("back", timeindex, ub1, timeindex+1, ub1)
    svgaddline("back", timeindex+1, ub1, timeindex+1, ub2)
   end-do
  end-do

  svgsetgraphscale(50)
  svgsetgraphlabels("Time","Resource usage")

  svgrefresh
 ! Uncomment to pause at every iteration:
  svgpause
 end-procedure
  
end-model

Back to examples browserPrevious exampleNext example