예제 #1
0
def test_tightest():
    c1 = SimpleTemporalConstraint('e1', 'e2', 3, 5, 'c1')
    c2 = SimpleTemporalConstraint('e3', 'e2', 4, 7, 'c2')
    c3 = SimpleTemporalConstraint('e1', 'e3', None, 3, 'c3')
    c4 = SimpleTemporalConstraint('e1', 'e3', None, 7, 'c4')
    network = TemporalNetwork([c1, c2, c3, c4])
    checker = DCCheckerBE(network)
    ldg = checker.to_ldg()
    assert (len(ldg.edges()) == 6)
    feasible, nc = eliminate(ldg, 'e2')
    assert (len(ldg.edges()) == 2)
예제 #2
0
def test_temporal_network():
    c1 = SimpleTemporalConstraint('e1', 'e2', 1, 3, 'c1')
    c2 = SimpleContingentTemporalConstraint('e2', 'e3', 2, 3)
    network = TemporalNetwork([c1, c2])
    # print(network)
    # print(network.get_constraints())
    # print(network.get_events())
    network.remove_event('e2')
    assert (len(network.get_constraints()) == 0)
    assert (len(network.get_events()) == 0)

    network.add_constraints([c1, c2])
    network.remove_event('e2',
                         remove_constraints=True,
                         remove_unconnected_events=False)
    assert (len(network.get_constraints()) == 0)
    assert (len(network.get_events()) == 2)

    network.add_constraints([c1, c2])
    network.remove_constraint('c1')
    assert (len(network.get_constraints()) == 1)
    network.remove_constraint(c2)
    assert (len(network.get_constraints()) == 0)
    assert (len(network.get_events()) == 0)

    network.add_constraint(c1)
    network.remove_constraint(c1, remove_events=False)
    assert (len(network.get_events()) == 2)
    network.remove_event('e1', remove_constraints=False)
    assert (len(network.get_events()) == 1)

    network = TemporalNetwork([c1, c2])
    checker = DCCheckerBE(network)
    ldg = checker.to_ldg()
    # print(ldg.nodes())
    # print(ldg.edges(data=True))
    assert (len(ldg.nodes()) == 4)
    assert (len(ldg.edges(data=True)) == 6)

    feasible, conflict = checker.is_controllable()
    assert (feasible)