IMsProblemCalculation.VariableStub

Syntax

VariableStub(Stub: IVariableStub): IMatrixDataSource;

Parameters

Stub. The variable which data should be accessed.

Description

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.

Example

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: IMsFormulaTransformVariables;

i, j: Integer;

MatrDS: IMatrixDataSource;

Matr: IMatrix;

MatrIter: IMatrixIterator;

Begin

Debug.WriteLine(Model calculation: + (Model As IMetabaseObject).Id);

Inputs := Model.Transform.Inputs;

For i := 0 To Inputs.Count - 1 Do

Debug.WriteLine("Data of input variable: " + (Inputs.Item(i) As IMetabaseObject).Id);

MatrDS := Calculation.VariableStub(Inputs.Item(i).VariableStub);

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;

Public Sub OnBreak(Breakpoint: IMsBreakpoint);

Begin

Debug.WriteLine(Breakpoint.Name);

End Sub OnBreak;

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:

IMsProblemCalculation