From 0e6e110a312316e114445a9358e2c1f89da8c09f Mon Sep 17 00:00:00 2001
From: aristidecod <sie.ouattara@etu.univ-amu.fr>
Date: Tue, 28 Jan 2025 00:05:36 +0100
Subject: [PATCH] ajout de varaible pour coimpter le nopmbre de noeuds

---
 src/App.java      |  4 ++--
 src/Backpack.java | 11 +++--------
 2 files changed, 5 insertions(+), 10 deletions(-)

diff --git a/src/App.java b/src/App.java
index 7757906..7e84a0f 100644
--- a/src/App.java
+++ b/src/App.java
@@ -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
diff --git a/src/Backpack.java b/src/Backpack.java
index b287831..b5f71b1 100644
--- a/src/Backpack.java
+++ b/src/Backpack.java
@@ -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;
-    }
 }
-- 
GitLab