This commit is contained in:
Artur Meski
2017-08-13 16:02:22 +01:00
parent c83779c9d5
commit dd4ea5d939

View File

@@ -28,6 +28,7 @@ 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"""
@@ -48,11 +49,13 @@ 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"""
@@ -61,6 +64,7 @@ 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"""
@@ -72,6 +76,7 @@ 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"""
@@ -84,6 +89,7 @@ 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
@@ -135,6 +141,7 @@ class SmtCheckerRSCParam(object):
enc_nz = simplify(And(enc_nz, v >= 0, v_ctx >= 0, v <= e_max, v_ctx <= e_max)) enc_nz = simplify(And(enc_nz, v >= 0, v_ctx >= 0, v <= e_max, v_ctx <= e_max))
return enc_nz return enc_nz
def enc_init_state(self, level): def enc_init_state(self, level):
"""Encodes the initial state at the given level""" """Encodes the initial state at the given level"""
@@ -149,6 +156,7 @@ class SmtCheckerRSCParam(object):
init_state_enc = simplify(And(rs_init_state_enc, ca_init_state_enc)) init_state_enc = simplify(And(rs_init_state_enc, ca_init_state_enc))
return init_state_enc return init_state_enc
def enc_produced_concentration(self, level, prod_entity): def enc_produced_concentration(self, level, prod_entity):
"""Encodes the produced concentrations for the given level and entity""" """Encodes the produced concentrations for the given level and entity"""
@@ -290,6 +298,7 @@ class SmtCheckerRSCParam(object):
def enc_transition_relation(self, level): def enc_transition_relation(self, level):
return simplify(And(self.enc_rs_trans(level), self.enc_automaton_trans(level))) return simplify(And(self.enc_rs_trans(level), self.enc_automaton_trans(level)))
def enc_rs_trans(self, level): def enc_rs_trans(self, level):
"""Encodes the transition relation""" """Encodes the transition relation"""
@@ -309,6 +318,7 @@ class SmtCheckerRSCParam(object):
return enc_trans return enc_trans
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"""
@@ -336,6 +346,7 @@ class SmtCheckerRSCParam(object):
return enc_trans return enc_trans
def enc_exact_state(self, level, state): def enc_exact_state(self, level, state):
"""Encodes the state at the given level with the exact concentration values""" """Encodes the state at the given level with the exact concentration values"""
@@ -355,6 +366,7 @@ class SmtCheckerRSCParam(object):
# enc = And(enc, self.v[level][entity] == 0) # enc = And(enc, self.v[level][entity] == 0)
# #
# return simplify(enc) # return simplify(enc)
def enc_min_state(self, level, state): def enc_min_state(self, level, state):
"""Encodes the state at the given level with the minimal required concentration levels""" """Encodes the state at the given level with the minimal required concentration levels"""
@@ -370,6 +382,7 @@ class SmtCheckerRSCParam(object):
# enc = And(enc, self.v[level][entity]) # enc = And(enc, self.v[level][entity])
return simplify(enc) return simplify(enc)
def enc_state_with_blocking(self, level, prop): def enc_state_with_blocking(self, level, prop):
"""Encodes the state at the given level with blocking certain concentrations""" """Encodes the state at the given level with blocking certain concentrations"""
@@ -386,6 +399,7 @@ class SmtCheckerRSCParam(object):
enc = And(enc, self.v[level][e_id] < conc) enc = And(enc, self.v[level][e_id] < conc)
return simplify(enc) return simplify(enc)
def decode_witness(self, max_level, print_model=False): def decode_witness(self, max_level, print_model=False):
@@ -419,6 +433,7 @@ class SmtCheckerRSCParam(object):
print(" " + self.rs.get_entity_name(var_id) + "=" + var_rep, end="") print(" " + self.rs.get_entity_name(var_id) + "=" + var_rep, end="")
print(" }") print(" }")
def check_rsltl(self, formula, print_witness=True, print_time=True, print_mem=True, max_level=None): def check_rsltl(self, formula, print_witness=True, print_time=True, print_mem=True, max_level=None):
"""Bounded Model Checking for rsLTL properties""" """Bounded Model Checking for rsLTL properties"""
@@ -495,6 +510,7 @@ class SmtCheckerRSCParam(object):
if print_mem: if print_mem:
print("[i] {: >60}".format(" Memory: " + repr(resource.getrusage(resource.RUSAGE_SELF).ru_maxrss/(1024*1024)) + " MB")) print("[i] {: >60}".format(" Memory: " + repr(resource.getrusage(resource.RUSAGE_SELF).ru_maxrss/(1024*1024)) + " MB"))
def dummy_unroll(self, levels): def dummy_unroll(self, levels):
"""Unrolls the variables for testing purposes""" """Unrolls the variables for testing purposes"""
@@ -504,6 +520,7 @@ class SmtCheckerRSCParam(object):
self.current_level += 1 self.current_level += 1
print(C_MARK_INFO + " Dummy Unrolling done.") print(C_MARK_INFO + " Dummy Unrolling done.")
def state_equality(self, level_A, level_B): def state_equality(self, level_A, level_B):
"""Encodes equality of two states at two different levels""" """Encodes equality of two states at two different levels"""
@@ -518,6 +535,7 @@ class SmtCheckerRSCParam(object):
eq_enc = simplify(And(eq_enc, eq_enc_ctxaut)) eq_enc = simplify(And(eq_enc, eq_enc_ctxaut))
return eq_enc return eq_enc
def get_loop_encodings(self): def get_loop_encodings(self):
@@ -537,6 +555,7 @@ class SmtCheckerRSCParam(object):
return loop_enc return loop_enc
def check_reachability(self, state, print_witness=True, def check_reachability(self, state, print_witness=True,
print_time=True, print_mem=True, max_level=1000): print_time=True, print_mem=True, max_level=1000):
"""Main testing function""" """Main testing function"""
@@ -598,9 +617,11 @@ class SmtCheckerRSCParam(object):
if print_mem: if print_mem:
print("[i] {: >60}".format(" Memory: " + repr(resource.getrusage(resource.RUSAGE_SELF).ru_maxrss/(1024*1024)) + " MB")) print("[i] {: >60}".format(" Memory: " + repr(resource.getrusage(resource.RUSAGE_SELF).ru_maxrss/(1024*1024)) + " MB"))
def get_verification_time(self): def get_verification_time(self):
return self.verification_time return self.verification_time
def show_encoding(self, state, print_witness=True, def show_encoding(self, state, print_witness=True,
print_time=False, print_mem=False, max_level=100): print_time=False, print_mem=False, max_level=100):
"""Encoding debug function""" """Encoding debug function"""
@@ -656,3 +677,5 @@ class SmtCheckerRSCParam(object):
if not (x == "y" or x == "yes"): if not (x == "y" or x == "yes"):
break break
# EOF