You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

55 lines
1.6 KiB

2 months ago
  1. import stormpy
  2. import stormpy.core
  3. import stormpy.examples
  4. import stormpy.examples.files
  5. import stormpy.info
  6. import pycarl
  7. def example_building_models_02():
  8. import stormpy.pars
  9. if stormpy.info.storm_ratfunc_use_cln():
  10. import pycarl.cln as pc
  11. else:
  12. import pycarl.gmp as pc
  13. def make_factorized_rf(var, cache):
  14. num = pc.FactorizedPolynomial(pc.Polynomial(var), cache)
  15. denom = pc.FactorizedPolynomial(pc.Rational(1))
  16. return pc.FactorizedRationalFunction(num, denom)
  17. # And the parametric
  18. path = stormpy.examples.files.drn_pdtmc_die
  19. model = stormpy.build_parametric_model_from_drn(path)
  20. parameters = model.collect_probability_parameters()
  21. bar_parameters = dict()
  22. for p in parameters:
  23. # Ensure that variables with that name are not recognized by pycarl.
  24. assert pycarl.variable_with_name(p.name + "_bar").is_no_variable
  25. bar_parameters[p] = pycarl.Variable(p.name + "_bar")
  26. substitutions = dict([[pc.Polynomial(1) - p, bar_parameters[p]] for p in parameters])
  27. print(substitutions)
  28. matrix = model.transition_matrix
  29. for e in matrix:
  30. val = e.value()
  31. if val.is_constant():
  32. continue
  33. val_pol = val.numerator.polynomial()
  34. cache = val.numerator.cache()
  35. for sub, repl in substitutions.items():
  36. if val_pol - sub == 0:
  37. print("Found substitution")
  38. e.set_value(make_factorized_rf(repl, cache))
  39. break # Assume only one substitution per entry
  40. print(matrix)
  41. if __name__ == '__main__':
  42. example_building_models_02()