如何使用DotNumerics求解线性规划问题? [英] How to Solve Linear programming problem using DotNumerics?

查看:193
本文介绍了如何使用DotNumerics求解线性规划问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在数值分析很感兴趣。我一直在使用DotNumerics开源应用程序。我的线性系统如下:

  1 * X + 3 * Y< = 150
2 * X + 1 * Y&其中; = 100
 

其中, X> = 0,Y> = 0

  Z = 10 * X + 15 * Y
 

我试图解决以Z (优化...)

我可以用单纯的方法来解决上述问题,因为在这个环节发现。我也通过电子邮件的作者,但他没有回答。

 使用DotNumerics.Optimization;
使用DotNumerics;

命名空间App.SimplexCalcLinearProgramming
{
    类节目
    {
        静态无效的主要(字串[] args)
        {
            单面单=新单();
            双[] initialGuess =新的双[2];
            initialGuess [0] = 0.1;
            initialGuess [1] = 2;
            双[]最小= simplex.ComputeMin(AmacFunction,initialGuess);
            。minimum.ToList()的ForEach(Q => Console.Write(q.ToString()+\ N));
           Console.ReadKey();
        }

        静态双AmacFunction(双[]×)
        {
            / *
             * 1 * X + 3 * Y&其中; = 150
             * 2 * X + 1 * Y&其中; = 100
             *
             *,其中x> = 0,Y> = 0
             *
             * Z = 10 * X + 15 * Y
             *
             *解决用于z
             * /
            双F = 0;
            F = 10 * X [0] + 15 * X [1];
            返回F;
        }
    }
}
 

解决方案

我不认为DotNumerics可以自己解决LP问题。据我跨$ P $磅的文档时,内尔德 - 米德(单纯形法)实施只用于解决简单minimalisation问题,而不是LP的问题。

上一次我在C#中解决了LP,我用了一个.NET包装,以 LP_Solve

如果您下载lpsolve包,它应该与.NET的一个例子。你也可以将它插入href="http://msdn.microsoft.com/en-us/devlabs/hh145003" rel="nofollow">微软求解器的基础(的看到这里),但我认为无国界医生有一定的许可问题,你不能运用自如的商业应用。但尽管如此,无国界医生可能是有趣的,看看为好。

同样,你可以简单地使用lpsolve不无国界医生。 Lpsolve是pretty的好LP解算器,除非你有大量的大小问题。然后,它可以替代品值得至少四周,性能/适应性比较特定的问题。

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

解决方案

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.

这篇关于如何使用DotNumerics求解线性规划问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆