Variable(Variable: IMsVariable): IMatrixDataSource;
Variable. The variable which data should be accessed.
The Variable property returns the object that gets access to the data of variable of modeling container that is passed by the Variable parameter.
The property is outdated, use IMsProblemCalculation.VariableStub.
The modeling container has its own data source to view data of variables. 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(The calculation of problem is finished);
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
Inputs: IMsVariables;
i, j: Integer;
MatrDS: IMatrixDataSource;
Matr: IMatrix;
MatrIter: IMatrixIterator;
Begin
Debug.WriteLine(Model calculation: + (Model As IMetabaseObject).Id);
Inputs := Model.Input;
For i := 0 To Inputs.Count - 1 Do
Debug.WriteLine("Data of input variable: " + (Inputs.Item(i) As IMetabaseObject).Id);
MatrDS := Calculation.Variable(Inputs.Item(i));
Matr := MatrDS.Execute(Null);
MatrIter := Matr.CreateIterator;
MatrIter.Move(IteratorDirection.First);
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 + from +
Calculation.PointCount.ToString);
End Sub OnStep;
End Class MCallback;
Sub Main;
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 Main;
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 user 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: