IMsUserOptimizationCallback.OnExecute

Syntax

OnExecute(Runtime: IMsUORuntime);

Parameters

Runtime. The current calculation of custom optimization problem.

Description

The OnExecute method implements the event that occurs during custom optimization problem calculation in each calendar point of the forecasting period.

Example

Executing the example requires that the repository contains a modeling container containing a custom optimization model. The problem should have a unit that implements a custom algorithm. Consider the example of this unit contents.

Add links to the Metabase, Ms, Ui, and Xml system assemblies.

Public Class UserClass: Object, IMsUserOptimizationCallback
    Private m_iValue: Integer = 0;
    Private m_strLog: String;

    Public Sub OnLoad(Xml: IXMLDOMElement);
    Begin
        m_iValue := xml.getAttribute("CAT");
    End Sub OnLoad;

    Public Sub OnSave(Xml: IXMLDOMElement);
    Begin
    End Sub OnSave;

    Public Sub OnBeforeExecute(Calculation: IMsMethodCalculation; Coord: IMsFormulaTransformCoord; Problem: IMsUserOptimizationProblem);
    Begin
    End Sub OnBeforeExecute;

    Public Sub OnExecute(Runtime: IMsUORuntime);
    Var
        pControl: IMsUORuntimeControlTerm;
        pConstraint: IMsUORuntimeConstraint;
    Begin
        pControl := Runtime.ControlVariables.Item(0);
        pConstraint := Runtime.Constraints.Item(0);
        // Display information about problem calculation in the information dialog box
        ResetLog;
        LogLine("Date: " + CultureInfo.Current.FormatShortDate(Runtime.Calculation.CurrentPoint));
        LogLine("Controlling variable: " + pControl.GenerateString + " = " + (pControl.Value As String) + " (" + m_iValue.ToString + ")");
        LogLine("Constraint expression: " + pConstraint.GenerateStringL + " <= " + pConstraint.GenerateStringM + " <= " + pConstraint.GenerateStringH);
        LogLine("Expression value: " + (pConstraint.ExecuteL As String) + " <= " + (pConstraint.ExecuteM As String) + " <= " + (pConstraint.ExecuteH As String));
        LogLine("Criterion function: " + Runtime.CriterionFunction.GenerateString + " = " + (Runtime.CriterionFunction.Execute As String));
        WinApplication.InformationBox(m_strLog);
    End Sub OnExecute;

    Public Sub OnAfterExecute(Calculation: IMsMethodCalculation; Coord: IMsFormulaTransformCoord; Problem: IMsUserOptimizationProblem);
    Begin
    End Sub OnAfterExecute;

    Public Sub OnSetupParams(Params: IMsModelParams);
    Begin
    End Sub OnSetupParams;

    Private Sub ResetLog;
    Begin
        m_strLog := "";
    End Sub ResetLog;

    Private Sub LogLine(strLine: String);
    Begin
        If Not m_strLog.IsEmpty Then
            m_strLog := m_strLog + #13 + #10;
        End If;
        m_strLog := m_strLog + strLine;
        Debug.WriteLine(strLine);
    End Sub LogLine;
End Class UserClass;

After the custom optimization problem is started, and the Fore example is executed, the information dialog box opens that contains values of calculation options in each calendar point of the forecasting period.

See also:

IMsUserOptimizationCallback