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

Retrieving data from a Mosel model

Mosel-VB.NET/ExSet.vb: Using sets in Mosel (requires burglari.bim)
  • retrieve a set by its model name
  • get the set size
  • get first and last set element
  • get the name or index of a set element
ExAs.vb: Using arrays with index sets (requires trans.bim)
  • get indexing sets of an array
  • get array type
  • enumerate array entries in usual and transposed order
  • enumerate true array entries
ExProb.vb: Accessing problems and solution information with Mosel (requires blend2.bim)
  • export problem to a file (MPS or LP format)
  • get problem status
  • get objective function value
  • get primal/dual solution values, and constraint activity
Note that these examples require the provided mos files to be pre-compiled.

These .vb files can be run from the VB.NET project Mosel-VB.NET.vbproj (required auxiliary files: frmMain.vb, frmMain.resx, OptimizerLog.vb).[download all files]

Source Files

Data Files


Imports System.IO
Imports Mosel

' Example of accessing sets in Mosel
Module ExSet

    Public Sub RunExSet(ByVal Log As TextWriter)
        Dim mosel As XPRM
        Dim model As XPRMModel
        Dim mySet As XPRMSet
        Dim first, last, i As Integer

        ' Initialise Mosel
        mosel = XPRM.Init
        ' Set Mosel work directory to folder containing our example source code
        mosel.WorkDir = Directory.GetParent(System.Reflection.Assembly.GetExecutingAssembly.Location).FullName
        ' Compile and load model
        model = mosel.CompileAndLoad("Models/burglari.mos")
        ' And run it

        ' Get the model object named 'ITEMS'
        ' (it must be a set)
        mySet = model.FindIdentifier("ITEMS")

        If (Not mySet.IsEmpty) Then
            ' Items in a set are indexed by numbers
            ' So get the first and last indexes
            first = mySet.FirstIndex
            last = mySet.LastIndex
            Log.WriteLine("Elements of set ITEMS:")
            For i = first To last
                Log.Write(" {0}, ", mySet.GetAsString(i))

            ' We've written this out explicitly to demonstrate set access, but the
            ' set actually knows how to output itself.  Uncomment the following line
            ' to see this in action
            ' Log.WriteLine(mySet.ToString)

            If (mySet.GetIndex("CD player") < 0) Then
                Log.WriteLine("'CD player' is not contained in 'ITEMS'")
            End If

        End If
    End Sub

End Module

Back to examples browserNext example