How to use the causality.causal_planner.ActionSequence function in causality

To help you get started, we’ve selected a few causality examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mjedmonds / OpenLock / causality / causal_planner.py View on Github external
depth = 0

        possible_action_seqs = []
        while frontier:
            if depth >= max_depth:
                break
            parent_vec, action_seq = frontier.pop(0)
            children_vecs, transition_actions = self.compute_perceptual_transition(
                parent_vec
            )
            for i in range(children_vecs.shape[0]):
                new_action_seq = copy.copy(action_seq)
                new_action_seq.append(transition_actions[i])
                # add as a possible path
                if np.equal(children_vecs[i], target_vec).all():
                    possible_action_seqs.append(ActionSequence(new_action_seq))
                # continue searching down the tree
                else:
                    frontier.append((children_vecs[i], new_action_seq))

            depth += 1

        return possible_action_seqs
github mjedmonds / OpenLock / causality / causal_planner.py View on Github external
assert (
                action_executed.size <= 1
            ), "More than one action in a single frame, should be impossible"
            if action_executed.size == 1:
                action_seq.append(action_executed[0])
            else:
                continue  # no action executed

            # add on the current action as a way to reach this fluent state
            if lin_fluent_vec in list(known_action_seqs.keys()):
                known_action_seqs[lin_fluent_vec].append(
                    ActionSequence(copy.copy(action_seq))
                )
            else:
                known_action_seqs[lin_fluent_vec] = [
                    ActionSequence(copy.copy(action_seq))
                ]

        return known_action_seqs
github mjedmonds / OpenLock / causality / causal_planner.py View on Github external
def concat(self, other):
        if self.action_seq_str is not None and other.action_seq_str is not None:
            return ActionSequence(
                self.action_seq + other.action_seq,
                self.action_seq_str + other.action_seq_str,
            )
        else:
            return ActionSequence(self.action_seq + other.action_seq)
github mjedmonds / OpenLock / causality / causal_planner.py View on Github external
lin_fluent_vec = common.linearize_fluent_vec(fluents[i])
            action_executed = np.where(prev_action_val > 0)[
                0
            ]  # find action executed at last frame
            assert (
                action_executed.size <= 1
            ), "More than one action in a single frame, should be impossible"
            if action_executed.size == 1:
                action_seq.append(action_executed[0])
            else:
                continue  # no action executed

            # add on the current action as a way to reach this fluent state
            if lin_fluent_vec in list(known_action_seqs.keys()):
                known_action_seqs[lin_fluent_vec].append(
                    ActionSequence(copy.copy(action_seq))
                )
            else:
                known_action_seqs[lin_fluent_vec] = [
                    ActionSequence(copy.copy(action_seq))
                ]

        return known_action_seqs