def test_allBadSpecsAreBad(spec):
    badSpecs = getAllBadSpecs(spec, 15)
    for badSpec in badSpecs:
        foundry = Foundry(
            Optimize()).applyAndTrackSpec(badSpec).applyAndTrackSpec(spec)
        assert foundry.check() == unsat
        assert len(foundry.getReasonsForUnsat()) != 0
예제 #2
0
def getAllBadSpecs(spec: Spec,
                   maxCount=None,
                   doShuffle=True,
                   filterOutUnsatisfiable=True) -> List[Spec]:
    badSpecs = []
    constraintsToInclude = powset(spec.constraints)
    constraintsToInvert = constraintsToInclude[::-1]

    constraintsToInclude = constraintsToInclude[:-1]
    constraintsToInvert = constraintsToInvert[:-1]

    if doShuffle:
        constraintsToInclude, constraintsToInvert = shuffle(
            constraintsToInclude, constraintsToInvert)

    if maxCount is None:
        maxCount = len(constraintsToInclude)
    else:
        maxCount = min(maxCount, len(constraintsToInclude))

    for i in range(maxCount):
        constraints = [
            pitchesLetterValueValid(spec.line)
        ]  # Needed ensure that the spec doesn't cheat on the gamut constraint
        constraints += constraintsToInclude[i]
        constraints += [x.inv() for x in constraintsToInvert[i]]
        badSpec = Spec(spec.line, constraints, spec.maximisations,
                       spec.minimisations)
        foundry = Foundry(Optimize()).applySpec(badSpec)

        if filterOutUnsatisfiable:
            if foundry.check() == sat:
                badSpecs.append(badSpec)
        else:
            badSpecs.append(badSpec)

    return badSpecs
예제 #3
0
def test_goodCFIsS1Sat(s1GoodCF):
    foundry = Foundry(Optimize())
    foundry.applySpec(s1GoodCF)
    assert foundry.check() == sat
예제 #4
0
def test_badCFIsS3Sat(s3BadCF):
    foundry = Foundry(Optimize())
    foundry.applySpec(s3BadCF)
    assert foundry.check() == sat
def test_allBadSpecsSatisfiable(spec):
    badSpecs = getAllBadSpecs(spec, 15)
    for badSpec in badSpecs:
        foundry = Foundry(Optimize()).applySpec(badSpec)
        assert foundry.check() == sat