VariableStub(Stub: IVariableStub): IMatrixDataSource;
Stub. The variable which data should be accessed.
The VariableStub property returns the object that enables the user to access the variable data of modeling container that is passed by the Stub parameter.
NOTE. The modeling container has its own data source implemented to view variables' data. The matrix is built by all elements of dimensions.
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.Transform.Inputs.Item(i) As IMetabaseObject).Id);
ModelCalc := Model.CreateCalculation;
Matr := ModelCalc.Variable(Model.Transform.Inputs.Item(i) As IMsVariable);
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;
Public Sub OnBreak(Breakpoint: IMsBreakpoint);
Begin
Debug.WriteLine(Breakpoint.Name);
End Sub OnBreak;
Public Sub OnWarning(Message: string);
Begin
Debug.WriteLine("Warning: "nbsp;+nbsp;Message);
End Sub OnWarning;
Public Sub OnStageStart(Stage: MsProblemCalculationStage; Data: Variant);
Begin
Debug.Write("Stage start ");
Select Case Stage
Case MsProblemCalculationStage.Init: Debug.WriteLine("'Initialization'");
Case MsProblemCalculationStage.DetermIdent: Debug.WriteLine("'Identification of determinate equations'");
Case MsProblemCalculationStage.Vector: Debug.WriteLine("'Identification of vector equations'");
Case MsProblemCalculationStage.Ident: Debug.WriteLine("'Identification of stochastic methods'");
Case MsProblemCalculationStage.Calc: Debug.WriteLine("'Model calculation'");
Case MsProblemCalculationStage.Save: Debug.WriteLine("'Save data'");
Case MsProblemCalculationStage.Finish: Debug.WriteLine("'Calculation end'");
Case MsProblemCalculationStage.Load: Debug.WriteLine("'Load data'");
End Select;
End Sub OnStageStart;
Public Sub OnStageFinish(Stage: MsProblemCalculationStage; Duration: Integer; Data: Variant);
Begin
Debug.WriteLine("Stage is completed. The elapsed time in milliseconds: " + Duration.ToString);
Debug.WriteLine("");
End Sub OnStageFinish;
Public Sub OnBeforeSaveData(Stub: IVariableStub; Matrix: IMatrix; var ValueFlag: Integer; Var Cancel: Boolean);
Begin
End Sub OnBeforeSaveData;
Public Sub OnSaveData(Stub: IVariableStub; Matrix: IMatrix; ValueFlag: Integer; AuditRecordKey: Variant);
Begin
End Sub OnSaveData;
Public Function OnGetActiveEvents: MsProblemCalculationCallbackEvents;
Begin
Return MsProblemCalculationCallbackEvents.All
End Function OnGetActiveEvents;
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. On working of the OnStep event the number of passed calculation steps is displayed in the console. On calculating the models that are the part of the problem, the data of input variables used on model calculation is displayed in the console.
See also: