Skip to content

Commit

Permalink
change policy tree output format
Browse files Browse the repository at this point in the history
  • Loading branch information
laDok8 committed Nov 23, 2024
1 parent 5acbbc5 commit d49ffcd
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 20 deletions.
16 changes: 8 additions & 8 deletions paynt/quotient/mdp_family.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,16 +110,16 @@ def policy_to_state_valuation_actions(self, policy):
]
return state_valuation_to_action

def policy_to_json(self, state_valuation_to_action, indent=""):
import json
json_string = "[\n"
def policy_to_json(self, state_valuation_to_action):
""" DT-Control json format """
json_whole = []
for index,valuation_action in enumerate(state_valuation_to_action):
json_unit = {}
valuation,action = valuation_action
if index > 0:
json_string += ",\n"
json_string += indent + json.dumps(valuation_action)
json_string += "\n" + indent + "]"
return json_string
json_unit["c"] = [{"origin":{"action-label":action}}]
json_unit["s"] = valuation
json_whole.append(json_unit)
return json_whole



Expand Down
15 changes: 6 additions & 9 deletions paynt/synthesizer/policy_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -792,23 +792,20 @@ def evaluate_all(self, family, prop, keep_value_only=False):


def run(self, optimum_threshold=None):
return self.evaluate(export_filename_base=paynt.synthesizer.synthesizer.Synthesizer.export_synthesis_filename_base)
return self.evaluate()


def export_evaluation_result(self, evaluations, export_filename_base):
import json
policies = self.policy_tree.extract_policies(self.quotient)
policies_string = "{\n"
policies_json = {}
for index,key_value in enumerate(policies.items()):
policy_id,policy = key_value
if index > 0:
policies_string += ",\n"
policy_json = self.quotient.policy_to_json(policy, indent= " ")
policy_json = self.quotient.policy_to_json(policy)
policies_json[policy_id] = policy_json
policies_string = json.dumps(policies_json, indent=4)

policies_string += f'"{policy_id}" : {policy_json}'
policies_string += "}\n"

policies_filename = export_filename_base + ".json"
policies_filename = export_filename_base + ".paynt.json"
with open(policies_filename, 'w') as file:
file.write(policies_string)

Expand Down
6 changes: 3 additions & 3 deletions paynt/synthesizer/synthesizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def export_evaluation_result(self, evaluations, export_filename_base):
''' to be overridden '''
pass

def evaluate(self, family=None, prop=None, keep_value_only=False, print_stats=True, export_filename_base=None):
def evaluate(self, family=None, prop=None, keep_value_only=False, print_stats=True):
'''
Evaluate each member of the family wrt the given property.
:param family if None, then the design space of the quotient will be used
Expand All @@ -143,8 +143,8 @@ def evaluate(self, family=None, prop=None, keep_value_only=False, print_stats=Tr
self.stat.finished_evaluation(evaluations)
logger.info("evaluation finished")

if export_filename_base is not None:
self.export_evaluation_result(evaluations, export_filename_base)
if self.export_synthesis_filename_base is not None:
self.export_evaluation_result(evaluations, self.export_synthesis_filename_base)

if print_stats:
self.stat.print()
Expand Down

0 comments on commit d49ffcd

Please sign in to comment.