Skip to content

Commit

Permalink
Fix anyoptimization#323: time termination criterion is limited to 24 …
Browse files Browse the repository at this point in the history
…hours maximum
  • Loading branch information
blankjul committed Dec 13, 2022
1 parent cd80389 commit 97b5fce
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
9 changes: 7 additions & 2 deletions pymoo/util/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,8 +332,13 @@ def distance_of_closest_points_to_others(X):


def time_to_int(t):
td = datetime.strptime(t, '%H:%M:%S') - datetime(1900, 1, 1)
return td.total_seconds()
vals = [int(e) for e in t.split(":")][::-1]
s = vals[0]
if len(vals) > 1:
s += 60 * vals[1]
if len(vals) > 2:
s += 3600 * vals[2]
return s


def powerset(iterable):
Expand Down
15 changes: 15 additions & 0 deletions tests/misc/test_termination.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from pymoo.termination.max_time import TimeBasedTermination


def test_time_based_termination_more_than_one_day():
termination = TimeBasedTermination("99:00:00")
assert termination.max_time == 356400

termination = TimeBasedTermination("105:10:00")
assert termination.max_time == 378600

termination = TimeBasedTermination("40")
assert termination.max_time == 40

termination = TimeBasedTermination("1:40")
assert termination.max_time == 100

0 comments on commit 97b5fce

Please sign in to comment.