From 043555c25049c2bd4ce8c2b9adf10096312e8f9f Mon Sep 17 00:00:00 2001 From: Gaetan D Date: Tue, 10 Jan 2017 21:47:58 +0100 Subject: [PATCH] done --- new_separation.py | 2 +- rapport/presentation.tex | 11 +++++-- testperfs.py | 70 +++++++++++++++++++++++++++++++++++++++- 3 files changed, 78 insertions(+), 5 deletions(-) diff --git a/new_separation.py b/new_separation.py index 96c870f..baec8aa 100644 --- a/new_separation.py +++ b/new_separation.py @@ -372,4 +372,4 @@ def test_separation_on_file (filename): -test_separation_on_file("brazil58") +test_separation_on_file("hk48") diff --git a/rapport/presentation.tex b/rapport/presentation.tex index 04bf76a..a133822 100644 --- a/rapport/presentation.tex +++ b/rapport/presentation.tex @@ -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} diff --git a/testperfs.py b/testperfs.py index 3093260..65f3d1a 100644 --- a/testperfs.py +++ b/testperfs.py @@ -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 -- GitLab