@ -6,6 +6,7 @@ Donc pour la question 3_4 : `python3 test.py 3_4`.
"""
import sys
import random
import graphe
import graphique
@ -101,7 +102,7 @@ def chronometre(fonctionTest, fonctionPreparation, parametres):
def testQuestion2_6 ( ) :
""" Mesure la performance de graphe.reseau """
prepare = lambda p : graphe . pointsAleatoires ( p , 10 )
valeurs_n = np . arange ( 1 , 200 )
valeurs_n = list ( map ( int , np . logspace ( 1 , 2.7 , 100 ) ) )
temps = chronometre ( graphe . reseau , prepare , valeurs_n )
pl . close ( ' all ' )
pl . title ( " Mesure du temps d ' exécution de `reseau`. " )
@ -347,6 +348,85 @@ def testQuestion4_2():
graphique . affiche ( g , ( 0 , 0 ) , 10. )
def testQuestion4_3 ( ) :
""" Mesure le temps de calcul. """
g = graphe . reseauRapide ( graphe . pointsAleatoires ( 1000 , 1000 ) )
prepare = lambda p : random . sample ( g . sommets , p )
valeurs_n = list ( map ( int , np . linspace ( 1 , 15 , 10 ) ) )
temps = chronometre ( g . voyageurDeCommerceNaif , prepare , valeurs_n )
pl . close ( ' all ' )
pl . title ( " Temps d ' exécution pour le voyageur de commerce. " )
pl . plot ( valeurs_n , temps )
pl . xlabel ( " n (nombre de points de la tournée) " )
pl . ylabel ( " temps " )
pl . show ( )
pl . title ( " Temps d ' exécution pour le voyageur de commerce. " )
pl . loglog ( valeurs_n , temps )
pl . xlabel ( " n (nombre de points de la tournée) " )
pl . ylabel ( " temps " )
pl . show ( )
def testQuestion4_6 ( ) :
g = graphe . pointsAleatoires ( 30 , 30 )
graphe . reseauRapide ( g )
g . fixeTempsCommeCout ( )
g . renomme ( " Algorithme de Prim (cout=temps) " )
p = g . Prim ( )
print ( " Poids de prim: " , p )
g . colorieSelection ( )
graphique . affiche ( g , ( 0 , 0 ) , 10. )
def testQuestion4_7 ( ) :
g = graphe . pointsAleatoires ( 30 , 30 )
graphe . reseauRapide ( g )
g . fixeTempsCommeCout ( )
g . renomme ( " Graphe de test (cout=temps) " )
tournee = [ g . sommets [ i ] for i in ( 0 , 1 , 2 , 7 ) ]
g1 = g . grapheDeCout ( tournee )
graphique . affiche ( g , ( 0 , 0 ) , 10. , blocage = False )
graphique . affiche ( g1 , ( 0 , 0 ) , 10. )
def testQuestion4_8 ( ) :
g = graphe . pointsAleatoires ( 30 , 30 )
graphe . reseauRapide ( g )
g . fixeTempsCommeCout ( )
g . renomme ( " Graphe de test (cout=temps) " )
g1 = copy . deepcopy ( g )
print ( " Tournée 0, 1, 2, 7 " )
tournee = [ g . sommets [ i ] for i in ( 0 , 1 , 2 , 7 ) ]
iti = g . tourneeApproximative ( tournee )
g . traceItineraire ( iti )
tournee = [ g1 . sommets [ i ] for i in ( 0 , 1 , 2 , 7 ) ]
cout , iti = g1 . voyageurDeCommerceNaif ( tournee )
g1 . traceItineraire ( iti )
graphique . affiche ( g , ( 0 , 0 ) , 10. , blocage = False )
graphique . affiche ( g1 , ( 0 , 0 ) , 10. )
def testQuestion4_9 ( ) :
""" Mesure le temps de calcul. """
g = graphe . reseauRapide ( graphe . pointsAleatoires ( 1000 , 1000 ) )
prepare = lambda p : random . sample ( g . sommets , p )
valeurs_n = list ( map ( int , np . logspace ( 1 , 2 , 30 ) ) )
temps = chronometre ( g . tourneeApproximative , prepare , valeurs_n )
pl . close ( ' all ' )
pl . title ( " Temps d ' exécution pour le voyageur de commerce approximatif. " )
pl . plot ( valeurs_n , temps )
pl . xlabel ( " n (nombre de points de la tournée) " )
pl . ylabel ( " temps " )
pl . show ( )
pl . title ( " Temps d ' exécution pour le voyageur de commerce approximatif. " )
pl . loglog ( valeurs_n , temps )
pl . xlabel ( " n (nombre de points de la tournée) " )
pl . ylabel ( " temps " )
pl . show ( )
if __name__ == ' __main__ ' :
n = sys . argv [ 1 ]
if n in ( ' --help ' , ' -h ' ) :