Skip to content

Commit cf20743

Browse files
committed
Update database.py
1 parent 258f44b commit cf20743

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

openevolve/database.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -986,18 +986,21 @@ def get_island_stats(self) -> List[dict]:
986986
return stats
987987

988988
def _calculate_island_diversity(self, programs: List[Program]) -> float:
989-
"""Calculate diversity within an island (optimized version)"""
989+
"""Calculate diversity within an island (deterministic version)"""
990990
if len(programs) < 2:
991991
return 0.0
992992

993993
total_diversity = 0
994994
comparisons = 0
995995

996-
# Sample fewer programs for performance
996+
# Use deterministic sampling instead of random.sample() to ensure consistent results
997997
sample_size = min(5, len(programs)) # Reduced from 10 to 5
998-
sample_programs = (
999-
random.sample(programs, sample_size) if len(programs) > sample_size else programs
1000-
)
998+
999+
# Sort programs by ID for deterministic ordering
1000+
sorted_programs = sorted(programs, key=lambda p: p.id)
1001+
1002+
# Take first N programs instead of random sampling
1003+
sample_programs = sorted_programs[:sample_size]
10011004

10021005
# Limit total comparisons for performance
10031006
max_comparisons = 6 # Maximum comparisons to prevent long delays

0 commit comments

Comments
 (0)