def test_build_context(self):
        RAF = Agent("RAF")
        HRAS = Agent("HRAS")
        MEK1 = Agent("MEK1")
        ERK1 = Agent("ERK1")
        SAF1 = Agent("SAF1")
        gtp = Label("GTP")
        phosphate = Label("phosphate")

        predicate = And(
            ModelHasRule(lambda r: And(
                    PregraphHas(r, RAF.bound(HRAS.labeled(gtp))),
                    PregraphHas(r, MEK1),
                    PostgraphHas(r, MEK1.labeled(phosphate))
            )),
            ModelHasRule(lambda r: And(
                    PregraphHas(r, MEK1.labeled(phosphate)),
                    PregraphHas(r, ERK1),
                    PostgraphHas(r, ERK1.labeled(phosphate))
            )),
            ModelHasRule(lambda r: And(
                    PregraphHas(r, ERK1.labeled(phosphate)),
                    PregraphHas(r, SAF1),
                    PostgraphHas(r, SAF1.labeled(phosphate))
            ))
        )
        solver = MySolver("RAF", "HRAS", "MEK1", "ERK1", "SAF1")
        solver.add(predicate)
        self.assertTrue(solver.check())
        self.assertIsNotNone(solver.model())
    def test_some_unsat_thing(self):
        RAF = Agent("RAF")
        HRAS = Agent("HRAS")
        MEK1 = Agent("MEK1")
        gtp = Label("GTP")
        phosphate = Label("phosphate")

        predicate = And(
            ModelHasRule(
                lambda r: And(PregraphHas(r, RAF.bound(HRAS.labeled(gtp))),
                              PregraphHas(r, MEK1),
                              PostgraphHas(r, MEK1.labeled(phosphate)))),
            Not(
                ModelHasRule(
                    lambda r: And(PregraphHas(r, RAF.bound(HRAS.labeled(gtp))),
                                  PregraphHas(r, MEK1),
                                  PostgraphHas(r, MEK1.labeled(phosphate))))))
        solver = MySolver("RAF", "HRAS", "MEK1")
        solver.add(predicate)
        self.assertFalse(solver.check())
        with self.assertRaises(ValueError):
            solver.model()
    def test_some_unsat_thing(self):
        RAF = Agent("RAF")
        HRAS = Agent("HRAS")
        MEK1 = Agent("MEK1")
        gtp = Label("GTP")
        phosphate = Label("phosphate")

        predicate = And(
            ModelHasRule(lambda r: And(
                    PregraphHas(r, RAF.bound(HRAS.labeled(gtp))),
                    PregraphHas(r, MEK1),
                    PostgraphHas(r, MEK1.labeled(phosphate))
            )),
            Not(ModelHasRule(lambda r: And(
                    PregraphHas(r, RAF.bound(HRAS.labeled(gtp))),
                    PregraphHas(r, MEK1),
                    PostgraphHas(r, MEK1.labeled(phosphate))
            )))
        )
        solver = MySolver("RAF", "HRAS", "MEK1")
        solver.add(predicate)
        self.assertFalse(solver.check())
        with self.assertRaises(ValueError):
            solver.model()
    def test_build_context(self):
        RAF = Agent("RAF")
        HRAS = Agent("HRAS")
        MEK1 = Agent("MEK1")
        ERK1 = Agent("ERK1")
        SAF1 = Agent("SAF1")
        gtp = Label("GTP")
        phosphate = Label("phosphate")

        predicate = And(
            ModelHasRule(
                lambda r: And(PregraphHas(r, RAF.bound(HRAS.labeled(gtp))),
                              PregraphHas(r, MEK1),
                              PostgraphHas(r, MEK1.labeled(phosphate)))),
            ModelHasRule(lambda r: And(
                PregraphHas(r, MEK1.labeled(phosphate)), PregraphHas(r, ERK1),
                PostgraphHas(r, ERK1.labeled(phosphate)))),
            ModelHasRule(lambda r: And(
                PregraphHas(r, ERK1.labeled(phosphate)), PregraphHas(r, SAF1),
                PostgraphHas(r, SAF1.labeled(phosphate)))))
        solver = MySolver("RAF", "HRAS", "MEK1", "ERK1", "SAF1")
        solver.add(predicate)
        self.assertTrue(solver.check())
        self.assertIsNotNone(solver.model())
Exemple #5
0
class SolverTestCase(TestCase):

    def setUp(self):
        self.solver = MySolver("A", "B")

    def test_quick_check_true(self):
        self.assertTrue(self.solver.quick_check(syndra_true))

    def test_quick_check_false(self):
        self.assertFalse(self.solver.quick_check(syndra_false))

    def test_quick_check_pushes_and_pops(self):
        self.assertTrue(self.solver.check())
        self.assertFalse(self.solver.quick_check(syndra_false))
        self.assertTrue(self.solver.check())

    def test_context(self):
        with self.solver.context():
            self.solver.add(syndra_false)
            self.assertFalse(self.solver.check())
        self.assertTrue(self.solver.check())

    def test_add(self):
        with self.solver.context():
            self.assertTrue(self.solver.check())
            self.solver.add(syndra_true)
            self.assertTrue(self.solver.check())
            self.solver.add(syndra_false)
            self.assertFalse(self.solver.check())

    def test_quick_check_valid_f_t(self):
        with self.solver.context():
            self.solver.add(syndra_false)
            self.assertTrue(self.solver.quick_check_valid(syndra_true))

    def test_quick_check_valid_f_f(self):
        with self.solver.context():
            self.solver.add(syndra_false)
            self.assertTrue(self.solver.quick_check_valid(syndra_false))

    def test_quick_check_valid_t_t(self):
        with self.solver.context():
            self.solver.add(syndra_true)
            self.assertTrue(self.solver.quick_check_valid(syndra_true))

    def test_quick_check_valid_t_f(self):
        with self.solver.context():
            self.solver.add(syndra_true)
            self.assertFalse(self.solver.quick_check_valid(syndra_false))

    def test_push_pop(self):
        self.assertTrue(self.solver.check())
        self.solver.push()
        self.assertTrue(self.solver.check())
        self.solver.add(syndra_false)
        self.assertFalse(self.solver.check())
        self.solver.pop()
        self.assertTrue(self.solver.check())
Exemple #6
0
if __name__ == '__main__':
    print "---"
    kinase = Agent("kinase")
    # phosphate = Label("phosphate")
    # oxalate = Label("oxalate")
    substrate = Agent("substrate")
    pred = ModelHasRule(lambda r: And(
            PregraphHas(r, kinase.bound(substrate)),
            PostgraphHas(r, kinase),
            PostgraphHas(r, substrate),
    ))

    solver = MySolver("kinase", "substrate")
    print "---"
    solver.add(pred)
    print solver.check()
    print solver.model()
    print "---"

    # RAF = Agent("RAF")
    # HRAS = Agent("HRAS")
    # MEK1 = Agent("MEK1")
    # ERK1 = Agent("ERK1")
    # SAF1 = Agent("SAF1")
    # gtp = Label("GTP")
    # phosphate = Label("phosphate")
    # solver = MySolver("RAF", "HRAS", "MEK1", "ERK1", "SAF1")
    # pred = And(
    #     ModelHasRule(lambda r: And(
    #             PregraphHas(r, RAF.bound(HRAS.labeled(gtp))),
    #             PregraphHas(r, MEK1),
if __name__ == '__main__':
    print "---"
    kinase = Agent("kinase")
    # phosphate = Label("phosphate")
    # oxalate = Label("oxalate")
    substrate = Agent("substrate")
    pred = ModelHasRule(lambda r: And(
        PregraphHas(r, kinase.bound(substrate)),
        PostgraphHas(r, kinase),
        PostgraphHas(r, substrate),
    ))

    solver = MySolver("kinase", "substrate")
    print "---"
    solver.add(pred)
    print solver.check()
    print solver.model()
    print "---"

    # RAF = Agent("RAF")
    # HRAS = Agent("HRAS")
    # MEK1 = Agent("MEK1")
    # ERK1 = Agent("ERK1")
    # SAF1 = Agent("SAF1")
    # gtp = Label("GTP")
    # phosphate = Label("phosphate")
    # solver = MySolver("RAF", "HRAS", "MEK1", "ERK1", "SAF1")
    # pred = And(
    #     ModelHasRule(lambda r: And(
    #             PregraphHas(r, RAF.bound(HRAS.labeled(gtp))),
    #             PregraphHas(r, MEK1),