AddUserOptimizationProblem(Problem: IMsUserOptimizationProblem; Level: DimCalendarLevel): IMsCalculationChainUserOptimization;
Problem. Custom optimization problem.
Level. Calendar level of optimization problem.
The AddUserOptimizationProblem method adds a custom optimization problem to calculation chain.
Executing the example requires that the repository contains a modeling container with the CONT_MODEL identifier. A custom optimization problem with the USER_OPTIMIZATION identifier is created in the container. The problem is set up to work with a metamodel.
Add links to the Dimensions, Metabase, Ms system assemblies.
Sub UserProc;
Var
Mb: IMetabase;
ModelspaceDescr: IMetabaseObjectDescriptor;
Problem: IMsProblem;
UserOptimization: IMsUserOptimizationProblem;
MetaModel: IMsMetaModel;
CalculationChain, FolderCont: IMsCalculationChainEntries;
Folder: IMsCalculationChainFolder;
Period: IMsModelPeriod;
UserOptChain: IMsCalculationChainUserOptimization;
Begin
Mb := MetabaseClass.Active;
// Get modeling container
ModelspaceDescr := Mb.ItemById("CONT_MODEL");
// Get problem
Problem := Mb.ItemByIdNamespace("USER_OPTIMIZATION", ModelspaceDescr.Key).Edit As IMsProblem;
// Get custom optimization problem
UserOptimization := Problem.Details As IMsUserOptimizationProblem;
// Get metamodel
MetaModel := Problem.MetaModel;
// Get calculation chain and create a folder in it
CalculationChain := MetaModel.CalculationChain;
CalculationChain.Clear;
Folder := CalculationChain.AddFolder("Custom optimization problem");
// Set parameters of folder calculation
Folder.Level := DimCalendarLevel.Year;
Period := Folder.Period;
Period.IdentificationEndDate := DateTime.ComposeDay(2009, 12, 31);
Period.IdentificationStartDate := DateTime.ComposeDay(2000, 1, 1);
Period.ForecastEndDate := DateTime.ComposeDay(2020, 12, 31);
Period.ForecastStartDate := DateTime.ComposeDay(2010, 1, 1);
FolderCont := Folder.Contents;
// Add a problem and constraint
UserOptChain := Folder.Contents.AddUserOptimizationProblem(UserOptimization, DimCalendarLevel.Year);
UserOptChain.Name := "Optimization problem";
Folder.Contents.AddUserOptimizationConstraint(UserOptChain, UserOptimization.Constraints.Item(0));
// Save changes
(MetaModel As IMetabaseObject).Save;
(Problem As IMetabaseObject).Save;
End Sub UserProc;
After executing the example, a folder is created in the metamodel calculation chain, to which a custom optimization problem and its constraint are added.
See also: