如何在 C# 中实现 Excel Solver 功能?

发布于 2024-08-29 04:47:48 字数 949 浏览 4 评论 0原文

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

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

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

所以基本上我的问题是,你们中是否有人知道我可以用于此目的的任何其他库,或者任何可以帮助我完成自己的求解器的教程,或者任何可以帮助我解决这个问题的想法。

谢谢。

其他信息:

这是我需要计算的数据:

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

这些变量的约束是:

  • 所有变量都必须为 0 <= varn <= 0.5 (其中 n 是变量的数量)
  • 所有变量的总和应等于 1

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

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

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

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

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

无论如何,我只是想展示这些数据,以便您可以了解我需要实现的计算类型。

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.

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.

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

The constraints for these variables are:

  • All of them need to be 0 <= varn <= 0.5 (where n is the number of the variable)
  • The sum of all the variables should be equal to 1

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

 (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.

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

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.

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦萦几度 2024-09-05 04:47:48

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

如果您为此目的找到了一个好的非商业/开源库,请告诉我。

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

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文