## L P 原

ludlows

``````# solves *bounded* LPs of the form:
# max cx
# sub to: Ax <= b
from sympy import *
from itertools import combinations
# enumerates all the vertices of {x | Ax <= b}
def enumeratevertices(A, b):
m, n = A.rows, A.cols
for rowlist in combinations(range(m), n):
Ap = A.extract(rowlist, range(n))
bp = b.extract(rowlist, [0])
if Ap.det() != 0:
xp = Ap.LUsolve(bp)
d = A * xp - b
feasible = True
for i in range(m):
if d[i] > 0:
feasible = False
if feasible:
yield xp
# finds the optimum using vertex enumeration
def findoptimum(A, b, c):
m, n = A.rows, A.cols
bestvalue, bestvertex = None, None
for vertex in enumeratevertices(A, b):
if bestvalue is None or (vertex.T*c)[0] > bestvalue:
bestvalue = (vertex.T * c)[0]
bestvertex = vertex
return bestvertex
def solve(A, b, c):
x = findoptimum(A, b, c)
if not x:
print 'LP is infeasible'
else:
print 'Vertex', x.T, 'is optimal'
print 'Optimal value is', c.T*x
if __name__ == '__main__':
A = Matrix([[-10,  -6, -9, -10],
[  8,  -6, -5,  -5],
[ -7,  -1, -9,   3],
[ -1,  -4,  5,  10],
[  1,   2,  0,  10],
[  2,  -9,  3,  -8],
[ -8,  -1, -8,   1],
[  7, -10,  4,  -4],
[-10,   2,  5,   8],
[ -7,   9,  4,  -4],
[ -1,   0,  0,   0],
[  0,  -1,  0,   0],
[  0,   0, -1,   0],
[  0,   0,  0,  -1]])
b = Matrix([9, 7, 3, 4, 8, 0, 3, 2, 4, 8, 0, 0, 0, 0])
c = Matrix([2, -2, -3, 8])
solve(A, b, c)``````

### ludlows

#include"stdio.h" #include"math.h" #include"time.h" #include"stdlib.h" #include"ctype.h" #include"string.h" #include"io.h" #define OK 1 #define ERROR 0 #define TRUE 1 #define FL......

---BearWolf
2013/11/20
83
0
C++单向链表及操作

（由于以前c++没认真学，所以画了几张图，站在内存的角度理解下，马上就搞明白了） typedef int ElemType; typedef struct Node{ ElemType data; struct Node *next; }Node, *LinkedList; L...

qq_36523667
01/09
0
0

rainchxy
2017/11/21
0
0

#include #include #include #include #define MAXSIZE 20 typedef struct node{ int count; char s[MAXSIZE]; struct node *next; }list,*linkP; FILE *fp; linkP L = (linkP)malloc(sizeof......

Vermouth0
2016/05/14
109
0

ExtreU
2014/10/09
363
5

SpringBoot + Mybatis 配置多数据源（Srping boot 二）

2分钟前
0
0

8分钟前
0
0
Mac 安装redis 及 redis desktop manager

1.安装redis 1.1 下载地址： http://download.redis.io/releases/ 1.2 本地新建个redis文件夹 1.3 切换到redis 安装下：cd /Users/用户名/Documents/redis/redis-3.2.5 1.4 make install 1.5......

qimh
13分钟前
0
0
Caffe(二)-Python-自定义网络

Pulsar-V
57分钟前
10
0
ActiveMQ从入门到精通（二）之可靠性机制

ActiveMQ的可靠性机制 缘由（ 确认JMS消息） 只要消息被确认之后，才认为消息被成功消费了。消息的成功消费包括三个阶段：客户端接收消息、客户端处理消息以及客户端确认消息。在事务性会话中...

4
0