:あなたはライブラリをインストール上のビットの知識を得た from scipy.optimize import linprog
import numpy as np
N = 5
N_AUX = N
c = np.hstack((np.zeros(N), np.ones(N_AUX))) # objective -> sum of aux-vars
A_orig = [[0, 1, -1, 0, 0, 0, 0, 0, 0, 0], # orig constraint 1
[0, 0, 1, -1, 0, 0, 0, 0, 0, 0], # orig constraint 2
[-1, -1, 0, 0, 0, 0, 0, 0, 0, 0], # more interesting problem
[0, -1, -1, 0, 0, 0, 0, 0, 0, 0]] # "" "" ""
A_aux = [[-1, 0, 0, 0, 0, -1, 0, 0, 0, 0],
[0, -1, 0, 0, 0, 0, -1, 0, 0, 0],
[0, 0, -1, 0, 0, 0, 0, -1, 0, 0],
[0, 0, 0, -1, 0, 0, 0, 0, -1, 0],
[0, 0, 0, 0, -1, 0, 0, 0, 0, -1],
[1, 0, 0, 0, 0, -1, 0, 0, 0, 0],
[0, 1, 0, 0, 0, 0, -1, 0, 0, 0],
[0, 0, 1, 0, 0, 0, 0, -1, 0, 0],
[0, 0, 0, 1, 0, 0, 0, 0, -1, 0],
[0, 0, 0, 0, 1, 0, 0, 0, 0, -1]]
A = np.vstack((A_orig, A_aux))
b = [7, 4, -5, -8] + [0 for i in range(N_AUX*2)]
bnds = [(0, 50) for i in range(N)] + [(None, None) for i in range(N_AUX)] # some custom bounds
res = linprog(c, A_ub=A, b_ub=b, bounds=bnds)
print(res)
# fun: 8.0
# message: 'Optimization terminated successfully.'
# nit: 10
# slack: array([ 5., 1., 0., 10., 6., 0., 0., 0., 0., 0., 0.,
# 0., 50., 45., 47., 50., 50., 0., 0.])
# status: 0
# success: True
# x: array([ 0., 5., 3., 0., 0., 0., 5., 3., 0., 0.])
場合、私はどのcvxpyを使用することをお勧めしますこの種の変換は自動的に(他の中でも)