ICalcLinearOptimizationBlock.TargetFunction

Syntax

TargetFunction: IDimSelectionSet;

Description

The TargetFunction property returns the collection of criterion function dimension selections.

Comments

To set up criterion function:

  1. Set a data consumer using the ICalcLinearOptimizationBlock.StubOut property.

  2. Check each data consumer dimension for correspondence with a calendar dimension using the IVariableStub.Dimension, IDimensionModel.IsCalendar properties. Calendar dimension should not be used in the criterion function.

  3. Add a dimension to the criterion function using the IDimSelectionSet.Add method if the dimension is not a calendar one.

  4. Remove the added dimension from the multidimensional iterator of the liner optimization block using the IMsDimIteratorDimensions.Remove or IMsDimIteratorDimensions.RemoveByKey method.

Controlling variables are created based on element selection in dimensions. The number of controlling variables is equal to the Cartesian product of selected dimension elements.

Example

Executing the example requires that the repository contains a calculation algorithm with the ALGORITHM identifier. A linear optimization block with any settings is created in the algorithm. A standard cube with the CUBE_OUTPUT identifier should also be created in the repository, to which calculation results will be loaded.

Add links to the Algo, Cubes, Dimensions, Metabase, Ms system assemblies. Add links to the assemblies required for working with calculation algorithms.

Sub UserProc;
Var
    MB: IMetabase;
    MObj: IMetabaseObjectDescriptor;
    Algo, CalcBlock: ICalcObject;
    List: ICalcObjectsList;
    CalcAlgo: ICalcAlgorithm;
    LinearBlock: ICalcLinearOptimizationBlock;
    OneDimension: IDimensionModel;
    DimInstance: IDimInstance;
    TargetFunction: IDimSelectionSet;
    Sel: IDimSelection;
    i, DimCount: Integer;
    IterDim: IMsDimIteratorDimension;
    StubOut: IVariableStub;
    Iter: IMsCalculationChainMultiDimIterator;
    IterDims: IMsDimIteratorDimensions;
    CubeOut: IStandardCube;
Begin
    MB := MetabaseClass.Active;
    // Get calculation algorithm
    MObj := MB.ItemById("ALGORITHM");
    Algo := CalcObjectFactory.CreateCalcObject(MObj, True);
    CalcAlgo := Algo As ICalcAlgorithm;
    // Get list of calculation algorithm objects
    List := CalcAlgo.Items;
    // Get the first linear optimization block
    CalcBlock := List.Item(0);
    LinearBlock := CalcBlock As ICalcLinearOptimizationBlock;
    // Set data consumer
    CubeOut := MB.ItemById("CUBE_OUTPUT").Edit As IStandardCube;
    LinearBlock.StubOut := CubeOut As IVariableStub;
    // Get the number of data consumer dimensions
    StubOut := LinearBlock.StubOut;
    DimCount := StubOut.DimensionCount;
    // Get collection of criterion function dimensions
    TargetFunction := LinearBlock.TargetFunction;
    // Add data consumer dimensions to criterion function
    For i := 0 To DimCount - 1 Do
        OneDimension := StubOut.Dimension(i);
        // Check if the dimension is a calendar one
        If Not OneDimension.IsCalendar Then
            // Get dimension data
            DimInstance := (OneDimension As IMetabaseObjectDescriptor).Open(NullAs IDimInstance;
            // Check dimension identifier (do not add facts to criterion function)
            If DimInstance.Ident <> "FACTS" Then
                // Get dimension selection
                Sel := TargetFunction.FindByKey(DimInstance.Key);
                // Add a dimension to criterion function if selection is set
                If Sel = Null Then
                    TargetFunction.Add(DimInstance);
                    // Get multidimensional iterator
                    Iter := LinearBlock.Iterator;
                    // Get dimensions, by which iteration will be executed
                    IterDims := Iter.Dimensions;
                    IterDim := IterDims.FindByKey(DimInstance.Key);
                    // Remove dimensions from iterator
                    IterDims.RemoveByKey(IterDim.Dimension.Key);
                End If;
            End If;
        End If;
    End For;
    // Save changes
    LinearBlock.SaveObject;
End Sub UserProc;

After executing the example, data consumer dimensions will be added to the criterion function in the linear optimization block.

See also:

ICalcLinearOptimizationBlock