Commit 03d1592f authored by Aliaume Lopez's avatar Aliaume Lopez

Merge branch 'master' of gitlab.crans.org:alopez/projet-optimisation

parents 2d3d9816 f09f7012
......@@ -440,7 +440,7 @@
\ds
Mais des performances immondes.
Mais ce n'est pas très rapide (inversion de matrice à chaque étape, notemment).
\end{frame}
......@@ -453,13 +453,18 @@ Mais des performances immondes.
\ds
Ce n'est pas très efficace. Ni très précis.
$24$s pour répondre à 100 instances (200 contraintes, 100 variables).
\ds
\es
\begin{block}{\texttt{CVXPy}}
Interface élégante de \texttt{CVXopt} associée à Python. Très efficace.
\end{block}
\ds
$4$s pour les 100 instances. Peu d'erreurs de faisabilité.
\end{frame}
\begin{frame}
......
......@@ -2,6 +2,39 @@ from lineartools import invert
import numpy as np
import random
import time
import scipy.optimize as scopt
import cvxpy as cvx
def vrai_simplexe (A,b,c):
AA = np.copy(np.array(A, dtype = float))
bb = np.copy(np.array(b, dtype = float))
cc = np.copy(np.array(c, dtype = float))
res = scopt.linprog(c=cc, A_eq=AA, b_eq=bb,
bounds=(0,None), method='simplex', callback=None,
options={ "maxiter" : 100000})
# logging.debug ("Résultat de l'appel à simplexe : {}".format (res))
return res
def simpl_cvx(A,b,c):
m,n = A.shape
assert(n == len(c) and (m==len(b)))
x = cvx.Variable(n)
objective = cvx.Minimize(cvx.sum_entries(c*x))
constraints = [0 <= x, A*x == b]
prob = cvx.Problem(objective, constraints)
opt = prob.solve()
s = prob.status
return({"status":s})
def testinv():
......@@ -23,8 +56,43 @@ def testinv():
b = time.clock()
sumlin += b-a
print("=============")
print("Numpy :"sumnp)
print("Numpy :",sumnp)
print("Gauss :",sumlin)
return
def testsimpl():
sumnp = 0
sumlin = 0
sumopt = 0
sumcvx = 0
for i in range(1000):
print("Iteration",i)
m = 100
n = 200
A = np.random.rand(m,n)*10 - 5*np.ones((m,n))
b = np.random.rand(m)*2
c = np.random.rand(n)
t =time.clock()
res = vrai_simplexe(A,b,c)
tt = time.clock()
sumopt += tt - t
print("Optimize",res["message"])
t = time.clock()
res = simpl_cvx(A,b,c)
tt = time.clock()
sumcvx += tt - t
print("CVX",res["status"])
print("=============")
print("Optimize :",sumopt)
print("CVX :",sumcvx)
return
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment