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





ComplexConstraints_adv.mos

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

   file ComplexConstraints_adv.mos
   ```````````````````````````````
   Improved version of model 'ComplexConstraints_std.mos'.
   -- Defining constraints with multiple conditions --

   (c) 2019-2025 Fair Isaac Corporation
       author: S.Heipcke
*******************************************************!)
model "Complex Constraints"
    !S:IMPORT
    uses "mmetc","mmsystem","mmxprs"

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

    writeln("#S:READ")
    declarations
        RN: range
        D: array(RN, RN) of real
        Dmax: array(RN) of real
        F,G: real
        q: array(RN, RN) of mpvar
    end-declarations

    initializations from "mmetc.diskdata:"
        D as "sparse,skiph," + DATA_FILE_PREFIX + "_H_ComplexConstraints_D.csv"
    end-initializations
    writeln("#E:READ")

    writeln("#S:PROC")
    F:=0.8
    G:= 0.7

    forall(m in RN) Dmax(m):= max(p in RN) D(m,p)

    declarations
        B: array(RN, RN) of boolean
    end-declarations
    ! Precalculate a repeated test condition
    forall(i in RN, k in RN)
        B(i,k):= (2 * D(i,k)<=G and D(i,k) + F * Dmax(k) <=G)

    forall(i in RN, k in RN, j in RN, m in RN |
        B(i,k) and B(j,m) and
        (i<j and k<>j and i<>m and D(i,k) + F*D(k,m) + D(m,j) > G) )
            q(i,k) + q(j,m) <= 1

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

    writeln("#S:TEST")
    forall (i in RN, k in RN, j in RN, m in RN |
        B(i,k) and B(j,m) and
        (i<j and k<>j and i<>m and D(i,k) + F*D(k,m) + D(m,j) > G) )
            writeln(i, " ", k, " ", j, " ", m)
    writeln("#E:TEST")
end-model

Back to examples browser