The Model Object

The Model object is used to store all the information that's + available for a particular model and perform actions, such as reading model files into memory and then solving them. The Model object is an element of the parent Models collection

Collections contained by the Model Object

ConstraintVectors

Returns the ConstraintVectors collection for the model. (Object Property)

DataConstants

Returns the DataConstants collection for the model. (Object Property)

DataVectors

Returns the DataVectors collection for the model. (Object Property)

IndexSets

Returns the IndexSets collection for the model. (Object Property)

Macros

Returns the Macros collection for the model. (Object Property)

PlainConstraints

Returns the PlainConstraints collection for the model. (Object Property)

PlainVariables

Returns the PlainVariables collection for the model. (Object Property)

Symbols

Returns the Symbols collection for the model. (Object Property)

VariableVectors

Returns the VariableVectors collection for the model. (Object Property)

CSharp Example:


    OptiMax MPL;
    Model planModel;
    VariableVector prodVarVector;
    ResultType result;

    MPL = new OptiMax();
    planModel = MPL.Models.Add("Planning");

    string WorkingDirectory = "c:\\mplwin4";
    string ModFilePath = WorkingDirectory + "\\" + "Planning.mpl";
    result = planModel.ReadModel(ModFilePath);
    prodVarVector = planModel.VariableVectors["Sales"];

        

Objects contained by the Model Object

Matrix

Returns the Matrix object for the model. (Object Property)

Solution

Returns the Solution object for the model. (Object Property)

CSharp Example:


    OptiMax MPL;
    Solver cpxSolver;
    Model planModel;
    Matrix planMatrix;
    Solution planSol;
    ResultType result;

    MPL = new OptiMax();
    planModel = MPL.Models.Add("Planning");
    cpxSolver = MPL.Solvers.Add("CPLEX");

    string WorkingDirectory = "c:\\mplwin4";
    string ModFilePath = WorkingDirectory + "\\" + "Planning.mpl";
    result = planModel.ReadModel(ModFilePath);
    result = planModel.Solve(cpxSolver);

    planMatrix = planModel.Matrix;
    planSol = planModel.Solution;

        

Properties for the Model Object

BeepAfterSolve

Specifies whether beep is sounded after model is solved. (Boolean Property - Read/Write)

ErrorNumber

The error number from the last Read or Parse method call. (Integer Property - Read Only)

ErrorLine

The error line number from the last Read or Parse method call. (Integer Property - Read Only)

ErrorColumn

The error column number from the last Read or Parse method call. (Integer Property - Read Only)

ErrorFilename

The error filename from the last Read or Parse method call. (String Property - Read Only)

ErrorMessage

The error message from the last Read or Parse method call. (String Property - Read Only)

CSharp Example:


   OptiMax MPL;
   Solver cpxSolver;
   Model planModel;
   ResultType result;

   MPL = new OptiMax();
   cpxSolver = MPL.Solvers.Add("CPLEX");

   string ModFilePath = WorkingDirectory + "\\" + "Planning.mpl";
   result = planModel.ReadModel(ModFilePath);
   if (result > 0)
      Console.WriteLine("MPL ERROR MESSAGE: " +  planModel.ErrorMessage);

        

FileName

The filename of the current model file. (String Property - Read Only)

LastResault

The result code from the last Read or Parse method call. (Integer Property - Read Only)

Name

The name of the model object. (String Property - Read/Write)

PathName

The full pathname for the current model file. (String Property - Read/Write)

ResultString

The result string from the last Read, Parse, or Solve method call. (String Property - Read/Write)

SolverEnvPtr

The native solver environment pointer for the current model. (Pointer property - Read Only)

SolverLpPtr

The native solver problem instance pointer for the current model. (Pointer property - Read Only)

Title

The model name that is given with the TITLE statement in MPL. (String Property - Read/Write)

WorkingDirectory

The current working directory for the model. (String Property - Read/Write)

Methods for the Model Object

CancelAsap

Cancel the current run as soon as possible. (Method)

CheckSyntax (Filename)

Checks the syntax for the model file. (Method)

ClearModel

Clears the model currently stored in memory. (Method)

Define (Name)

Defines a conditional directive for the model. (Method)

LoadProblem (Solver)

Loads the current model into the solver. (Method)

Parse (Source)

Parses in a string source containing MPL model statements, appending it to the model already in memory. (Method)

ParseModel (Source)

Parses in a string source containing MPL model statements, clearing the existing model in memory. (Method)

CSharp Example:


    public integer ParseCuttingStockModel()
    {
    csModel.ParseModel("TITLE CuttingStock")
    csModel.Parse("INDEX  cuts :=  EXCELRANGE(""CutStock.xls"", ""CutsTable"", 1);");
    csModel.Parse("INDEX  patterns    :=  EXCELRANGE(PatternTable,1);");
    csModel.Parse("DATA   PriceSheet       :=  EXCELRANGE(PriceSheet);");
    csModel.Parse("DATA   SheetsAvail      :=  EXCELRANGE(SheetsAvail);");
    csModel.Parse("DATA   CutWidths[cuts]  :=  EXCELSPARSE(CutsTable,2);");
    csModel.Parse("DATA   CutDemand[cuts]  :=  EXCELSPARSE(CutsTable,3);");
    csModel.Parse("DATA   PatWaste[patterns]  :=  EXCELRANGE(PatternTable);");
    csModel.Parse("DATA   CutsInPattern[patterns, cuts]  :=  EXCELRANGE(Patterns);");
    csModel.Parse("VAR  SheetsCut  -> T1 EXPORT TO " +
        " EXCELRANGE(""CutStock.xls"", SheetsToCut);");
    csModel.Parse("VAR  TotalCost  -> TC EXPORT TO EXCELRANGE(TotalCost);");
    csModel.Parse("VAR  PatternCount[patterns] -> PT EXPORT TO EXCELRANGE(PatCount);");
    csModel.Parse("VAR   ExcessCuts[cuts]  ->  X;");
    csModel.Parse("MODEL");
    csModel.Parse("   MIN z = PriceSheet*SheetsCut;");
    csModel.Parse("SUBJECT TO  TotCost:  TotalCost = PriceSheet * SheetsCut;");
    csModel.Parse("SUBJECT TO  RawAvail: SheetsCut <= SheetsAvail;");
    csModel.Parse("SUBJECT TO  Sheets: SheetsCut = "SUM(patterns: PatterCount);");
    csModel.Parse("SUBJECT TO  CutReq[cuts]:" +
        "SUM(patterns:  CutsInPattern[patterns, cuts] * PatternCount[patterns])" +
        "=  CutDemand[cuts]  +  ExcessCuts[cuts];");
    }

        

ReadFile (FileName)

Reads a model file containing MPL model statements, appending it to the model already in memory. (Method)

ReadModel (FileName)

Reads model file containing MPL model statements, clearing the existing model in memory. (Method)

Solve (Solver)

Solves the model currently stored in the Matrix object. (Method)

VisualBasic Example:


    Dim MPL As OptiMax
    Dim planModel as Model
    Dim dietModel as Model
    Dim theModel as Model

    Set MPL = New OptiMax
    MPL.Solvers.Add "CPLEX"

    planModel = MPL.Models.Add "planning"
    dietModel = MPL.Models.Add "diet"

    For Each theModel In MPL.Models
        theModel.ReadModel(theModel.Name & ".mpl")
        theModel.Solve
    Next theModel


        

WriteMpsFile (FileName)

Writes out an MPS file for the current model. (Method)

VisualBasic Example:


    Dim MPL As OptiMax
    Dim planModel As Model

    Set MPL = New OptiMax

    MPL.WorkingDirectory = "c:\mplwin4"
    Set planModel = MPL.Models.Add("Planning")
    planModel.ReadModel ("planning.mpl")
    planModel.WriteMpsFile ("planning.mps")

        

SolveModel (FileName)

Reads the file into a new model and then solves it. (Method)

ToString

Returns a string representing the Model object. (Method)

WriteInputFile (FileName)

Writes out an input file for the current model. (Method)

WriteMappingFile (FileName)

Writes out an mapping file for the current model. (Method)

WriteSolutionFile (FileName)

Writes out a solution file for the current model solution. (Method)

VisualBasic Example:


    Dim planModel as Model

    Set MPL = New OptiMax
    MPL.Solvers.Add "CPLEX"

    Set planModel = MPL.Models.Add "planning"
    planModel.ReadModel("planning.mpl")
    planModel.Solve
    planModel.WriteSolutionFile("planning.sol")

        

Back To Top | Maximal Home Page | Table of Contents | Previous Page | Next Page