Chapitre 5: Méta-heuristiques · A. Blondin Massé (UQAM) Chapitre 5: Méta-heuristiques INF889B...

76
Chapitre 5: Méta-heuristiques INF889B — Algorithmes d’optimisation combinatoire Alexandre Blondin Massé Université du Québec à Montréal Hiver 2020 A. Blondin Massé (UQAM) Chapitre 5: Méta-heuristiques INF889B Hiver 2020 1 / 73

Transcript of Chapitre 5: Méta-heuristiques · A. Blondin Massé (UQAM) Chapitre 5: Méta-heuristiques INF889B...

Page 1: Chapitre 5: Méta-heuristiques · A. Blondin Massé (UQAM) Chapitre 5: Méta-heuristiques INF889B Hiver 2020 19/73 Implémentation (2/4) struct Instance { // An instance of the set

Chapitre 5: Méta-heuristiquesINF889B — Algorithmes d’optimisation combinatoire

Alexandre Blondin Massé

Université du Québec à Montréal

Hiver 2020

A. Blondin Massé (UQAM) Chapitre 5: Méta-heuristiques INF889B Hiver 2020 1 / 73

Page 2: Chapitre 5: Méta-heuristiques · A. Blondin Massé (UQAM) Chapitre 5: Méta-heuristiques INF889B Hiver 2020 19/73 Implémentation (2/4) struct Instance { // An instance of the set

Plan

1 Stratégie gloutonne

2 Recherche locale

3 Recuit simulé

4 Recherche taboue

A. Blondin Massé (UQAM) Chapitre 5: Méta-heuristiques INF889B Hiver 2020 2 / 73

Page 3: Chapitre 5: Méta-heuristiques · A. Blondin Massé (UQAM) Chapitre 5: Méta-heuristiques INF889B Hiver 2020 19/73 Implémentation (2/4) struct Instance { // An instance of the set

Stratégie gloutonne

A. Blondin Massé (UQAM) Chapitre 5: Méta-heuristiques INF889B Hiver 2020 3 / 73

Page 4: Chapitre 5: Méta-heuristiques · A. Blondin Massé (UQAM) Chapitre 5: Méta-heuristiques INF889B Hiver 2020 19/73 Implémentation (2/4) struct Instance { // An instance of the set

Idée générale

• Soit 𝒮 l’ensemble des instances possibles pour un problème• Soit 𝑓 la fonction objectif à minimiser• On souhaite trouver un ensemble 𝑆 ∈ 𝒮 qui minimise 𝑓• On démarre avec 𝑆 ← ∅• On choisit 𝑠1 qui semble le plus intéressant• On ajoute 𝑠1 à 𝑆• Puis on répète, jusqu’à ce qu’on ne puisse plus rien ajouter

Remarque• Similaire à la recherche locale• Mais on construit une solution• Plutôt que de l’améliorer

A. Blondin Massé (UQAM) Chapitre 5: Méta-heuristiques INF889B Hiver 2020 4 / 73

Page 5: Chapitre 5: Méta-heuristiques · A. Blondin Massé (UQAM) Chapitre 5: Méta-heuristiques INF889B Hiver 2020 19/73 Implémentation (2/4) struct Instance { // An instance of the set

Pseudocode

1: fonction ConstructionGloutonne(𝐸 : ensemble)2: 𝑆 ← ∅3: tant que il existe 𝑒 ∈ 𝐸 tel que 𝑆 ∪ {𝑒} est admissible faire4: Soit 𝑒 le candidat le meilleur5: 𝑆 ← 𝑆 ∪ {𝑒}6: retourner 𝑆

À détailler• Quels sont les candidats?• Qu’est-ce qu’une solution admissible?• Comment choisir le meilleur candidat?

A. Blondin Massé (UQAM) Chapitre 5: Méta-heuristiques INF889B Hiver 2020 5 / 73

Page 6: Chapitre 5: Méta-heuristiques · A. Blondin Massé (UQAM) Chapitre 5: Méta-heuristiques INF889B Hiver 2020 19/73 Implémentation (2/4) struct Instance { // An instance of the set

Ratio d’approximation• Soit 𝑃 un problème d’optimisation• Soit 𝑓 la fonction à minimiser• Soit 𝑆∗ une solution de 𝑃 telle que 𝑓(𝑆∗) est minimale• Soit 𝛼 un nombre qui dépend de la taille de 𝑃• Et soit 𝐴 un algorithme qui résoud le problème 𝑃• On dit que 𝐴 a un ratio d’approximation 𝛼 si pour toute

instance, la solution 𝑆 retournée par 𝐴 vérifie

𝑓(𝑆) ≤ 𝛼𝑓(𝑆∗)

Remarque• Plusieurs problèmes NP-difficiles peuvent être approximés à

l’aide d’algorithmes gloutons• Souvent, les algorithmes sont faciles à implémenter

A. Blondin Massé (UQAM) Chapitre 5: Méta-heuristiques INF889B Hiver 2020 6 / 73

Page 7: Chapitre 5: Méta-heuristiques · A. Blondin Massé (UQAM) Chapitre 5: Méta-heuristiques INF889B Hiver 2020 19/73 Implémentation (2/4) struct Instance { // An instance of the set

Recouvrement d’un ensemble• En anglais, appelé set cover• Soient 𝑛 et 𝑚 deux entiers positifs• On prend un ensemble 𝑋 = {𝑥1, 𝑥2, … , 𝑥𝑛} d’éléments• Et une collection d’ensembles 𝒮 = {𝑆1, 𝑆2, … , 𝑆𝑚} telle que

𝑚⋃𝑖=1

𝑆𝑖 = 𝑋

• Finalement, soit 𝑤 ∶ 𝒮 → ℝ+ une fonction qui associe à 𝑆 ∈ 𝒮un poids 𝑤(𝑆).

• Un recouvrement de 𝑋 est un sous-ensemble 𝒮′ ⊆ 𝒮 tel que

⋃𝑆∈𝒮′

𝑆 = 𝑋

• On cherche un recouvrement 𝒮′ qui minimise 𝑤(𝒮′)A. Blondin Massé (UQAM) Chapitre 5: Méta-heuristiques INF889B Hiver 2020 7 / 73

Page 8: Chapitre 5: Méta-heuristiques · A. Blondin Massé (UQAM) Chapitre 5: Méta-heuristiques INF889B Hiver 2020 19/73 Implémentation (2/4) struct Instance { // An instance of the set

Exemple (1/2)• Soient 𝑛 = 10 et 𝑚 = 8• Prenons

𝑋 = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}• Et 𝒮 = {𝑆0, 𝑆1, … , 𝑆7} défini par

𝑆0 = {0, 1, 3, 5} 𝑤(𝑆0) = 2.0𝑆1 = {0, 2, 4, 8, 9} 𝑤(𝑆1) = 1.0𝑆2 = {1, 3, 5, 7, 9} 𝑤(𝑆2) = 3.0𝑆3 = {6, 7, 8, 9} 𝑤(𝑆3) = 2.0𝑆4 = {1, 4} 𝑤(𝑆4) = 1.0𝑆5 = {2, 4, 6} 𝑤(𝑆5) = 3.0𝑆6 = {0, 1, 2, 3, 5, 8, 9} 𝑤(𝑆6) = 4.0𝑆7 = {1, 2, 4, 8} 𝑤(𝑆7) = 5.0

• Comment peut-on construire une solution optimale?A. Blondin Massé (UQAM) Chapitre 5: Méta-heuristiques INF889B Hiver 2020 8 / 73

Page 9: Chapitre 5: Méta-heuristiques · A. Blondin Massé (UQAM) Chapitre 5: Méta-heuristiques INF889B Hiver 2020 19/73 Implémentation (2/4) struct Instance { // An instance of the set

Exemple (2/2)

• Meilleur rendement: 𝑆1 (5 éléments pour 1.0)• Prochain: 𝑆0 (3 nouveaux éléments pour 2.0)• Puis: 𝑆3 (2 nouveaux éléments pour 2.0)• Les 10 éléments sont couverts pour un poids total de 5.0.• Difficile de vérifier si la solution est optimale

• Par contre, on peut montrer que le ratio d’approximationdans l’exemple est 𝐻(7) ≈ 2.593, où

𝐻(𝑑) =𝑑

∑𝑖=1

1𝑖 ≈ ln 𝑑

est le 𝑑-ième nombre harmonique

A. Blondin Massé (UQAM) Chapitre 5: Méta-heuristiques INF889B Hiver 2020 9 / 73

Page 10: Chapitre 5: Méta-heuristiques · A. Blondin Massé (UQAM) Chapitre 5: Méta-heuristiques INF889B Hiver 2020 19/73 Implémentation (2/4) struct Instance { // An instance of the set

Exemple (2/2)

• Meilleur rendement: 𝑆1 (5 éléments pour 1.0)• Prochain: 𝑆0 (3 nouveaux éléments pour 2.0)• Puis: 𝑆3 (2 nouveaux éléments pour 2.0)• Les 10 éléments sont couverts pour un poids total de 5.0.• Difficile de vérifier si la solution est optimale• Par contre, on peut montrer que le ratio d’approximation

dans l’exemple est 𝐻(7) ≈ 2.593, où

𝐻(𝑑) =𝑑

∑𝑖=1

1𝑖 ≈ ln 𝑑

est le 𝑑-ième nombre harmonique

A. Blondin Massé (UQAM) Chapitre 5: Méta-heuristiques INF889B Hiver 2020 9 / 73

Page 11: Chapitre 5: Méta-heuristiques · A. Blondin Massé (UQAM) Chapitre 5: Méta-heuristiques INF889B Hiver 2020 19/73 Implémentation (2/4) struct Instance { // An instance of the set

Pseudocode

1: fonction SetCover(𝑋 : ensemble, 𝒮 : collection)2: 𝑌 ← ∅3: 𝑆 ← ∅4: tant que 𝑌 ≠ 𝑋 faire5: Soit 𝑇 ∈ 𝒮 qui maximise #nouveaux éléments/coût6: 𝑆 ← 𝑆 ∪ {𝑇 }7: 𝑌 ← 𝑌 ∪ 𝑇8: retourner 𝑆

A. Blondin Massé (UQAM) Chapitre 5: Méta-heuristiques INF889B Hiver 2020 10 / 73

Page 12: Chapitre 5: Méta-heuristiques · A. Blondin Massé (UQAM) Chapitre 5: Méta-heuristiques INF889B Hiver 2020 19/73 Implémentation (2/4) struct Instance { // An instance of the set

Théorème

Chvátal, 1979• Soit 𝑋 un ensemble de 𝑛 éléments• Soit 𝒮 une collection de sous-ensembles de 𝑋• Soit 𝑤 ∶ 𝒮 → ℝ+ une fonction de poids• Alors l’algorithme glouton décrit précédemment a un ratio

d’approximation de 𝐻(𝑠max), où

𝑠max = max{|𝑆| ∶ 𝑆 ∈ 𝒮}

Raz et Safra, 1997Il n’existe pas d’algorithme polynomial pour ce problème ayant unratio d’approximation significativement meilleur

A. Blondin Massé (UQAM) Chapitre 5: Méta-heuristiques INF889B Hiver 2020 11 / 73

Page 13: Chapitre 5: Méta-heuristiques · A. Blondin Massé (UQAM) Chapitre 5: Méta-heuristiques INF889B Hiver 2020 19/73 Implémentation (2/4) struct Instance { // An instance of the set

Non optimalité• En général, l’algorithme glouton ne trouve pas une solution

optimale• Exemple: 𝑛 = 12, 𝑚 = 3,

𝑋 = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}

et 𝒮 = {𝑆0, 𝑆1, 𝑆2}, où

𝑆0 = {0, 1, 2, 3, 4} 𝑤(𝑆0) = 6.0𝑆1 = {0, 1, 2, 5, 6} 𝑤(𝑆1) = 15.0𝑆2 = {3, 4, 7, 8, 8, 10, 11} 𝑤(𝑆2) = 7.0

• L’algorithme glouton choisit 𝑆2, 𝑆0 et 𝑆1• Alors que 𝑆1 et 𝑆2 suffisent

A. Blondin Massé (UQAM) Chapitre 5: Méta-heuristiques INF889B Hiver 2020 12 / 73

Page 14: Chapitre 5: Méta-heuristiques · A. Blondin Massé (UQAM) Chapitre 5: Méta-heuristiques INF889B Hiver 2020 19/73 Implémentation (2/4) struct Instance { // An instance of the set

Démonstration (1/6)• Pour simplifier l’argument, on montre plutôt que le ratio est

𝐻(|𝑋|)1: fonction SetCover(𝑋 : ensemble, 𝒮 : collection)2: 𝑌 ← ∅3: 𝑆 ← ∅4: tant que 𝑌 ≠ 𝑋 faire5: Soit 𝑇 ∈ 𝒮 qui minimise poids(𝑇 )/|𝑇 − 𝑌 |6: pour 𝑥 ∈ 𝑇 − 𝑌 faire7: poids(𝑥) ← poids(𝑇 )/|𝑇 − 𝑌 |8: fin pour9: 𝑆 ← 𝑆 ∪ {𝑇 }

10: 𝑌 ← 𝑌 ∪ 𝑇11: retourner 𝑆

A. Blondin Massé (UQAM) Chapitre 5: Méta-heuristiques INF889B Hiver 2020 13 / 73

Page 15: Chapitre 5: Méta-heuristiques · A. Blondin Massé (UQAM) Chapitre 5: Méta-heuristiques INF889B Hiver 2020 19/73 Implémentation (2/4) struct Instance { // An instance of the set

Démonstration (2/6)

• Soit 𝒮∗ = {𝑆∗1, 𝑆∗

2, … , 𝑆∗ℓ} une solution optimale

• Soit 𝒮greedy la solution gloutonne• Alors

poids(𝒮greedy) = ∑𝑥∈𝑋

poids(𝑥) (1)

• Soient 𝑥1, 𝑥2, …, 𝑥𝑛 les éléments de 𝑋 couverts parl’algorithme glouton dans l’ordre

• On montre maintenant que pour 𝑖 = 1, 2, … , 𝑛, on a

poids(𝑥𝑖) ≤ poids(𝒮∗)|𝑋 − 𝑋𝑖|

(2)

A. Blondin Massé (UQAM) Chapitre 5: Méta-heuristiques INF889B Hiver 2020 14 / 73

Page 16: Chapitre 5: Méta-heuristiques · A. Blondin Massé (UQAM) Chapitre 5: Méta-heuristiques INF889B Hiver 2020 19/73 Implémentation (2/4) struct Instance { // An instance of the set

Démonstration (3/6)• Pour 𝑖 = 1, 2, … , 𝑛, soit 𝑋𝑖 = {𝑥1, 𝑥2, … , 𝑥𝑖}• Alors

𝑋 − 𝑋𝑖 = (𝑋 − 𝑋𝑖) ∩ 𝑋

= (𝑋 − 𝑋𝑖) ∩ (ℓ

⋃𝑗=1

𝑆∗𝑗 )

=ℓ

⋃𝑗=1

((𝑋 − 𝑋𝑖) ∩ 𝑆∗𝑗 )

• Ceci implique

|𝑋 − 𝑋𝑖| ≤ℓ

∑𝑗=1

∣(𝑋 − 𝑋𝑖) ∩ 𝑆∗𝑗 ∣ (3)

A. Blondin Massé (UQAM) Chapitre 5: Méta-heuristiques INF889B Hiver 2020 15 / 73

Page 17: Chapitre 5: Méta-heuristiques · A. Blondin Massé (UQAM) Chapitre 5: Méta-heuristiques INF889B Hiver 2020 19/73 Implémentation (2/4) struct Instance { // An instance of the set

Démonstration (4/6)• Aussi, pour 𝑖 = 1, 2, … , 𝑛, remarquons que

poids(𝑥𝑖) ≤ poids(𝑆∗𝑗 )

|(𝑋 − 𝑋𝑖) ∩ 𝑆∗𝑗 | , pour tout 𝑗 = 1, 2, … , ℓ

• En effet, par contradiction, supposons qu’il existe𝑗 ∈ {1, 2, … , ℓ} tel que

poids(𝑥𝑖) > poids(𝑆∗𝑗 )

|(𝑋 − 𝑋𝑖) ∩ 𝑆∗𝑗 |

• Alors cela voudrait dire que l’algorithme glouton n’a pas choisi𝑆∗

𝑗 plus tôt, alors qu’il avait un poids moindre• L’inéquation se réécrit

poids(𝑥𝑖) |(𝑋 − 𝑋𝑖) ∩ 𝑆∗𝑗 | ≤ poids(𝑆∗

𝑗 ) (4)

pour tout 𝑗 = 1, 2, … , ℓ.A. Blondin Massé (UQAM) Chapitre 5: Méta-heuristiques INF889B Hiver 2020 16 / 73

Page 18: Chapitre 5: Méta-heuristiques · A. Blondin Massé (UQAM) Chapitre 5: Méta-heuristiques INF889B Hiver 2020 19/73 Implémentation (2/4) struct Instance { // An instance of the set

Démonstration (5/6)Pour 𝑖 = 1, 2, … , 𝑛, on obtient donc

poids(𝒮∗) =ℓ

∑𝑗=1

poids(𝑆∗𝑗 )

≥ℓ

∑𝑗=1

poids(𝑥𝑖) |(𝑋 − 𝑋𝑖) ∩ 𝑆∗𝑗 |

= poids(𝑥𝑖)ℓ

∑𝑗=1

|(𝑋 − 𝑋𝑖) ∩ 𝑆∗𝑗 |

≥ poids(𝑥𝑖) |𝑋 − 𝑋𝑖|

Ainsi,poids(𝑥𝑖) ≤ poids(𝒮∗)

|𝑋 − 𝑋𝑖|A. Blondin Massé (UQAM) Chapitre 5: Méta-heuristiques INF889B Hiver 2020 17 / 73

Page 19: Chapitre 5: Méta-heuristiques · A. Blondin Massé (UQAM) Chapitre 5: Méta-heuristiques INF889B Hiver 2020 19/73 Implémentation (2/4) struct Instance { // An instance of the set

Démonstration (6/6)Enfin,

poids(𝒮greedy) =𝑛

∑𝑖=1

poids(𝑥𝑖)

≤𝑛

∑𝑖=1

poids(𝒮∗)𝑛 − 𝑖 + 1

= poids(𝒮∗)𝑛

∑𝑖=1

1𝑛 − 𝑖 + 1

= poids(𝒮∗)𝑛

∑𝑖=1

1𝑖

= poids(𝒮∗) 𝐻(𝑛)

A. Blondin Massé (UQAM) Chapitre 5: Méta-heuristiques INF889B Hiver 2020 18 / 73

Page 20: Chapitre 5: Méta-heuristiques · A. Blondin Massé (UQAM) Chapitre 5: Méta-heuristiques INF889B Hiver 2020 19/73 Implémentation (2/4) struct Instance { // An instance of the set

Implémentation (1/4)$ bin/set-cover < examples/example -1.setcoverA set cover instance of 10 elements and 8 subsets

Subset #0 (w = 2.00): 0 1 3 5Subset #1 (w = 1.00): 0 2 4 8 9Subset #2 (w = 3.00): 1 3 5 7 9Subset #3 (w = 2.00): 6 7 8 9Subset #4 (w = 1.00): 1 4Subset #5 (w = 3.00): 2 4 6Subset #6 (w = 4.00): 0 1 2 3 5 8 9Subset #7 (w = 5.00): 1 2 4 8

A collection of 0 (out of 8) subsets covering 0 (out of 10) elementsTotal weight: 0.000000Adding subset #1A collection of 1 (out of 8) subsets covering 5 (out of 10) elements

Subset #1 (w = 1.00): 0 2 4 8 9Total weight: 1.000000Adding subset #0A collection of 2 (out of 8) subsets covering 8 (out of 10) elements

Subset #0 (w = 2.00): 0 1 3 5Subset #1 (w = 1.00): 0 2 4 8 9

Total weight: 3.000000Adding subset #3A collection of 3 (out of 8) subsets covering 10 (out of 10) elements

Subset #0 (w = 2.00): 0 1 3 5Subset #1 (w = 1.00): 0 2 4 8 9Subset #3 (w = 2.00): 6 7 8 9

Total weight: 5.000000

A. Blondin Massé (UQAM) Chapitre 5: Méta-heuristiques INF889B Hiver 2020 19 / 73

Page 21: Chapitre 5: Méta-heuristiques · A. Blondin Massé (UQAM) Chapitre 5: Méta-heuristiques INF889B Hiver 2020 19/73 Implémentation (2/4) struct Instance { // An instance of the set

Implémentation (2/4)

struct Instance { // An instance of the set cover problemunsigned int num_elements; // The number of elementsunsigned int num_subsets; // The number of subsetsbool **subsets; // An array of subsetsfloat *weights; // The weight for each subset

};

struct Collection { // A collection of subsetsconst struct Instance *instance; // A set cover instanceunsigned int num_elements; // The number of elementsunsigned int num_subsets; // The number of subsetsbool *has_subset; // The subset belongs to the collection?bool *is_covered; // Is the element covered?float weight; // The weight of the collection

};

A. Blondin Massé (UQAM) Chapitre 5: Méta-heuristiques INF889B Hiver 2020 20 / 73

Page 22: Chapitre 5: Méta-heuristiques · A. Blondin Massé (UQAM) Chapitre 5: Méta-heuristiques INF889B Hiver 2020 19/73 Implémentation (2/4) struct Instance { // An instance of the set

Implémentation (3/4)

// Instancevoid load_instance(struct Instance *instance);void print_subset(const struct Instance *instance,

unsigned int s);void print_instance(const struct Instance *instance);void free_instance(struct Instance *instance);

// Collectionvoid alloc_collection(struct Collection *collection,

const struct Instance *instance);void free_collection(struct Collection *collection);void print_collection(const struct Collection *collection);void add_subset_to_collection(struct Collection *collection,

unsigned int s);unsigned int num_uncovered(const struct Collection *collection,

unsigned int s);unsigned int subset_with_lowest_cost(const struct Collection *collection);

A. Blondin Massé (UQAM) Chapitre 5: Méta-heuristiques INF889B Hiver 2020 21 / 73

Page 23: Chapitre 5: Méta-heuristiques · A. Blondin Massé (UQAM) Chapitre 5: Méta-heuristiques INF889B Hiver 2020 19/73 Implémentation (2/4) struct Instance { // An instance of the set

Implémentation (4/4)

int main(int argc, char *argv[]) {struct Instance instance;load_instance(&instance);print_instance(&instance);struct Collection collection;alloc_collection(&collection, &instance);print_collection(&collection);do {

unsigned int s = subset_with_lowest_cost(&collection);add_subset_to_collection(&collection, s);printf("Adding subset #%d\n", s);print_collection(&collection);

} while (collection.num_elements < instance.num_elements);free_collection(&collection);free_instance(&instance);return 0;

}

A. Blondin Massé (UQAM) Chapitre 5: Méta-heuristiques INF889B Hiver 2020 22 / 73

Page 24: Chapitre 5: Méta-heuristiques · A. Blondin Massé (UQAM) Chapitre 5: Méta-heuristiques INF889B Hiver 2020 19/73 Implémentation (2/4) struct Instance { // An instance of the set

Couverture des arêtes par les sommets

Définition• Soit 𝐺 = (𝑉 , 𝐸) un graphe non orienté• Soit 𝑈 ⊆ 𝑉• On dit que 𝑈 est une couverture des arêtes par les sommets

si pour toute arête {𝑢, 𝑣}, on a 𝑢 ∈ 𝑈 ou 𝑣 ∈ 𝑈

Difficulté• Trouver une couverture minimale est NP-difficile• Problème appelé vertex cover en anglais• Nous avons vu un algorithme résoluble à paramètre fixé si la

taille d’une solution 𝑘 est bornée

A. Blondin Massé (UQAM) Chapitre 5: Méta-heuristiques INF889B Hiver 2020 23 / 73

Page 25: Chapitre 5: Méta-heuristiques · A. Blondin Massé (UQAM) Chapitre 5: Méta-heuristiques INF889B Hiver 2020 19/73 Implémentation (2/4) struct Instance { // An instance of the set

Question

• Le problème vertex cover est un cas particulier du problèmeset cover

• Montrer pourquoi c’est vrai• En déduire un algorithme d’approximation glouton• Calculer le ratio d’approximation

A. Blondin Massé (UQAM) Chapitre 5: Méta-heuristiques INF889B Hiver 2020 24 / 73

Page 26: Chapitre 5: Méta-heuristiques · A. Blondin Massé (UQAM) Chapitre 5: Méta-heuristiques INF889B Hiver 2020 19/73 Implémentation (2/4) struct Instance { // An instance of the set

Programmation linéaire

• Le problème vertex cover peut être approximé plusefficacement

• Plus précisément, on connaît un algorithme 2-approximatif• L’idée consiste à traduire le problème en un programme

linéaire en nombres entiers• En anglais, ILP = integer linear program• On utilise ensuite une méthode appelée primale-duale• Elle s’applique à plusieurs autres situations

A. Blondin Massé (UQAM) Chapitre 5: Méta-heuristiques INF889B Hiver 2020 25 / 73

Page 27: Chapitre 5: Méta-heuristiques · A. Blondin Massé (UQAM) Chapitre 5: Méta-heuristiques INF889B Hiver 2020 19/73 Implémentation (2/4) struct Instance { // An instance of the set

Modélisation du problème

• Soit 𝐺 = (𝑉 , 𝐸) un graphe non orienté• Soit 𝑤 ∶ 𝑉 → ℝ+ une fonction de poids• Pour chaque 𝑣 ∈ 𝑉 , soit 𝑥𝑣 ∈ {0, 1} une variable binaire• On souhaite

minimiser ∑𝑣∈𝑉

𝑤(𝑣)𝑥𝑣

sous les contraintes 𝑥𝑢 + 𝑥𝑣 ≥ 1, pour toute {𝑢, 𝑣} ∈ 𝐸• Le problème est évidemment difficile à résoudre• En revanche, il devient facile si on permet que 𝑥𝑣 ∈ [0, 1] ∩ ℝ

A. Blondin Massé (UQAM) Chapitre 5: Méta-heuristiques INF889B Hiver 2020 26 / 73

Page 28: Chapitre 5: Méta-heuristiques · A. Blondin Massé (UQAM) Chapitre 5: Méta-heuristiques INF889B Hiver 2020 19/73 Implémentation (2/4) struct Instance { // An instance of the set

Problème dual

• Tout programme linéaire a un problème dual (nous yreviendrons)

• Dans notre cas, soit 𝑁(𝑣) l’ensemble des voisins de 𝑣• Et soit 𝑦𝑢,𝑣 ≥ 0 une variable associée à chaque arête• Le problème dual consiste à

maximiser ∑{𝑢,𝑣}∈𝐸

𝑦𝑢,𝑣

sous les contraintes ∑𝑢∈𝑁(𝑣)

𝑦𝑢,𝑣 ≤ 𝑤(𝑣), pour tout 𝑣 ∈ 𝑉

• Dans le cas où 𝑤(𝑣) = 1 pour tout 𝑣 ∈ 𝑉 , le problème dualrevient à calculer un couplage maximal dans 𝐺

A. Blondin Massé (UQAM) Chapitre 5: Méta-heuristiques INF889B Hiver 2020 27 / 73

Page 29: Chapitre 5: Méta-heuristiques · A. Blondin Massé (UQAM) Chapitre 5: Méta-heuristiques INF889B Hiver 2020 19/73 Implémentation (2/4) struct Instance { // An instance of the set

Problème du couplage

• Soit 𝐺 = (𝑉 , 𝐸) un graphe non orienté• Un sous-graphe 𝑀 = (𝑉 ′, 𝐸′) de 𝐺 est appelé un couplage de

𝐺 si chacun de ses sommets est de degré au plus 1

𝑎𝑏

𝑐

𝑑

𝑒

𝑓

𝑔

ℎ𝑖

A. Blondin Massé (UQAM) Chapitre 5: Méta-heuristiques INF889B Hiver 2020 28 / 73

Page 30: Chapitre 5: Méta-heuristiques · A. Blondin Massé (UQAM) Chapitre 5: Méta-heuristiques INF889B Hiver 2020 19/73 Implémentation (2/4) struct Instance { // An instance of the set

Primal-dual (1/2)• Problème primal:

minimiser ∑𝑣∈𝑉

𝑤(𝑣)𝑥𝑣

sous les contraintes 𝑥𝑢 + 𝑥𝑣 ≥ 1, pour toute {𝑢, 𝑣} ∈ 𝐸• Problème dual:

maximiser ∑{𝑢,𝑣}∈𝐸

𝑦𝑢,𝑣

sous les contraintes ∑𝑢∈𝑁(𝑣)

𝑦𝑢,𝑣 ≤ 𝑤(𝑣), pour tout 𝑣 ∈ 𝑉

• Propriété de dualité faible: si 𝑥 et 𝑦 sont des solutionsadmissibles, alors

∑{𝑢,𝑣}∈𝐸

𝑦𝑢,𝑣 ≤ ∑𝑣∈𝑉

𝑤(𝑣)𝑥𝑣

A. Blondin Massé (UQAM) Chapitre 5: Méta-heuristiques INF889B Hiver 2020 29 / 73

Page 31: Chapitre 5: Méta-heuristiques · A. Blondin Massé (UQAM) Chapitre 5: Méta-heuristiques INF889B Hiver 2020 19/73 Implémentation (2/4) struct Instance { // An instance of the set

Primal-dual (2/2)

𝑎𝑏

𝑐

𝑑

𝑒

𝑓

𝑔

ℎ𝑖

Couplage maximal4 arêtes ≤

𝑎𝑏

𝑐

𝑑

𝑒

𝑓

𝑔

ℎ𝑖

Couverture minimale5 sommets

A. Blondin Massé (UQAM) Chapitre 5: Méta-heuristiques INF889B Hiver 2020 30 / 73

Page 32: Chapitre 5: Méta-heuristiques · A. Blondin Massé (UQAM) Chapitre 5: Méta-heuristiques INF889B Hiver 2020 19/73 Implémentation (2/4) struct Instance { // An instance of the set

Algorithme d’approximation: idée générale

• On considère le problème dual• On initialise toutes les valeurs à 0• On augmente le plus possible et uniformément toutes les

variables, sauf celles qui sont déjà à leur limite• Puis on répète jusqu’à ce qu’on ne puisse plus augmenter• On obtient la couverture en retenant les variables pour

lesquelles la contrainte a été atteinte• Noter que la contrainte est atteinte si

∑𝑢∈𝑁(𝑣)

𝑦𝑢,𝑣 = 𝑤(𝑣)

A. Blondin Massé (UQAM) Chapitre 5: Méta-heuristiques INF889B Hiver 2020 31 / 73

Page 33: Chapitre 5: Méta-heuristiques · A. Blondin Massé (UQAM) Chapitre 5: Méta-heuristiques INF889B Hiver 2020 19/73 Implémentation (2/4) struct Instance { // An instance of the set

Exemple

• Soit le graphe ci-bas avec 𝑤(𝑣) = 1 pour tout 𝑣 ∈ 𝑉• Alors on obtient la couverture {𝑏, 𝑐, 𝑒, 𝑔, ℎ}

𝑎

𝑏

𝑐

𝑑

𝑒

𝑓

𝑔

𝑖

A. Blondin Massé (UQAM) Chapitre 5: Méta-heuristiques INF889B Hiver 2020 32 / 73

Page 34: Chapitre 5: Méta-heuristiques · A. Blondin Massé (UQAM) Chapitre 5: Méta-heuristiques INF889B Hiver 2020 19/73 Implémentation (2/4) struct Instance { // An instance of the set

Algorithme glouton (Clarkson, 1983)

1: fonction CouvertureApproximative(𝐺 : graphe) : couverture2: 𝑊(𝑣) ← 𝑤(𝑣) pour tout 𝑣 ∈ 𝑉3: 𝐷(𝑣) ← deg(𝑣) pour tout 𝑣 ∈ 𝑉4: 𝑆 ← ∅5: tant que 𝐸 ≠ ∅ faire6: Soit 𝑣 ∈ 𝑉 tel que 𝑊(𝑣)/𝐷(𝑣) est minimal7: pour 𝑢 ∈ 𝑁(𝑣) faire8: 𝐸 ← 𝐸 − {{𝑢, 𝑣}}9: 𝑊(𝑢) ← 𝑊(𝑢) − 𝑊(𝑣)/𝐷(𝑣)

10: 𝐷(𝑢) ← 𝐷(𝑢) − 111: 𝑆 ← 𝑆 ∪ {𝑣}12: 𝑉 ← 𝑉 − {𝑣}

A. Blondin Massé (UQAM) Chapitre 5: Méta-heuristiques INF889B Hiver 2020 33 / 73

Page 35: Chapitre 5: Méta-heuristiques · A. Blondin Massé (UQAM) Chapitre 5: Méta-heuristiques INF889B Hiver 2020 19/73 Implémentation (2/4) struct Instance { // An instance of the set

Ratio d’approximation

ThéorèmeL’algorithme précédent retourne une couverture des arêtes par lessommets avec un ratio d’approximation de 2Idée de la preuve

• Soit 𝑆 l’ensemble obtenu par l’algorithme• 𝑆 est bien une couverture puisque pour chaque arête, {𝑢, 𝑣},

on a

∑𝑤∈𝑁(𝑢)

𝑦𝑢,𝑤 = 𝑤(𝑢) ou ∑𝑤∈𝑁(𝑣)

𝑦𝑣,𝑤 = 𝑤(𝑣)

A. Blondin Massé (UQAM) Chapitre 5: Méta-heuristiques INF889B Hiver 2020 34 / 73

Page 36: Chapitre 5: Méta-heuristiques · A. Blondin Massé (UQAM) Chapitre 5: Méta-heuristiques INF889B Hiver 2020 19/73 Implémentation (2/4) struct Instance { // An instance of the set

Recherche locale

A. Blondin Massé (UQAM) Chapitre 5: Méta-heuristiques INF889B Hiver 2020 35 / 73

Page 37: Chapitre 5: Méta-heuristiques · A. Blondin Massé (UQAM) Chapitre 5: Méta-heuristiques INF889B Hiver 2020 19/73 Implémentation (2/4) struct Instance { // An instance of the set

Idée de base

• Soit 𝑓 la fonction objectif (à minimiser)• On démarre avec une solution admissible 𝑆• On explore le voisinage 𝒩(𝑆) de 𝑆• On sélectionne 𝑆′ ∈ 𝒩(𝑆) tel que 𝑓(𝑆′) est minimal• Si 𝑓(𝑆′) < 𝑓(𝑆), alors on remplace 𝑆 par 𝑆′

• Puis on répète• Sinon, on arrête et on retourne le résultat

Remarque• Il s’agit d’un algorithme glouton puisqu’on sélectionne la

meilleure solution localement• Comme il n’y a pas de retour en arrière (backtracking), la

solution retournée n’est généralement pas optimale

A. Blondin Massé (UQAM) Chapitre 5: Méta-heuristiques INF889B Hiver 2020 36 / 73

Page 38: Chapitre 5: Méta-heuristiques · A. Blondin Massé (UQAM) Chapitre 5: Méta-heuristiques INF889B Hiver 2020 19/73 Implémentation (2/4) struct Instance { // An instance of the set

Pseudocode

1: fonction RechercheLocale(𝑆 : solution admissible)2: 𝑆best ← 𝑆3: pour 𝑆′ ∈ 𝒩(𝑆) faire4: si 𝑓(𝑆′) < 𝑓(𝑆) alors5: 𝑆best ← 𝑆′

6: si 𝑓(𝑆best) < 𝑓(𝑆) alors7: retourner RechercheLocale(𝑆best)8: sinon9: retourner 𝑆

A. Blondin Massé (UQAM) Chapitre 5: Méta-heuristiques INF889B Hiver 2020 37 / 73

Page 39: Chapitre 5: Méta-heuristiques · A. Blondin Massé (UQAM) Chapitre 5: Méta-heuristiques INF889B Hiver 2020 19/73 Implémentation (2/4) struct Instance { // An instance of the set

Fonction de voisinage et distanceVoisinage

• Soit 𝒮 l’espace des solutions admissibles• Une fonction de voisinage pour 𝒮 est une fonction de la forme

𝒩 ∶ 𝒮 → 2𝒮

telle que dist(𝑆, 𝒩(𝑆)) est petite pour toute 𝑆 ∈ 𝒮

DistanceOn dit que dist est une distance si elle respecte les propriétéssuivantes:

1 dist(𝑆, 𝑆′) ≥ 02 dist(𝑆, 𝑆′) = 0 ⇔ 𝑆 = 𝑆′

3 dist(𝑆, 𝑆′) = dist(𝑆′, 𝑆)4 dist(𝑆, 𝑆′) ≤ dist(𝑆, 𝑆″) + dist(𝑆″, 𝑆′)

A. Blondin Massé (UQAM) Chapitre 5: Méta-heuristiques INF889B Hiver 2020 38 / 73

Page 40: Chapitre 5: Méta-heuristiques · A. Blondin Massé (UQAM) Chapitre 5: Méta-heuristiques INF889B Hiver 2020 19/73 Implémentation (2/4) struct Instance { // An instance of the set

Écart local (locality gap)• Soit 𝑓 une fonction objectif qu’on souhaite minimiser• Soit 𝑆 ∈ 𝒮 une solution admissible• Alors 𝑆 est un minimum global si 𝑓(𝑆) ≤ 𝑓(𝑆′) pour tout

𝑆′ ∈ 𝒮• Et 𝑆 est un minimum local si 𝑓(𝑆) ≤ 𝑓(𝑆′) pour tout

𝑆′ ∈ 𝒩(𝑆)• Soit ℒ l’ensemble de tous les minimums locaux• Et soit 𝑆∗ un minimum global• Alors on définit l’écart local (locality gap) par

𝛼 = max { 𝑓(𝑆)𝑓(𝑆∗) ∣ 𝑆 ∈ ℒ}

Question• Peut-on borner le ratio 𝛼 ?• Si oui, alors on obtient un algorithme d’approximation de

ratio 𝛼A. Blondin Massé (UQAM) Chapitre 5: Méta-heuristiques INF889B Hiver 2020 39 / 73

Page 41: Chapitre 5: Méta-heuristiques · A. Blondin Massé (UQAM) Chapitre 5: Méta-heuristiques INF889B Hiver 2020 19/73 Implémentation (2/4) struct Instance { // An instance of the set

Traitement de tâches

• Un ensemble de tâches 𝐽• Un ensemble de machines 𝑀• Une fonction 𝑡 ∶ 𝐽 → ℝ∗ qui indique le temps pris par chaque

tâche• Objectif: compléter toutes les tâches en un temps minimum

Exemple d’instance• 𝐽 = {𝑗1, 𝑗2, 𝑗3, 𝑗4, 𝑗5, 𝑗6}• 𝑀 = {𝑚1, 𝑚2, 𝑚3}• La fonction 𝑡 est donnée par le tableau suivant

𝑖 1 2 3 4 5 6𝑡(𝑗𝑖) 3.0 2.0 3.0 4.0 2.0 1.0

A. Blondin Massé (UQAM) Chapitre 5: Méta-heuristiques INF889B Hiver 2020 40 / 73

Page 42: Chapitre 5: Méta-heuristiques · A. Blondin Massé (UQAM) Chapitre 5: Méta-heuristiques INF889B Hiver 2020 19/73 Implémentation (2/4) struct Instance { // An instance of the set

Représentation possible• Une fonction 𝑆 ∶ 𝑀 → 2𝐽 qui associe à chaque machine la liste

des tâches qu’elle traitera• Exemple: 𝑆(𝑚1) = {𝑗1, 𝑗2, 𝑗6}, 𝑆(𝑚2) = {𝑗4},

𝑆(𝑚3) = {𝑗5, 𝑗3}• Calcul de 𝑡(𝑆) pour tout 𝑆:

𝑡(𝑆) = max⎧{⎨{⎩

∑𝑗∈𝑆(𝑚)

𝑡(𝑗) ∣ 𝑚 ∈ 𝑀⎫}⎬}⎭

Représentation alternative• Une fonction 𝑆 ∶ 𝐽 → 𝑀 qui associe à chaque tâche une

machine• Plus facile à implémenter!

A. Blondin Massé (UQAM) Chapitre 5: Méta-heuristiques INF889B Hiver 2020 41 / 73

Page 43: Chapitre 5: Méta-heuristiques · A. Blondin Massé (UQAM) Chapitre 5: Méta-heuristiques INF889B Hiver 2020 19/73 Implémentation (2/4) struct Instance { // An instance of the set

Fonction de voisinageQuestion

• Soit 𝑆 ∶ 𝐽 → 𝑀 une solution• Comment peut-on modifier 𝑆 pour obtenir une solution 𝑆′

proche de 𝑆?

Réponses• (jump) On choisit une tâche au hasard et on la change de

machine• (𝑘-jump) On choisit 𝑘 tâches au hasard et on les change de

machine• (optimal jump) On choisit une tâche traitée par une machine de

charge maximale et on la place sur une machine de chargeminimale

• (swap) On échange deux tâches qui sont sur des machinesdifférentes

A. Blondin Massé (UQAM) Chapitre 5: Méta-heuristiques INF889B Hiver 2020 42 / 73

Page 44: Chapitre 5: Méta-heuristiques · A. Blondin Massé (UQAM) Chapitre 5: Méta-heuristiques INF889B Hiver 2020 19/73 Implémentation (2/4) struct Instance { // An instance of the set

Fonction de voisinageQuestion

• Soit 𝑆 ∶ 𝐽 → 𝑀 une solution• Comment peut-on modifier 𝑆 pour obtenir une solution 𝑆′

proche de 𝑆?

Réponses• (jump) On choisit une tâche au hasard et on la change de

machine• (𝑘-jump) On choisit 𝑘 tâches au hasard et on les change de

machine• (optimal jump) On choisit une tâche traitée par une machine de

charge maximale et on la place sur une machine de chargeminimale

• (swap) On échange deux tâches qui sont sur des machinesdifférentes

A. Blondin Massé (UQAM) Chapitre 5: Méta-heuristiques INF889B Hiver 2020 42 / 73

Page 45: Chapitre 5: Méta-heuristiques · A. Blondin Massé (UQAM) Chapitre 5: Méta-heuristiques INF889B Hiver 2020 19/73 Implémentation (2/4) struct Instance { // An instance of the set

Théorème (Graham, 1966)• Soit 𝒩 ∶ 𝒮 → 2𝒮 la fonction qui associe à une solution 𝑆 toutes

les solutions obtenues de 𝑆 en déplaçant une tâche d’unemachine maximalement chargée vers une machineminimalement chargée

• Soit 𝑓 ∶ 𝒮 → ℝ × ℕ la fonction objectif qui associe à unesolution 𝑆 le couple (𝑡, 𝑚), où 𝑡 est temps maximal detraitement d’une machine et 𝑚 le nombre de machines dont ladurée est maximale

• Soit ≺ la relation définie sur ℝ × ℕ par

(𝑡1, 𝑚1) ≺ (𝑡2, 𝑚2) ssi 𝑡1 < 𝑡2 ou (𝑡1 = 𝑡2 et 𝑚1 < 𝑚2)

• Alors l’algorithme d’approximation utilisant 𝒩 et 𝑓 trouvetoujours une solution avec écart local d’au plus 2 − 1/𝑚, où 𝑚est le nombre de machines

A. Blondin Massé (UQAM) Chapitre 5: Méta-heuristiques INF889B Hiver 2020 43 / 73

Page 46: Chapitre 5: Méta-heuristiques · A. Blondin Massé (UQAM) Chapitre 5: Méta-heuristiques INF889B Hiver 2020 19/73 Implémentation (2/4) struct Instance { // An instance of the set

Implémentation (1/2)

Code source complet disponible sur GitLabstruct Batch { // A batch to process

unsigned int num_machines; // The number of available machinesunsigned int num_jobs; // The number of jobs to processfloat *durations; // The duration of each job

};

struct Schedule { // A schedule for processing the batchconst struct Batch *batch; // The scheduled batchunsigned int *assigned_machine; // The machine assigned to each jobfloat *duration_by_machine; // The total duration for each machine

};

struct Search { // A naive searchstruct Schedule schedule; // The current schedulefloat optimal_duration; // The optimal duration found so farbool verbose; // If true, prints trace to stdout

};

A. Blondin Massé (UQAM) Chapitre 5: Méta-heuristiques INF889B Hiver 2020 44 / 73

Page 47: Chapitre 5: Méta-heuristiques · A. Blondin Massé (UQAM) Chapitre 5: Méta-heuristiques INF889B Hiver 2020 19/73 Implémentation (2/4) struct Instance { // An instance of the set

Implémentation (2/2)// Operation on batchesvoid load_batch(struct Batch *batch);void print_batch(const struct Batch *batch);void free_batch(struct Batch *batch);

// Operation on schedulesfloat min_duration(const struct Schedule *schedule);float max_duration(const struct Schedule *schedule);unsigned int num_machines_max_load(const struct Schedule *schedule);void update_schedule_durations(struct Schedule *schedule);void alloc_schedule(struct Schedule *schedule,

const struct Batch *batch);void initialize_random_schedule(struct Schedule *schedule,

const struct Batch *batch);void print_schedule(const struct Schedule *schedule);void free_schedule(struct Schedule *schedule);

// Approximation algorithmvoid move_job(struct Schedule *schedule,

unsigned int j, unsigned int m);bool improve_schedule(struct Schedule *schedule);

// Naive algorithmvoid compute_optimal_schedule_recursive(struct Search *search,

unsigned int j);float optimal_duration(const struct Batch *batch,

bool verbose);

A. Blondin Massé (UQAM) Chapitre 5: Méta-heuristiques INF889B Hiver 2020 45 / 73

Page 48: Chapitre 5: Méta-heuristiques · A. Blondin Massé (UQAM) Chapitre 5: Méta-heuristiques INF889B Hiver 2020 19/73 Implémentation (2/4) struct Instance { // An instance of the set

Représentation d’un ensemble de tâches• Format simple pour minimiser le travail de chargement• Soit m et j le nombre de machines et le nombre de tâches• Alors on utilise le format suivant:

m jt1t2[...]tj

Exemple:$ cat examples/example -1.jobs3 632[...]1

A. Blondin Massé (UQAM) Chapitre 5: Méta-heuristiques INF889B Hiver 2020 46 / 73

Page 49: Chapitre 5: Méta-heuristiques · A. Blondin Massé (UQAM) Chapitre 5: Méta-heuristiques INF889B Hiver 2020 19/73 Implémentation (2/4) struct Instance { // An instance of the set

Exemple d’exécution$ bin/jobs-processing rn < examples/example -1.jobs5.000000

$ bin/jobs-processing ra < examples/example -1.jobs6.000000

$ bin/jobs-processing va < examples/example -1.jobsA batch of 6 jobs to be processed by 3 machines whose durations are

t(j0) = 3.00t(j1) = 2.00t(j2) = 3.00t(j3) = 4.00t(j4) = 2.00t(j5) = 1.00

[...]A schedule of 6 jobs dispatched onto 3 machines as follows:

Job #0 is assigned to machine #0Job #1 is assigned to machine #2Job #2 is assigned to machine #0Job #3 is assigned to machine #1Job #4 is assigned to machine #2Job #5 is assigned to machine #2Machine #0's duration is 6.000000Machine #1's duration is 4.000000Machine #2's duration is 5.000000

6.000000

A. Blondin Massé (UQAM) Chapitre 5: Méta-heuristiques INF889B Hiver 2020 47 / 73

Page 50: Chapitre 5: Méta-heuristiques · A. Blondin Massé (UQAM) Chapitre 5: Méta-heuristiques INF889B Hiver 2020 19/73 Implémentation (2/4) struct Instance { // An instance of the set

Expérimentation

A. Blondin Massé (UQAM) Chapitre 5: Méta-heuristiques INF889B Hiver 2020 48 / 73

Page 51: Chapitre 5: Méta-heuristiques · A. Blondin Massé (UQAM) Chapitre 5: Méta-heuristiques INF889B Hiver 2020 19/73 Implémentation (2/4) struct Instance { // An instance of the set

Voyageur de commerce• Soit 𝐺 = (𝑉 , 𝐸) le graphe simple complet de 𝑛 sommets• On considère une fonction de poids sur les arêtes

𝑤 ∶ 𝐸 → ℝ+ ∪ {+∞}• On cherche un cycle hamiltonien dont le poids total est

minimal

0

12

34

24

65

3

415

2

4

4! tournées possibles

0

12

34

24

65

3

415

2

4

4

6

3

1

4

poids = 18A. Blondin Massé (UQAM) Chapitre 5: Méta-heuristiques INF889B Hiver 2020 49 / 73

Page 52: Chapitre 5: Méta-heuristiques · A. Blondin Massé (UQAM) Chapitre 5: Méta-heuristiques INF889B Hiver 2020 19/73 Implémentation (2/4) struct Instance { // An instance of the set

Difficulté

• C’est un problème NP-difficile• Réduction à partir du problème du cycle hamiltonien• Espace de solutions: l’ensemble des permutations de 𝑛• Le nombre de solutions possibles est donc 𝑛!• Devient (𝑛 − 1)! si on fixe la première ville• Plusieurs approches non exactes proposées, généralement assez

efficaces

A. Blondin Massé (UQAM) Chapitre 5: Méta-heuristiques INF889B Hiver 2020 50 / 73

Page 53: Chapitre 5: Méta-heuristiques · A. Blondin Massé (UQAM) Chapitre 5: Méta-heuristiques INF889B Hiver 2020 19/73 Implémentation (2/4) struct Instance { // An instance of the set

Fonction de voisinage• Soit 𝑛 un entier positif• Soit 𝐶 l’ensemble des cycles hamiltoniens du graphe complet

de 𝑛 sommets• Soit 𝑐 ∈ 𝐶• Soient 𝑒1 = {𝑢1, 𝑣1} et 𝑒2 = {𝑢2, 𝑣2} deux arêtes de 𝑐, où 𝑢1,

𝑣1, 𝑢2, 𝑣2 apparaissent dans l’ordre dans 𝑐• Alors on peut construire un nouveau cycle hamiltonien 𝑐′ en

remplaçant les arêtes 𝑒1 et 𝑒2 par 𝑒′1 = {𝑢1, 𝑢2} et

𝑒′2 = {𝑣1, 𝑣2}

• Soit 𝒩 ∶ 𝐶 → 2𝐶 l’ensemble des voisins obtenus par unéchange d’arêtes

• Que vaut |𝒩(𝑐)| ?

→ J’ai 𝑛 choix pour la 1re arête→ J’ai 𝑛 − 1 choix pour la 2e arête→ On divise par 2 pour tenir compte de la symétrie→ Donc 𝑛(𝑛 − 1)/2 ∈ Θ(𝑛2) voisins

A. Blondin Massé (UQAM) Chapitre 5: Méta-heuristiques INF889B Hiver 2020 51 / 73

Page 54: Chapitre 5: Méta-heuristiques · A. Blondin Massé (UQAM) Chapitre 5: Méta-heuristiques INF889B Hiver 2020 19/73 Implémentation (2/4) struct Instance { // An instance of the set

Fonction de voisinage• Soit 𝑛 un entier positif• Soit 𝐶 l’ensemble des cycles hamiltoniens du graphe complet

de 𝑛 sommets• Soit 𝑐 ∈ 𝐶• Soient 𝑒1 = {𝑢1, 𝑣1} et 𝑒2 = {𝑢2, 𝑣2} deux arêtes de 𝑐, où 𝑢1,

𝑣1, 𝑢2, 𝑣2 apparaissent dans l’ordre dans 𝑐• Alors on peut construire un nouveau cycle hamiltonien 𝑐′ en

remplaçant les arêtes 𝑒1 et 𝑒2 par 𝑒′1 = {𝑢1, 𝑢2} et

𝑒′2 = {𝑣1, 𝑣2}

• Soit 𝒩 ∶ 𝐶 → 2𝐶 l’ensemble des voisins obtenus par unéchange d’arêtes

• Que vaut |𝒩(𝑐)| ?→ J’ai 𝑛 choix pour la 1re arête→ J’ai 𝑛 − 1 choix pour la 2e arête→ On divise par 2 pour tenir compte de la symétrie→ Donc 𝑛(𝑛 − 1)/2 ∈ Θ(𝑛2) voisins

A. Blondin Massé (UQAM) Chapitre 5: Méta-heuristiques INF889B Hiver 2020 51 / 73

Page 55: Chapitre 5: Méta-heuristiques · A. Blondin Massé (UQAM) Chapitre 5: Méta-heuristiques INF889B Hiver 2020 19/73 Implémentation (2/4) struct Instance { // An instance of the set

Recherche locale

• En 1995, Johnson et McGeoch ont étudié l’heuristique baséesur la recherche locale donnait de bons résultats en pratique

• En particulier, ils ont montré que si les 𝑛 villes sont distribuéesaléatoirement dans le plan…

• …alors en moyenne, on obtient des solutions dont l’écart localest de 25%

• Nous verrons que cette heuristique est très performantelorsque combinée à d’autres (colonies de fourmis, algorithmesmémétiques, etc.)

A. Blondin Massé (UQAM) Chapitre 5: Méta-heuristiques INF889B Hiver 2020 52 / 73

Page 56: Chapitre 5: Méta-heuristiques · A. Blondin Massé (UQAM) Chapitre 5: Méta-heuristiques INF889B Hiver 2020 19/73 Implémentation (2/4) struct Instance { // An instance of the set

Arbres de recouvrement• Soit 𝐺 = (𝑉 , 𝐸) un graphe simple• Soit 𝑇 = (𝑉 ′, 𝐸′) un sous-arbre de 𝐺• 𝑇 est un arbre de recouvrement de 𝐺 si 𝑉 ′ = 𝑉 et 𝐸′ ⊆ 𝐸• Algorithmes connus: Prim et Kruskal (voir INF7440, par

exemple), qui s’exécutent en temps polynomial• Variante: on cherche un arbre de recouvrement qui maximise

le nombre de feuilles dans l’arbre• Cette variante est NP-difficile

𝑎𝑏

𝑐

𝑑

𝑒

𝑓

𝑔

Un graphe

𝑎𝑏

𝑐

𝑑

𝑒

𝑓

𝑔

Arbre de recouvrementA. Blondin Massé (UQAM) Chapitre 5: Méta-heuristiques INF889B Hiver 2020 53 / 73

Page 57: Chapitre 5: Méta-heuristiques · A. Blondin Massé (UQAM) Chapitre 5: Méta-heuristiques INF889B Hiver 2020 19/73 Implémentation (2/4) struct Instance { // An instance of the set

Fonction de voisinage• Soient 𝑇 et 𝑇 ′ deux arbres de recouvrement• Alors on dit que 𝑇 et 𝑇 ′ sont voisins s’ils diffèrent

d’exactement deux arêtes• Ainsi, 𝒮 est l’ensemble des arbres de recouvrement et

𝒩(𝑇 ) = {𝑇 ′ ∈ 𝒮 ∣ 𝑇 et 𝑇 ′ diffèrent de deux arêtes}

𝑎𝑏

𝑐

𝑑

𝑒

𝑓

𝑔

ℎ𝑎

𝑏

𝑐

𝑑

𝑒

𝑓

𝑔

Deux arbres voisins

A. Blondin Massé (UQAM) Chapitre 5: Méta-heuristiques INF889B Hiver 2020 54 / 73

Page 58: Chapitre 5: Méta-heuristiques · A. Blondin Massé (UQAM) Chapitre 5: Méta-heuristiques INF889B Hiver 2020 19/73 Implémentation (2/4) struct Instance { // An instance of the set

Pseudocode

1: fonction RechercheLocale(𝑇 : arbre de recouvrement)2: 𝑇best ← 𝑇3: pour chaque {𝑢, 𝑣} ∈ 𝐸(𝐺) − 𝐸(𝑇 ) faire4: 𝑐 ← l’unique chemin dans 𝑇 entre 𝑢 et 𝑣5: pour {𝑢′, 𝑣′} ∈ 𝐸(𝑐) faire6: 𝑇 ′ ← 𝑇 ∪ {{𝑢, 𝑣}} − {{𝑢′, 𝑣′}}7: si 𝑇 ′ a plus de feuilles que 𝑇 alors8: 𝑇best ← 𝑇 ′

9: si 𝑇best a moins de feuilles que 𝑇 alors10: retourner RechercheLocale(𝑇best)11: sinon12: retourner 𝑇

A. Blondin Massé (UQAM) Chapitre 5: Méta-heuristiques INF889B Hiver 2020 55 / 73

Page 59: Chapitre 5: Méta-heuristiques · A. Blondin Massé (UQAM) Chapitre 5: Méta-heuristiques INF889B Hiver 2020 19/73 Implémentation (2/4) struct Instance { // An instance of the set

Complexité• Supposons que 𝐺 = (𝑉 , 𝐸) ait 𝑛 sommets et 𝑚 arêtes• On choisit une arête {𝑢, 𝑣} de 𝐺 qui n’est pas dans 𝑇• Il y a un unique chemin 𝑐 entre 𝑢 et 𝑣 dans 𝑇• On obtient 𝑇 ′ en ajoutant {𝑢, 𝑣} et en enlevant n’importe

quelle arête {𝑢′, 𝑣′} dans le chemin 𝑐• Ainsi, on a au plus 𝑚 choix pour {𝑢, 𝑣}• Et au plus 𝑛 − 1 choix pour {𝑢′, 𝑣′}• Donc au total, il y a 𝒪(𝑚𝑛) voisins

Nombre d’itérations• On commence avec au moins 2 feuilles• À chaque tour, on augmente d’au plus 1 feuille• On finit avec au plus 𝑛 − 1 feuilles• Donc au total au plus 𝑛 − 3 itérations

Complexité totale: 𝒪(𝑚𝑛2)

A. Blondin Massé (UQAM) Chapitre 5: Méta-heuristiques INF889B Hiver 2020 56 / 73

Page 60: Chapitre 5: Méta-heuristiques · A. Blondin Massé (UQAM) Chapitre 5: Méta-heuristiques INF889B Hiver 2020 19/73 Implémentation (2/4) struct Instance { // An instance of the set

Écart local

Théorème (Lu et Ravi, 1992)• Soit 𝛼 le ratio de l’écart maximal entre un optimum local et un

optimum global• Alors 𝛼 ≤ 5

Théorème (Lu et Ravi, 1992)• Si on permet d’échanger deux paires d’arêtes, alors 𝛼 ≤ 3

DémonstrationArguments combinatoires basés sur les propriétés des arbres derecouvrement et sur le lien entre degré et feuilles (lemme despoignées de main)

A. Blondin Massé (UQAM) Chapitre 5: Méta-heuristiques INF889B Hiver 2020 57 / 73

Page 61: Chapitre 5: Méta-heuristiques · A. Blondin Massé (UQAM) Chapitre 5: Méta-heuristiques INF889B Hiver 2020 19/73 Implémentation (2/4) struct Instance { // An instance of the set

Recuit simulé

A. Blondin Massé (UQAM) Chapitre 5: Méta-heuristiques INF889B Hiver 2020 58 / 73

Page 62: Chapitre 5: Méta-heuristiques · A. Blondin Massé (UQAM) Chapitre 5: Méta-heuristiques INF889B Hiver 2020 19/73 Implémentation (2/4) struct Instance { // An instance of the set

Idée généraleCombinaison de deux stratégies

• On souhaite améliorer localement la solution actuelle→ Recherche locale• Et permettre aussi des sauts dans l’espace de solution

→ Diversification

Inspiration• Recuit → obtenir un état de basse énergie dans un solide• Initialement, la température est élevée

→ l’arrangement est aléatoire et irrégulier• Puis on la diminue progressivement pour stabiliser

→ la structure se cristallise et s’organise• La température initiale doit être suffisamment élevée• Le refroidissement doit être suffisamment lent

A. Blondin Massé (UQAM) Chapitre 5: Méta-heuristiques INF889B Hiver 2020 59 / 73

Page 63: Chapitre 5: Méta-heuristiques · A. Blondin Massé (UQAM) Chapitre 5: Méta-heuristiques INF889B Hiver 2020 19/73 Implémentation (2/4) struct Instance { // An instance of the set

Modèle• En 1953, Metropolis et al. proposent un modèle discret pour

simuler l’évolution d’un solide qui subit un recuit• Utilise une technique de Monte Carlo (algorithme randomisé)

Idée• Le solide se trouve dans un état 𝑖, pour 𝑖 = 1, 2, … , 𝑛• Soit 𝐸𝑖 l’énergie du solide à l’état 𝑖• On calcule un état 𝑗 en déformant légèrement 𝑖• Si 𝐸𝑗 − 𝐸𝑖 ≤ 0, alors 𝐸𝑖+1 ← 𝐸𝑗• Sinon, on change l’état avec probabilité

exp (𝐸𝑖 − 𝐸𝑗𝑘𝐵𝑇 )

où 𝑇 est la température courante et 𝑘𝐵 est la constante deBoltzmann

A. Blondin Massé (UQAM) Chapitre 5: Méta-heuristiques INF889B Hiver 2020 60 / 73

Page 64: Chapitre 5: Méta-heuristiques · A. Blondin Massé (UQAM) Chapitre 5: Méta-heuristiques INF889B Hiver 2020 19/73 Implémentation (2/4) struct Instance { // An instance of the set

Pseudocode

1: procedure RecuitSimulé2: Soit 𝑆 une solution initiale3: Soit 𝑐 un réel positif4: tant que condition d’arrêt faire5: pour 𝑖 ← 1, 2, … , 𝐿 faire6: Choisir aléatoirement un voisin 𝑆′ de 𝑆7: si 𝑆′ est meilleur que 𝑆 alors8: 𝑆 ← 𝑆′

9: sinon10: Soit 𝑟 ∈ [0, 1) choisi aléatoirement11: si 𝑟 < exp((𝑓(𝑆) − 𝑓(𝑆′))/𝑐) alors 𝑆 ← 𝑆′

12: Mettre à jour 𝐿 et 𝑐

A. Blondin Massé (UQAM) Chapitre 5: Méta-heuristiques INF889B Hiver 2020 61 / 73

Page 65: Chapitre 5: Méta-heuristiques · A. Blondin Massé (UQAM) Chapitre 5: Méta-heuristiques INF889B Hiver 2020 19/73 Implémentation (2/4) struct Instance { // An instance of the set

Paramètres

Deux paramètres• 𝑐: paramètre de contrôle

→ doit évoluer avec le temps• 𝐿: nombre de voisins à considérer

→ généralement fixé

Plan de refroidissement• En anglais, cooling schedule• On doit préciser la valeur initiale 𝑐0• Et comment calculer 𝑐𝑖+1 en fonction de 𝑐𝑖, pour 𝑖 = 0, 1, …

A. Blondin Massé (UQAM) Chapitre 5: Méta-heuristiques INF889B Hiver 2020 62 / 73

Page 66: Chapitre 5: Méta-heuristiques · A. Blondin Massé (UQAM) Chapitre 5: Méta-heuristiques INF889B Hiver 2020 19/73 Implémentation (2/4) struct Instance { // An instance of the set

Plan de refroidissement statique

Initialisation• On peut choisir 𝑐0 ≈ Δ𝑓max où Δ𝑓max est la différence de coût

maximale entre deux voisins quelconques→ généralement impossible à calculer de façon exacte→ souvent approximé

Mise à jour• On prend 𝑐𝑖+1 = 𝛼𝑐𝑖, où 0 < 𝛼 < 1• Typiquement, on prend 0.8 ≤ 𝛼 ≤ 0.99

Nombre de répétitionsSouvent 𝐿 est proportionnel à la taille du voisinage

A. Blondin Massé (UQAM) Chapitre 5: Méta-heuristiques INF889B Hiver 2020 63 / 73

Page 67: Chapitre 5: Méta-heuristiques · A. Blondin Massé (UQAM) Chapitre 5: Méta-heuristiques INF889B Hiver 2020 19/73 Implémentation (2/4) struct Instance { // An instance of the set

Plan de refroidissement dynamique

Initialisation• On fixe 𝑐0 à une petite valeur• Puis on multiplie 𝑐0 par une constante > 1 jusqu’à ce que le

ratio de solutions acceptées approche 1

Nombre de répétitionsS’il y a beaucoup d’améliorations, on augmente le nombred’itérations

TerminaisonOn arrête lorsqu’il y a stagnation

A. Blondin Massé (UQAM) Chapitre 5: Méta-heuristiques INF889B Hiver 2020 64 / 73

Page 68: Chapitre 5: Méta-heuristiques · A. Blondin Massé (UQAM) Chapitre 5: Méta-heuristiques INF889B Hiver 2020 19/73 Implémentation (2/4) struct Instance { // An instance of the set

Comportement asymptotiqueHypothèses

• Le graphe de voisinage est fortement connexe• Tout état est atteignable de tout autre état à partir d’une

hauteur non nulle• La famille {𝑐𝑖}+∞

𝑖=1 satisfait

𝑐𝑖 = Γlog(𝑖 + 1)

pour une constante Γ qui majore l’écart entre un maximum localet le maximum global

Convergence• Alors l’algorithme converge vers une solution optimale• Si on attend assez longtemps

A. Blondin Massé (UQAM) Chapitre 5: Méta-heuristiques INF889B Hiver 2020 65 / 73

Page 69: Chapitre 5: Méta-heuristiques · A. Blondin Massé (UQAM) Chapitre 5: Méta-heuristiques INF889B Hiver 2020 19/73 Implémentation (2/4) struct Instance { // An instance of the set

Voyageur de commerce• Soit 𝐺 = (𝑉 , 𝐸) le graphe simple complet de 𝑛 sommets• On considère une fonction de poids sur les arêtes

𝑤 ∶ 𝐸 → ℝ+ ∪ {+∞}

0

12

34

24

65

3

415

2

4

0

12

34

24

65

3

415

2

4

4

6

3

1

4

• On cherche une tournée de poids minimal• Voir démonstrationA. Blondin Massé (UQAM) Chapitre 5: Méta-heuristiques INF889B Hiver 2020 66 / 73

Page 70: Chapitre 5: Méta-heuristiques · A. Blondin Massé (UQAM) Chapitre 5: Méta-heuristiques INF889B Hiver 2020 19/73 Implémentation (2/4) struct Instance { // An instance of the set

Recherche taboue

A. Blondin Massé (UQAM) Chapitre 5: Méta-heuristiques INF889B Hiver 2020 67 / 73

Page 71: Chapitre 5: Méta-heuristiques · A. Blondin Massé (UQAM) Chapitre 5: Méta-heuristiques INF889B Hiver 2020 19/73 Implémentation (2/4) struct Instance { // An instance of the set

Caractéristiques principales

Mémoire flexible• Tient compte de l’historique• Sans mémoire: algorithmes randomisés, recuit simulé• Mémoire rigide: séparation et évaluation progressive,

recherche A∗

Mécanismes de contrôle• Contraintes: restrictions taboues• Liberté: critère d’aspiration

Type de mémoire• Court terme: intensification de la recherche• Long terme: diversification de la recherche

A. Blondin Massé (UQAM) Chapitre 5: Méta-heuristiques INF889B Hiver 2020 68 / 73

Page 72: Chapitre 5: Méta-heuristiques · A. Blondin Massé (UQAM) Chapitre 5: Méta-heuristiques INF889B Hiver 2020 19/73 Implémentation (2/4) struct Instance { // An instance of the set

Pseudocode

1: procedure RechercheTaboue2: Soit 𝑆 une solution initiale3: 𝐵 ← ∅4: tant que il reste des itérations ou pas de stagnation faire5: 𝑆′ ← ∅6: pour chaque solution admissible 𝑆″ voisine de 𝑆 faire7: Si 𝑆″ est strictement meilleur que 𝑆′ alors 𝑆′ ← 𝑆″

8: Si 𝑆″ est strictement meilleur que 𝐵 alors 𝐵 ← 𝑆″

9: 𝑆 ← 𝑆′

10: Mettre à jour les restrictions taboues

A. Blondin Massé (UQAM) Chapitre 5: Méta-heuristiques INF889B Hiver 2020 69 / 73

Page 73: Chapitre 5: Méta-heuristiques · A. Blondin Massé (UQAM) Chapitre 5: Méta-heuristiques INF889B Hiver 2020 19/73 Implémentation (2/4) struct Instance { // An instance of the set

Choix du meilleur candidat

• On vérifie chaque candidat potentiel• Meilleur trouvé jusqu’à maintenant?

→ oui: mettre à jour• Est-ce que le candidat est tabou?

→ non: mettre à jour comme candidat admissible→ oui: satisfait le critère d’aspiration?→ oui: mettre à jour comme candidat admissible→ non: on passe au candidat suivant

Critère d’aspiration• Permet de court-circuiter le tabou• Exemple: solution strictement meilleure depuis le début,

découverte d’un nouveau sous-espace de recherche

A. Blondin Massé (UQAM) Chapitre 5: Méta-heuristiques INF889B Hiver 2020 70 / 73

Page 74: Chapitre 5: Méta-heuristiques · A. Blondin Massé (UQAM) Chapitre 5: Méta-heuristiques INF889B Hiver 2020 19/73 Implémentation (2/4) struct Instance { // An instance of the set

Exemple: arbre de recouvrement contraint• On considère un graphe simple 𝐺 = (𝑉 , 𝐸)• On cherche un arbre de recouvrement 𝑇 de 𝐺 de poids

minimal• Respectant certaines contraintes

→ on ne peut choisir simultanément certaines arêtes→ on doit choisir certaines arêtes conditionnellement

𝑥50

𝑥29

𝑥42

𝑥3

18

𝑥712

𝑥1

6

𝑥6 8

𝑥1 + 𝑥2 + 𝑥6 ≤ 1

𝑥1 ≤ 𝑥3

Pénalité: 50

A. Blondin Massé (UQAM) Chapitre 5: Méta-heuristiques INF889B Hiver 2020 71 / 73

Page 75: Chapitre 5: Méta-heuristiques · A. Blondin Massé (UQAM) Chapitre 5: Méta-heuristiques INF889B Hiver 2020 19/73 Implémentation (2/4) struct Instance { // An instance of the set

Stratégie taboueVoisinage𝑇 et 𝑇 ′ sont voisins s’ils diffèrent d’exactement deux arêtes

Restriction taboueChaque arête ajoutée devient taboue pour les deux prochainesitérations

Critère d’aspirationSi on trouve un nouveau maximum global, on le sauvegarde

ExempleEffectuer la trace sur l’exemple précédent en commençant avec

{𝑥1, 𝑥4, 𝑥5, 𝑥6}

A. Blondin Massé (UQAM) Chapitre 5: Méta-heuristiques INF889B Hiver 2020 72 / 73

Page 76: Chapitre 5: Méta-heuristiques · A. Blondin Massé (UQAM) Chapitre 5: Méta-heuristiques INF889B Hiver 2020 19/73 Implémentation (2/4) struct Instance { // An instance of the set

Observations

Taille de la liste taboue?• Expérimentation: entre 5 et 12 semble optimal• Nombre récurrent: 7

Diversification• Recherche taboue souvent combinée à d’autres stratégies• Différents types de mémoire

En pratique• Excellents résultats dans plusieurs problèmes• Très générique: peut être appliqué à n’importe quel problème

d’optimisation en principe

A. Blondin Massé (UQAM) Chapitre 5: Méta-heuristiques INF889B Hiver 2020 73 / 73