Add(Selection: IDimSelectionSet): IMsFormulaTransformSlice;
Selection. The selection, based of which the slice is made.
The Add method creates a variable slice. The selection, based of which the slice is made, is passed by the Selection parameter.
Executing the example requires a modeling container with two variables that have additional dimensions.
Sub Main;
Var
MB: IMetabase;
CrInf: IMetabaseObjectCreateInfo;
MObj: IMetabaseObject;
Model: IMsModel;
Trans: IMsFormulaTransform;
VarTrans: IMsFormulaTransformVariable;
Slice, Slice1: IMsFormulaTransformSlice;
Selector: IMsFormulaTransformSelector;
Formula: IMsFormula;
NonLinear: IMsNonLinearRegressionTransform;
Varr: IMsVariable;
TransVar: IMsFormulaTransformVariable;
TermX1, TermX2: IMsFormulaTerm;
SelectionFact: IDimSelectionSetFactory;
Selection: IDimSelectionSet;
s: String;
i: Integer;
Begin
MB := MetabaseClass.Active;
//create a model
CrInf := Mb.CreateCreateInfo;
CrInf.ClassId := MetabaseObjectClass.KE_CLASS_MSMODEL;
CrInf.Id := "New_NonLinReg";
CrInf.Name := "New_NonLinReg";
CrInf.Parent := Mb.ItemById("KONT_MODEL");
CrInf.Permanent := False;
MObj := Mb.CreateObject(CrInf).Edit;
Model := MObj As IMsModel;
Trans := Model.Transform;
// add output variable
Varr := MB.ItemByIdNamespace("Var_1", MB.ItemById("KONT_MODEL").Key).Bind As IMsVariable;
Model.Output.Add(Varr);
//create empty mark
SelectionFact := New DimSelectionSetFactory.Create;
Selection := SelectionFact.CreateDimSelectionSet;
//if in output variable there are additional dimensions, mark there an element with an index 3
For i := 0 To Varr.Dimensions.Count - 1 Do
Selection.Add((Varr.Dimensions.Item(i).Model As IMetabaseObject).Open(Null) As IDimInstance);
Selection.Item(i).SelectElement(3, False);
End For;
VarTrans := Trans.Outputs.Item(0);
//receive the slice in output variable
Slice := VarTrans.Slices.Add(Selection);
Selector := Model.Transform.CreateSelector;
Selector.Slice := Slice;
Formula := Model.Transform.Transform(Selector);
Formula.Kind := MsFormulaKind.NonLinearRegression;
NonLinear := Formula.Method As IMsNonLinearRegressionTransform;
// add input variable
Varr := MB.ItemByIdNamespace("Var_Factor", MB.ItemById("KONT_MODEL").Key).Bind As IMsVariable;
Model.Input.Add(Varr);
TransVar := Model.Transform.Inputs.Item(0);
//fix the mark by all additional dimensions
For i := 0 To Varr.Dimensions.Count - 1 Do
Selection.Add((Varr.Dimensions.Item(i).Model As IMetabaseObject).Open(Null) As IDimInstance);
Selection.Item(i).DeselectAll;
Selection.Item(i).SelectElement(1, False);
End For;
//add the slice to the variable
Slice := TransVar.Slices.Add(Selection);
//create the mark for second slice
For i := 0 To Varr.Dimensions.Count - 1 Do
Selection.Item(i).DeselectAll;
Selection.Item(i).SelectElement(3, False);
End For;
//add the second slice to the variable
Slice1 := TransVar.Slices.Add(Selection);
//create two terms by different slices in the variable
TermX1 := NonLinear.Operands.Add(Slice);
TermX2 := NonLinear.Operands.Add(Slice1);
//creation of the equation
s := "A0+" + Trans.SliceToTerm(TermX1.Slice, TermX1.Lag.AsString) + "/10+ " + Trans.SliceToTerm(TermX2.Slice, TermX2.Lag.AsString);
NonLinear.Expression.AsString := s;
MObj.Save;
End Sub Main;
After executing the example a model is created in the modeling container. An output variable is added to the model; element with the index 3 is selected in all additional dimensions of this variable. Specification of calculation is adjusted for the received slice. The method of non-linear regression is used for calculation. A variable with some elements fixed in additional dimensions is added to the list of input variables. Then, the expression elements are obtained, and equation is composed.
See also: