Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Solve Linear programming problem using DotNumerics?

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;
        }
    }
}
like image 322
loki Avatar asked May 18 '11 18:05

loki


1 Answers

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.

like image 150
Ben Schwehn Avatar answered Oct 13 '22 02:10

Ben Schwehn