AddTargetTrajectory(TargetEntry: IMsCalculationChainTarget): IMsCalculationChainTargetTrajectory;
TargetEntry. Criterion function.
The AddTargetTrajectory method adds a trajectory to the specified criterion function.
It is necessary to add a trajectory to the calculation chain if modeling problem to be set up is used to work in the web application.
To add a criterion function to the calculation chain, use the IMsCalculationChainEntries.AddTargetProblem method.
After adding criterion function trajectory for criterion problem set scenario for criterion function trajectory and criterion problem scenario.
Executing the example requires that the repository contains a modeling container with the MS identifier containing a modeling problem with the CHAIN_TARGET_TRAJECTORY identifier. This problem must be used for web application and contain a criterion function.
Add links to the Cube, Dimensions, Matrix, Metabase, Ms system assemblies.
Sub UserProc;
Var
mb: IMetabase;
MsObj: IMetabaseObjectDescriptor;
Ms: IMsModelSpace;
Problem: IMsProblem;
CalcChain: IMsCalculationChainEntries;
I, j, TrajectoryScenarioKey: Integer;
MetaTarget: IMsCalculationChainTarget;
TargetProblem: IMsTargetProblem;
MetaTrajectory: IMsCalculationChainTargetTrajectory;
ScenarioTree: IMsScenarioTreeEntries;
ScenElement: IMsScenarioTreeElement;
Scenario: IMsScenario;
Model: IMsModel;
OutputsVar: IMsFormulaTransformVariables;
CubeInst: ICubeInstance;
Des: ICubeInstanceDestination;
DimSS: IDimSelectionSet;
DimS: IDimSelection;
Elem: IDimElementArray;
Elements: IDimElements;
Mat: IMatrix;
Coord: IMatrixCoord;
Sto: ICubeInstanceStorage;
Begin
// Get current repository
mb := MetabaseClass.Active;
// Get modeling container
MsObj := mb.ItemById("MS");
Ms := MsObj.Edit As IMsModelSpace;
// Get modeling problem
Problem := mb.ItemByIdNamespace("CHAIN_TARGET_TRAJECTORY", MsObj.Key).Edit As IMsProblem;
// Get calculation chain
CalcChain := Problem.MetaModel.CalculationChain;
j := CalcChain.Count - 1;
i := 0;
Repeat
// Search for criterion function in calculation chain
If CalcChain.Item(i).Type = MsCalculationChainEntryType.Target Then
MetaTarget := CalcChain.Item(i) As IMsCalculationChainTarget;
End If;
// Remove existing trajectories from calculation chain
If CalcChain.Item(i).Type = MsCalculationChainEntryType.TargetTrajectory Then
CalcChain.Remove(i);
j := j - 1;
End If;
i := i + 1;
Until i > j;
// Add a criterion problem trajectory to calculation chain
MetaTrajectory := CalcChain.AddTargetTrajectory(MetaTarget);
TargetProblem := MetaTrajectory.TargetEntry.TargetProblem;
// Get modeling container scenario
ScenarioTree := Ms.ScenarioTree;
// Add a scenario for criterion function trajectory
ScenElement := ScenarioTree.AddScenario;
ScenElement.Name := "Scenario for criterion function trajectory";
Scenario := ScenElement.Scenario;
// Get key of this scenario
TrajectoryScenarioKey := Scenario.InternalKey;
// Specify created scenario in criterion problem
Problem.Scenarios.AddScenario(Scenario);
TargetProblem.TrajectoryScenario := Scenario;
// Add a scenario for criterion problem
ScenElement := ScenarioTree.AddScenario;
ScenElement.Name := "Scenario for criterion problem";
Scenario := ScenElement.Scenario;
// Specify created scenario in criterion problem
Problem.Scenarios.AddScenario(Scenario);
TargetProblem.TargetScenario := Scenario;
// Save changes in modeling container scenarios
(Ms As IMetabaseObject).Save;
// Get model containing criterion function parameters
Model := TargetProblem.Model;
// Get modeling variable data corresponding to criterion function data
OutputsVar := Model.Transform.Outputs;
CubeInst := (OutputsVar.Item(0).VariableStub As IMetabaseObject).Open(Null) As ICubeInstance;
// Change criterion function trajectory data by scenario dimension
Des := CubeInst.Destinations.Item(2);
DimSS := Des.CreateDimSelectionSet;
// Determine that data for annual frequency is changed
DimS := DimSS.Item(0);
Elem := DimS.Dimension.Levels.Item(0).Elements;
For Each i In Elem Do
DimS.SelectElement(i, False);
End For;
// Determine that data is changed by scenario created for criterion problem trajectory
DimS := DimSS.Item(1);
DimS.DeselectAll;
Elements := DimS.Dimension.Elements;
For i := 0 To Elements.Count - 1 Do
If Elements.Id(i) = TrajectoryScenarioKey.ToString Then
DimS.SelectElement(i, False);
j := i;
End If;
End For;
DimSS.Item(2).SelectAll;
// Get current data
Mat := Des.Execute(DimSS);
Mat.ValueFlag := Mat.ValueFlag + 1;
Coord := Mat.CreateCoord;
Coord.Item(1) := j;
Coord.Item(2) := 0;
// Change current data
For Each i In Elem Do
Coord.Item(0) := i;
Mat.Item(Coord) := 10 + 0.1 * i;
End For;
Sto := Des.CreateStorage;
// Save changes in data of criterion function trajectory
Sto.SaveMatrix(Mat, Mat.ValueFlag);
// Save changes in modeling problem
(Problem As IMetabaseObject).Save;
End Sub UserProc;
After executing the example a trajectory is added for criterion function, trajectory value is set.
See also: