Florian il y a 6 ans
Parent
commit
beb2008e1c
1 fichiers modifiés avec 12 ajouts et 5 suppressions
  1. 12 5
      plan_gen.py

+ 12 - 5
plan_gen.py

@@ -7,8 +7,8 @@ import numpy as np
 import lxml.etree as etree
 
 # constants
-MIN_DEPARTURE_TIME = 8 * 3600 # '08:00:00'
-MAX_DEPARTURE_TIME = 9 * 3600 # '09:00:00'
+MIN_DEPARTURE_TIME = '08:00:00'
+MAX_DEPARTURE_TIME = '09:00:00'
 WORK_DURATION = '04:00:00'
 
 def read_nodes(input_network):
@@ -18,10 +18,17 @@ def read_nodes(input_network):
     tree = etree.parse(input_network)
     return [node for node in tree.xpath("/network/nodes/node")]
 
+def get_seconds(time_str):
+    ''' returns seconds from a time string '''
+    h, m, s = time_str.split(':')
+    return int(h) * 3600 + int(m) * 60 + int(s)
+
 def rand_time(low, high):
-    ''' returns a random time between low and high bounds (in seconds) '''
-    delta = np.random.randint(high - low)
-    return time.strftime('%H:%M:%S', time.gmtime(low + delta))
+    ''' returns a random time between low and high bounds '''
+    low_s = get_seconds(low)
+    high_s = get_seconds(high)
+    delta = np.random.randint(high_s - low_s)
+    return time.strftime('%H:%M:%S', time.gmtime(low_s + delta))
 
 def rand_node_xy(nodes, clusters):
     ''' returns a random node coordinates from a list of nodes '''