我有两个稀疏矩阵E和D,它们在同一个地方有非零项.现在我希望将其E/D
作为稀疏矩阵,仅在D非零时定义.
例如,请使用以下代码:
import numpy as np
import scipy
E_full = np.matrix([[1.4536000e-02, 0.0000000e+00, 0.0000000e+00, 1.7914321e+00, 2.6854320e-01, 4.1742600e-01, 0.0000000e+00],
[9.8659000e-03, 0.0000000e+00, 0.0000000e+00, 1.9106752e+00, 5.7283640e-01, 1.4840370e-01, 0.0000000e+00],
[1.3920000e-04, 0.0000000e+00, 0.0000000e+00, 9.4346500e-02, 2.8285900e-02, 4.3967800e-02, 0.0000000e+00],
[0.0000000e+00, 4.5182676e+00, 0.0000000e+00, 0.0000000e+00, 7.3000000e-06, 1.5100000e-05, 4.0746900e-02],
[0.0000000e+00, 0.0000000e+00, 3.4002088e+00, 4.6826200e-02, 0.0000000e+00, 2.4246900e-02, 3.4529236e+00]])
D_full = np.matrix([[0.36666667, 0. , 0. , 0.33333333, 0.2 , 0.1 , 0. ],
[0.23333333, 0. , 0. , 0.33333333, 0.4 , 0.03333333, 0. ],
[0.06666667, 0. , 0. , 0.33333333, 0.4 , …
Run Code Online (Sandbox Code Playgroud) 我正在使用 cvxpy,自从更新到 1.0.6 以来,我在调用 GLPK 时得到了不需要的输出。
import cvxpy as cvx
x = cvx.Variable(2)
p = cvx.Problem(cvx.Minimize(x[0]), [x[0] + x[1] == 1, x[0] - x[1] >= 1])
p.solve(solver = cvx.GLPK)
Run Code Online (Sandbox Code Playgroud)
在 IPython3 中,这会创建输出
GLPK Simplex Optimizer, v4.61
2 rows, 2 columns, 4 non-zeros
0: obj = 0.000000000e+00 inf = 2.000e+00 (2)
1: obj = 1.000000000e+00 inf = 0.000e+00 (0)
* 2: obj = 1.000000000e+00 inf = 0.000e+00 (0)
OPTIMAL LP SOLUTION FOUND
Out[5]: 1.0
Run Code Online (Sandbox Code Playgroud)
在 0.4.11 中,我只得到了1.0
打印,我想恢复这种行为。对于其他求解器,有该verbose
选项,但对于 …
我有一个带有整数约束的 LP,我想使用 Python 以精确算术求解它。其实我只需要一个可行点。
编辑:“精确算术”这里指的是无界枚举数和分母的有理数。
之前的尝试:
ImportError: libqsopt_ex.so.2: cannot open shared object file: No such file or directory
,尽管据我所知,我给出了该库的路径。速度只是一个中等问题。我的较大实例有大约 500 个带有框约束的变量和 40 个等式,但涉及的数量可能很大。