IMsModelCalculation.Variable

Syntax

Variable(Variable: IMsVariable): IMatrix;

Parameters

Variable. The variable which data must be obtained.

Description

The Variable property returns the matrix with the variable data passed by the Variable parameter.

Example

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(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

i, j: Integer;

ModelCalc: IMsModelCalculation;

Matr: IMatrix;

MatrIter: IMatrixIterator;

Begin

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

For i := 0 To Model.Input.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 + 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. When the OnModelCalculation event is handled, all the input variable models data used in the problem calculation is displayed in the console.

See also:

IMsModelCalculation