lp_solve中线性规划的非负比率约束

时间:2016-04-29 18:28:34

标签: math optimization linear-programming lpsolve

使用lp_solve我需要将两个线性函数的比率约束为非负的:

HTTPS

但lp_solve不提供括号。是否有可能解决它,所以我不需要括号,或者这是lp_solve的一般问题?

2 个答案:

答案 0 :(得分:4)

您正尝试将以下形式的约束添加到线性程序中:

(-0.275 y0 + 0.15 y1 + 0.15 y2 + 0.236 y3 + 0.14745 y4) / (-0.175 y0 + 0.05 y1 + 0.05 y2 + 0.136 y3 + 0.04745 y4) >= 0;

为简单起见,我会定义A = (-0.275 y0 + 0.15 y1 + 0.15 y2 + 0.236 y3 + 0.14745 y4)B = (-0.175 y0 + 0.05 y1 + 0.05 y2 + 0.136 y3 + 0.04745 y4)。因此,您的约束是:

A / B >= 0

这意味着必须满足以下两个条件之一:

  1. A >= 0B >= 0
  2. A <= 0B <= 0
  3. 这会在您的公式中引入非凸性,因为点(A, B) = (4, 4)(A, B) = (-2, -6)都是可行的,但它们的中点(A, B) = (1, -1)是不可行的。因为你的可行集是非凸的,所以实际上不可能使用带有所有连续变量的线性程序来模拟你的情况,正如你在代码中尝试的那样。

    您需要在配方中引入二元变量来模拟这种非凸性。对此进行建模的一种自然方法是,如果zA >= 0使二进制变量B >= 0等于1,则z和{{A <= 0等于0 1}}。然后你可以引入以下约束(这里B <= 0是一个大的正常数):

    M

    如果A <= Mz B <= Mz A >= M(z-1) B >= M(z-1) z binary ,那么约束会给我们z=0-M <= A <= 0,而如果-M <= B <= 0,则约束会给我们z=1和{{1} }。如果所选的0 <= A <= M值足够大,这将捕捉您的情况。

答案 1 :(得分:0)

你的解决方案配方齐全,lpsolve解决得很好。但结果可能不是您所期望的。例如,我得到:z = 0且x187 = 0(A = B = 0)。 问题是A和B是仅依赖于x187的表达式,因此您应该简化该除法表达式!选择的大M应该更小?

Model name:  'model build from GLP-Solve' - run #1    
Objective:   Minimize(R0)

SUBMITTED
Model size:       12 constraints,      53 variables,          311 non-zeros.
Sets:                                   0 GUB,                  0 SOS.

Using DUAL simplex for phase 1 and PRIMAL simplex for phase 2.
The primal and dual simplex pricing strategy set to 'Devex'.


Relaxed solution       276710632.306 after         23 iter is B&B base.

Feasible solution      276710632.306 after         23 iter,         0 nodes (gap 0.0%)

Optimal solution       276710632.306 after         23 iter,         0 nodes (gap 0.0%).

Excellent numeric accuracy ||*|| = 0

 MEMO: lp_solve version 5.5.2.0 for 64 bit OS, with 64 bit REAL variables.
      In the total iteration count 23, 17 (73.9%) were bound flips.
      There were 0 refactorizations, 0 triggered by time and 0 by density.
       ... on average 6.0 major pivots per refactorization.
      The largest [LUSOL v2.2.1.0] fact(B) had 13 NZ entries, 1.0x largest basis.
      The maximum B&B level was 1, 0.5x MIP order, 1 at the optimal solution.
      The constraint matrix inf-norm is 1e+06, with a dynamic range of 6.39386e+08.
      Time to load data was 0.001 seconds, presolve used 0.000 seconds,
       ... 0.000 seconds in simplex solver, in total 0.001 seconds.

如果我们删除A,B和z限制,我们会得到相同的结果:

Model name:  'model build from GLP-Solve' - run #1    
Objective:   Minimize(R0)

SUBMITTED
Model size:        6 constraints,      50 variables,          299 non-zeros.
Sets:                                   0 GUB,                  0 SOS.

Using DUAL simplex for phase 1 and PRIMAL simplex for phase 2.
The primal and dual simplex pricing strategy set to 'Devex'.


Optimal solution       276710632.306 after         22 iter.

Excellent numeric accuracy ||*|| = 0

 MEMO: lp_solve version 5.5.2.0 for 64 bit OS, with 64 bit REAL variables.
      In the total iteration count 22, 17 (77.3%) were bound flips.
      There were 0 refactorizations, 0 triggered by time and 0 by density.
       ... on average 5.0 major pivots per refactorization.
      The largest [LUSOL v2.2.1.0] fact(B) had 7 NZ entries, 1.0x largest basis.
      The constraint matrix inf-norm is 1, with a dynamic range of 639.386.
      Time to load data was 0.002 seconds, presolve used 0.001 seconds,
       ... 0.001 seconds in simplex solver, in total 0.004 seconds.