How to use the causality.common.linearize_fluent_vec 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
# setup fluent space
        fluent_space = common.tabulate(self.fluent_labels)

        # setup known action_seqs
        known_action_seqs = dict()
        action_seq = []
        for i in range(0, fluents.shape[0]):
            fluent_vec = fluents[i]

            if i == 0:
                self.initial_fluent_state = fluent_vec
                continue

            prev_action_val = actions[i - 1]

            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))
                )