Show contents 

Ms > About the MS Assembly > General Principles of Programming using Ms Assembly > Modeling Problem

Modeling Problem

Mind the following features on creating a modeling problem and working with it:

The IMsproblem interface is used to work with a modeling problem using the Fore language. Using methods and properties of this interface the user can set up problem parameters and calculate it.

To work with a modeling problem, the user need to set the calculated metamodel (the IMsproblem.MetaModel property) and determine problem type (the IMsproblem.Details property). Problem calculation options mostly depend on selected problem type. All problem types are based on the IMsproblemDetails interface which sets forecasting period and sample period of a problem. To work with a specific problem type, the user needs to use one of the child interfaces of IMsproblemDetails:

NOTE. The example given below requires objects listed in variable description section.

For example, the ControProblem object should be created to determine parameters of optimal control problem:

Sub UserProc;
Var
    Problem: IMsProblem;
    ControlProblem: IMsTransformationProblem;
Begin
    ControlProblem := New MsTransformationProblem.Create;
    Problem.Details := ControlProblem;
End Sub UserProc;

Programming of problem calculation options depends on problem type. For details refer to description of appropriate interfaces.

Creating and Calculating Modeling Problem

After creating a metamodel Metamodel for Balance of Trade Calculation the user needs to create a modeling problem, with the help of which the chain is calculated in accordance with the Fact scenario.

To run the unit that creates and calculates problem, the user needs to add links to the Metabase and Ms assemblies.

Sub UserProc;
Var
    MB: IMetabase;
    KMDesc: IMetabaseObjectDescriptor;
    CrInfo: IMetabaseObjectCreateInfo;
    MObj: IMetabaseObject;
    Problem: IMsProblem;
    TranfProblem: IMsTransformationProblem;
    CalcSett: IMsProblemCalculationSettings;
    Calculation: IMsProblemCalculation;
Begin
    MB := MetabaseClass.Active;
    KMDesc := MB.ItemById("MODEL_SPACE");
    // Create a modeling problem
    CrInfo := MB.CreateCreateInfo;
    CrInfo.ClassID := MetabaseObjectClass.KE_CLASS_MSPROBLEM;
    CrInfo.Id := "PROBLEM_BALANCE";
    CrInfo.Name := "Balance calculation problem";
    CrInfo.Parent := KMDesc;
    MObj := MB.CreateObject(CrInfo).Edit;
    Problem := MObj As IMsProblem;
    // Set calculated metamodel
    Problem.MetaModel := MB.ItemByIdNamespace("META_MODEL_BALANCE", KMDesc.Key).Bind As IMsMetaModel;
    // Set up problem calculation type: transformation problem
    TranfProblem := New MsTransformationProblem.Create;
    Problem.Details := TranfProblem;
    MObj.Save;
    Debug.WriteLine("Problem is calculated '" + MObj.Name + "' with identifier '" + MObj.Id + "'");
    // Problem calculation
    CalcSett := Problem.CreateCalculationSettings;
    CalcSett.FactIncluded := True;
    Calculation := Problem.Calculate(CalcSett);
    Calculation.SaveHistory := True;
    Calculation.Run;
End Sub UserProc;

After executing the example the Problem of Balance of Trade Calculation transformation problem with the PROBLEM_BALANCE identifier is created, information about it is displayed in the console window. The problem calculation is based on the Fact scenario in series mode. Calculation history is saved.

Displaying the calculation results is described in the View Variable Values section.

See also:

General Principles of Programming using Ms Assembly