Exemple #1
0
    def test_search_one_backward_step_3(self, cfg):
        # given
        gs = GoalSequenceSearcher()
        start = "01111111"
        goal = "10111111"
        gs.forward_perceptions.append(Perception(start))
        gs.backward_perceptions.append(Perception(goal))
        reliable_classifiers = ClassifiersList(
            Classifier(condition="#1######",
                       action=1,
                       effect="#0######",
                       cfg=cfg),
            Classifier(condition="0#######",
                       action=1,
                       effect="1#######",
                       cfg=cfg))
        forward_size = 1
        forward_point = 0

        # when
        act_seq, size = gs._search_one_backward_step(reliable_classifiers,
                                                     forward_size,
                                                     forward_point)

        # then
        assert act_seq is None
        assert len(gs.backward_classifiers) == 2
Exemple #2
0
    def test_form_sequence_backwards_5(self, cfg):
        # given
        gs = GoalSequenceSearcher()
        cl0 = Classifier(condition="01010101",
                         action=2,
                         effect="0000000",
                         cfg=cfg)
        cl1 = Classifier(condition="11111111",
                         action=0,
                         effect="0000000",
                         cfg=cfg)
        cl2 = Classifier(condition="11111111",
                         action=1,
                         effect="0000000",
                         cfg=cfg)
        gs.backward_classifiers = [
            ClassifiersList(cl0),
            ClassifiersList(cl0, cl1)
        ]
        i = 2
        idx = 0

        # when
        seq = gs._form_sequence_backwards(i, idx, cl2)

        # then
        assert len(seq) == 3
        assert cl0.action in seq
        assert cl1.action in seq
        assert cl2.action in seq
        assert seq == [cl2.action, cl0.action, cl1.action]
Exemple #3
0
def search_goal_sequence(classifiers: ClassifiersList,
                         start_state: Perception,
                         goal: Perception,
                         theta_r: float) -> list:
    """
    Searches a path from start to goal using a bidirectional method in the
    environmental model (i.e. the list of reliable classifiers).

    Parameters
    ----------
    classifiers: ClassifiersList
    start_state: Perception
    goal: Perception
    theta_r: int
        quality theta_r

    Returns
    -------
    list
        sequence of actions
    """
    reliable_classifiers = \
        get_quality_classifiers_list(classifiers,
                                     quality=theta_r)

    return GoalSequenceSearcher().search_goal_sequence(
        reliable_classifiers, start_state, goal)
Exemple #4
0
    def test_search_goal_sequence_1(self):
        # given
        gs = GoalSequenceSearcher()
        start = Perception("11111111")
        goal = Perception("11111110")

        empty_list = ClassifiersList()

        # when
        result = gs.search_goal_sequence(empty_list, start=start, goal=goal)

        # then
        assert result == []
Exemple #5
0
    def test_form_sequence_forwards_1(self, cfg):
        # given
        gs = GoalSequenceSearcher()
        cl0 = Classifier(condition="01010101",
                         action=2,
                         effect="0000000",
                         cfg=cfg)
        i = 0
        idx = 0

        # when
        seq = gs._form_sequence_forwards(i, idx, cl0)

        # then
        assert len(seq) == 1
        assert cl0.action in seq
Exemple #6
0
    def test_form_new_classifiers_1(self, cfg):
        # given
        gs = GoalSequenceSearcher()
        cls_list = [ClassifiersList()]
        cl = Classifier(condition="01010101",
                        action=2,
                        effect="0000000",
                        cfg=cfg)
        i = 0

        # when
        new_classifiers = gs._form_new_classifiers(cls_list, i, cl)

        # then
        assert len(new_classifiers) == 1
        assert cl in new_classifiers
Exemple #7
0
    def test_search_goal_sequence_4(self, cfg):
        # given
        gs = GoalSequenceSearcher()
        start = "01111111"
        goal = "00111111"

        reliable_classifiers = ClassifiersList(
            Classifier(condition="#1######",
                       action=1,
                       effect="#0######",
                       cfg=cfg))

        # when
        result = gs.search_goal_sequence(reliable_classifiers,
                                         start=start,
                                         goal=goal)
        # then
        assert result == [1]
Exemple #8
0
    def test_form_new_classifiers_2(self, cfg):
        # given
        gs = GoalSequenceSearcher()
        cl0 = Classifier(condition="01010101",
                         action=2,
                         effect="0000000",
                         cfg=cfg)
        cl1 = Classifier(condition="11111111",
                         action=0,
                         effect="0000000",
                         cfg=cfg)
        cls_list = [ClassifiersList(cl0)]
        i = 1

        # when
        new_classifiers = gs._form_new_classifiers(cls_list, i, cl1)

        # then
        assert len(new_classifiers) == 2
        assert cl0 in new_classifiers
        assert cl1 in new_classifiers
def search_goal_sequence(classifiers: ClassifiersList, p0: Perception,
                         p1: Perception) -> List:
    """
    Searches a path from start to goal using a bidirectional method in the
    environmental model (i.e. the list of reliable classifiers).

    Parameters
    ----------
    classifiers: ClassifiersList
    p0: Perception
        start state
    p1: Perception
        destination state

    Returns
    -------
    list
        sequence of actions
    """
    reliable = [cl for cl in classifiers if cl.is_reliable()]
    gs = GoalSequenceSearcher()

    return gs.search_goal_sequence(ClassifiersList(*reliable), p0, p1)