用cvxpy进行线性编程 [英] Linear Programming with cvxpy
问题描述
我想问您关于优化线性程序的问题.
I would like to ask you regarding on the Linear Program for optimization.
我有一个目标函数,约束函数如下,
I have an objective function, and constraint functions as below,
- 变量(x1,x2,x3,x4,x5,x6)是产品数量,现在产品数量必须为固定数字.
-
此问题的目标是优化产品数量.
- variables(x1, x2, x3, x4, x5, x6) are quantities of the products, and the quantities of products have to be fixed numbers now.
the goal of this problem is the optimizing the quantities of products.
-
目标函数(c.T * [x1,x2,x3,x4,x5,x6])
Objective Function (c.T * [x1, x2, x3, x4, x5, x6])
[[c11, c12, c13, c14, c15 c16],
[c21, c22, c23, c24, c25, c26],
X [x1, x2, x3, x4, x5, x6]
[c31, c32, c33, c34, c35, c36],
[c41, c42, c43, c44, c45, c45]]
我要优化的结果将如下所示
The result that I would like to optimize is going to be as below
c11*x1 + c12*x2 + c13*x3 + c14*x4 + c15*x5 + c16*x6 +
c21*x1 + c22*x2 + c23*x3 + c24*x4 + c25*x5 + c26*x6 +
c31*x1 + c32*x2 + c33*x3 + c34*x4 + c35*x5 + c36*x6 +
c41*x1 + c42*x2 + c43*x3 + c44*x4 + c45*x5 + c46*x6 = optimized value
- 约束函数
1)约束_1
5500000 * x1 + 2500000 * x2 + 825000 * x3 + 5500000 * x4 + 5500000 * x5 + 5500000 * x6 <= 800000000
5500000*x1+2500000*x2+825000*x3+5500000*x4+5500000*x5+5500000*x6 <= 800000000
2)约束_2
x1 <= 10
x2 <= 10
x3 <= 10
x4 <= 10
x5 <= 10
x6 <= 10
我遇到的问题是"Cs(c1,1〜c4,5)的目标函数"中的问题.
The problem that I am suffering from is the in the "Objective Function of Cs(c1,1 ~ c4,5)".
我解决了线性编程,该函数在目标函数中具有整数值,但在矩阵中没有.
I have solved the Linear Programming that has integers values in the Objective Functions, but not the matrix.
我已经尝试了所有其他方式,但是现在我确实需要帮助.
I have tried all other ways that I could, but now I really need helps on this.
请对此问题提出任何想法或代码.
Please kindly suggest me any kind of ideas or codes for this question.
推荐答案
假设您已将原始cij存储在numpy数组中,则可能需要先对诸如c11 + c21 + c31 + c41之类的术语进行汇总.这可以通过汇总每列来完成,请尝试c.sum(axis = 0)
Suppose you have store the original cij in a numpy array, you might like to sum up terms like c11+c21+c31+c41 first. This can be done by summing up each column, try c.sum(axis = 0)
>>> import numpy as np
>>> c = np.arange(24).reshape(4,6)
>>> c
array([[ 0, 1, 2, 3, 4, 5],
[ 6, 7, 8, 9, 10, 11],
[12, 13, 14, 15, 16, 17],
[18, 19, 20, 21, 22, 23]])
>>> c = c.sum(axis=0)
>>> c
array([36, 40, 44, 48, 52, 56])
这篇关于用cvxpy进行线性编程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!