forum.alglib.net
http://forum.alglib.net/

ALGLIB in .NET DLL
http://forum.alglib.net/viewtopic.php?f=2&t=41
Page 1 of 1

Author:  alusr1 [ Wed Jul 14, 2010 10:22 pm ]
Post subject:  ALGLIB in .NET DLL

I ported MinLBFGS and MinASA to a .NET DLL in Visual Basic 2010 Express. This port also includes the required base Ap and LinMin classes, as well as the test routines (with clocking) for both optimizers. I also wrote a separate GUI program that can invoke any number of ALGLIB tests from the DLL and present results, so that the DLL is extendable.

The MinLBFGS and MinASA classes present both the classic structure-oriented interface with Shared routines (so that the unit test routines can compile unchanged), as well as the modern class-oriented interface where the State and Report structures become private members of the class.

The resulting DLL is not a true Windows DLL but rather a .NET assembly. In your Visual Studio project, all you have to do is add a reference to this DLL. Then all the exported classes and routines automatically show up with correct types in the context-sensitive help in the VS editor, which hugely speeds up development.

The big benefit is that because this DLL runs on the Common Language Runtime (CLR), it should work with any other CLR-based languages, such as C#, and not just Visual Basic. In addition, unlike with the Common Object Model (COM) interface, there is no significant runtime overhead, so the code executes almost as fast as if it were statically linked to the base program. The final benefit is sharing of a single copy of the DLL among many client programs running simultaneously.

If there is interest, I can share the source code, in hope that users would port other ALGLIB modules to this DLL and share it with the community. Similarly, Sergey may take a look at this code and consider adding a translator from AlgoPascal directly to Visual Basic .NET, so that future bug fixes and enhancements are easily incorporated in this DLL.

Please express interest by replying to this post. If there are a sufficient number of requests, I will post it on some public share.

Author:  Doug Jenkins [ Wed Jul 14, 2010 11:16 pm ]
Post subject:  Re: ALGLIB in .NET DLL

Hi alusr1 - following your earlier posts I have downloaded VB 2010 Express and bought myself a VB book, so I'm definitely interested in your dll, and especially in the source code. I don't have an awful lot of time to spend on these things, but I think I might try the ODE solver routines in VB.Net, to see how they compare with the VBA version.

Author:  Sergey.Bochkanov [ Thu Jul 15, 2010 11:44 am ]
Post subject:  Re: ALGLIB in .NET DLL

I've thought that .NET allows different languages to interoperate. So anyone can compile C# version of ALGLIB and use it from VB.NET. Am I wrong?

Author:  alusr1 [ Thu Jul 15, 2010 1:50 pm ]
Post subject:  Re: ALGLIB in .NET DLL

I have not looked at the C# version, since I never worked in that language. Does it offer class-like interface, or the classic structure-oriented interface with static (shared) routines?

Author:  Sergey.Bochkanov [ Thu Jul 15, 2010 6:27 pm ]
Post subject:  Re: ALGLIB in .NET DLL

Second case. Unit = class, function = static method.

Author:  alusr1 [ Fri Jul 16, 2010 1:13 am ]
Post subject:  Re: ALGLIB in .NET DLL

In that case, my Visual Basic DLL has some merit :-) because it also offers a true class interface that hides/protects internal data through Properties and instance-oriented members. So, for example, this is a calling sequence for MinASA:

...
Dim asa As AlgLib.MinAsaClass
asa = New AlgLib.MinAsaClass(n, x, bl, bu)
asa.SetCond(EpsG, EpsF, EpsX, MaxIters)
Do While asa.Iteration()
asa.F = f(n, asa.X)
g(n, asa.X, f, asa.G, silent)
Loop
asa.Results(x)
AlgLib.ApClass.ConsoleOutputString(testName & "#Iterations=" & asa.IterationsCount & ", #FuncEvals=" & asa.NFEV & _
", TermType='" & AlgLib.MinAsaClass.TermTypeToString(asa.TerminationType) & "'" & _
", #ActiveConstraints=" & asa.ActiveConstraints & vbCrLf & vbCrLf)
...

In the code above, AlgLib refers to the .NET DLL that is referenced by the test project, f(...) is an objective function to be minimized, and g(...) is a non-analytical gradient subroutine taking f() as one of its arguments. As you can see, there is no need to separately create, initialize or pass by reference the State or Result structures because they are cleanly contained in the "asa" instance. The AlgLib.MinAsaClass.TermTypeToString(asa.TerminationType) is a Shared function that returns a short description of the TerminationType (BTW, it would be great to use an enum for TerminationType).

Anyway, if there is sufficient interest in the source code, I can post it on a public share.

Page 1 of 1 All times are UTC
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/