Commits

Chris Mutel committed 637cc8e

Correctly set up Monte Carlo classes as iterators

  • Participants
  • Parent commits 0e8a5d4

Comments (0)

Files changed (1)

bw2calc/monte_carlo.py

         self.bio_rng = MCRandomNumberGenerator(self.bio_params, seed=seed)
         self.cf_rng = MCRandomNumberGenerator(self.cf_params, seed=seed)
 
+    def __iter__(self):
+        return self
+
     def next(self):
         self.build_technosphere_matrix(self.tech_rng.next())
         self.build_biosphere_matrix(self.bio_rng.next())
 
         self.lci_calculation()
         self.lcia_calculation()
+        return self.score
 
     def solve_linear_system(self):
         if not self.iter_solver or self.guess == None:
                 raise
             return solution
 
-    def iterate(self):
-        # TODO: use yield or __iter__? What is most pythonic?
-        self.next()
-        return self.score
-
 
 class ComparativeMonteCarlo(LCA):
     """First draft approach at comparative LCA"""
         self.bio_rng = MCRandomNumberGenerator(self.bio_params, seed=seed)
         self.cf_rng = MCRandomNumberGenerator(self.cf_params, seed=seed)
 
+    def __iter__(self):
+        return self
+
     def next(self):
         self.build_technosphere_matrix(self.tech_rng.next())
         self.build_biosphere_matrix(self.bio_rng.next())