FillWithTargetProblem(TargetEntryKey: Integer
Calculation: IMsMethodCalculation;
ScenarioKeys: Array;
[Workbook: IMetabaseObject = Null]);
FillWithTargetProblem(TargetEntryKey: integer
Calculation: Prognoz.Platform.Interop.Ms.IMsMethodCalculation;
EntryKeys: System.Array;
[Workbook: Prognoz.Platform.Interop.Metabase.IMetabaseObject = Null]);
TargetEntryKey. Criterion function key
Calculation. Parameters of calculation of the model containing a criterion function.
ScenarioKeys. Array of scenario keys, by which data should be obtained.
Workbook. External workbook, to which the results should be unloaded.
The FillWithTargetProblem method fills a workbook with criterion function data by specified scenarios.
To get data by the Fact scenario, add the -1 value to the ScenarioKeys array.
If Workbook = Null, the internal workbook with loaded data is returned by the IMsMetaModelVisualController.Workbook property. The MsWorkbookType.TargetProblem value should be specified as value of the WorkbookType parameter.
Executing the example requires that the repository contains a modeling container with the MS identifier containing a criterion function with the FILLMODEL identifier. Optimization scenario must be set for a problem. The repository must also contain a workbook with the WBK_TARGET identifier.
Add links to the Metabase, Ms, Ui system assemblies.
Sub UserProc;
Var
mb: IMetabase;
MsObj: IMetabaseObjectDescriptor;
Meta: IMsMetaModel;
MetaVisual: IMsMetaModelVisualController;
ScArr: Array Of Integer;
pr: IMsProblem;
i, j, TarjetKey: Integer;
ChainEn: IMsCalculationChainEntries;
Model: IMsModel;
Transform: IMsFormulaTransform;
Calc: IMsMethodCalculation;
ScenTree: IMsScenarioTreeEntries;
Target: IMsTargetProblem;
Wbk: IMetabaseObject;
UiTarget: IUiCommandTarget;
Begin
mb := MetabaseClass.Active;
// Get modeling container
MsObj := mb.ItemById("MS");
// Get modeling problem
pr := mb.ItemByIdNamespace("FILLMODEL", MsObj.Key).Bind As IMsProblem;
// Get metamodel
Meta := pr.MetaModel;
MetaVisual := Meta.VisualController;
ChainEn := Meta.CalculationChain;
// Get criterion function key
TarjetKey := -1;
For i := 0 To ChainEn.Count - 1 Do
If ChainEn.Item(i).Type = MsCalculationChainEntryType.Target Then
TarjetKey := ChainEn.Item(i).Key;
End If;
End For;
// Create an array of scenario keys
ScArr := New Integer[2];
// Add the Fact scenario key
ScArr[0] := -1;
// Add criterion function scenario key
ScenTree := (MsObj.Bind As IMsModelSpace).ScenarioTree;
Target := pr.AdditionalDetails.Item(0) As IMsTargetProblem;
j := Target.OptimisticScenario.InternalKey;
ScArr[1] := ScenTree.FindByInternalKey(j).Key;
// Get model containing criterion function parameters
Model := Target.Model;
// Create model calculation parameters
Transform := Model.Transform;
Calc := Transform.CreateCalculation;
// Fill a workbook with criterion function data
MetaVisual.FillWithTargetProblem(TarjetKey, Calc, ScArr, Wbk);
// Get workbook
Wbk := MetaVisual.Workbook(MsWorkbookType.TargetProblem);
// Open the workbook
UiTarget := WinApplication.Instance.GetObjectTarget(Wbk);
UiTarget.Execute("Object.Edit", Null);
End Sub UserProc;
After executing the example the workbook filled with criterion function by specified scenarios is opened.
The requirements and result of the Fore.NET example execution match with those in the Fore example.
Imports Prognoz.Platform.Interop.Ms;
Imports Prognoz.Platform.Interop.Ui;
…
Public Shared Sub Main(Params: StartParams);
Var
mb: IMetabase;
MsObj: IMetabaseObjectDescriptor;
Meta: IMsMetaModel;
MetaVisual: IMsMetaModelVisualController;
ScArr: Array Of Integer;
pr: IMsProblem;
i: Integer;
j, TarjetKey: uinteger;
ChainEn: IMsCalculationChainEntries;
Model: IMsModel;
Transform: IMsFormulaTransform;
Calc: IMsMethodCalculation;
ScenTree: IMsScenarioTreeEntries;
Target: IMsTargetProblem;
Wa: IWinApplicationClass;
Wbk: IMetabaseObject;
UiTarget: IUiCommandTarget;
Begin
mb := Params.Metabase;
// Get modeling container
MsObj := mb.ItemById["MS"];
// Get modeling problem
pr := mb.ItemByIdNamespace["FILLMODEL", MsObj.Key].Bind() As IMsProblem;
// Get metamodel
Meta := pr.MetaModel;
MetaVisual := Meta.VisualController;
ChainEn := Meta.CalculationChain;
// Get criterion function key
TarjetKey := uinteger.MaxValue;
For i := 0 To ChainEn.Count - 1 Do
If ChainEn.Item[i].Type = MsCalculationChainEntryType.mccetTarget Then
TarjetKey := ChainEn.Item[i].Key;
End If;
End For;
// Create an array of scenario keys
ScArr := New Integer[2];
// Add the Fact scenario key
ScArr[0] := -1;
// Add criterion function scenario key
ScenTree := (MsObj.Bind() As IMsModelSpace).ScenarioTree;
Target := pr.AdditionalDetails.Item[0] As IMsTargetProblem;
j := Target.OptimisticScenario.InternalKey;
ScArr[1] := ScenTree.FindByInternalKey(j).Key As integer;
// Get model containing criterion function parameters
Model := Target.Model;
// Create model calculation parameters
Transform := Model.Transform;
Calc := Transform.CreateCalculation();
// Fill a workbook with criterion function data
MetaVisual.FillWithTargetProblem(TarjetKey As integer, Calc, ScArr, Wbk);
// Get workbook
Wbk := MetaVisual.Workbook[MsWorkbookType.mswtTargetProblem];
// Open the workbook
Wa := New WinApplicationClassClass();
UiTarget := Wa.Instance[Null].GetObjectTarget(Wbk);
UiTarget.Execute("Object.Edit", Null, Null);
End Sub;
See also: