AddTargetProblem(TargetProblem: IMsTargetProblem;
Level: DimCalendarLevel): IMsCalculationChainTarget;
TargetProblem. Criterion problem, for which criterion function is added.
Level. Calendar frequency of added criterion function.
The AddTargetProblem method adds a criterion function to calculation chain of metamodel.
It is necessary to add a criterion function to calculation chain if modeling problem being set up will be used to work in the web application.
If TargetProblem is set to Null, the criterion function will be created automatically and will be added to the collection of problem additional parameters. To set up parameters of the created criterion function, use the IMsCalculationChainTarget.TargetProblem property.
After adding a criterion function to calculation chain, set optimization 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_CONSTRANT identifier. This problem must be used in the web application and contain several scenarios.
Add links to the Dimensions, Metabase, Ms system assemblies.
Sub UserProc;
Var
mb: IMetabase;
MsObj: IMetabaseObjectDescriptor;
Ms: IMsModelSpace;
Problem: IMsProblem;
MetaModel: IMsMetaModel;
CalcChain: IMsCalculationChainEntries;
Transform: IMsFormulaTransform;
TransformVarables: IMsFormulaTransformVariables;
TransVar: IMsFormulaTransformVariable;
Slice: IMsFormulaTransformSlice;
Target: IMsTargetProblem;
AdditionalDetails: IMsProblemDetailsArray;
MetaTarget: IMsCalculationChainTarget;
OperandTerm: IMsFormulaTerm;
exVar: Boolean;
MetaVisual: IMsMetaModelVisualController;
VarOutp: IMsCalculationChainVariable;
VarEx: Boolean;
InVarKey, InModelKey: Integer;
InpKeys: Array[1] Of Integer;
SimpleModel: IMsModel;
Operands: IMsFormulaTermList;
Begin
// Get current repository
mb := MetabaseClass.Active;
// Get modeling container
MsObj := mb.ItemById("MS");
Ms := MsObj.Bind As IMsModelSpace;
// Get modeling problem
Problem := mb.ItemByIdNamespace("CHAIN_TARGET_CONSTRANT", MsObj.Key).Edit As IMsProblem;
// Get calculation chain and clear it
MetaModel := Problem.EditMetaModel;
CalcChain := MetaModel.CalculationChain;
CalcChain.Clear;
// If required, create an internal time series database for metamodel
MetaVisual := MetaModel.VisualController;
If Not MetaVisual.HasVariableRubricator Then
MetaVisual.HasVariableRubricator := True;
End If;
// Create an internal variable
VarOutp := MetaVisual.CreateVariable("Internal variable", "", DimCalendarLevel.Year, VarEx);
InpKeys[0] := VarOutp.Key;
// Create an internal model
SimpleModel := MetaVisual.CreateSimpleModel(-1, InpKeys, VarOutp.Key, MsFormulaKind.LinearRegression, "", InVarKey, InModelKey, -1, -1, True);
// Create a criterion problem
Target := New MsTargetProblem.Create;
// Set criterion problem parameters
AdditionalDetails := Problem.AdditionalDetails;
AdditionalDetails.Clear;
AdditionalDetails.AddDetails(Target, VarOutp.Slice);
// Set optimization problem scenario
Target.OptimisticScenario := Problem.Scenarios.Item(0);
// Add criterion function variables
Operands := Target.Operands;
Transform := SimpleModel.Transform;
TransformVarables := Transform.Outputs;
TransVar := TransformVarables.Item(0);
Slice := TransVar.Slices.Item(0);
OperandTerm := Operands.Add(Slice);
// Set criterion function
Target.CriterionFunction.AsString := OperandTerm.TermToInnerText;
// Add criterion problem to calculation chain
MetaTarget := CalcChain.AddTargetProblem(Target, DimCalendarLevel.Year);
// Set custom name for criterion problem
MetaTarget.UseCustomName := True;
MetaTarget.Name := "New criterion function";
// Save changes
(Problem As IMetabaseObject).Save;
End Sub UserProc;
After executing the example the internal model and criterion function are added to the modeling problem.
See also: