def annotate_properties(cls, program, jani, constant_str, properties, optimality_criterion): constants_map = cls.constants_map(program, jani, constant_str) properties = [ AnnotatedProperty( stormpy.Property(f"property-{i}", p.raw_formula.clone().substitute(constants_map)), jani, add_prerequisites=False # FIXME: check prerequisites? ) for i, p in enumerate(properties) ] if optimality_criterion is not None: optimality_criterion = stormpy.Property( "optimality_property", optimality_criterion.raw_formula.clone().substitute(constants_map) ) return properties, optimality_criterion
def _annotate_properties(self, constant_str): _constants_map = self._constants_map(constant_str, self.sketch) self.properties = [ AnnotatedProperty(stormpy.Property( "property-{}".format(i), p.raw_formula.clone().substitute(_constants_map)), self.sketch, add_prerequisites=self._check_prereq) for i, p in enumerate(self.properties) ]
def get_violation_property(self, best_so_far, bound_translator): vp = stormpy.Property( "optimality_violation", self._criterion.raw_formula.clone(), comment="Optimality criterion with adapted bound") if self._direction == "min": bound = best_so_far - best_so_far * self._eps ct = stormpy.logic.ComparisonType.LESS else: bound = best_so_far + best_so_far * self._eps ct = stormpy.logic.ComparisonType.GREATER bound = bound_translator(bound) vp.raw_formula.set_bound(ct, bound) return vp
def __init__(self, prop, sketch=None, add_prerequisites=True): self.property = prop self.prerequisite_property = None if add_prerequisites and prop.raw_formula.is_reward_operator: assert prop.raw_formula.has_bound assert sketch prereq_thresh = prop.raw_formula.threshold_expr.manager.create_rational( stormpy.Rational(1)) operator = stormpy.ProbabilityOperator( prop.raw_formula.subformula.clone()) operator.set_bound(stormpy.logic.ComparisonType.GEQ, prereq_thresh) new_prop = stormpy.parse_properties_for_jani_model( str(operator), sketch) self.prerequisite_property = stormpy.Property( prop.name + "_prereq", new_prop[0].raw_formula, comment="Prerequisite")
def compute_model_parameters(program, props, compute_prob0_expressions=True): model = stormpy.build_symbolic_model( program.substitute_nonstandard_predicates(), props) model_depth = model.compute_depth() raw_formula_copy = props[0].raw_formula.clone() if raw_formula_copy.has_bound: raise NotImplementedError("Not implemented") else: raw_formula_copy.set_bound( stormpy.logic.ComparisonType.LEQ, program.expression_manager.create_rational(0)) qualitative_prop = stormpy.Property("prob0", raw_formula_copy) result = stormpy.model_checking( model, qualitative_prop, only_initial_states=False).get_truth_values() expressions, mapping = result.to_expression(program.expression_manager) expr_manager = program.expression_manager subst = dict() for k in result.meta_variables: if model.dd_manager.get_meta_variable( k).type == stormpy.DdMetaVariableType.Bool: assert len( model.dd_manager.get_meta_variable(k).compute_indices()) == 1 idx = model.dd_manager.get_meta_variable(k).compute_indices()[0] if idx not in mapping: continue subst[mapping[idx]] = expr_manager.get_variable( model.dd_manager.get_meta_variable(k).name).get_expression() elif model.dd_manager.get_meta_variable( k).type == stormpy.DdMetaVariableType.Int: max_offset = len( model.dd_manager.get_meta_variable(k).compute_indices()) for offset, idx in enumerate( model.dd_manager.get_meta_variable(k).compute_indices()): if idx not in mapping: continue pow = int(math.pow(2, max_offset - offset - 1)) expr = stormpy.storage.Expression.Modulo( stormpy.storage.Expression.Divide( stormpy.storage.Expression.Minus( expr_manager.get_variable( model.dd_manager.get_meta_variable( k).name).get_expression(), expr_manager.create_integer( model.dd_manager.get_meta_variable( k).lowest_value)), expr_manager.create_integer(pow)), expr_manager.create_integer(2)) subst[mapping[idx]] = stormpy.storage.Expression.Eq( expr, expr_manager.create_integer(1)).simplify() else: assert False for k, v in subst.items(): print("{} -> {}".format(k.name, v)) if compute_prob0_expressions: prob0expressions = [] final_res = None for expr in expressions: expr = expr.substitute(subst) if expr.is_variable(): final_res = expr elif expr.get_operand(0).is_variable(): prob0expressions.append( (expr.get_operand(0), expr.get_operand(1))) elif expr.get_operand(1).is_variable(): prob0expressions.append( (expr.get_operand(1), expr.get_operand(0))) prob0expressions.append(final_res) else: prob0expressions = ["false"] return model_depth, prob0expressions