FICO
FICO Xpress Optimization Examples Repository
FICO Optimization Community FICO Xpress Optimization Home
Back to examples browser

Mosel files for the Mosel-Python comparison blog

Description

Mosel files for the blog post comparing Mosel and Python.

Instructions for running these files:
  1. Extract the data files into the same directory as the Mosel files
  2. To run a single file via the command line, call Mosel and pass the filename followed by "DATA_FILE_PREFIX=" and the first 2 digits of the data file. For example: mosel SparseGrouping_std.mos DATA_FILE_PREFIX=00
Further explanation of this example: See the blog 4 Main Takeaways from Comparing Xpress Mosel and Python for Optimization Models


Source Files

Data Files





ProductsMachines_std.mos

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

   file ProductsMachines_std.mos
   ```````````````````````````````
   -- Multiple conditions on loop over block of statements --

   (c) 2019-2025 Fair Isaac Corporation
       author: S.Heipcke
*******************************************************!)
model "Products and Machines"

    !S:IMPORT
    uses "mmsheet", "mmxprs"

    parameters
        DATA_FILE_PREFIX = "00"
    end-parameters
    writeln("#E:IMPORT")

    writeln("#S:READ")
    declarations
        PRODS, MACH: range
        z: dynamic array(PRODS,MACH) of mpvar
        y: dynamic array(PRODS,MACH) of mpvar
        K: array(PRODS,MACH) of integer
        T: array(MACH) of integer 
        U: array(PRODS) of integer 
    end-declarations

    initializations from "mmsheet.csv:skiph;" + DATA_FILE_PREFIX + "_H_ProductsMachines_T.csv"
        T  as "[]"
    end-initializations

    initializations from "mmsheet.csv:skiph;" + DATA_FILE_PREFIX + "_H_ProductsMachines_U.csv"
        U  as "[]"
    end-initializations

    initializations from "mmsheet.csv:skiph;" + DATA_FILE_PREFIX + "_H_ProductsMachines_K.csv"
        K  as "[]"
    end-initializations
    writeln("#E:READ")

    writeln("#S:PROC")
    forall(p in PRODS, m in MACH | K(p,m)=1 and 3*T(m)<13) do
        create(z(p,m))
        create(y(p,m))
        y(p,m) is_binary
        z(p,m) <= U(p)
    end-do

    loadprob(0)
    writeln("#E:PROC")

    writeln("#S:TEST")
    forall(p in PRODS, m in MACH | K(p,m)=1 and 3*T(m)<13) do
        writeln(p, " ", m)
    end-do
    writeln("#E:TEST")
end-model
Back to examples browser