Bladeren bron

restart from correct number of obtained samples

Jérôme BUISINE 4 jaren geleden
bovenliggende
commit
6887a1e191
1 gewijzigde bestanden met toevoegingen van 9 en 0 verwijderingen
  1. 9 0
      optimization/ILSSurrogate.py

+ 9 - 0
optimization/ILSSurrogate.py

@@ -153,6 +153,15 @@ class ILSSurrogate(Algorithm):
         # enable resuming for ILS
         self.resume()
 
+        # count number of surrogate obtained and restart using real evaluations done
+        nsamples = None
+        with open(self.solutions_file, 'r') as f:
+            nsamples = len(f.readlines()) - 1 # avoid header
+
+        if self.getGlobalEvaluation() < nsamples:
+            print(f'Restart using {nsamples} of {self.start_train_surrogate} real evaluations obtained')
+            self.numberOfEvaluations = nsamples
+
         if self.start_train_surrogate > self.getGlobalEvaluation():
         
             # get `self.start_train_surrogate` number of real evaluations and save it into surrogate dataset file