简体   繁体   English

Python线性编程

[英]Python Linear Programming

I am trying to solve the following equation: 我正在尝试解决以下方程式:

maximize x^{T}Ax where x is a 3 X 1 vector of the variables to be maximized and A is a 3 X 3 matrix of values. maximize x^{T}Ax ,其中x是要最大化的变量的3 X 1向量, A3 X 3值矩阵。

So basically x^{T} = [a,b,c] which are the unknowns to be maximized and A could be something like 所以基本上x^{T} = [a,b,c]是要最大化的未知数,而A可能类似于

A = [ [29, 29, 79], [28, 28, 48], [9, 40, 0 ]]

Could someone show me how to represent this in the form of a maximization problem using PuLP or some other linear programming package in python? 有人可以告诉我如何使用PuLP或python中的其他线性编程包以最大化问题的形式来表示吗?

Any help would be much appreciated. 任何帮助将非常感激。 I am extremely new to this area and have not idea how to get started representing this formulation. 我对这个领域非常陌生,还不知道如何开始代表这种表述。

I have so far tried to use CVXPY to model this function. 到目前为止,我已经尝试使用CVXPY对该函数进行建模。 I have the following code but am seeing an error: 我有以下代码,但看到错误:

    [1] A = np.array([[29,29,79],[28,28,48],[9,40,0]])
    [2] x=Variable(3)
    [3] objective=Minimize(x.T*A*x)
     Warning: Forming a nonconvex expression (affine)*(affine).
  warnings.warn("Forming a nonconvex expression (affine)*(affine).")
    [4] constraints=[0<=x,x<=1,sum_entries(x)==1] #what I'm trying to say is each entry of x should be between 0 and 1 and all entries should add up to 1.
    [5] prob = Problem(objective, constraints)
    [6] prob.solve()
    DCPError: Problem does not follow DCP rules.

I don't believe PuLP supports quadratic programming (QP). 我不相信PuLP支持二次编程(QP)。 Your model is quadratic and PuLP is only for linear programming models (LPs and MIPs). 您的模型是二次方的,而PuLP仅适用于线性编程模型(LP和MIP)。 There are quite a few options to express QPs in Python. 有很多选项可以用Python表达QP。 High performance commercial solvers often provide Python bindings, and otherwise you can look at for example CVXOPT . 高性能的商业求解器通常提供Python绑定,否则您可以查看例如CVXOPT Notice that only convex QPs are "easy" to solve. 注意只有凸QP是“容易”解决的。 If you have a non-convex QP things become much more difficult and you may need to look at a global solver (there not as many of those type of solvers). 如果您有非凸型QP,那么事情会变得更加困难,您可能需要查看全局求解器(这些类型的求解器不多)。 Non-convex QPs can be reformulated via the KKT conditions as a linear MIP model, although these models may not always perform very well. 可以通过KKT条件将非凸型QP重新构造为线性MIP模型,尽管这些模型可能并不总是性能很好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM