def check_preconditions_on_path(self, path_state): """ Returns proto_segments: list of tuples (start_index, end_index) of segment in path segment_constraints: a function with args (segment, PathState), and which returns 1 if the segment is within the action constraints, 0 otherwise Notes: both segment[0] and segment[1] are valid points for action a in the path proto_segments are expected to be resized downstream to fit within a task sequence. For this reason segment_constraints is returned along with the segments, so that the downstream can check whether the resized segments are still valid. """ # custom precondition function is_point_valid = \ np.logical_or.reduce([ np.logical_and( path_state.path_features_uncertainties()[kSF["crowdedness"], :] < UNCERTAINTY_THRESH, path_state.path_features_values()[kSF["crowdedness"], :] >= 0.5, ), np.logical_and( path_state.path_features_uncertainties()[kSF["permissivity"], :] < UNCERTAINTY_THRESH, path_state.path_features_values()[kSF["permissivity"], :] <= 0.5, ), ]).astype(np.uint8) # transform bool along path is_point_valid to action segments proto_segments = segments_from_bool1d(is_point_valid) # segment constraints # segment_constraints = minlength_segment_constraint segment_constraints = no_segment_constraint return proto_segments, segment_constraints
def check_preconditions_on_path(self, path_state): """ Returns proto_segments: list of tuples (start_index, end_index) of segment in path segment_constraints: a function with args (segment, PathState), and which returns 1 if the segment is within the action constraints, 0 otherwise Notes: both segment[0] and segment[1] are valid points for action a in the path proto_segments are expected to be resized downstream to fit within a task sequence. For this reason segment_constraints is returned along with the segments, so that the downstream can check whether the resized segments are still valid. """ # custom precondition function is_point_valid = \ np.ones_like(path_state.path_features_values()[kSF["crowdedness"], :], dtype=np.uint8) # transform bool along path is_point_valid to action segments proto_segments = segments_from_bool1d(is_point_valid) # segment constraints segment_constraints = no_segment_constraint return proto_segments, segment_constraints