7

I'm really interested in numerical analysis. I have been using DotNumerics Open Source Application. My linear system is the following:

1 * x + 3 * y <= 150
2 * x + 1 * y <= 100

where x >= 0, y >= 0

z = 10 * x + 15 * y

I am trying to solve z (optimization...)

I can use Simplex method to solve above problem as found in this link. I have also emailed the author, however he has not replied.

using DotNumerics.Optimization;
using DotNumerics;

namespace App.SimplexCalcLinearProgramming
{
    class Program
    {
        static void Main(string[] args)
        {
            Simplex simplex = new Simplex();
            double[] initialGuess = new double[2];
            initialGuess[0] = 0.1;
            initialGuess[1] = 2;
            double[] minimum = simplex.ComputeMin(AmacFunction, initialGuess);
            minimum.ToList().ForEach(q => Console.Write(q.ToString() + "\n"));
           Console.ReadKey();
        }

        static double AmacFunction(double[] x)
        {
            /*
             * 1 * x + 3 * y <= 150
             * 2 * x + 1 * y <= 100
             *
             * where x >= 0, y >= 0
             *
             * z = 10 * x + 15 * y
             *
             * Solve for z
             */
            double f = 0;
            f = 10*x[0]+15*x[1];
            return f;
        }
    }
}
user7116
  • 63,008
  • 17
  • 141
  • 172
loki
  • 2,926
  • 8
  • 62
  • 115
  • 1
    Ooh, didn't know about that tool. I will have to look at this later – Marc Gravell May 18 '11 at 18:40
  • Have not used dotNumerics, but if it is a LP you are trying to solve, have you considered using the - Microsoft Solver http://msdn.microsoft.com/en-us/library/ff524509(v=vs.93).aspx – Gangadhar May 18 '11 at 18:40

1 Answers1

7

I don't think DotNumerics can solve LP problems by itself. As far as I interpret the documentation, the Nelder–Mead (downhill simplex method) implemented is only used to solve simple minimalisation problems, not LP problems.

The last time I've solved LP in c#, I used a .net wrapper to LP_Solve.

If you download the lpsolve package, it should come with an example for .net. You can also plug it into the microsoft solver foundation (see here), but I think MSF has some licensing issues and you can't use it freely for commercial applications. But still, MSF may be interesting to check out as well.

Again, you can simply use lpsolve without MSF. Lpsolve is a pretty good LP solver unless you have massive size problems. Then it may be worth to at least around for alternatives and compare performance/adaptability to your particular problem.

Ben Schwehn
  • 4,505
  • 1
  • 27
  • 45
  • my maths may be getting rusty, but IIRC minimalisation is a subset to linear programming problems (at least for linear systems) – sehe May 18 '11 at 18:48
  • I have not looked at it this way. But I guess you could say that minimalisation of a linear system is like solving an LP that has no constraints? – Ben Schwehn May 18 '11 at 18:49
  • I was replying to "minimalisation is a subset to linear programming". I've seen algorithms referred to as "simplex method" that had not much relation to LP at all, more like "hey, it kinda uses triangles, lets call it simplex". But I'm really not sure. It's a while ago :) – Ben Schwehn May 18 '11 at 18:51
  • Ok, I'm lost. You're probably right and my maths _are_ getting rusty – sehe May 18 '11 at 18:53
  • Perhaps a confusion of terms. The http://en.wikipedia.org/wiki/Nelder%E2%80%93Mead_method that dotnumerics implements seems to be a fairly straigtforward optimisation method and no direct relation to the simplex used in LP. Other than that it uses triangles (or higer dimensional polytopes). But I have no formal training in real maths :) I'm gladly corrected if I'm talking nonsense! – Ben Schwehn May 18 '11 at 18:58
  • Hi! i really like interest :) Lp_Solve Great! @Ben Schwehn . But i think that simplex method is useful to solve LP problem.Can you give same example about Microsoft solver foundation... – loki May 18 '11 at 18:59
  • I have only very quickly checked out MSF about a year ago, sorry. The "official" examples will be more useful than my shady memory. lpsolve will probably use some interior point simplex method to solve a LP you give it to solve. But a lot of smart people worked on it, so I'm sure they have some fancy optimised algorithms implemented. The good old simplex method (the original one from Dantzig) is pretty straightforward to implement yourself though, perhaps a fun excersise. – Ben Schwehn May 18 '11 at 19:05
  • The pdf you referenced crashes my pdf reader :/ I will have a look tomorrow (perhaps :) ). This discussion made me sad because I obviously forgot more about LPs than I still remember... :) – Ben Schwehn May 18 '11 at 19:09
  • anyway, I learned about LP from the lecture notes here: http://www.inf.ed.ac.uk/teaching/courses/agta/ and the V. Chvatal, Linear Programming, 1983 book. Both are very approachable for someone with little background in maths. The book teaches you how to do the simplex method yourself, old school style, with pen and paper. Also perhaps useful is that lp_solve comes with a gui that lets you play around with simple LPs. – Ben Schwehn May 18 '11 at 19:25