How to Solve Linear programming problem using DotNumerics?

北城以北 提交于 2019-12-04 21:07:53

问题


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;
        }
    }
}

回答1:


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.



来源:https://stackoverflow.com/questions/6049405/how-to-solve-linear-programming-problem-using-dotnumerics

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!