我试过你的问题。如下所示,MSF 产生了相似的残差,如果不是更小的话。
我的 Microsoft Solver Foundation 的 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