我试过你的问题。 如下所示,MSF导致类似的残留误差(如果不是更小的话)。
微软求解基金会我的C#代码:
using System;
using Microsoft.SolverFoundation.Services;
namespace akMSFStackOverflow
{
class Program
{
static void Main(string[] args)
{
SolverContext context = SolverContext.GetContext();
Decision a = new Decision(Domain.RealNonnegative, "A");
Decision b = new Decision(Domain.RealNonnegative, "B");
Model model = context.CreateModel();
model.AddDecisions(a, b);
Term c = 1.0 - a - b; // a + b + c sum up to 100%
Term errA = (a * 0.20 + b * 0.35 + c * 0.10) - 0.15; // resulting percentage of A should be 15%
Term errB = (a * 0.70 + c * 0.80) - 0.70;
Term errC = (a * 0.10 + b * 0.65) - 0.10;
Term errD = (c * 0.10) - 0.05;
Term goal = errA * errA + errB * errB + errC * errC + errD * errD;
// ingredients sum up to 100% of the required volume
// constraint is not necessary as c is defined to be 1 - a - b
model.AddConstraints("total", 1.0 == a + b + c);
model.AddGoal("goal", GoalKind.Minimize, goal);
// could specify the IPM solver, as we have a quadratic goal
Solution solution = context.Solve();
Report report = solution.GetReport();
Console.WriteLine("a={0} b={1}", a, b);
Console.Write("{0}", report);
}
}
}
结果:
goal: 0,000173076935386814
A: 0,369230770226158
B: 0,0846153845073738
Excel 2010中求解想出了:
goal: 0.00017308
A: 0.36923685
B: 0.08461443
你确定你正试图最小化相同的结果?也许这两种方法正在使用不同的差异度量。 – Guvante
@Guvante感谢您的关注。我会仔细检查我是否使用相同的差异度量,虽然我是OML的新手,也许我缺少一些东西。 – Hannish
@Guvante我认为你是对的,我发现两个差异测量有轻微的差异,我修改了它,但问题仍然存在,虽然现在得到的结果可能足够相似以保持这种方式。请发表您的评论作为答复我批准它,谢谢。 – Hannish