Modeling Problem

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

To work with a modeling problem by Fore language, use the IMsproblem interface. 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 Main;

Var

Problem: IMsProblem;

ControlProblem: IMsTransformationProblem;

Begin

ControlProblem := New MsTransformationProblem.Create;

Problem.Details := ControlProblem;

End Sub Main

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 module that creates and calculates problem, the user needs to add links to the Ms, Metabase assemblies.

Sub Main;

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");

// Creating 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;

// Installing the calculated metamodel

Problem.MetaModel := MB.ItemByIdNamespace("META_MODEL_BALANCE", KMDesc.Key).Bind As IMsMetaModel;

// Problem calculation setup: transformation problem

TranfProblem := New MsTransformationProblem.Create;

Problem.Details := TranfProblem;

MObj.Save;

Debug.WriteLine(The MObj.Name problem + with the MObj.Id identifier + is created +);

// Problem calculation

CalcSett := Problem.CreateCalculationSettings;

CalcSett.FactIncluded := True;

Calculation := Problem.Calculate(CalcSett);

Calculation.SaveHistory := True;

Calculation.Run;

End Sub Main

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