MPL OptiMax Samples

 

Visual Basic - Read and Solve multiple models


Private Sub cmdSolve_Click()

    Dim MPL As OptiMax
    Dim mplModel As Model
    Dim planModel As Model
    Dim capriModel As Model
    Dim dietModel As Model
    Dim Result As Integer
    Dim cpxSolver As Solver

    Set MPL = New OptiMax
    Set cpxSolver = MPL.Solvers.Add("c:\mplwin4\CPLEX65.dll")

    MPL.WorkingDirectory = "c:\mplwin4"
    Set planModel  = MPL.Models.Add("Planning.mpl")
    Set capriModel = MPL.Models.Add("Capri.mpl")
    Set dietModel  = MPL.Models.Add("Diet.mpl")

    For Each mplModel In MPL.Models
        Result = mplModel.ReadModel(mplModel.Name)
    Next mplModel

    For Each mplModel In MPL.Models
        Result = mplModel.Solve
    Next mplModel

End Sub