StepDate;
The StepDate method executes step-by-step calculation of modeling problem by calendar frequency points.
On one step, all models for all scenarios on a certain date are calculated.
Executing the example requires that the repository includes a modeling container with the MODEL_SPACE identifier including a modeling problem with the PROBLEM identifier.
Add links to the Matrix, Metabase, Ms system assemblies.
Sub StepDate;
Var
mb: IMetabase;
MSKey: Integer;
Problem: IMsProblem;
Setts: IMsProblemCalculationSettings;
Calc: IMsProblemCalculation;
State: IMsCalculationState;
Model: IMsModel;
Slice: IMsFormulaTransformSlice;
MatrixDS: IMatrixDataSource;
Matr: IMatrix;
Iter: IMatrixIterator;
TrVar: IMsFormulaTransformVariable;
Begin
mb := MetabaseClass.Active;
// Get modeling problem
MSKey := mb.GetObjectKeyById("MODEL_SPACE");
Problem := mb.ItemByIdNamespace("PROBLEM", MSKey).Bind As IMsProblem;
// Create problem calculation settings
Setts := Problem.CreateCalculationSettings;
// Perform step-by-step calculation of the problem
Calc := Problem.Calculate(Setts);
Repeat
Calc.StepDate;
State := Calc.CalculationState;
Debug.WriteLine(State.Message);
Until State.Model <> Null;
// Display the information about the name of the calculated model
Model := State.Model;
Debug.WriteLine("Model: " + Model.Name);
// Get output variable data
TrVar := Model.Transform.Outputs.Item(0);
Slice := TrVar.Slices.Item(0);
MatrixDS := State.DataMultiDim(Slice);
Matr := MatrixDS.Execute(Null);
// Display output variable data
Debug.WriteLine("Current values of modeling variable '" + TrVar.Name + "'");
Iter := Matr.CreateIterator;
Iter.Move(IteratorDirection.First);
While Iter.Valid Do
Debug.WriteLine(" " + Iter.Value);
Iter.Move(IteratorDirection.Next);
End While;
// Abort problem calculation
Calc.Stop;
End Sub StepDate;
Example execution result: step-by-step calculation of the PROBLEM problem is started, after calculation the name of the calculated model and data of the output variable are displayed in the console window.
See also: