Skip to content
Snippets Groups Projects
Commit 909a7464 authored by OUATTARA Sie's avatar OUATTARA Sie
Browse files

Merge branch 'dev1' into 'main'

ajout de varaible pour coimpter le nopmbre de noeuds

See merge request !6
parents 2f5c2e1d 0e6e110a
No related branches found
No related tags found
1 merge request!6ajout de varaible pour coimpter le nopmbre de noeuds
...@@ -3,7 +3,7 @@ import java.util.List; ...@@ -3,7 +3,7 @@ import java.util.List;
public class App { public class App {
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
Backpack backpack= new InstanceReader().read("src/sacTest"); Backpack backpack= new InstanceReader().read("/home/aristidecod/Documents/branch-and-bound/src/sac0");
backpack.solve(); backpack.solve();
} }
} }
\ No newline at end of file
...@@ -10,6 +10,7 @@ public class Backpack { ...@@ -10,6 +10,7 @@ public class Backpack {
private int currentValue = 0; private int currentValue = 0;
private final boolean[] currentSolution; private final boolean[] currentSolution;
private final boolean[] bestSolution; private final boolean[] bestSolution;
private int nodesExplored = 0;
public Backpack(int capacity, List<Loot> loots) { public Backpack(int capacity, List<Loot> loots) {
this.capacity = capacity; this.capacity = capacity;
...@@ -23,6 +24,7 @@ public class Backpack { ...@@ -23,6 +24,7 @@ public class Backpack {
explore_from(0); explore_from(0);
System.out.println("La valeur optimale est : " + bestValue); System.out.println("La valeur optimale est : " + bestValue);
System.out.println("Objets inclus dans la solution optimale : " + Arrays.toString(bestSolution)); System.out.println("Objets inclus dans la solution optimale : " + Arrays.toString(bestSolution));
System.out.println("Nombre de nœuds explorés : " + nodesExplored);
} }
public String toString(){ public String toString(){
...@@ -59,6 +61,7 @@ public class Backpack { ...@@ -59,6 +61,7 @@ public class Backpack {
} }
private void explore_from(int index) { private void explore_from(int index) {
nodesExplored++;
// Si on a exploré tous les objets // Si on a exploré tous les objets
if (index >= loots.size()) { if (index >= loots.size()) {
if (currentValue > bestValue) { if (currentValue > bestValue) {
...@@ -92,12 +95,4 @@ public class Backpack { ...@@ -92,12 +95,4 @@ public class Backpack {
// on explore sans l'objet // on explore sans l'objet
explore_from(index + 1); explore_from(index + 1);
} }
public int getBestValue() {
return bestValue;
}
public boolean[] getBestSolution() {
return bestSolution;
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment