Hi,
Looking at
posting.php?f=2&t=154 gave me the inspiration to do the same with my free Microsoft Visual C# 2008 Express Edition.
For minBleic I defined following interface:
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using System.Runtime.InteropServices;
public class AlglibException : System.ApplicationException
{
public AlglibException(string message)
: base(message)
{
}
}
[Guid("6DB79AF2-F441-44AC-8412-22B06BFDD9E4")]
public interface INTERFACE_MINBLEIC
{
double[] GetX();
void SetF(double F_);
void SetG(ref double[] G_);
void minbleiccreate(int m, ref double[] x);
void minbleicsetbc(ref double[] bndl, ref double[] bndu);
void minbleicsetlc(ref double[,] c, ref int[] ct, int k);
void minbleicsetlc(ref double[,] c, ref int[] ct);
void minbleicsetinnercond(double epsg, double epsf, double epsx);
void minbleicsetoutercond(double epsx, double epsi);
void minbleicsetbarrierwidth(double mu);
void minbleicsetbarrierdecay(double mudecay);
void minbleicsetmaxits(int maxits);
bool minbleiciteration();
void minbleicresults(ref double[] x);
}
[ClassInterface(ClassInterfaceType.None), Guid("6DB79AF2-F441-63AC-8412-22B06BFDD9E4")]
public class MINBLEIC_C : INTERFACE_MINBLEIC
{
public alglib.minbleicstate csobj;
public alglib.minbleicreport rep;
public double[] GetX()
{
return csobj.innerobj.x;
}
public void SetF(double F_)
{
csobj.innerobj.f = F_;
}
public void SetG(ref double[] G_)
{
csobj.innerobj.g = G_;
}
public void minbleiccreate(int m, ref double[] x)
{
try
{
alglib.minbleiccreate(m, x, out csobj);
}
catch (alglib.alglibexception _E_Alglib)
{
throw new AlglibException(_E_Alglib.msg);
}
}
public void minbleicsetbc(ref double[] bndl, ref double[] bndu)
{
try
{
alglib.minbleicsetbc(csobj, bndl, bndu);
}
catch (alglib.alglibexception _E_Alglib)
{
throw new AlglibException(_E_Alglib.msg);
}
}
public void minbleicsetlc(ref double[,] c, ref int[] ct, int k)
{
try
{
alglib.minbleicsetlc(csobj, c, ct, k);
}
catch (alglib.alglibexception _E_Alglib)
{
throw new AlglibException(_E_Alglib.msg);
}
}
public void minbleicsetlc(ref double[,] c, ref int[] ct)
{
try
{
alglib.minbleicsetlc(csobj, c, ct);
}
catch (alglib.alglibexception _E_Alglib)
{
throw new AlglibException(_E_Alglib.msg);
}
}
public void minbleicsetinnercond(double epsg, double epsf, double epsx)
{
try
{
alglib.minbleicsetinnercond(csobj, epsg, epsf, epsx);
}
catch (alglib.alglibexception _E_Alglib)
{
throw new AlglibException(_E_Alglib.msg);
}
}
public void minbleicsetoutercond(double epsx, double epsi)
{
try
{
alglib.minbleicsetoutercond(csobj, epsx, epsi);
}
catch (alglib.alglibexception _E_Alglib)
{
throw new AlglibException(_E_Alglib.msg);
}
}
public void minbleicsetbarrierwidth(double mu)
{
try
{
alglib.minbleicsetbarrierwidth(csobj, mu);
}
catch (alglib.alglibexception _E_Alglib)
{
throw new AlglibException(_E_Alglib.msg);
}
}
public void minbleicsetbarrierdecay(double mudecay)
{
try
{
alglib.minbleicsetbarrierdecay(csobj, mudecay);
}
catch (alglib.alglibexception _E_Alglib)
{
throw new AlglibException(_E_Alglib.msg);
}
}
public void minbleicsetmaxits(int maxits)
{
try
{
alglib.minbleicsetmaxits(csobj, maxits);
}
catch (alglib.alglibexception _E_Alglib)
{
throw new AlglibException(_E_Alglib.msg);
}
}
public bool minbleiciteration()
{
bool functionReturnValue = false;
try
{
functionReturnValue = alglib.minbleiciteration(csobj);
}
catch (alglib.alglibexception _E_Alglib)
{
throw new AlglibException(_E_Alglib.msg);
}
return functionReturnValue;
}
public void minbleicresults(ref double[] x)
{
try
{
alglib.minbleicresults(csobj, out x, out rep);
}
catch (alglib.alglibexception _E_Alglib)
{
throw new AlglibException(_E_Alglib.msg);
}
}
}
After successful registration of the assembly, I was able to include the generated object library as a reference to my MS Access VBA Project. Then I slightly (increased to vector dimension in minbleiccreate) modified the test function to:
Public Sub TestBLEIC()
Dim ALGLIB As MINBLEIC_C
Dim N As Integer
Dim X() As Double
Dim epsf As Double
Dim epsx As Double
Dim epsg As Double
Dim maxits As Long
N = 1
ReDim X(0 To N)
epsf = 0.00001
epsx = 0.00001
epsg = 0.00001
maxits = 100000
X(0) = 1
X(1) = 1
Set ALGLIB = New MINBLEIC_C
ALGLIB.minbleiccreate N + 1, X
ALGLIB.minbleicsetinnercond epsg, epsf, epsx
ALGLIB.minbleicsetoutercond epsx, epsx
ALGLIB.minbleicsetmaxits maxits
Do While ALGLIB.minbleiciteration()
ALGLIB.SetF Func1(ALGLIB.GetX)
ALGLIB.SetG Grad1(ALGLIB.GetX)
Loop
ALGLIB.minbleicresults X
Debug.Print X(0), X(1) 'result -3.00668489998603 3.00013617674979
End Sub
Public Function Func1(ByRef X() As Double) As Double
Func1 = 100 * (X(0) + 3) ^ 4 + (X(1) - 3) ^ 4
End Function
Public Function Grad1(X() As Double) As Double()
Dim res(0 To 1) As Double
res(0) = 400 * (X(0) + 3) ^ 3
res(1) = 4 * (X(1) - 3) ^ 3
Grad1 = res
End Function
Apparently, it worked. I got -3.0027738605718, 2.99082160246955 as solution...
Many thanks for the great work of you all!