Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/345.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 求解带约束的线性方程_Python_Linear Programming - Fatal编程技术网

Python 求解带约束的线性方程

Python 求解带约束的线性方程,python,linear-programming,Python,Linear Programming,我对线性规划这门学科相当陌生,如果有任何建议,我都会很感激 我有一个稍微复杂的方程,但这里有一个更简单的问题: x1 + x2 = 10 #subject to the following constraints: 0 <= x1 <= 5 and 3x1 <= x2 <= 20 x1+x2=10 #受以下限制: 0您的问题可以表述为 min 0*x1+0*x2 ("zero coefficients") 服从 x1+x2=10 3x1-x2<=0 x2

我对线性规划这门学科相当陌生,如果有任何建议,我都会很感激

我有一个稍微复杂的方程,但这里有一个更简单的问题:

x1 + x2 = 10 
#subject to the following constraints: 
0 <= x1 <= 5 and 
3x1 <= x2 <= 20 
x1+x2=10
#受以下限制:

0您的问题可以表述为

min 0*x1+0*x2 ("zero coefficients")
服从

x1+x2=10
3x1-x2<=0
x2<=20 (note that this constraint follows from x1,x2>=0 and their sum being 10)
x1+x2=10

3x1-x2您的问题可以表述为

min 0*x1+0*x2 ("zero coefficients")
服从

x1+x2=10
3x1-x2<=0
x2<=20 (note that this constraint follows from x1,x2>=0 and their sum being 10)
x1+x2=10

3x1-x2一目了然,这是二次规划吗?据我所知,至少有两个Python库可以帮助解决这个问题。它只是简单的线性规划,在Python中定义和求解线性规划的一个很好的库是cvxpy。如果设置一个系数为零的目标函数,可以使用线性规划解决这个问题。在该设置中,
x1+x2=10
也是一个约束,并且
3x1@KarstenW. 你能解释一下你所说的零系数目标函数是什么意思吗?这是一个二次规划的例子吗?据我所知,至少有两个Python库可以帮助解决这个问题。它只是简单的线性规划,在Python中定义和求解线性规划的一个很好的库是cvxpy。如果设置一个系数为零的目标函数,可以使用线性规划解决这个问题。在该设置中,
x1+x2=10
也是一个约束,并且
3x1@KarstenW. 你能解释一下零系数的目标函数是什么意思吗?谢谢@Karsten的解释。。我通过阅读约束编程来解决这个问题——在没有目标函数时特别有用。谢谢@Karsten的解释。。我通过阅读约束编程来解决这个问题——在没有目标函数时特别有用。