예제 #1
0
 def pack(self, comb_class: Tiling) -> StrategyPack:
     try:
         return InsertionEncodingVerificationStrategy().pack(comb_class)
     except StrategyDoesNotApply:
         pass
     if self.no_factors:
         raise InvalidOperationError("Cannot get a simpler specification")
     if (
         any(isinstance(ass, ComponentAssumption) for ass in comb_class.assumptions)
         and len(comb_class.find_factors()) == 1
     ):
         raise InvalidOperationError(
             "Can't find generating function with component assumption."
         )
     return StrategyPack(
         initial_strats=[FactorFactory()],
         inferral_strats=[],
         expansion_strats=[],
         ver_strats=[
             BasicVerificationStrategy(),
             OneByOneVerificationStrategy(),
             InsertionEncodingVerificationStrategy(),
             MonotoneTreeVerificationStrategy(no_factors=True),
             LocalVerificationStrategy(no_factors=True),
         ],
         name="factor pack",
     )
예제 #2
0
 def pack(self, tiling: Tiling) -> StrategyPack:
     if any(
             isinstance(ass, ComponentAssumption)
             for ass in tiling.assumptions):
         raise InvalidOperationError(
             "Can't find generating function with component assumption.")
     try:
         return InsertionEncodingVerificationStrategy().pack(tiling)
     except StrategyDoesNotApply:
         pass
     if self.no_factors:
         raise InvalidOperationError(
             "Cannot get a specification for a tiling in the database")
     return StrategyPack(
         initial_strats=[FactorFactory()],
         inferral_strats=[],
         expansion_strats=[],
         ver_strats=[
             BasicVerificationStrategy(),
             OneByOneVerificationStrategy(),
             InsertionEncodingVerificationStrategy(),
             MonotoneTreeVerificationStrategy(no_factors=True),
         ],
         name="factor pack",
     )
예제 #3
0
def test_with_unions_not_workable(diverse_tiling):
    strats = list(
        FactorFactory(
            interleaving="all",
            unions=True,
            workable=False,
        )(diverse_tiling))
    assert sum(1 for s in strats if s.workable) == 0
    assert sum(1 for s in strats if not s.workable) == 14
예제 #4
0
def test_rule(factor_rules, factor_with_int_rules, factor_with_mon_int_rules,
              not_fact_tiling):
    all_rules = factor_rules + factor_with_int_rules + factor_with_mon_int_rules
    assert all(not rule.inferrable for rule in all_rules)
    assert all(
        len(rule.strategy.partition) == len(rule.children)
        for rule in all_rules)
    assert all(rule.workable for rule in all_rules)
    assert all(not rule.possibly_empty for rule in all_rules)
    assert all(rule.ignore_parent for rule in all_rules)
    assert not list(FactorFactory(interleaving="all")(not_fact_tiling))
예제 #5
0
def factor() -> dict:
    """Apply factor strategy to given tiling."""
    interleaving = request.args.get("interleaving", None)
    tiling, verification_tactics = _get_tiling_input()
    try:
        strats = FactorFactory(interleaving=interleaving)(tiling)
    except InvalidOperationError as exc:
        raise BadRequest() from exc
    strat = _first_or_bad(strats)
    rule = strat(tiling)
    return rule_as_json(rule, verification_tactics)
예제 #6
0
def test_all_union_rules():
    t = Tiling(obstructions=[
        GriddedPerm(Perm((0, 1)), ((0, 0), ) * 2),
        GriddedPerm(Perm((0, 1)), ((1, 1), ) * 2),
        GriddedPerm(Perm((0, 1)), ((2, 2), ) * 2),
    ])
    fo = FactorFactory(unions=True)(t)
    f2 = Tiling(obstructions=[GriddedPerm(Perm((0, 1)), ((0, 0), ) * 2)])
    # The full factorisation rule is not returned
    assert all(rule(t).children != [f2, f2, f2] for rule in fo)
    # The tiling are marked as not workable by default
    assert all(not rule(t).workable for rule in fo)
    # The workable can be turned on for union of factor
    assert all(rule(t).workable for rule in fo)
예제 #7
0
 def _pack_for_shift(comb_class: Tiling) -> StrategyPack:
     if any(isinstance(ass, ComponentAssumption) for ass in comb_class.assumptions):
         raise InvalidOperationError(
             "Can't find generating function with component assumption."
         )
     return StrategyPack(
         name="LocallyFactorable",
         initial_strats=[FactorFactory(), RequirementCorroborationFactory()],
         inferral_strats=[],
         expansion_strats=[[FactorInsertionFactory()]],
         ver_strats=[
             BasicVerificationStrategy(),
             OneByOneVerificationStrategy(),
             InsertionEncodingVerificationStrategy(),
             MonotoneTreeVerificationStrategy(no_factors=True),
             LocalVerificationStrategy(no_factors=True),
         ],
     )
예제 #8
0
def test_standard_factor():
    tiling = Tiling(
        obstructions=[GriddedPerm(Perm((0, 1)), [(0, 0), (0, 0)])],
        requirements=[[
            GriddedPerm(Perm((0, 1)), [(1, 1), (1, 1)]),
            GriddedPerm(Perm((0, 1)), [(1, 1), (1, 2)]),
        ]],
    )
    strats = [s(tiling).children for s in FactorFactory()(tiling)]
    assert len(strats) == 1
    factors = strats[0]
    assert set(factors) == set([
        Tiling(requirements=[[
            GriddedPerm(Perm((0, 1)), [(0, 0), (0, 0)]),
            GriddedPerm(Perm((0, 1)), [(0, 0), (0, 1)]),
        ]]),
        Tiling(obstructions=[GriddedPerm(Perm((0, 1)), [(0, 0), (0, 0)])]),
    ])
예제 #9
0
def test_factor_all_interleaving(diverse_tiling):
    strats = [
        s(diverse_tiling).children
        for s in FactorFactory(interleaving="all")(diverse_tiling)
    ]
    assert len(strats) == 1
    factors = strats[0]
    assert len(factors) == 4
    print(diverse_tiling)
    assert set(factors) == set([
        Tiling(
            obstructions=[
                GriddedPerm(Perm((0, 2, 3, 1)), [(0, 0), (1, 1), (1, 1),
                                                 (2, 0)])
            ],
            requirements=[[GriddedPerm(Perm((0, )), [(2, 0)])]],
        ),
        Tiling(
            obstructions=[
                GriddedPerm(Perm((0, 1)), [(0, 0), (0, 0)]),
                GriddedPerm(Perm((1, 0)), [(0, 0), (0, 0)]),
            ],
            requirements=[[GriddedPerm(Perm((0, )), [(0, 0)])]],
        ),
        Tiling(
            obstructions=[
                GriddedPerm(Perm((0, 1)), [(0, 0), (0, 0)]),
                GriddedPerm(Perm((1, 0)), [(0, 0), (0, 0)]),
            ],
            requirements=[[GriddedPerm(Perm((0, )), [(0, 0)])]],
        ),
        Tiling(requirements=[[
            GriddedPerm(Perm((1, 0)), [(0, 2), (0, 1)]),
            GriddedPerm(Perm((0, 2, 1)), [(0, 1), (0, 2), (1, 2)]),
        ]]),
    ])
예제 #10
0
def test_with_unions(diverse_tiling):
    strats = list(
        FactorFactory(interleaving="all", unions=True)(diverse_tiling))
    assert len(strats) == 14
    assert sum(1 for s in strats if s.workable) == 1
    assert sum(1 for s in strats if not s.workable) == 13
예제 #11
0
def test_not_factorable(simple_tiling):
    assert len(list(FactorFactory()(simple_tiling))) == 0
    assert len(list(
        FactorFactory(interleaving="monotone")(simple_tiling))) == 0
    assert len(list(FactorFactory(interleaving="all")(simple_tiling))) == 0
예제 #12
0
def factor_with_mon_int_rules(tiling):
    return [s(tiling) for s in FactorFactory(interleaving="monotone")(tiling)]
예제 #13
0
def factor_with_int_rules(tiling):
    return [s(tiling) for s in FactorFactory(interleaving="all")(tiling)]
예제 #14
0
def factor_rules(tiling):
    return [s(tiling) for s in FactorFactory()(tiling)]