def subset_test():
    a = SubSet([1, 2, 3, 4, {1: 2}])
    print(a)

    a.add(1)
    a.add_from([1, 2])
    a |= [3, 4]

    assert (a._set == {1, 2, 3, 4})

    a |= [{1: 2}]
    assert (a._list == [{1: 2}])

    b = SubSet([1, '2'])
    b.add('2')
    assert (b._set == {'2'})
    assert (not bool(b._list))
    assert (b._superset == [1, '2'])

    superset = [1, 2]
    s = SubSet(superset)
    s |= [1, 2]
    print(s)
    assert (s._set == {1, 2})
    assert (not bool(s._list))

    #s.add(3)

    return a
def subset_test():
    a = SubSet([1, 2, 3, 4, {1: 2}])
    print (a)

    a.add(1)
    a.add_from([1, 2])
    a |= [3, 4]

    assert a._set == {1, 2, 3, 4}

    a |= [{1: 2}]
    assert a._list == [{1: 2}]

    b = SubSet([1, "2"])
    b.add("2")
    assert b._set == {"2"}
    assert not bool(b._list)
    assert b._superset == [1, "2"]

    superset = [1, 2]
    s = SubSet(superset)
    s |= [1, 2]
    print (s)
    assert s._set == {1, 2}
    assert not bool(s._list)

    # s.add(3)

    return a
示例#3
0
def solve(ks, goal_label, spec):
    """Solve the minimum violation planning problem

    This follows from
    J. Tumova, G.C Hall, S. Karaman, E. Frazzoli and D. Rus.
    Least-violating Control Strategy Synthesis with Safety Rules, HSCC 2013.

    @param ks: the Kripke structure
    @param goal_label: a label in ks.atomic_propositions that indicates the goal
    @param spec: the prioritized safety specification of type
        tulip.spec.prioritized_safety.PrioritizedSpecification

    @return: (best_cost, best_path, weighted_product_automaton) where
       * best_cost is the optimal cost of reaching the goal
       * best_path is the optimal path to the goal
       * weighted_product_automaton is the weighted product automaton ks times spec
    """

    assert isinstance(ks, KS)
    assert isinstance(spec, PrioritizedSpecification)
    assert ks.atomic_propositions == spec.atomic_propositions
    (wpa, null_state) = _construct_weighted_product_automaton(ks, spec)

    goal_states = [
        state for state in ks.states if goal_label in ks.states[state]["ap"]
    ]
    accepting_goal_states = SubSet(wpa.states.accepting)
    accepting_goal_states.add_from(set(product(goal_states,
                                               spec.get_states())))

    (cost, product_path) = dijkstra_multiple_sources_multiple_targets(
        wpa, wpa.states.initial, accepting_goal_states, cost_key="cost")

    state_path = [state[0] for state in product_path if state[0] != null_state]

    return (cost, state_path, product_path, wpa)