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

ajout de varaible pour coimpter le nopmbre de noeuds

parent 67753d94
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;
public class App {
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();
}
}
\ No newline at end of file
......@@ -10,6 +10,7 @@ public class Backpack {
private int currentValue = 0;
private final boolean[] currentSolution;
private final boolean[] bestSolution;
private int nodesExplored = 0;
public Backpack(int capacity, List<Loot> loots) {
this.capacity = capacity;
......@@ -23,6 +24,7 @@ public class Backpack {
explore_from(0);
System.out.println("La valeur optimale est : " + bestValue);
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(){
......@@ -59,6 +61,7 @@ public class Backpack {
}
private void explore_from(int index) {
nodesExplored++;
// Si on a exploré tous les objets
if (index >= loots.size()) {
if (currentValue > bestValue) {
......@@ -92,12 +95,4 @@ public class Backpack {
// on explore sans l'objet
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