Get latest information about PGSL here.

VB.NET Interface to PGSL 4

Dr. Benny Raphael

I have developed interfaces to PGSL in many languages, java, matlab, Excel VBA and VB.NET. If you are interested, please contact me. VB.NET interface (beta) is available for public download here (51 KB) under GNU public license. There is a readme.txt file in the distribution that explains how to use the interface.


If you want to know about how to use PGSL VB Interface before downloading the zip file, the contents of the readme.txt file are reproduced below.

PGSL Version 4 VB Interface
Copyright (C) Benny Raphael

There are two parts.

a) The main C code containing the PGSL algorithm + some wrapper functions. This is stored in the directory PGSLMain. The Visual studio .NET solution PGSLMain.sln can be used compile it into a .NET console application.

b) The VB control for defining the optimisation problem. This is stored in the directory PGSLVBCntrl. The Visual studio .NET solution PGSLVBInterface.sln can be used compile it into a .NET class library.

In order to solve your optimisation problem, follow these steps.
1. Copy Sample.vb to YourProblem.vb.
2. Double click on PGSLVBInterface.sln to launch visual studio.NET. Add YourProblem.vb to the project. Modify YourProblem.vb to setup your problem.
3. Build the solution. It creates PGSLVBCntrl.dll in the bin directory.
4. Launch PGSLMain.sln. In PGSLMain.cpp, replace the following line optimisationSetup = new Sample(); with optimisationSetup = new YourProblem();
5. You may not need to do this step, but is recommended to force the compiler to reload your VB class library. In the Solution explorer, delete PGSLVBCntrl from the "References". Click on Build/Build Solution. It will give many errors. Now right-Click on References and select "Add reference". In the following dialog, Browse and select PGSLVBInterface.dll.
6. Compile and run. Remember that it takes about one minute for .NET to initialise!! So be patient. Once it starts running, it is as quick as the C version.


If you want to know how you define your optimisation problem in VB.NET, see the following sample problem defined in Sample.vb


' This is a sample class to denote how a PGSL problem is defined in the VB version
Public Class Sample
    Inherits PGSLVBWrapper

    Sub New()
        Dim xmin As Double = -5.12
        Dim xmax As Double = 5.11
        Dim xprecision As Double = 0.0001

        ' Perform any other initialisation of variables here

        MyBase.numVariables = 3
        MyBase.threshold = 0.0001
        MyBase.axes(0) = New Axis(xmin, xmax, xprecision)   ' Specifying the bounds and precision for the first variable
        MyBase.axes(1) = New Axis(xmin, xmax, xprecision)   ' Specifying the bounds and precision for the second variable
        MyBase.axes(2) = New Axis(xmin, xmax, xprecision)   ' Specifying the bounds and precision for the third variable
        MyBase.NS = 2
        MyBase.NPUC = 1
        MyBase.NFC = 60
        MyBase.NSDC = 20

    End Sub

    ' This is the objective function to be minimised
    ' the argument point contains the values of variables suggested by PGSL.  The user should 
    ' compute and return the evaluation of the point as a double
    Public Overrides Function objectiveFunction() As Double
        Dim x1 As Double = currentPoint(0)
        Dim x2 As Double = currentPoint(1)
        Dim x3 As Double = currentPoint(2)

        Dim value = (x1 - 1) * (x1 - 1) + (x2 - 2) * (x2 - 2) + (x3 - 3) * (x3 - 3)
        objectiveFunction = value

    End Function

    ' this function is called by PGSL after the completion of the optimisation
    ' Use this function to perform any saving of results 
    Public Overrides Function optimisationCompleted() As Integer

        'This is how the results are obtained
        Dim bestcost As Double = MyBase.globalMinimum
        Dim x1 As Double = MyBase.minimumPoint(0)
        Dim x2 As Double = MyBase.minimumPoint(1)
        Dim x3 As Double = MyBase.minimumPoint(2)
        Dim totalNumEvaluations = MyBase.numEvaluations

        ' Save results here

    End Function
End Class