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). It is recommended to add an explicit 'exists' condition in loops over sparse arrays to improve the performance of the enumeration (doesx1.mos). Through the automatic finalization mechanism or via an explicit call to finalize a dynamic set is turned into a constant set, all subsequently declared arrays that are indexed by this set will be created as static arrays (doesx2.mos).
File(s): doesx.mos, doesx1.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, rev. Sep. 2018
*******************************************************!)

model doesx
 public declarations
  IR = 1..15
  WHICH: set of integer
  x: dynamic array(IR) of mpvar
  Obj,C: linctr
 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 resulting problem definition in Mosel
end-model

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

   file doesx1.mos
   ```````````````
   Working with dynamic arrays of variables.
   -- Using 'exists' in enumerations --
   
   (c) 2008 Fair Isaac Corporation
       author: Bob Daniel, 2001, rev. Nov. 2021
*******************************************************!)

model doesx1
 public declarations
  IR = 1..15
  WHICH: set of integer
  x: dynamic array(IR) of mpvar
  Obj,C: linctr
 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 | exists(x(i))) x(i)
 C:= sum(i in IR | exists(x(i))) i * x(i) >= 5

 exportprob(0, "", Obj)    ! Display the resulting problem definition in Mosel
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, rev. Sep. 2021
*******************************************************!)

model doesx2
 public declarations
  WHICH: set of integer
  Obj,C: linctr
 end-declarations

 initializations from 'doesx.dat'
  WHICH
 end-initializations

 public 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)    ! Display the resulting problem definition in Mosel
end-model

© 2001-2024 Fair Isaac Corporation. All rights reserved. This documentation is the property of Fair Isaac Corporation (“FICO”). Receipt or possession of this documentation does not convey rights to disclose, reproduce, make derivative works, use, or allow others to use it except solely for internal evaluation purposes to determine whether to purchase a license to the software described in this documentation, or as otherwise set forth in a written software license agreement between you and FICO (or a FICO affiliate). Use of this documentation and the software described in it must conform strictly to the foregoing permitted uses, and no other use is permitted.