7

I'm trying to solve some simple equations in .NET. I came across Math.NET and evaluate it. The Solver() methods seemed to be what I need but I can't figure out how to use side conditions with this method.

To illustrate my problem I will give you a sample:

Given:  
0 <= a_i <= 100  
0 <= b <= 100
0 <= c
a_i, b and c are given

x_1, ..., x_n should be optimized

f(x) = x_1*a_1 + x_2*a_2 + ... + x_n*a_n = b

Side conditions:  
g(x) = x_1 + x_2 + ... + x_n = c  
0 <= x_i

Is it possible to solve such a problem using the solve method or any other component of Math.NET or do you know any (free for commercial use) .NET library that can be used for solving this? I wouldn't like to write an algorithm for such a common problem by myself.

Best regards & thanks in advance

Jay
  • 2,141
  • 6
  • 26
  • 37
  • possible duplicate of [Free Optimization Library in C#](http://stackoverflow.com/questions/1211201/free-optimization-library-in-c) – duffymo Sep 30 '11 at 14:04

3 Answers3

2

ALGLIB is great for these tasks. Check out their page on constrained optimization.

EDIT: It has both a free license (GPL) and a commercial license starting from $370.

Andreas
  • 6,447
  • 2
  • 34
  • 46
2

IMHO Microsoft Solver Foundation is the way to go for this. The Express Version is free AFAIK and powerful enough for most smaller applications.

As I see now the Express Version is only indented for exploration - but there is (now?) a Standard-Lib for MSDN subscribers so I don't remove this post yet, as you might have a MSDN subscribtion.

Random Dev
  • 51,810
  • 9
  • 92
  • 119
1

You need an optimizer with constraints like simplex method or Marquardt non-linear optimization.

duffymo
  • 305,152
  • 44
  • 369
  • 561
  • the problem looks rather linear to me ;) - right from the book, Simplex or interior Points are both fine for this - but is this really a answer? – Random Dev Sep 30 '11 at 14:11
  • You can't find what you're looking for unless you know its name. – duffymo Sep 30 '11 at 14:31
  • I finally decided to port my Simplex I wrote once at university to NET, works fine :) – Jay Dec 03 '11 at 01:45