以下に説明する問題があります
x1'、x2'、x3'、x4'、x5' の値を見つける必要があります。
(x1-x1')^2+(x2-x2')^2+(x3-x3')^2+(x4-x4')^2+(x5-x5')^2 = 最小値
と
x1' + x2' + x3' + x4' + x5' = 1
x1 + x2 + x3 + x4 + x5 = 1
注:a、b、c、d、e、x1、x2、x3、x4、x5の値はわかっています
この場合、誰かが私を助けてくれますか?
google/or-toolsライブラリを試しましたが、条件を追加して最小値を見つけることができません。
MPSolver solver = createSolver(solverType);
double infinity = MPSolver.infinity();
MPVariable x1 = solver.makeNumVar(0.0, infinity, "x1");
MPVariable x2 = solver.makeNumVar(0.0, infinity, "x2");
MPVariable x3 = solver.makeNumVar(0.0, infinity, "x3");
MPVariable x4 = solver.makeNumVar(0.0, infinity, "x4");
MPVariable x5 = solver.makeNumVar(0.0, infinity, "x5");
// 0.15 <= x1 <= 0.35
MPConstraint c1 = solver.makeConstraint(-infinity, 0.35);
c1.setCoefficient(x1, 1);
MPConstraint c2 = solver.makeConstraint(0.15, infinity);
c2.setCoefficient(x1, 1);
// 0.1 <= x2 <= 0.3
MPConstraint c3 = solver.makeConstraint(-infinity, 0.3);
c3.setCoefficient(x2, 1);
MPConstraint c4 = solver.makeConstraint(0.1, infinity);
c4.setCoefficient(x2, 1);
// 0.0 <= x3 <= 0.2
MPConstraint c5 = solver.makeConstraint(-infinity, 0.2);
c5.setCoefficient(x3, 1);
MPConstraint c6 = solver.makeConstraint(0.0, infinity);
c6.setCoefficient(x3, 1);
// 0.15 <= x4 <= 0.35
MPConstraint c7 = solver.makeConstraint(-infinity, 0.35);
c7.setCoefficient(x4, 1);
MPConstraint c8 = solver.makeConstraint(0.15, infinity);
c8.setCoefficient(x4, 1);
// 0.1 <= x5 <= 0.3
MPConstraint c9 = solver.makeConstraint(-infinity, 0.3);
c9.setCoefficient(x5, 1);
MPConstraint c10 = solver.makeConstraint(0.1, infinity);
c10.setCoefficient(x5, 1);
// x1 + x2 + x3 + x4 + x5 = 1
MPConstraint c11 = solver.makeConstraint(-infinity, 1.0);
c11.setCoefficient(x1, 1);
c11.setCoefficient(x2, 1);
c11.setCoefficient(x3, 1);
c11.setCoefficient(x4, 1);
c11.setCoefficient(x5, 1);
MPConstraint c12 = solver.makeConstraint(1.0, infinity);
c12.setCoefficient(x1, 1);
c12.setCoefficient(x2, 1);
c12.setCoefficient(x3, 1);
c12.setCoefficient(x4, 1);
c12.setCoefficient(x5, 1);
MPObjective objective = solver.objective();
objective.setCoefficient(x1, 1);
objective.setCoefficient(x2, 1);
objective.setCoefficient(x3, 1);
objective.setCoefficient(x4, 1);
objective.setCoefficient(x5, 1);
objective.setMinimization();