如何在C#中实现Excel Solver功能? [重复]

时间:2022-01-10 05:20:43

This question already has an answer here:

这个问题在这里已有答案:

I have an application in C#, I need to do some optimization calculations, like Excel Solver Add-in does, one option is certainly to write my own solver implementation, but I'm kind of short of time, so I'm looking into libraries that already exist that can help me with this.

我在C#中有一个应用程序,我需要做一些优化计算,就像Excel Solver Add-in一样,一个选项肯定是编写我自己的求解器实现,但是我有点时间,所以我正在研究已经存在的库可以帮助我解决这个问题。

I've been trying the Microsoft Solver Foundation, which seems pretty neat and cool, the problem is that it doesn't seem to work with the kind of calculations that I need to do.

我一直在尝试Microsoft Solver Foundation,这看起来非常整洁和酷,问题是它似乎不适用于我需要做的那种计算。

At the end of this question I'm adding the information about the calculations I need to perform and optimize.

在这个问题的最后,我正在添加有关我需要执行和优化的计算的信息。

So basically my question is if any of you know of any other library that I can use for this purpose, or any tutorial that can help to do my own solver, or any idea that gives me a lead to solve this issue.

所以基本上我的问题是,如果你们中的任何人知道我可以用于此目的的任何其他库,或任何可以帮助我自己的解算器的教程,或任何能让我领导解决这个问题的想法。

Thanks.

谢谢。

Additional Info:

附加信息:

This is the data I need to calculate:

这是我需要计算的数据:

I have 7 variables, lets call them var1, var2,...,var7

我有7个变量,让我们称之为var1,var2,...,var7

The constraints for these variables are:

这些变量的约束是:

  • All of them need to be 0 <= varn <= 0.5 (where n is the number of the variable)
  • 所有这些都需要为0 <= varn <= 0.5(其中n是变量的数量)
  • The sum of all the variables should be equal to 1
  • 所有变量的总和应该等于1

The objective is to maximize the target formula, which in Excel looks like this:

目标是最大化目标公式,在Excel中如下所示:

 (MMULT(TRANSPOSE(L26:L32),M14:M20)) / (SQRT(MMULT(MMULT(TRANSPOSE(L26:L32),M4:S10),L26:L32))) 

The range that you see in this formula, L26:L32, is actually the range with the variables from above, var1, var2,..., varn.

您在此公式中看到的范围L26:L32实际上是具有上述变量的范围,var1,var2,...,varn。

M14:M20 and M4:S10 are ranges with data that I get from different sources, there are more likely decimal values.

M14:M20和M4:S10是具有从不同来源获得的数据的范围,更可能是十进制值。

As I said before, I was using Microsoft Solver Foundation, I modeled pretty much everything with it, I created functions that handle the operations of the target formula, but when I tried to solve the model it always fail, I think it is because of the complexity of the operations.

正如我之前所说,我使用的是Microsoft Solver Foundation,我用它来模拟几乎所有内容,我创建了处理目标公式操作的函数,但是当我尝试解决模型时它总是失败,我认为这是因为操作的复杂性。

In any case, I just wanted to show these data so you can have an idea about the kind of calculations that I need to implement.

在任何情况下,我只是想显示这些数据,以便您可以了解我需要实现的计算类型。

1 个解决方案

#1


2  

Here are some commercial .NET libraries containing different kind of multivariate optimization functions which can be a replacement for Excel's solver:

以下是一些商业.NET库,包含不同类型的多变量优化函数,可以替代Excel的求解器:

If you find a good non-commercial / open source library for this purpose, let me know.

如果你找到一个很好的非商业/开源图书馆,请告诉我。

#1


2  

Here are some commercial .NET libraries containing different kind of multivariate optimization functions which can be a replacement for Excel's solver:

以下是一些商业.NET库,包含不同类型的多变量优化函数,可以替代Excel的求解器:

If you find a good non-commercial / open source library for this purpose, let me know.

如果你找到一个很好的非商业/开源图书馆,请告诉我。