Expression: IExpression;
Expression: Prognoz.Platform.Interop.ForeSystem.IExpression;
The Expression property returns cycle calculation condition.
To set up condition calculation parameters, use the IMsCalculationChainIterator.Transform property.
To limit the number of cycle iterations, use the IMsCalculationChainIterator.MaxIterations property.
To enable one-time cycle execution without checking of condition, use the IMsCalculationChainIterator.PostCondition property.
Executing the example requires that the repository contains a modeling container with the MS identifier that contains a metamodel with the METAMODEL_ITERATOR identifier.
Add links to the Metabase, Ms system assemblies.
Sub UserProc;
Var
mb: IMetabase;
MsKey: Integer;
MetaModel: IMsMetaModel;
Param: IMsModelParam;
CalcChain: IMsCalculationChainEntries;
Iterator: IMsCalculationChainIterator;
Model: IMsModel;
Trans, IterTrans: IMsFormulaTransform;
Slice: IMsFormulaTransformSlice;
Selector: IMsFormulaTransformSelector;
Formula: IMsFormula;
TransformVar: IMsFormulaTransformVariable;
Determ: IMsDeterministicTransform;
Expr: IExpression;
Begin
mb := MetabaseClass.Active;
// Get the modelling container key
MsKey := mb.GetObjectKeyById("MS");
// Get the metamodel
MetaModel := mb.ItemByIdNamespace("METAMODEL_ITERATOR", MsKey).Edit As IMsMetaModel;
// Clear all metamodel parameters
MetaModel.Params.Clear;
// Add a new parameter
Param := MetaModel.Params.Add;
Param.DefaultValue := 0;
Param.Id := "THRESHOLD";
Param.Name := "THRESHOLD";
// Clear metamodel calculation chain
CalcChain := MetaModel.CalculationChain;
CalcChain.Clear;
// Create a cycle in metamodel calculation chain
Iterator := CalcChain.AddIterator("While/Repeat");
// Set cycle execution condition
Iterator.PostCondition := True;
Iterator.MaxIterations := 600;
Expr := Iterator.Expression;
Expr.AsString := "{THRESHOLD}<5";
If Expr.ErrorInfo <> Null Then
Debug.WriteLine(Expr.ErrorInfo.ErrorMessage);
End If;
// Set condition calculation mode
IterTrans := Iterator.Transform;
IterTrans.CalculationType := MsCalculationType.Pointwise;
IterTrans.CalculationDirection := MsCalculationDirection.Forward;
// Set internal model in metamodel calculation chain
Model := Iterator.Contents.AddExclusiveModel.EditModel;
Model.AutoName := True;
// Set model calculation parameters
Trans := Model.Transform;
Trans.CalculationType := MsCalculationType.Pointwise;
Trans.CalculationDirection := MsCalculationDirection.Forward;
// Specify the THRESHOLD parameter as a modeling variable
TransformVar := Trans.Outputs.AddParamVariable("THRESHOLD");
Slice := TransformVar.Slices.Add(Null);
Selector := Trans.CreateSelector;
Selector.Slice := Slice;
Formula := Trans.Transform(Selector);
Formula.Kind := MsFormulaKind.Deterministic;
Determ := Formula.Method As IMsDeterministicTransform;
// Set model calculation formula
Expr := Determ.Expression;
Expr.AsString := "{THRESHOLD}+RandBetween(-2,3)";
If Expr.ErrorInfo <> Null Then
Debug.WriteLine(Expr.ErrorInfo.ErrorMessage);
End If;
// Save metamodel
(MetaModel As IMetabaseObject).Save;
End Sub UserProc;
After executing the example the cycle is created in the metamodel that is executed until the THRESHOLD value is less than 5. If the condition is not executed during 600 iterations, the cycle is finished.
The requirements and result of the Fore.NET example execution match with those in the Fore example.
Imports Prognoz.Platform.Interop.ForeSystem;
Imports Prognoz.Platform.Interop.Ms;
…
Public Shared Sub Main(Params: StartParams);
Var
mb: IMetabase;
MsKey: uinteger;
MetaModel: IMsMetaModel;
Param: IMsModelParam;
CalcChain: IMsCalculationChainEntries;
Iterator: IMsCalculationChainIterator;
Model: IMsModel;
Trans, IterTrans: IMsFormulaTransform;
Slice: IMsFormulaTransformSlice;
Selector: IMsFormulaTransformSelector;
Formula: IMsFormula;
TransformVar: IMsFormulaTransformVariable;
Determ: IMsDeterministicTransform;
Expr: IExpression;
Begin
mb := Params.Metabase;
// Get the modelling container key
MsKey := mb.GetObjectKeyById("MS");
// Get the metamodel
MetaModel := mb.ItemByIdNamespace["METAMODEL_ITERATOR", MsKey].Edit() As IMsMetaModel;
// Clear all metamodel parameters
MetaModel.Params.Clear();
// Add a new parameter
Param := MetaModel.Params.Add();
Param.DefaultValue := 0;
Param.Id := "THRESHOLD";
Param.Name := "THRESHOLD";
// Clear metamodel calculation chain
CalcChain := MetaModel.CalculationChain;
CalcChain.Clear();
// Create a cycle in metamodel calculation chain
Iterator := CalcChain.AddIterator("While/Repeat");
// Set cycle execution condition
Iterator.PostCondition := True;
Iterator.MaxIterations := 600;
Expr := Iterator.Expression;
Expr.AsString := "{THRESHOLD}<5";
If Expr.ErrorInfo <> Null Then
System.Diagnostics.Debug.WriteLine(Expr.ErrorInfo.ErrorMessage);
End If;
// Set condition calculation mode
IterTrans := Iterator.Transform;
IterTrans.CalculationType := MsCalculationType.mctPointwise;
IterTrans.CalculationDirection := MsCalculationDirection.mcdForward;
// Set internal model in metamodel calculation chain
Model := Iterator.Contents.AddExclusiveModel().EditModel;
Model.AutoName := True;
// Set model calculation parameters
Trans := Model.Transform;
Trans.CalculationType := MsCalculationType.mctPointwise;
Trans.CalculationDirection := MsCalculationDirection.mcdForward;
// Specify the THRESHOLD parameter as a modeling variable
TransformVar := Trans.Outputs.AddParamVariable("THRESHOLD");
Slice := TransformVar.Slices.Add(Null);
Selector := Trans.CreateSelector();
Selector.Slice := Slice;
Formula := Trans.Transform[Selector];
Formula.Kind := MsFormulaKind.mfkDeterministic;
Determ := Formula.Method As IMsDeterministicTransform;
// Set model calculation formula
Expr := Determ.Expression;
Expr.AsString := "{THRESHOLD}+RandBetween(-2,3)";
If Expr.ErrorInfo <> Null Then
System.Diagnostics.Debug.WriteLine(Expr.ErrorInfo.ErrorMessage);
End If;
// Save metamodel
(MetaModel As IMetabaseObject).Save();
End Sub;
See also: