Skip to content

Commit

Permalink
get_times: Return is_executed
Browse files Browse the repository at this point in the history
Add removed tasks to archive
  • Loading branch information
Angela Enriquez committed Dec 7, 2020
1 parent fbf3eb9 commit 126f9ed
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions stn/stn.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,23 +322,22 @@ def update_task(self, task):
constraints = [((i), (i + 1)) for i in new_constraints_between[:-1]]
self.add_intertimepoints_constraints(constraints, task)

def remove_task(self, position=1):
def remove_task(self, position=1, archived_stn=None):
""" Removes the task from the given position"""

self.logger.info("Removing task at position: %s", position)
departure_node_id = 2 * position + (position-2)
start_node_id = departure_node_id + 1
finish_node_id = start_node_id + 1

node_ids = [departure_node_id, start_node_id, finish_node_id]

new_constraints_between = list()

if self.has_node(departure_node_id-1) and self.has_node(finish_node_id+1):
new_constraints_between = [departure_node_id-1, departure_node_id]

# Remove node and all adjacent edges
self.remove_node(departure_node_id)
self.remove_node(start_node_id)
self.remove_node(finish_node_id)
archived_stn = self.remove_node_ids(node_ids, archived_stn)

self.displace_nodes(departure_node_id)

Expand All @@ -351,6 +350,8 @@ def remove_task(self, position=1):
# wait time between finish of one task and departure of the next one
self.add_constraint(i, j)

return archived_stn

def remove_node_ids(self, node_ids, archived_stn=None):
# Assumes that the node_ids are in consecutive order from node_id 1 onwards
for i in node_ids:
Expand Down Expand Up @@ -540,13 +541,14 @@ def get_time(self, task_id, node_type='departure', lower_bound=True):
return _time

def get_times(self, task_id, node_type='departure'):
_time = None
for i, data in self.nodes.data():
if 'data' in data and task_id == data['data'].task_id and data['data'].node_type == node_type:
lower_bound = -self[i][0]['weight']
upper_bound = self[0][i]['weight']
_time = (lower_bound, upper_bound)
return _time
is_executed = data['data'].is_executed
return _time, is_executed
return None, None

def get_node_earliest_time(self, node_id):
return -self[node_id][0]['weight']
Expand Down

0 comments on commit 126f9ed

Please sign in to comment.