Variable(Variable: IMsVariable): IMatrix;
Variable. The variable which data must be obtained.
The Variable property returns a matrix with variable data.
Executing the example requires that the repository contains a modeling container with the KONT_MODEL identifier. The modeling problem with the Problem_1 identifier is created and set up in this container.
Public Class MCallback: Object, IMsProblemCalculationCallback
Public Calculation: IMsProblemCalculation;
Public Sub OnError(Message: String);
Begin
Debug.WriteLine(Message);
End Sub OnError;
Public Sub OnFinish;
Begin
Debug.WriteLine(Problem calculation is completed);
Calculation := Null;
End Sub OnFinish;
Public Sub OnMessage(Message: String);
Begin
Debug.Write(DateTime.Now);
Debug.WriteLine(": " + Message);
End Sub OnMessage;
Public Sub OnModelCalculation(Model: IMsModel);
Var
i, j: Integer;
ModelCalc: IMsModelCalculation;
Matr: IMatrix;
MatrIter: IMatrixIterator;
Begin
Debug.WriteLine("Model calculation: " + (Modelnbsp;Asnbsp;IMetabaseObject).Id);
For i := 0 To Model.Transform.Inputs.Count - 1 Do
Debug.WriteLine("Variable data: " + (Model.Input.Item(i) As IMetabaseObject).Id);
ModelCalc := Model.CreateCalculation;
Matr := ModelCalc.Variable(Model.Input.Item(i));
MatrIter := Matr.CreateIterator;
MatrIter.Move(IteratorDirection.First);
j := 0;
While MatrIter.Valid Do
Debug.WriteLine("j = " + j.ToString + " " + (MatrIter.Value As String) + " ");
MatrIter.Move(IteratorDirection.Next);
j := j + 1;
End While;
End For;
End Sub OnModelCalculation;
Public Sub OnStep;
Begin
Debug.WriteLine("Executed steps: " + Calculation.PointPassed.ToString + " of " + Calculation.PointCount.ToString);
End Sub OnStep;
End Class MCallback;
Sub UserProc;
Var
MB: IMetabase;
MObj: IMetabaseObject;
Problem: IMsProblem;
CallBack: MCallback;
CalcSett: IMsProblemCalculationSettings;
Calculation: IMsProblemCalculation;
Begin
MB := MetabaseClass.Active;
MObj := MB.ItemByIdNamespace("Problem_1", MB.ItemById("KONT_MODEL").Key).Edit;
Problem := MObj As IMsProblem;
CallBack := New MCallback.Create;
CalcSett := Problem.CreateCalculationSettings;
CalcSett.Callback := CallBack;
Calculation := Problem.Calculate(CalcSett);
CallBack.Calculation := Calculation;
Calculation.Run;
MObj.Save;
End Sub UserProc;
After executing the example the problem with the PROBLEM_1 identifier is calculated. To track events during the calculation, use an object of the MCallback custom class. When the OnModelCalculation event is handled, the console displays all the input variable models data used on problem calculation. When the OnStep event is handled, the console displays the number of passed calculation steps.
See also: