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





SparseGrouping_std.mos

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

   file SparseGrouping_std.mos
   ```````````````````````````
   -- Multiple cases within a loop over a sparse array --

   (c) 2019-2025 Fair Isaac Corporation
       author: S.Heipcke
*******************************************************!)
model "Sparse Grouping"

    !S:IMPORT
    uses "mmsheet"

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

    writeln("#S:READ")
    declarations
        ISet: range
        C: dynamic array(ISet,ISet,ISet,ISet) of real
        G: dynamic array(ISet,ISet,ISet,ISet) of integer
    end-declarations

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

    writeln("#S:PROC")
    forall(i,j,k,l in ISet | exists(C(i,j,k,l)))
        if C(i,j,k,l) < 100 then
            G(i,j,k,l) := 1
        elif C(i,j,k,l) < 1000 then
            G(i,j,k,l) := 2
        else
            G(i,j,k,l) := 3
        end-if
    writeln("#E:PROC")

    writeln("#S:TEST")
    forall(i,j,k,l in ISet | exists(G(i,j,k,l)) ) do
        writeln(i, " ", j, " ", k, " ", l, " ", G(i,j,k,l))
    end-do
    writeln("#E:TEST")
end-model

Back to examples browser