File: roblp.py

package info (click to toggle)
cvxopt 1.1.9%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 2,652 kB
  • sloc: ansic: 22,447; python: 11,344; makefile: 75
file content (19 lines) | stat: -rwxr-xr-x 496 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# The robust LP example of section 10.5 (Examples).

from cvxopt import normal, uniform  
from cvxopt.modeling import variable, dot, op, sum  
from cvxopt.blas import nrm2  
     
m, n = 500, 100  
A = normal(m,n)  
b = uniform(m)  
c = normal(n)  
     
x = variable(n)  
op(dot(c,x), A*x+sum(abs(x)) <= b).solve()  
     
x2 = variable(n)  
y = variable(n)  
op(dot(c,x2), [A*x2+sum(y) <= b, -y <= x2, x2 <= y]).solve()

print("\nDifference between two solutions %e" %nrm2(x.value - x2.value))