Calculate(Settings: IMsProblemCalculationSettings): IMsProblemCalculation;
Settings. Settings of parameters for calculating opened instance of modeling problem.
The Calculate method calculates opened instance of modeling problem with specified settings.
To create an object that contains settings of opened instance of modeling problem for calculation, use the IMsProblemInstance.CreateCalculationSettings method.
Executing the example requires that the repository contains a modeling container with the CONT_MODEL identifier, containing a modeling problem with the PROBLEM identifier and a metamodel with the METAMODEL identifier.
Add links to the Metabase, Ms system assemblies.
Sub UserProc;
Var
Mb: IMetabase;
MsKey: Integer;
ProblemDesc, MetaModelDesc: IMetabaseObjectDescriptor;
pParam, mParam: IMetabaseObjectParam;
MetaModel: IMsMetaModel;
Control: IMetabaseObjectControl;
ParamControl: IMetabaseObjectParamControl;
ModelParam: IMsModelParam;
Instance: IMsProblemInstance;
Calculation: IMsProblemCalculation;
CalcSettings: IMsProblemCalculationSettings;
ParamValues: IMetabaseObjectParamValues;
Begin
Mb := MetabaseClass.Active;
// Get modeling container key
MsKey := Mb.GetObjectKeyById("CONT_MODEL");
// Get metamodel
MetaModelDesc := Mb.ItemByIdNamespace("METAMODEL", MsKey).EditDescriptor;
// Add a metamodel parameter
MetaModelDesc.Params.Clear;
mParam := MetaModelDesc.Params.Add;
mParam.Id := "PARAMINT";
mParam.Name := "Additional value";
MetaModelDesc.SaveDescriptor;
// Get modeling problem
ProblemDesc := Mb.ItemByIdNamespace("PROBLEM", MsKey).EditDescriptor;
// Add a problem parameter
ProblemDesc.Params.Clear;
pParam := ProblemDesc.Params.Add;
pParam.Id := "PARAMINT";
pParam.Name := "Additional value";
// Set up metamodel parameter control via problem parameter
Control := ProblemDesc.Params.ControlInfo.FindByKey(MetaModelDesc.Key);
ParamControl := Control.FindByKey(pParam.Key);
ParamControl.Expression.AsString := ":" + ParamControl.ControlledParam.Id;
ProblemDesc.SaveDescriptor;
// Set parameter to send value to metamodel
MetaModel := MetaModelDesc.Edit As IMsMetaModel;
MetaModel.Params.Clear;
ModelParam := MetaModel.Params.Add;
ModelParam.Id := "PARAMINT";
ModelParam.Name := "Additional value";
ModelParam.ObjectParam := mParam;
// Save metamodel
(MetaModel As IMetabaseObject).Save;
// Set purpose of added metamodel parameter via problem
ParamValues := ProblemDesc.Params.CreateEmptyValues;
ParamValues.FindById("PARAMINT").Value := 100;
// Get opened instance of modeling problem
Instance := ProblemDesc.Open(ParamValues) As IMsProblemInstance;
// Determine calculation settings
CalcSettings := Instance.CreateCalculationSettings;
CalcSettings.FactIncluded := True;
CalcSettings.BreakOnError := True;
// Execute calculation
Calculation := Instance.Calculate(CalcSettings);
Calculation.Run;
Debug.WriteLine("Opened instance of modeling problem has been calculated " + Instance.Problem.Id);
End Sub UserProc;
Imports Prognoz.Platform.Interop.Metabase;
Imports Prognoz.Platform.Interop.Ms;
…
Public Shared Sub Main(Params: StartParams);
Var
Mb: IMetabase;
MsKey: UInteger;
ProblemDesc, MetaModelDesc: IMetabaseObjectDescriptor;
pParam, mParam: IMetabaseObjectParam;
MetaModel: IMsMetaModel;
Control: IMetabaseObjectControl;
ParamControl: IMetabaseObjectParamControl;
ModelParam: IMsModelParam;
Instance: IMsProblemInstance;
Calculation: IMsProblemCalculation;
CalcSettings: IMsProblemCalculationSettings;
ParamValues: IMetabaseObjectParamValues;
Begin
Mb := Params.Metabase;
// Get modeling container key
MsKey := Mb.GetObjectKeyById("CONT_MODEL");
// Get metamodel
MetaModelDesc := Mb.ItemByIdNamespace["METAMODEL", MsKey].EditDescriptor();
// Add a metamodel parameter
MetaModelDesc.Params.Clear();
mParam := MetaModelDesc.Params.Add();
mParam.Id := "PARAMINT";
mParam.Name := "Additional value";
MetaModelDesc.SaveDescriptor();
// Get modeling problem
ProblemDesc := Mb.ItemByIdNamespace["PROBLEM", MsKey].EditDescriptor();
// Add a problem parameter
ProblemDesc.Params.Clear();
pParam := ProblemDesc.Params.Add();
pParam.Id := "PARAMINT";
pParam.Name := "Additional value";
// Set up metamodel parameter control via problem parameter
Control := ProblemDesc.Params.ControlInfo.FindByKey(MetaModelDesc.Key);
ParamControl := Control.FindByKey(pParam.Key);
ParamControl.Expression.AsString := ":" + ParamControl.ControlledParam.Id;
ProblemDesc.SaveDescriptor();
// Set parameter to send value to metamodel
MetaModel := MetaModelDesc.Edit() As IMsMetaModel;
MetaModel.Params.Clear();
ModelParam := MetaModel.Params.Add();
ModelParam.Id := "PARAMINT";
ModelParam.Name := "Additional value";
ModelParam.ObjectParam := mParam;
// Save metamodel
(MetaModel As IMetabaseObject).Save();
// Set purpose of added metamodel parameter via problem
ParamValues := ProblemDesc.Params.CreateEmptyValues();
ParamValues.FindById("PARAMINT").Value := 100;
// Get opened instance of modeling problem
Instance := ProblemDesc.Open(ParamValues) As IMsProblemInstance;
// Determine calculation settings
CalcSettings := Instance.CreateCalculationSettings();
CalcSettings.FactIncluded := True;
CalcSettings.BreakOnError := True;
// Execute calculation
Calculation := Instance.Calculate(CalcSettings);
Calculation.Run();
System.Diagnostics.Debug.WriteLine("Opened instance of modeling problem has been calculated " + Instance.Problem.Id);
End Sub;
After executing the example the opened instance of modeling problem is calculated with the specified value of the PARAMINT added parameter in the metamodel and with calculation settings. The console displays the message with the identifier of the calculated modeling problem.
See also: