IMsModelParams.Add

Fore Syntax

Add: IMsModelParam;

Fore.NET Syntax

Add: Prognoz.Platform.Interop.Ms.IMsModelParam;

Description

The Add method adds parameter to the collection.

Comments

To remove the specific parameter from the collection, use the IMsModelParams.Remove and IMsModelParams.RemoveByKey methods, to remove all parameters, use the IMsModelParams.Clear method.

Fore Example

Executing the example requires that the repository contains a modeling container with the MODEL_SPACE identifier. The container must include a metamodel with the METAMODEL identifier which is calculated by the problem with the PROBLEM identifier. The calculation chain of the metamodel must contain a model of determinate equation with the MODEL identifier.

Add links to the Dal, Metabase, Ms, Transform system assemblies.

Sub ParamsAdd;
Var
    mb: IMetabase;
    Ms: IMetabaseObjectDescriptor;
    Problem: IMsProblem;
    MetaModel: IMsMetaModel;
    Model: IMsModel;
    MMParams: IMsModelParams;
    Param: IMsModelParam;
    CalcSett: IMsProblemCalculationSettings;
    Calc: IMsProblemCalculation;
    Method: IMsDeterministicTransform;
    ParamsVals: IMsModelParamValues;
Begin
    mb := MetabaseClass.Active;
    // Get modeling container
    Ms := mb.ItemById("MODEL_SPACE");
    // Get metamodel
    MetaModel := mb.ItemByIdNamespace("METAMODEL", Ms.Key).Edit As IMsMetaModel;
    // Set metamodel parameters
    MMParams := MetaModel.Params;
    MMParams.Clear;
    // Add the parameter determining the lower bound of values
    Param := MMParams.Add;
    Param.Name := "MIN_VALUE";
    Param.Id := "MIN_VALUE";
    Param.Tag := "No default value";
    Param.Hidden := True;
    Param.DataType := DbDataType.Integer;
    Param.ParamType := TsParamType.Simple;
    // Add the parameter determining the upper bound of values
    Param := MMParams.Add;
    Param.Name := "MAX_VALUE";
    Param.Id := "MAX_VALUE";
    Param.Tag := "No default value";
    Param.Hidden := True;
    Param.DataType := DbDataType.Integer;
    Param.ParamType := TsParamType.Simple;
    // Save changes of the metamodel
    (MetaModel As IMetabaseObject).Save;
    // Get model
    Model := mb.ItemByIdNamespace("MODEL", Ms.Key).Edit As IMsModel;
    Method := Model.Transform.FormulaItem(0).Method As IMsDeterministicTransform;
    // Set the expression to calculate the model, which is based on the parameter values
    Method.Expression.AsString := "RandBetween({MIN_VALUE}, {MAX_VALUE})";
    // Save changes in the model
    (Model As IMetabaseObject).Save;
    // Get modeling problem
    Problem := mb.ItemByIdNamespace("PROBLEM", Ms.Key).Edit As IMsProblem;
    // Set problem calculation parameters
    CalcSett := Problem.CreateCalculationSettings;
    // Set parameter values
    ParamsVals := CalcSett.ParamValues;
    ParamsVals.FindById("MIN_VALUE").Value := -100;
    ParamsVals.FindById("MAX_VALUE").Value := 100;
    CalcSett.FactIncluded := True;
    // Perform calculation
    Calc := Problem.Calculate(CalcSett);
    Calc.Run;
End Sub ParamsAdd;

After executing the example two parameters are created in the METAMODEL metamodel. The calculation formula for the MODEL model is based on these parameters. The metamodel chain is calculated. Parameter values are set before calculation.

Fore.NET Example

The requirements and result of the Fore.NET example execution match with those in the Fore example.

Imports Prognoz.Platform.Interop.Dal;
Imports Prognoz.Platform.Interop.Ms;
Imports Prognoz.Platform.Interop.Transform;

Public Shared Sub Main(Params: StartParams);
Var
    mb: IMetabase;
    Ms: IMetabaseObjectDescriptor;
    Problem: IMsProblem;
    MetaModel: IMsMetaModel;
    Model: IMsModel;
    MMParams: IMsModelParams;
    Param: IMsModelParam;
    CalcSett: IMsProblemCalculationSettings;
    Calc: IMsProblemCalculation;
    Method: IMsDeterministicTransform;
    ParamsVals: IMsModelParamValues;
Begin
    mb := Params.Metabase;
    // Get modeling container
    Ms := mb.ItemById["MODEL_SPACE"];
    // Get metamodel
    MetaModel := mb.ItemByIdNamespace["METAMODEL", Ms.Key].Edit() As IMsMetaModel;
    // Set metamodel parameters
    MMParams := MetaModel.Params;
    MMParams.Clear();
    // Add the parameter determining the lower bound of values
    Param := MMParams.Add();
    Param.Name := "MIN_VALUE";
    Param.Id := "MIN_VALUE";
    Param.Tag := "No default value";
    Param.Hidden := True;
    Param.DataType := DbDataType.ddtInteger;
    Param.ParamType := TsParamType.tsptSimple;
    // Add the parameter determining the upper bound of values
    Param := MMParams.Add();
    Param.Name := "MAX_VALUE";
    Param.Id := "MAX_VALUE";
    Param.Tag := "No default value";
    Param.Hidden := True;
    Param.DataType := DbDataType.ddtInteger;
    Param.ParamType := TsParamType.tsptSimple;
    // Save changes of the metamodel
    (MetaModel As IMetabaseObject).Save();
    // Get model
    Model := mb.ItemByIdNamespace["MODEL", Ms.Key].Edit() As IMsModel;
    Method := Model.Transform.FormulaItem[0].Method As IMsDeterministicTransform;
    // Set the expression to calculate the model, which is based on the parameter values
    Method.Expression.AsString := "Randbetween({MIN_VALUE}, {MAX_VALUE})";
    // Save changes in the model
    (Model As IMetabaseObject).Save();
    // Get modeling problem
    Problem := mb.ItemByIdNamespace["Problem", Ms.Key].Edit() As IMsProblem;
    // Set problem calculation parameters
    CalcSett := Problem.CreateCalculationSettings();
    // Set parameter values
    ParamsVals := CalcSett.ParamValues;
    ParamsVals.FindById("MIN_VALUE").Value := -100;
    ParamsVals.FindById("MAX_VALUE").Value := 100;
    CalcSett.FactIncluded := True;
    // Perform calculation
    Calc := Problem.Calculate(CalcSett);
    Calc.Run();
End Sub;

See also:

IMsModelParams