FICO
FICO Xpress Optimization Examples Repository
FICO Optimization Community FICO Xpress Optimization Home
Back to examples browserNext example

Dynamic package loading

Description
This example shows how to work with dynamic package loading in order to allow endusers to modify the definition of an optimization problem without disclosing the actual model source:
  1. Compile the package template in usrpkgtempl.mos into usrpkg.bim
  2. Compile the main model in foliomipusrpkg.mos
  3. Share the BIM files and the source of usrpkgtempl.mos with end users
  4. Compile the completed package in usrpkg.mos
  5. Run the compiled model (without recompilation) in foliomipusrpkg.bim with the new version of the package in usrpkg.bim


Source Files
By clicking on a file name, a preview is opened at the bottom of this page.
foliomipusrpkg.mos[download]
usrpkg.mos[download]
usrpkgtempl.mos[download]

Data Files





usrpkg.mos

(!******************************************************
   Mosel Example Problems
   ======================

   file usrpkg.mos
   ```````````````
   Entry point template populated with user constraint definitions,  
   including addition of new variables

   Compile to file 'usrpkg.bim'   
   
  (c) 2021 Fair Isaac Corporation
      author: S.Heipcke, Apr. 2021
*******************************************************!)
package usrpkg
  uses "advmod"
    ! Any libraries loaded here also need to be loaded by the main model

 ! Entities from main model available to this package
 ! (this results in an implicit 'public' declaration of these entities)
  requirements
    Return,LimRisk: linctr
    SHARES: set of string
    frac: array(SHARES) of mpvar 
  end-requirements

  declarations
    newv: array(set of string) of mpvar
    ! It is not possible to work in the declarations with a set name stated
    ! in the 'requirements', so here we simply keep the index set unnamed
  end-declarations

  public procedure userctrdef
    ! Change a constraint definition
    settype(LimRisk, CT_GEQ)
    setcoeff(LimRisk, -0.1)

    ! Add a new set of variables and constraints
    forall(s in SHARES) create(newv(s))
    forall(s in SHARES) newv(s) is_binary
    forall(s in SHARES) indicator(1, newv(s), frac(s)>=0.1)
    sum(s in SHARES) newv(s)>=5

    ! Add new variables to the objective
    Return+=sum(s in SHARES) newv(s)
  end-procedure
end-package

Back to examples browserNext example