from tulip import tlp def computeProba(graph, rules, position, ban): react={} #Reaction rates for M1 react["R1"] = float(1) react["R2"] = float(1) react["R3"] = float(1) react["R4"] = float(1) react["R5"] = float(1) react["R6"] = float(1) react["R7"] = float(1)/float(3) react["R8"] = float(1)/float(3) react["R9"] = float(1)/float(3) react["R10"] = float(1)/float(3) react["R11"] = float(1) react["R12"] = float(1) react["R13"] = float(1) react["R14"] = float(1) #Reaction rates for M2 react["R1_u"] = float(1) react["R2_u"] = float(1) react["R3_u"] = float(1)/float(3) react["R4_u"] = float(1)/float(3) react["R5_u"] = float(1) react["R6_u"] = float(1)/float(9) react["R7_u"] = float(1) #number of applications of each rule num={} #Overall number of rule applications total=0.0 for g in rules: #Check if the rule can be applied. #Equivalent to the strategy match(R). params = tlp.getDefaultPluginParameters("Check Rule", graph) params["Rule Name"] = g params["Property for Position"]=graph.getBooleanProperty(position) params["Property for Ban"]=graph.getBooleanProperty(ban) graph.applyAlgorithm("Check Rule", params) #retrieve the number of morphisms created by the rule number = params["number of instances"] num[g]=float(number) total += number * react[g] #compute application probability for each rule proba={} for g in rules: if(total==0): proba[g]=0 else: proba[g] = num[g]*react[g]/total; #built a list of strings where elements are #the name of a rule followed by its application probability #Tulip does not understand Python dictionary yet list_proba=[] for i in proba: list_proba.append(i) list_proba.append(str(proba[i])) return list_proba