def test_modification_voisinage(): """Modification et reversion par voisinage.""" graphe = Graphe.default(3) mouv = Mouvement((1, 2, 3)) graphe.modification(mouv) assert graphe.voisinage[1] == [3, 2] assert graphe.dernier is mouv graphe.inversion() assert graphe.voisinage[1] == [2, 3] assert graphe.dernier is None
def test_modification_demarrage(): """Modification et reversion par démarrage.""" graphe = Graphe.default(3) mouv = Mouvement((1, 2)) graphe.modification(mouv) assert graphe.demarrage == [2, 1, 3] assert graphe.dernier is mouv graphe.inversion() assert graphe.demarrage == [1, 2, 3] assert graphe.dernier is None
def test_initialisation_moins_simple(): """Cas plus complexe.""" gra = Graphe.default(10) assert gra.demarrage == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] assert gra.voisinage[1] == list(range(2, 11)) assert gra.voisinage[2] == [1, 4, 6, 8, 10] assert gra.voisinage[3] == [1, 6, 9] assert gra.voisinage[4] == [1, 2, 8] assert gra.voisinage[5] == [1, 10] assert gra.voisinage[6] == [1, 2, 3] assert gra.voisinage[7] == [1] assert gra.voisinage[8] == [1, 2, 4] assert gra.voisinage[9] == [1, 3] assert gra.voisinage[10] == [1, 2, 5]
def recuit(nb_max, temperature): """Implémente le recuit pour l'itérateur de température donné""" graphe = Graphe.default(nb_max) meilleure = glouton(graphe) for temp in temperature: ch1 = glouton(graphe) graphe.mutation() ch2 = glouton(graphe) if len(ch2) > len(ch1): if len(ch2) > len(meilleure): meilleure = ch2 elif rd.random() > exp((len(ch2) - len(ch1)) / temp): graphe.inversion() return graphe, meilleure, temp
def test_initialisation_simplissime(): """Vérification sur le graphe le plus simple.""" gra = Graphe.default(2) assert gra.demarrage == [1, 2] assert (gra.voisinage[1] == [2]) and (gra.voisinage[2] == [1])
def test_graphe_adhoc(): """Via le constructeur basique.""" graphe = Graphe(demarrage=[1, 2, 3], voisinage={1: [2, 3], 2: [1], 3: [1]}) assert isinstance(graphe, Graphe)
def test_glouton(): """Cas moins simple""" graphe = Graphe.default(10) assert glouton(graphe) == [1, 2, 4, 8]
def test_glouton_simple(): """Test de l'algorithme glouton sur le graphe le plus simple.""" graphe = Graphe.default(2) assert glouton(graphe) == [1, 2]