Mind the following features on creating a modeling problem and working with it:
The object class Modeling Problem- MetabaseObjectClass.KE_CLASS_MSPROBLEM.
The user must determine a parent container because a modeling problem can be stored only within a container.
On creating, a modeling problem does not contain any scenarios, and it is calculated in accordance with the Fact scenario.
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 parameters 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:
IMsControlProblem. Optimal control problem. Consists in searching for such values of controlling variables, at which the condition of criterion function value optimization is met.
IMsLinearDecompositionProblem. Forward-looking forecasting. It differs from other problems because equations of this problem may include lagged variables not only at previous time moments (t-lag), but at the next time moments (t+lag).
IMsForecastingProblem. Forecasting problem. Models are calculated one after another for each scenario point: firstly, all models are calculated by the first scenario point, then all models are calculated by the second scenario point, and so on.
IMsTransformationProblem. Transformation problem. Models are calculated one after another for all scenario points: at the beginning the first model is calculated by all scenario points, then the second model is calculated by all scenario points, and so on.
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 parameters depends on problem type. For more details refer to description of appropriate interfaces.
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: