Initializing help system before first use

Conditional creation of decision variables


Type: Modelling: variable creation
Rating: 2 (easy-medium)
Description: If an array of decision variables of type mpvar is created as a dynamic array then its entries must be created explicitly using the subroutine create (doesx.mos). Using finalize it is possible to turn a dynamic set into a constant set (doesx2.mos).
File(s): doesx.mos, doesx2.mos
Data file(s): doesx.dat


doesx.mos
(!******************************************************
   Mosel User Guide Example Problems
   ================================= 

   file doesx.mos
   ``````````````
   Working with dynamic arrays of variables.
   
   (c) 2008 Fair Isaac Corporation
       author: Bob Daniel, 2001
*******************************************************!)

model doesx
 declarations
  IR = 1..15
  WHICH: set of integer
  x: dynamic array(IR) of mpvar
 end-declarations

! Read data from file
 initializations from 'doesx.dat'
  WHICH
 end-initializations

! Create the x variables that exist
 forall(i in WHICH) create(x(i))

! Build a little model to show what esists
 Obj:= sum(i in IR) x(i)
 C:= sum(i in IR) i * x(i) >= 5

 exportprob(0, "", Obj)               ! Display the model
end-model

doesx2.mos
(!******************************************************
   Mosel User Guide Example Problems
   ================================= 

   file doesx2.mos
   ```````````````
   Using 'finalize' to turn a dynamic set into 
   a constant set.
   
   (c) 2008 Fair Isaac Corporation
       author: Bob Daniel, 2001
*******************************************************!)

model doesx2
 declarations
  WHICH: set of integer
 end-declarations

 initializations from 'doesx.dat'
  WHICH
 end-initializations

 finalize(WHICH)

 declarations
  x: array(WHICH) of mpvar        ! Here the array is _not_ dynamic
 end-declarations                 !  because the set has been finalized

 Obj:= sum(i in WHICH) x(i)
 C:= sum(i in WHICH) i * x(i) >= 5

 exportprob(0, "", Obj)
end-model