RSC with Param; RSCA for Param, SMTChecker for Param

This commit is contained in:
Artur Meski
2017-08-13 13:48:42 +01:00
parent e1db24c8a9
commit 27c86497e4
5 changed files with 151 additions and 36 deletions

View File

@@ -1,4 +1,5 @@
from rs.reaction_system_with_concentrations import ReactionSystemWithConcentrations from rs.reaction_system_with_concentrations import ReactionSystemWithConcentrations
from rs.reaction_system_with_concentrations_param import ReactionSystemWithConcentrationsParam
from rs.context_automaton_with_concentrations import ContextAutomatonWithConcentrations from rs.context_automaton_with_concentrations import ContextAutomatonWithConcentrations
class ReactionSystemWithAutomaton(object): class ReactionSystemWithAutomaton(object):
@@ -11,6 +12,17 @@ class ReactionSystemWithAutomaton(object):
self.rs.show(soft) self.rs.show(soft)
self.ca.show() self.ca.show()
def is_concentr_and_param_compatible(self):
"""
Checks if the underlying RS/CA are compatible
with parameters and concentrations
"""
if not isinstance(self.rs, ReactionSystemWithConcentrationsParam):
return False
if not isinstance(self.ca, ContextAutomatonWithConcentrations):
return False
return True
def is_with_concentrations(self): def is_with_concentrations(self):
if not isinstance(self.rs, ReactionSystemWithConcentrations): if not isinstance(self.rs, ReactionSystemWithConcentrations):
return False return False

View File

@@ -102,7 +102,10 @@ class ReactionSystemWithConcentrationsParam(ReactionSystem):
return reactants,inhibitors,products return reactants,inhibitors,products
def add_reaction(self, R, I, P): def add_reaction(self, R, I, P):
"""Adds a reaction""" """Adds a reaction
R, I, and P are sets of entities (not their IDs)
"""
if P == []: if P == []:
raise RuntimeError("No products defined") raise RuntimeError("No products defined")
@@ -201,6 +204,8 @@ class ReactionSystemWithConcentrationsParam(ReactionSystem):
def get_reactions_by_product(self): def get_reactions_by_product(self):
"""Sorts reactions by their products and returns a dictionary of products""" """Sorts reactions by their products and returns a dictionary of products"""
assert False
if self.reactions_by_prod != None: if self.reactions_by_prod != None:
return self.reactions_by_prod return self.reactions_by_prod
@@ -247,6 +252,9 @@ class ReactionSystemWithConcentrationsParam(ReactionSystem):
return reactions_by_prod return reactions_by_prod
def get_reaction_system(self): def get_reaction_system(self):
"""
Translates RSC into RS
"""
rs = ReactionSystem() rs = ReactionSystem()
@@ -372,36 +380,51 @@ class ReactionSystemWithConcentrationsParam(ReactionSystem):
return rs return rs
class ReactionSystemWithAutomaton(object): # class ReactionSystemWithAutomaton(object):
#
def __init__(self, reaction_system, context_automaton): # def __init__(self, reaction_system, context_automaton):
self.rs = reaction_system # self.rs = reaction_system
self.ca = context_automaton # self.ca = context_automaton
#
def show(self, soft=False): # def show(self, soft=False):
self.rs.show(soft) # self.rs.show(soft)
self.ca.show() # self.ca.show()
#
def is_with_concentrations(self): # def is_concentr_and_param_compatible(self):
if not isinstance(self.rs, ReactionSystemWithConcentrations): # """
return False # Checks if the underlying RS/CA are compatible
if not isinstance(self.ca, ContextAutomatonWithConcentrations): # with parameters and concentrations
return False # """
return True # if not isinstance(self.rs, ReactionSystemWithConcentrationsParam):
# return False
def sanity_check(self): # if not isinstance(self.ca, ContextAutomatonWithConcentrations):
pass # return False
# return True
def get_ordinary_reaction_system_with_automaton(self): #
# def is_with_concentrations(self):
if not self.is_with_concentrations(): # """
raise RuntimeError("Not RS/CA with concentrations") # Checks if the underlying RS and CA provide
# concentration levels
ors = self.rs.get_reaction_system() # """
oca = self.ca.get_automaton_with_flat_contexts(ors) # if not isinstance(self.rs, ReactionSystemWithConcentrations):
# return False
return ReactionSystemWithAutomaton(ors, oca) # if not isinstance(self.ca, ContextAutomatonWithConcentrations):
# return False
# return True
#
# def sanity_check(self):
# pass
#
# def get_ordinary_reaction_system_with_automaton(self):
#
# if not self.is_with_concentrations():
# raise RuntimeError("Not RS/CA with concentrations")
#
# ors = self.rs.get_reaction_system()
# oca = self.ca.get_automaton_with_flat_contexts(ors)
#
# return ReactionSystemWithAutomaton(ors, oca)
#
# class ReactionSystemWithConcentrationWithAutomaton(ReactionSystemWithAutomaton): # class ReactionSystemWithConcentrationWithAutomaton(ReactionSystemWithAutomaton):
# #

View File

@@ -11,7 +11,86 @@ def run_tests():
# process() # process()
# heat_shock_response() # heat_shock_response()
# scalable_chain(print_system=True) # scalable_chain(print_system=True)
example44() # example44()
example44_param()
def example44_param():
r = ReactionSystemWithConcentrationsParam()
r.add_bg_set_entity(("x",2))
r.add_bg_set_entity(("y",4))
r.add_bg_set_entity(("h",2))
r.add_bg_set_entity(("m",1))
r.add_reaction([("y",1),("x",1)], [("y",2),("h",1)], [("y",2)])
r.add_reaction([("y",2),("x",2)], [("y",3),("h",1)], [("y",3)])
r.add_reaction([("y",3),("h",1)], [("y",4),("h",2)], [("y",4)])
r.add_reaction([("y",4),("h",1)], [("h",2)], [("y",3)])
r.add_reaction([("y",4),("x",2)], [("h",1)], [("y",2)])
r.add_reaction([("m",1)], [("y",3)], [("m",1)])
c = ContextAutomatonWithConcentrations(r)
c.add_init_state("0")
c.add_state("1")
c.add_transition("0", [("y",1),("m",1),("x",1)], "1")
c.add_transition("1", [("x",1)], "1")
c.add_transition("1", [("x",1),("h",1)], "1")
c.add_transition("1", [("x",2)], "1")
c.add_transition("1", [("x",2),("h",1)], "1")
c.add_transition("1", [("h",1)], "1")
rc = ReactionSystemWithAutomaton(r,c)
rc.show()
smt_rsc = SmtCheckerRSCParam(rc)
# Universal property which seems to be true: (holds also existentially)
f1 = Formula_rsLTL.f_G(BagDescription.f_entity("x") > 0,
Formula_rsLTL.f_Implies(
(BagDescription.f_entity('y') == 2),
Formula_rsLTL.f_X(
(BagDescription.f_entity("x") > 1),
BagDescription.f_entity("y") >= 3
)
)
)
# lets see if we can find a counterexample to this property:
neg_f1 = Formula_rsLTL.f_F(BagDescription.f_entity("x") > 0,
Formula_rsLTL.f_And(
(BagDescription.f_entity('y') == 2),
Formula_rsLTL.f_X(
(BagDescription.f_entity("x") > 1),
BagDescription.f_entity("y") < 3
)
)
)
# we fix the property f1
# this one holds:
f2 = Formula_rsLTL.f_G(BagDescription.f_entity("x") > 0,
Formula_rsLTL.f_Implies(
(BagDescription.f_entity('y') == 2),
Formula_rsLTL.f_X(
(BagDescription.f_entity("x") > 1) & (BagDescription.f_entity("h") < 1),
BagDescription.f_entity("y") >= 3
)
)
)
# neg_f1 = Formula_rsLTL.f_X(BagDescription.f_TRUE(), Formula_rsLTL.f_F(BagDescription.f_entity("x") > 0,
# Formula_rsLTL.f_And(
# (BagDescription.f_entity('y') > 0),
# Formula_rsLTL.f_X(
# BagDescription.f_entity("x") > 0,
# Formula_rsLTL.f_X(
# BagDescription.f_entity("x") > 1,
# BagDescription.f_entity("y") < 3
# )
# )
# )
# ))
# smt_rsc.check_rsltl(formula=neg_f1)
def example44(): def example44():

View File

@@ -1,5 +1,6 @@
#from smt.smt_checker import SmtChecker #from smt.smt_checker import SmtChecker
from smt.smt_checker_rs import SmtCheckerRS from smt.smt_checker_rs import SmtCheckerRS
from smt.smt_checker_rsc import SmtCheckerRSC from smt.smt_checker_rsc import SmtCheckerRSC
from smt.smt_checker_rsc_param import SmtCheckerRSCParam
from smt.smt_checker_rs_na import SmtCheckerRSNA from smt.smt_checker_rs_na import SmtCheckerRSNA
from smt.smt_checker_distrib_rs import SmtCheckerDistribRS from smt.smt_checker_distrib_rs import SmtCheckerDistribRS

View File

@@ -14,14 +14,14 @@ from logics import rsLTL_Encoder
# def simplify(x): # def simplify(x):
# return x # return x
class SmtCheckerRSC(object): class SmtCheckerRSCParam(object):
def __init__(self, rsca): def __init__(self, rsca):
rsca.sanity_check() rsca.sanity_check()
if not rsca.is_with_concentrations(): if not rsca.is_concentr_and_param_compatible():
raise RuntimeError("RS and CA with concentrations expected") raise RuntimeError("RS and CA with concentrations (and parameters) expected")
self.rs = rsca.rs self.rs = rsca.rs
self.ca = rsca.ca self.ca = rsca.ca