AddTargetProblem(TargetProblem: IMsTargetProblem;
Level: DimCalendarLevel
): IMsCalculationChainTarget;
AddTargetProblem(TargetProblem: Prognoz.Platform.Interop.Ms.IMsTargetProblem;
Level: Prognoz.Platform.Interop.Dimensions.DimCalendarLevel
): Prognoz.Platform.Interop.Ms.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 the metamodel calculation chain.
It is necessary to add a criterion function to calculation chain if modeling problem being set 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 criterion function to the 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.
The requirements and result of the Fore.NET example execution match with those in the Fore example.
Imports Prognoz.Platform.Interop.Dimensions;
Imports Prognoz.Platform.Interop.Ms;
…
Public Shared Sub Main(Params: StartParams);
Var
mb: IMetabase;
MsObj: IMetabaseObjectDescriptor;
Ms: IMsModelSpace;
Problem: IMsProblem;
MetaModel: IMsMetaModel;
CalcChain: IMsCalculationChainEntries;
Transform: IMsFormulaTransform;
TransformVarables: IMsFormulaTransformVariables;
TransVar: IMsFormulaTransformVariable;
Slice: IMsFormulaTransformSlice;
Target: MsTargetProblem;
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 := Params.Metabase;
// 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.dclYear,
Var VarEx, uinteger.maxValue, False);
InpKeys[0] := VarOutp.Key As integer;
// Create an internal model
SimpleModel := MetaVisual.CreateSimpleModel(-1, InpKeys, VarOutp.Key As integer, MsFormulaKind.mfkLinearRegression,
"" , Var InVarKey, Var InModelKey, uinteger.maxValue, uinteger.maxValue, 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.dclYear);
// Set custom name for criterion problem
MetaTarget.UseCustomName := True;
MetaTarget.Name := "New criterion function";
// Save changes
(Problem As IMetabaseObject).Save();
End Sub;
See also: