IMsModelParams.Add

Syntax

Add: 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.

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 options
    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.

See also:

IMsModelParams