The procedure for requesting AWR support has changed. Please read all about the new AWR product support process.
Page tree
Skip to end of metadata
Go to start of metadata

This script sample code for a dialog for users to enter how many iterations of specific optimizers to run. It then performs the specified optimizations. Note, optimizers are set by index, but the order could change so there is a function to find the optimizer by name and return the index.

Option Explicit

Dim ng As Integer
Dim np As Integer
Dim nr As Integer
Dim ns As Integer

' Code Module
Sub Main
        Dim x As Integer
        Begin Dialog UserDialog 370,210,"Specify Iterations" ' %GRID:10,7,1,1
                Text 170,14,120,14,"ITERATIONS:",.Text1
                CheckBox 30,35,130,14,"Pointer (Robust)",.prb
                CheckBox 30,63,90,14,"Random",.rdm
                CheckBox 30,91,90,14,"Simplex",.spx
                CheckBox 30,119,90,14,"Gradient",.grd
                TextBox 170,35,90,21,.nPrb
                TextBox 170,63,90,21,.nRdm
                TextBox 170,91,90,21,.nSpx
                TextBox 170,119,90,21,.nGrd
                OKButton 60,168,90,21
                CancelButton 190,168,90,21
        End Dialog
        Dim dlg As UserDialog

        dlg.nPrb = "100"
        dlg.nRdm = "100"
        dlg.nSpx = "100"
        dlg.nGrd = "100"
        If x = 0 Then
                End 'cancell pressed
        End If

        np = Val(dlg.nPrb)
        nr = Val(dlg.nRdm)
        ns = Val(dlg.nSpx)
        ng = Val(dlg.nGrd)

        Project.Optimizer.StopAtMin = True

        If dlg.Prb Then
                Project.Optimizer.Type = find_opt_type("Pointer - Robust Optimization") 'must find index by name as index can change version to version.
                Project.Optimizer.MaxIterations = np
                Project.Optimizer.StopAtMin = True
                While Project.Optimizer.Running = True
        End If

        If dlg.Rdm Then
                Project.Optimizer.Type = find_opt_type("Random (Local)")
                Project.Optimizer.MaxIterations = nr
                While Project.Optimizer.Running = True
        End If

        If dlg.Spx Then
                Project.Optimizer.Type = find_opt_type("Simplex Optimizer")
                Project.Optimizer.MaxIterations = ns
                While Project.Optimizer.Running = True
        End If

        If dlg.Grd Then
                Project.Optimizer.Type =  find_opt_type("Gradient Optimization")
                Project.Optimizer.MaxIterations = ng
                While Project.Optimizer.Running = True
        End If

End Sub
Function find_opt_type(nm As String) As Integer
        Dim typ As Integer
        Dim i As Integer
        typ = -1
        For i = 1 To Project.Optimizer.TypeCount
                'Debug.Print Project.Optimizer.TypeName(i) & ": " & i
                If nm = Project.Optimizer.TypeName(i) Then
                        typ = i
                End If
        Next i
        If typ = -1 Then
                MsgBox ("could not find optimizer name specified:" & nm)
        End If
        find_opt_type = typ
End Function