FillWithTargetConstraints(TargetEntryKey: Integer;
EntryKeys: Array;
Calculation: IMsMethodCalculation;
[Workbook: IMetabaseObject = Null]);
TargetEntryKey. Criterion function key
EntryKeys. Array of criterion function constraint keys.
Calculation. Parameters of calculation of the model containing a criterion function.
Workbook. External workbook, to which the results should be loaded.
The FillWithTargetConstraints method fills a workbook with data of criterion function constraints.
If Workbook = Null, the internal workbook with loaded data is returned by the IMsMetaModelVisualController.Workbook property. It is required to specify the MsWorkbookType.TargetConstraints value 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 and one or several criterion function constraints. The repository must also contain a workbook with the WBK_TARGET identifier.
Add links to the Metabase, Ms system assemblies.
Sub UserProc;
Var
mb: IMetabase;
MsObj: IMetabaseObjectDescriptor;
Meta: IMsMetaModel;
MetaVisual: IMsMetaModelVisualController;
ScArr, ConstrArr: Array Of Integer;
pr: IMsProblem;
i, j, TarjetKey: Integer;
ChainEn: IMsCalculationChainEntries;
Model: IMsModel;
Transform: IMsFormulaTransform;
Calc: IMsMethodCalculation;
Wbk: IMetabaseObject;
ScenTree: IMsScenarioTreeEntries;
Target: IMsTargetProblem;
Constraints: IMsTargetConstraints;
Constr: IMsTargetConstraint;
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;
Target := pr.AdditionalDetails.Item(0) As IMsTargetProblem;
Constraints := Target.Constraints;
ConstrArr := New Integer[Constraints.Count];
For i := 0 To Constraints.Count - 1 Do
Constr := Constraints.Item(i);
ConstrArr[i] := Constr.Key;
End For;
// Get model containing criterion function parameters
Model := Target.Model;
// Create model calculation parameters
Transform := Model.Transform;
Calc := Transform.CreateCalculation;
// Get workbook
Wbk := mb.ItemById("WBK_TARGET").Edit;
// Fill a workbook with criterion function data
MetaVisual.FillWithTargetConstraints(TarjetKey, ConstrArr, Calc, ScArr, Wbk);
// Save workbook
Wbk.Save;
End Sub UserProc;
After executing the example, data of criterion function constraints is loaded to the WBK_TARGET workbook.
See also: