ControlVariables: IMsUORuntimeControlTerms;
The ControlVariables property returns a collection of controlling variables.
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 Ms and Xml system assemblies.
Public Class UserOptimization: Object, IMsUserOptimizationCallback
Public Sub OnLoad(Xml: IXMLDOMElement);
Begin
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
CtrlVars: IMsUORuntimeControlTerms;
CtrlVar: IMsUORuntimeControlTerm;
i, c: Integer;
Begin
CtrlVars := Runtime.ControlVariables;
c := CtrlVars.Count;
Debug.WriteLine("--------------------------------------");
For i := 0 To c - 1 Do
Debug.WriteLine("Controlling variable " + i.ToString);
CtrlVar := CtrlVars.Item(i);
Debug.Indent;
Debug.WriteLine("TermToText: " + CtrlVar.Term.TermToText);
Debug.WriteLine("Value: " + CtrlVar.Value);
Debug.WriteLine("String: " + CtrlVar.GenerateString);
Debug.Unindent;
End For;
// Calculate equations in the current point
Runtime.Equations.ExecuteAll;
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;
End Class UserOptimization;
When a custom optimization problem is is started, the OnExecute event will occur in each calculation point. The development environment console will display text views and values of controlling variables in each calculation point. After this all equations will be calculated.
See also: