Consider the example of creating a modeling problem, which type is Modeling Problem.
Executing the example requires a modeling container with the MS identifier containing a metamodel with the METAMODEL identifier. This metamodel should contain one or several forecast models.
Add links to the Metabase, Ms system assemblies.
Sub ProblemCreation;
Var
MB: IMetabase;
MSObj: IMetabaseObject;
MS: IMsModelSpace;
CrInfo: IMetabaseObjectCreateInfo;
ProblemObj: IMetabaseObject;
Problem: IMsProblem;
ScenTree: IMsScenarioTreeEntries;
ScenElement: IMsScenarioTreeElement;
Scenario: IMsScenario;
ScenProblem: IMsProblemScenarios;
Forecasting: IMsForecastingProblem;
Period: IMsModelPeriod;
Begin
// Get current repository
MB := MetabaseClass.Active;
// Get modeling container
MSObj := MB.ItemById("MS").Edit;
MS := MSObj As IMsModelSpace;
// Set basic parameters for problem creation
CrInfo := MB.CreateCreateInfo;
CrInfo.ClassID := MetabaseObjectClass.KE_CLASS_MSPROBLEM;
CrInfo.Id := MB.GenerateId("PROBLEM", MSObj.Key);
CrInfo.Name := "Forecasting problem";
CrInfo.Parent := MSObj.EditDescriptor;
// Create a problem and open it for edit
ProblemObj := MB.CreateObject(CrInfo).Edit;
Problem := ProblemObj As IMsProblem;
// Specify metamodel calculated by the problem
Problem.MetaModel := MB.ItemByIdNamespace("METAMODEL", MSObj.Key).Bind As IMsMetaModel;
// Get all modeling scenarios contained in container
ScenTree := MS.ScenarioTree;
// Add a new scenario
ScenElement := (ScenTree.AddScenario(False, True));
ScenElement.Name := "Basic scenario";
Scenario := ScenElement.Scenario;
// Get scenarios of modeling problem and add created scenario to them
ScenProblem := Problem.Scenarios;
ScenProblem.AddScenario(Scenario);
// Save changes in modeling container
MSObj.Save;
// Create parameters for forecasting problem
Forecasting := New MsForecastingProblem.Create;
// Set problem periods
Period := Forecasting.Period;
Period.IdentificationStartDate := DateTime.Parse("01.01.2001");
Period.IdentificationEndDate := DateTime.Parse("31.12.2014");
Period.ForecastStartDate := DateTime.Parse("01.01.2015");
Period.ForecastEndDate := DateTime.Parse("31.12.2019");
// Specify that forecasting problem is calculated
Problem.Details := Forecasting;
// Determine that cubes are used for reports by variables
Problem.UseCubes := True;
// Save the model
ProblemObj.Save;
End Sub ProblemCreation;
See also: