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

Renewable and non-renewable resources

Description
Examples of the definition of resource constraints for renewable and non-renewable resources.
  • Provision/requirement of a renewable resource modeled with task and resource objects (renewa.mos).
  • Production/consumption of a non-renewable resource modeled with task and resource objects (renewb.mos). Alternative formulation with a 'producer_consumer' constraint (renewb2.mos)
Further explanation of this example: 'Xpress Kalis Mosel User Guide', Section 5.5 Renewable and non-renewable resources


Source Files
By clicking on a file name, a preview is opened at the bottom of this page.
renewa.mos[download]
renewb.mos[download]
renewb2.mos[download]

Data Files





renewb.mos

(!******************************************************
   CP Example Problems
   ===================

   file renewb.mos
   ```````````````
   Production/consumption of a non-renewable resource.
   
   (c) 2008 Artelys S.A. and Fair Isaac Corporation
   
*******************************************************!)

model "Non-renewable resource"
 uses "kalis"

 declarations   
  FIRST = {'P1','P2'}
  ENDFIRST = {'EndP1', 'EndP2'}
  FINAL = {'P3','P4','P5'}
  JOBS = FIRST+ENDFIRST+FINAL

  MIND,MAXD: array(JOBS) of integer  ! Limits on job durations
  RESAMT: array(JOBS) of integer  ! Resource use/production
  HORIZON: integer                ! Time horizon
  PROFIT: array(FINAL) of real    ! Profit from production
  COST: array(JOBS) of real       ! Cost of production
  CAP: integer                    ! Available resource quantity

  totalProfit: cpfloatvar
  task: array(JOBS) of cptask     ! Task objects for jobs
  intermProd: cpresource          ! Non-renewable resource (intermediate prod.)
 end-declarations
 
 initializations from 'Data/renewb.dat'
  [MIND,MAXD] as 'DUR' RESAMT HORIZON PROFIT COST CAP
 end-initializations

! Setting up resources
 set_resource_attributes(intermProd, KALIS_DISCRETE_RESOURCE, CAP)
 setname(intermProd, "IntP") 

! Setting up the tasks
 forall(j in JOBS) do
  setname(task(j), j)
  setduration(task(j), MIND(j), MAXD(j)) 
  setdomain(getend(task(j)), 0, HORIZON) 
 end-do 

! Production tasks
 forall(j in ENDFIRST) produces(task(j), RESAMT(j), intermProd)
 forall(j in FIRST) getend(task(j)) = getend(task("End"+j))

! Consumer tasks
 forall(j in FINAL) consumes(task(j), RESAMT(j), intermProd)

! Objective function: total profit
 totalProfit = sum(j in FINAL) PROFIT(j)*getduration(task(j)) -
               sum(j in JOBS) COST(j)*getduration(task(j))                                
 if cp_schedule(totalProfit,true)=0 then
  exit(1)
 end-if

 writeln("Total profit: ", getsol(totalProfit))
 writeln("Job\tStart\tEnd\tDuration")
 forall(j in JOBS) 
  writeln(j, "\t ", getsol(getstart(task(j))), "\t ", getsol(getend(task(j))),
          "\t ", getsol(getduration(task(j))))
 
end-model

Back to examples browserPrevious exampleNext example