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

Names handling for decision variables and constraints

Description
This example shows the effect of compilation options on the names generated for decision variables and constraints from the model entity names depending on the declaration of the entities. Compile and execute this model with and without trace or debug options to see the effect of "setname" or the "RECLOC" parameter setting on the generated names.


Source Files





namesgen.mos

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

   file namesgen.mos 
   `````````````````
   Compile with and without trace or debug options to
   see the effect of "setname" and "RECLOC" on the 
   generated names, eg from the command line:
     mosel exe namesgen
     mosel exe -g namesgen
     mosel exe -G namesgen
 
   (c) 2015 Fair Isaac Corporation
       author: S. Heipcke, Nov. 2015, rev. Jun. 2020
*******************************************************!)

model "testing setname"
  uses "mmxprs"
  uses "mmsystem"

  declarations
    R= 1..10
  ! Uncomment one of the following two lines:
    x: array(R) of mpvar
  !  public x: array(R) of mpvar

    Ctr1: linctr
    public Ctr2: linctr

    public mat1,mat2: text
  end-declarations

  procedure defineconstraints
    declarations
      Ctr3: linctr
    end-declarations

    Ctr1:= x(1)+x(2)+x(3) <= 11      ! Globally declared, private
    Ctr2:= x(3)+x(4)+x(5) <= 12      ! Globally declared, public
    Ctr3:= x(5)+x(6)+x(6) <= 13      ! Declared locally
    Ctr4:= x(6)+x(7)+x(8) <= 14      ! Undeclared, named, local

   ! These two have no "setname" -> automatic names are always generated
   ! with "-G" these names will contain localization info
    Ctr5:= x(7)+x(8)+x(9) <= 15      ! Undeclared, named, local
    x(8)+x(9)+x(10) <= 16            ! Undeclared, unnamed, local

    setname(Ctr1, "MyCtr1")          ! Takes effect with default settings
    setname(Ctr2, "MyCtr2")          ! Always ignored
    setname(Ctr3, "MyCtr3")          ! Always applied
    setname(Ctr4, "MyCtr4")          ! Always applied
  end-procedure

 ! This setting needs to be made before defining the constraints:
  setparam("RECLOC", true)           ! Enable automatic names generation
                                     ! with localization info for "-G"

 ! Define constraints problem within a subroutine
  defineconstraints

 ! Adding some global definitions
  Ctr7:= x(1)+x(3)+x(5) <= 17        ! Undeclared, named, global
  setname(Ctr7, "MyCtr7")            ! Takes effect with default settings only
 ! These two have no "setname" -> automatic names with default comp
  x(2)+x(4)+x(8) <= 18               ! Undeclared, unnamed, global
                                     ! -G: name with localization info
  Ctr9:= x(3)+x(6)+x(9) <= 19        ! Undeclared, named, global
                                     ! -g/-G: named after entity name

  Obj:=sum(i in R) x(i)


  writeln("######## Mosel problem ########")
  exportprob("",Obj)                 ! Display problem def. in Mosel


 ! Load problem into Optimizer and output the resulting matrix
  writeln("######## Optimizer problem (loading names) ########")
  setparam("XPRS_LOADNAMES", true)   ! Enable names loading
  loadprob(Obj)
  writeprob("text:mat1", "l")        ! Write out in LP-format
  writeln(mat1)
  

  writeln("######## Optimizer problem (not loading names) ########")
  setparam("XPRS_LOADNAMES", false)  ! Disable names loading
  loadprob(true,Obj)                 ! Force problem reloading
  writeprob("text:mat2", "l")        ! Write out in LP-format
  writeln(mat2)

end-model

Back to examples browserPrevious example