introducing parameters
This commit is contained in:
@@ -2,7 +2,7 @@ from rs.reaction_system import ReactionSystem
|
|||||||
from rs.context_automaton import ContextAutomaton
|
from rs.context_automaton import ContextAutomaton
|
||||||
|
|
||||||
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.reaction_system_with_concentrations_param import ReactionSystemWithConcentrationsParam, ParameterObj
|
||||||
from rs.context_automaton_with_concentrations import ContextAutomatonWithConcentrations
|
from rs.context_automaton_with_concentrations import ContextAutomatonWithConcentrations
|
||||||
|
|
||||||
from rs.extended_context_automaton import ExtendedContextAutomaton
|
from rs.extended_context_automaton import ExtendedContextAutomaton
|
||||||
|
|||||||
@@ -3,17 +3,21 @@ from colour import *
|
|||||||
|
|
||||||
from rs.reaction_system import ReactionSystem
|
from rs.reaction_system import ReactionSystem
|
||||||
|
|
||||||
class ParameterSet(object):
|
class ParameterObj(object):
|
||||||
|
|
||||||
def __init__(self, name):
|
def __init__(self, name):
|
||||||
self.name = name
|
self.name = name
|
||||||
|
|
||||||
|
def __repr__(self):
|
||||||
|
return "@{0}".format(self.name)
|
||||||
|
|
||||||
|
|
||||||
class ReactionSystemWithConcentrationsParam(ReactionSystem):
|
class ReactionSystemWithConcentrationsParam(ReactionSystem):
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
|
||||||
self.reactions = []
|
self.reactions = []
|
||||||
|
self.parametric_reactions = []
|
||||||
self.meta_reactions = dict()
|
self.meta_reactions = dict()
|
||||||
self.permanent_entities = dict()
|
self.permanent_entities = dict()
|
||||||
self.background_set = []
|
self.background_set = []
|
||||||
@@ -85,7 +89,13 @@ class ReactionSystemWithConcentrationsParam(ReactionSystem):
|
|||||||
if R == [] and not ignore_empty_R:
|
if R == [] and not ignore_empty_R:
|
||||||
raise RuntimeError("No reactants defined")
|
raise RuntimeError("No reactants defined")
|
||||||
|
|
||||||
|
#
|
||||||
|
# REACTANTS
|
||||||
|
#
|
||||||
reactants = []
|
reactants = []
|
||||||
|
if isinstance(R, ParameterObj):
|
||||||
|
reactants = R
|
||||||
|
else:
|
||||||
for r in R:
|
for r in R:
|
||||||
self.is_valid_entity_with_concentration(r)
|
self.is_valid_entity_with_concentration(r)
|
||||||
self.has_non_zero_concentration(r)
|
self.has_non_zero_concentration(r)
|
||||||
@@ -93,7 +103,14 @@ class ReactionSystemWithConcentrationsParam(ReactionSystem):
|
|||||||
reactants.append((self.get_entity_id(entity), level))
|
reactants.append((self.get_entity_id(entity), level))
|
||||||
if self.max_concentration < level:
|
if self.max_concentration < level:
|
||||||
self.max_concentration = level
|
self.max_concentration = level
|
||||||
|
|
||||||
|
#
|
||||||
|
# INHIBITORS
|
||||||
|
#
|
||||||
inhibitors = []
|
inhibitors = []
|
||||||
|
if isinstance(I, ParameterObj):
|
||||||
|
inhibitors = I
|
||||||
|
else:
|
||||||
for i in I:
|
for i in I:
|
||||||
self.is_valid_entity_with_concentration(i)
|
self.is_valid_entity_with_concentration(i)
|
||||||
self.has_non_zero_concentration(i)
|
self.has_non_zero_concentration(i)
|
||||||
@@ -101,7 +118,14 @@ class ReactionSystemWithConcentrationsParam(ReactionSystem):
|
|||||||
inhibitors.append((self.get_entity_id(entity), level))
|
inhibitors.append((self.get_entity_id(entity), level))
|
||||||
if self.max_concentration < level:
|
if self.max_concentration < level:
|
||||||
self.max_concentration = level
|
self.max_concentration = level
|
||||||
|
|
||||||
|
#
|
||||||
|
# PRODUCTS
|
||||||
|
#
|
||||||
products = []
|
products = []
|
||||||
|
if isinstance(P, ParameterObj):
|
||||||
|
products = P
|
||||||
|
else:
|
||||||
for p in P:
|
for p in P:
|
||||||
self.is_valid_entity_with_concentration(p)
|
self.is_valid_entity_with_concentration(p)
|
||||||
self.has_non_zero_concentration(p)
|
self.has_non_zero_concentration(p)
|
||||||
@@ -110,6 +134,10 @@ class ReactionSystemWithConcentrationsParam(ReactionSystem):
|
|||||||
|
|
||||||
return reactants, inhibitors, products
|
return reactants, inhibitors, products
|
||||||
|
|
||||||
|
def is_parametric_reaction(self, reaction):
|
||||||
|
result = any([isinstance(r_set, ParameterObj) for r_set in reaction])
|
||||||
|
return result
|
||||||
|
|
||||||
def add_reaction(self, R, I, P):
|
def add_reaction(self, R, I, P):
|
||||||
"""Adds a reaction
|
"""Adds a reaction
|
||||||
|
|
||||||
@@ -119,6 +147,10 @@ class ReactionSystemWithConcentrationsParam(ReactionSystem):
|
|||||||
if P == []:
|
if P == []:
|
||||||
raise RuntimeError("No products defined")
|
raise RuntimeError("No products defined")
|
||||||
reaction = self.process_rip(R,I,P)
|
reaction = self.process_rip(R,I,P)
|
||||||
|
|
||||||
|
if self.is_parametric_reaction(reaction):
|
||||||
|
self.parametric_reactions.append(reaction)
|
||||||
|
else:
|
||||||
self.reactions.append(reaction)
|
self.reactions.append(reaction)
|
||||||
|
|
||||||
def add_reaction_without_reactants(self, R, I, P):
|
def add_reaction_without_reactants(self, R, I, P):
|
||||||
@@ -174,6 +206,14 @@ class ReactionSystemWithConcentrationsParam(ReactionSystem):
|
|||||||
return s
|
return s
|
||||||
|
|
||||||
def state_to_str(self, state):
|
def state_to_str(self, state):
|
||||||
|
"""
|
||||||
|
If state is a parameter, we return
|
||||||
|
the string representation of the whole state
|
||||||
|
which should be the name of the parameter
|
||||||
|
"""
|
||||||
|
if isinstance(state, ParameterObj):
|
||||||
|
return str(state)
|
||||||
|
else:
|
||||||
s = ""
|
s = ""
|
||||||
for ent,level in state:
|
for ent,level in state:
|
||||||
s += self.get_entity_name(ent) + "=" + str(level) + ", "
|
s += self.get_entity_name(ent) + "=" + str(level) + ", "
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ def trivial_param():
|
|||||||
|
|
||||||
r.add_reaction([("x", 1)], [("c", 1)], [("y", 2)])
|
r.add_reaction([("x", 1)], [("c", 1)], [("y", 2)])
|
||||||
r.add_reaction([("y", 1)], [("c", 1)], [("z", 1)])
|
r.add_reaction([("y", 1)], [("c", 1)], [("z", 1)])
|
||||||
r.add_reaction([("z", 1)], [("c", 1)], [("final", 1)])
|
r.add_reaction(ParameterObj("P1"), [("c", 1)], [("final", 1)])
|
||||||
|
|
||||||
c = ContextAutomatonWithConcentrations(r)
|
c = ContextAutomatonWithConcentrations(r)
|
||||||
c.add_init_state("0")
|
c.add_init_state("0")
|
||||||
@@ -43,7 +43,7 @@ def trivial_param():
|
|||||||
BagDescription.f_TRUE(),
|
BagDescription.f_TRUE(),
|
||||||
BagDescription.f_entity("final") >= 1)
|
BagDescription.f_entity("final") >= 1)
|
||||||
|
|
||||||
smt_rsc.check_rsltl(formula=f2)
|
smt_rsc.check_rsltl(formula=f2, max_level=5)
|
||||||
|
|
||||||
|
|
||||||
def example44_param():
|
def example44_param():
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ from logics import rsLTL_Encoder
|
|||||||
# def simplify(x):
|
# def simplify(x):
|
||||||
# return x
|
# return x
|
||||||
|
|
||||||
def MAX(a, b):
|
def z3_max(a, b):
|
||||||
return If(a > b, a, b)
|
return If(a > b, a, b)
|
||||||
|
|
||||||
class SmtCheckerRSCParam(object):
|
class SmtCheckerRSCParam(object):
|
||||||
@@ -31,7 +31,6 @@ class SmtCheckerRSCParam(object):
|
|||||||
|
|
||||||
self.initialise()
|
self.initialise()
|
||||||
|
|
||||||
|
|
||||||
def initialise(self):
|
def initialise(self):
|
||||||
"""Initialises all the variables used by the checker"""
|
"""Initialises all the variables used by the checker"""
|
||||||
|
|
||||||
@@ -41,7 +40,6 @@ class SmtCheckerRSCParam(object):
|
|||||||
|
|
||||||
# intermediate products:
|
# intermediate products:
|
||||||
self.v_improd = []
|
self.v_improd = []
|
||||||
|
|
||||||
self.v_improd_for_entities = []
|
self.v_improd_for_entities = []
|
||||||
|
|
||||||
self.next_level_to_encode = 0
|
self.next_level_to_encode = 0
|
||||||
@@ -55,13 +53,11 @@ class SmtCheckerRSCParam(object):
|
|||||||
|
|
||||||
self.verification_time = None
|
self.verification_time = None
|
||||||
|
|
||||||
|
|
||||||
def reset(self):
|
def reset(self):
|
||||||
"""Reinitialises the state of the checker"""
|
"""Reinitialises the state of the checker"""
|
||||||
|
|
||||||
self.initialise()
|
self.initialise()
|
||||||
|
|
||||||
|
|
||||||
def prepare_all_variables(self):
|
def prepare_all_variables(self):
|
||||||
"""Prepares all the variables"""
|
"""Prepares all the variables"""
|
||||||
|
|
||||||
@@ -70,7 +66,6 @@ class SmtCheckerRSCParam(object):
|
|||||||
self.prepare_intermediate_product_variables()
|
self.prepare_intermediate_product_variables()
|
||||||
self.next_level_to_encode += 1
|
self.next_level_to_encode += 1
|
||||||
|
|
||||||
|
|
||||||
def prepare_context_variables(self):
|
def prepare_context_variables(self):
|
||||||
"""Prepares all the context variables"""
|
"""Prepares all the context variables"""
|
||||||
|
|
||||||
@@ -82,7 +77,6 @@ class SmtCheckerRSCParam(object):
|
|||||||
|
|
||||||
self.v_ctx.append(variables)
|
self.v_ctx.append(variables)
|
||||||
|
|
||||||
|
|
||||||
def prepare_state_variables(self):
|
def prepare_state_variables(self):
|
||||||
"""Prepares all the state variables"""
|
"""Prepares all the state variables"""
|
||||||
|
|
||||||
@@ -95,7 +89,6 @@ class SmtCheckerRSCParam(object):
|
|||||||
|
|
||||||
self.ca_state.append(Int("CA"+str(level)+"_state"))
|
self.ca_state.append(Int("CA"+str(level)+"_state"))
|
||||||
|
|
||||||
|
|
||||||
def prepare_intermediate_product_variables(self):
|
def prepare_intermediate_product_variables(self):
|
||||||
"""
|
"""
|
||||||
Prepares the intermediate product variables
|
Prepares the intermediate product variables
|
||||||
@@ -261,17 +254,16 @@ class SmtCheckerRSCParam(object):
|
|||||||
enc = None
|
enc = None
|
||||||
|
|
||||||
if len(elements) == 1:
|
if len(elements) == 1:
|
||||||
enc = MAX(0, elements[0])
|
enc = z3_max(0, elements[0])
|
||||||
|
|
||||||
elif len(elements) > 1:
|
elif len(elements) > 1:
|
||||||
|
|
||||||
enc = 0
|
enc = 0
|
||||||
for i in range(len(elements) - 1):
|
for i in range(len(elements) - 1):
|
||||||
enc = MAX(enc, MAX(elements[i], elements[i + 1]))
|
enc = z3_max(enc, z3_max(elements[i], elements[i + 1]))
|
||||||
|
|
||||||
return enc
|
return enc
|
||||||
|
|
||||||
|
|
||||||
def enc_automaton_trans(self, level):
|
def enc_automaton_trans(self, level):
|
||||||
"""Encodes the transition relation for the context automaton"""
|
"""Encodes the transition relation for the context automaton"""
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user