需要帮助解决一些已知值的最小稀疏线性

时间:2016-05-12 01:43:59

标签: java python-2.7 math mathematical-optimization cvxopt

我有下面描述的问题

enter image description here

我需要找到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();

2 个答案:

答案 0 :(得分:3)

这是具有凸目标函数的基本约束优化问题。     https://en.wikipedia.org/wiki/Constrained_optimization 有许多软件可以帮助您完成此任务。例如
    http://cvxopt.org/documentation/index.html

答案 1 :(得分:1)

我非常感谢龙龙先生。

以下是他帮助我解决问题的解决方案:

Row