def coputeButtSuccProb(): #if flagCompute1.get()==0: node.parmetersInTheWorld = 1 #root.treeToXml("output/testforGUI.xml") node.debugMode = False if CheckVar1.get(): tree = xmlTree(filePlanName.get(), None, filePlanAttribName.get()) root = tree.getRoot() root.treeToXml("output/testforGUI.xml") for j in range(node.parmetersInTheWorld): root.runPlanAccurate(j) gui.addLableRes( root.getChild(0).getProbAtIndex(j), None, 0.5, 0.25) if exportVarSuccProb.get(): fd.write("Accurate: Result: " + str(root.getChild(0).getProbAtIndex(j)) + " \n") root.treeToXml("output/testGUI1.xml") if CheckVar2.get(): tree = xmlTree(filePlanName.get(), None, filePlanAttribName.get()) root = tree.getRoot() for j in range(node.parmetersInTheWorld): for i in range(int(varSamplSuccProb.get())): root.runPlan(j) gui.addLableRes( root.getChild(0).getProbAtIndex(j), None, 0.5, 0.35) if exportVarSuccProb.get(): fd.write("Sampeling: # samples: " + varSamplSuccProb.get() + " Result: " + str(root.getChild(0).getProbAtIndex(j)) + " \n") root.treeToXml("output/testGUI2.xml")
def test5(): print "-------TEST 5-------" start = time.time() tree = xmlTree("tests/small_test.xml") root = tree.getRoot() node.parmetersInTheWorld = 1 node.debugMode = False for i in range(1000): root.runPlan(0) for i in range(1000): root.runPlan(1) root.treeToXml("output/small_test_after_offline.xml") print "Finished gathering offline statistics." print "-------Debug mode-------" tree = xmlTree("output/small_test_after_offline.xml") node.debugMode = True root = tree.getRoot() for i in range(1000): root.runPlan(0) for i in range(1000): root.runPlan(1) root.treeToXml("output/small_test_debug_mode.xml") print("test 5: success!") print "Success probability in debug mode: Clear sky = %f, Cloudy = %f" %(root.getChild(0).getProbAtIndex(0),root.getChild(0).getProbAtIndex(1)) print "Average success time in debug mode with clear sky = %f" %(root.getChild(0).getAverageSuccTime(0)) print "Average success time in debug mode when Cloudy = %f" %(root.getChild(0).getAverageSuccTime(1)) elapsed = (time.time() - start) print "Time: %f" %elapsed print "-----------------------"
def coputeSuccProb(fd, stat, filePlanName, filePlanAttribName, runtime=0, samples=0): #if flagCompute1.get()==0: node.parmetersInTheWorld = 1 #root.treeToXml("output/testforGUI.xml") node.debugMode = False if stat[0]: tree = xmlTree(filePlanName, None, filePlanAttribName) root = tree.getRoot() root.treeToXml(__location__ + "/output/testforGUI.xml") for j in range(node.parmetersInTheWorld): root.runPlanAccurate(j) fd.write("Accurate: Result: " + str(root.getChild(0).getProbAtIndex(j)) + " \n") root.treeToXml(__location__ + "/output/testGUI1.xml") if stat[1]: tree = xmlTree(filePlanName, None, filePlanAttribName) root = tree.getRoot() for j in range(node.parmetersInTheWorld): for i in range(int(samples)): root.runPlan(j) fd.write("Sampeling: # samples: " + str(samples) + " Result: " + str(root.getChild(0).getProbAtIndex(j)) + " \n") root.treeToXml(__location__ + "/output/testGUI.xml")
def test25(): print "-------TEST 25-------" start = time.time() tree = xmlTree("tests/small_test.xml") root = tree.getRoot() node.parmetersInTheWorld = 1 node.debugMode = False for i in range(1000): root.runPlan(0) for i in range(1000): root.runPlan(1) root.treeToXml("output/small_test_after_offline.xml") print "Finished gathering offline statistics." print "-------Debug mode-------" node.debugMode = True tree = xmlTree("output/small_test_after_offline.xml") root = tree.getRoot() for i in range(100): root.runPlan(0) for i in range(100): root.runPlan(1) root.treeToXml("output/small_test_debug_mode.xml") print("test 4.3: success!") print "Success probability in debug mode: Clear sky = %f, Cloudy = %f" % ( root.getChild(0).getProbAtIndex(0), root.getChild(0).getProbAtIndex(1)) print "Average success time in debug mode with clear sky = %f" % ( root.getChild(0).getAverageSuccTime(0)) print "Average success time in debug mode when Cloudy = %f" % ( root.getChild(0).getAverageSuccTime(1)) elapsed = (time.time() - start) print "Time: %f" % elapsed print "-----------------------"
def coputeButtDur(): node.parmetersInTheWorld = 1 node.debugMode = False if CheckVar12.get(): tree = xmlTree(filePlanName.get(), None, filePlanAttribName.get()) root = tree.getRoot() for j in range(node.parmetersInTheWorld): root.runPlanAccurate(j) tmp = root.getChild(0).getLessThenTProb(j, float(varT.get())) gui.addLableRes( root.getChild(0).getLessThenTProb(j, float(varT.get())), None, 0.5, 0.62) if exportVarSuccProb.get(): fd.write("Accurate: " + "T:" + varT.get() + " Result: " + str(tmp) + " \n") root.treeToXml("output/testGUI1.xml") if CheckVar22.get(): tree = xmlTree(filePlanName.get(), None, filePlanAttribName.get()) root = tree.getRoot() for j in range(node.parmetersInTheWorld): root.runPlanApproximate(j, float(varAppParam.get()), float(varT.get())) tmp = root.getChild(0).getLessThenTProb(j, float(varT.get())) gui.addLableRes( root.getChild(0).getLessThenTProb(j, float(varT.get())), None, 0.5, 0.72) gui.addLable("Error Range:[", None, 0.6, 0.72) gui.addLableRange( str(root.getChild(0).getLBound(j)) + "," + str(root.getChild(0).getUBound(j)) + "]", None, 0.71, 0.72) if exportVarSuccProb.get(): fd.write("Approxite: " + "T:" + varT.get() + " Result: " + str(tmp) + " \n") root.treeToXml("output/testGUI2.xml") if CheckVar32.get(): tree = xmlTree(filePlanName.get(), None, filePlanAttribName.get()) root = tree.getRoot() for j in range(node.parmetersInTheWorld): for i in range(int(varSamplDur.get())): root.runPlan(j) gui.addLableRes( root.getChild(0).getLessThenTProb(j, float(varT.get())), None, 0.5, 0.82) tmp = root.getChild(0).getLessThenTProb(j, float(varT.get())) if exportVarSuccProb.get(): fd.write("Sampeling: # samples: " + varSamplSuccProb.get() + "T:" + varT.get() + " Result: " + str(tmp) + " \n") root.treeToXml("output/testGUI3.xml")
def updateNode(idStr, dur, T, tree): fd = open(__location__ + "/output/outputFile", "a") finished_node = tree.getWrappedNode(idStr) finished_node.setDebug("True" + " " + dur) tree.treeToXml(__location__ + "/output/" + Ctree.filePath[6:-4] + "_after_run_debug_true.xml") tree = xmlTree(__location__ + "/output/" + Ctree.filePath[6:-4] + "_after_run_debug_true.xml") root = tree.getRoot() node.debugMode = True for i in range(1000): root.runPlan(0) if root: fd.write( "-------------------------------Astimated Duration After Step " + idStr + "-----------------------------------\n") fd.write("Success probability in offline mode monitor: Mission: " + str(root.getChild(0).getLessThenTProb(0, T)) + " \n") fd.write("Average success time monitor: Mission: " + str(root.getChild(0).getAverageSuccTime(0)) + " \n") fd.write("SD success time monitor: Mission:" + str(root.getChild(0).getSDSuccTime(0)) + " \n") fd.close() root.treeToXml(__location__ + "/output/plan_after_run.xml") return (root.getChild(0).getLessThenTProb(0, T), root.getChild(0).getAverageSuccTime(0), root.getChild(0).getSDSuccTime(0))
def test30(): start = time.time() tree = xmlTree("tests/small_test_integration.xml", None, "tests/small_test_integration_tsk_attrib.xml") root = tree.getRoot() node.parmetersInTheWorld = 1 # root.treeToXml("output/event3_m.xml") print("test 30.1: success!") node.debugMode = False for i in range(1000): root.runPlan(0) # for i in range(100): # root.runPlan(1) root.treeToXml("output/small_test_integration.xml") print("test 30.2: success!") print "Success probability in offline mode: %f" % root.getChild( 0).getProbAtIndex(0) print "Average success time = %f" % root.getChild(0).getAverageSuccTime(0) elapsed = (time.time() - start) print "Time: %f" % elapsed
def test9(): tree = xmlTree("tests/test9.xml") #root it node type plan root = tree.getRoot() #this child is type- seq child = root.getChild(0) #this child is type- tsk tskChild = child.getChild(0) #get dist from the distTable distC = tskChild.getSuccDistAtIndex(2) distU = tskChild.getSuccDistAtIndex(1) distN = tskChild.getSuccDistAtIndex(0) if( distC.whoAmI() == "Computed" and float(distC.getCountByTime(0.1)) == 5 and float(distC.getCountByTime(257)) == 977): print ("test 9.1: success!") else: ("test 9: failed :-( - check computed dist") if( distU.whoAmI() == "Uniform" and float(distU.parmA) == 0 and float(distU.parmB) == 5 ): print ("test 9.2: success!") else: ("test 9.2: failed :-( - check uniform dist") if ( distN.whoAmI() == "Normal"): print ("test 9.3: success!") else: ("test 9.3: failed :-( - check normal dist")
def test3(): start = time.time() tree = xmlTree("tests/event3.xml") root = tree.getRoot() node.parmetersInTheWorld = 1 root.treeToXml("output/testE31.xml") print("test 3.1: success!") node.debugMode = False for i in range(100): root.runPlan(0) for i in range(100): root.runPlan(1) root.treeToXml("output/testE32.xml") print("test 3.2: success!") print "Success probability in offline mode: Clear sky = %f, Cloudy = %f" %(root.getChild(0).getProbAtIndex(0),root.getChild(0).getProbAtIndex(1)) print "Average success time with clear sky = %f" %(root.getChild(0).getAverageSuccTime(0)) print "Average success time when Cloudy = %f" %(root.getChild(0).getAverageSuccTime(1)) elapsed = (time.time() - start) print "Time: %f" %elapsed print "-------Debug mode-------" node.debugMode = True for i in range(100): root.runPlan(0) for i in range(100): root.runPlan(1) root.treeToXml("output/testE33.xml") print("test 3.3: success!") print "Success probability in debug mode: Clear sky = %f, Cloudy = %f" %(root.getChild(0).getProbAtIndex(0),root.getChild(0).getProbAtIndex(1)) print "Average success time in debug mode with clear sky = %f" %(root.getChild(0).getAverageSuccTime(0)) print "Average success time in debug mode when Cloudy = %f" %(root.getChild(0).getAverageSuccTime(1)) elapsed = (time.time() - start) elapsed = (time.time() - start) print "Time: %f" %elapsed
def test5(): tree = xmlTree("tests/test3.xml") #remember- root is alwayes type/tag- plan root = tree.getRoot() ans = [] ans.append(root.getAttrib("probability")) firstChild = root.getChild(0) ans.append(firstChild.getAttrib("probability")) ans.append((firstChild.getChild(0)).getAttrib("probability")) ans.append((firstChild.getChild(1)).getAttrib("probability")) ans.append((firstChild.getChild(2)).getAttrib("probability")) ans.append((firstChild.getChild(3)).getAttrib("probability")) ans.append((firstChild.getChild(4)).getAttrib("probability")) ans.append((firstChild.getChild(5)).getAttrib("probability")) #ans 1+2 dosn't have attribut- None if ans[0] != None or ans[1] != None: print("test 5: failed :-(") for index in range(2, 7): if ans[index] != "0.1 0.5": print("test 5: failed :-(") print(index) print("test 5: success!")
def test5(): tree = xmlTree("tests/test3.xml") #remember- root is alwayes type/tag- plan root = tree.getRoot() ans = [] ans.append(root.getAttrib("probability")) firstChild = root.getChild(0) ans.append(firstChild.getAttrib("probability")) ans.append((firstChild.getChild(0)).getAttrib("probability")) ans.append((firstChild.getChild(1)).getAttrib("probability")) ans.append((firstChild.getChild(2)).getAttrib("probability")) ans.append((firstChild.getChild(3)).getAttrib("probability")) ans.append((firstChild.getChild(4)).getAttrib("probability")) ans.append((firstChild.getChild(5)).getAttrib("probability")) #ans 1+2 dosn't have attribut- None if ans[0] !=None or ans[1] != None : print("test 5: failed :-(") for index in range(2,7): if ans[index] != "0.1 0.5": print("test 5: failed :-(") print (index) print("test 5: success!")
def test19(): tree = xmlTree("tests/test9.xml") #root it node type plan root = tree.getRoot() #this child is type- seq child = root.getChild(0) #this child is type- tsk tskChild = child.getChild(0) #get dist from the distTable distC = tskChild.getSuccDistAtIndex(2) distU = tskChild.getSuccDistAtIndex(1) distN = tskChild.getSuccDistAtIndex(0) if (distC.whoAmI() == "Computed" and float(distC.getCountByTime(0.1)) == 5 and float(distC.getCountByTime(257)) == 977): print("test 19.1: success!") else: ("test 19: failed :-( - check computed dist") if (distU.whoAmI() == "Uniform" and float(distU.parmA) == 0 and float(distU.parmB) == 5): print("test 19.2: success!") else: ("test 19.2: failed :-( - check uniform dist") if (distN.whoAmI() == "Normal"): print("test 19.3: success!") else: ("test 19.3: failed :-( - check normal dist")
def coputeDur(fd, stat, filePlanName, filePlanAttribName, T, runtime=0, accuracy=0, samples=0): node.parmetersInTheWorld = 1 node.debugMode = False if stat[0]: tree = xmlTree(filePlanName, None, filePlanAttribName) root = tree.getRoot() tree.createWrapperTreeMap("id") for j in range(node.parmetersInTheWorld): root.runPlanAccurate(j) tmp = root.getChild(0).getLessThenTProb(j, float(T)) fd.write("Accurate: " + "T:" + str(T) + " Result: " + str(tmp) + " \n") root.treeToXml(__location__ + "/output/testGUI1.xml") return tree if stat[1]: tree = xmlTree(filePlanName, None, filePlanAttribName) root = tree.getRoot() tree.createWrapperTreeMap("id") for j in range(node.parmetersInTheWorld): root.runPlanApproximate(j, float(accuracy), float(T)) tmp = root.getChild(0).getLessThenTProb(j, float(T)) fd.write("Approxite: " + "T:" + str(T) + " Result: " + str(tmp) + " \n") root.treeToXml(__location__ + "/output/testGUI2.xml") return tree if stat[2]: tree = xmlTree(filePlanName, None, filePlanAttribName) root = tree.getRoot() tree.createWrapperTreeMap("id") for j in range(node.parmetersInTheWorld): for i in range(int(samples)): root.runPlan(j) tmp = root.getChild(0).getLessThenTProb(j, float(T)) fd.write("Sampeling: # samples: " + str(samples) + "T:" + str(T) + " Result: " + str(tmp) + " \n") root.treeToXml(__location__ + "/output/testGUI.xml") return tree
def nodeDataInDebugMode(nodeTime, nodeSuccFail, nodeID, monitordNodeID, numOfIter, param): newTree = xmlTree("output/" + Ctree.filePath[6:-4] + "_after_run_debug_false.xml") newTree.createWrapperTreeMap("id") monitorNode = None # print "E="+ str(Ctree.myTree.getWrappedNode(monitordNodeID).getAverageSuccTime(0)) # print "prob="+str(Ctree.myTree.getWrappedNode(monitordNodeID).getProbAtIndex(0)) #get pointer to the monitored node finished_node = newTree.getWrappedNode(nodeID) finished_node.setDebug(str(nodeSuccFail) + " " + str(nodeTime)) newTree.treeToXml("output/" + Ctree.filePath[6:-4] + "_" + monitordNodeID + "_after_run_debug_true.xml") node.debugMode = True newTree = xmlTree("output/" + Ctree.filePath[6:-4] + "_" + monitordNodeID + "_after_run_debug_true.xml") root = newTree.getRoot() for i in range(numOfIter): root.runPlan(param) #print tree to xml file newTree.treeToXml("output/" + Ctree.filePath[6:-4] + "_" + monitordNodeID + "_after_run_debug_true.xml") newTree = xmlTree("output/" + Ctree.filePath[6:-4] + "_" + monitordNodeID + "_after_run_debug_true.xml") newTree.createWrapperTreeMap("id") #check if the node monitor is the root if monitordNodeID == "": root = newTree.getRoot() monitorNode = root.getChild(0) else: monitorNode = newTree.getWrappedNode(monitordNodeID) #take E,prob and standarte deviation from the debug node, E = monitorNode.getAverageSuccTime(param) prob = monitorNode.getProbAtIndex(param) sd = monitorNode.getSDSuccTime(param) #clear tree from calculations root = newTree.getRoot() root.clearWholeTree() #print update tree to xml file newTree.treeToXml("output/" + Ctree.filePath[6:-4] + "_" + monitordNodeID + "_after_run_debug_true.xml") return (prob, sd, E)
def main(argv): # create the tree parser. recive filename tree = xmlTree(argv) # get root from the tree root = tree.getRoot() # get child at place 0 in the child-list child = root.addNode("tsk") child.setAttrib("probability", "0.5, 0.2, 0.1, 0.9") # set new attribute to child, time="12" # child.setAttrib("time", "12") # write the tree back to xml file- OUT.xml tree.treeToXml(argv)
def constructTree(event_file, param): # if the tree is not null then don't calculate the tree. if Ctree.myTree != None: return Ctree.filePath = event_file # event_file_full_path = event_file #tsk_attributes_full_path = event_file_full_path[0:-4] + "_tsk_attribs.xml" Ctree.myTree = xmlTree(Ctree.filePath, None, Ctree.filePath[0:-4] + "_tsk_attribs.xml") print Ctree.filePath[0:-4] + "_tsk_attribs.xml" Ctree.myTree.createWrapperTreeMap("id") root = Ctree.myTree.getRoot() node.debugMode = False for i in range(1000): root.runPlan(param) Ctree.myTree.treeToXml("output/" + Ctree.filePath[6:-4] + "_after_run_debug_false.xml") Ctree.myTree = xmlTree("output/" + Ctree.filePath[6:-4] + "_after_run_debug_false.xml") Ctree.myTree.createWrapperTreeMap("id")
def test2(): tree = xmlTree("tests/test2.xml") root = tree.getRoot() # root is always a plan newNode = root.getChild(0) ChildList = newNode.getChildren() #iterate over first node children: count = 0 for childNode in ChildList: count += 1 if count == 5: print("test 2: success!") else: print("test 2: failed :-(")
def test6(): tree = xmlTree("tests/test2.xml") root = tree.getRoot() firstChild = root.getChild(0) childList = firstChild.getChildren() for childNode in childList: childNode.setMonitor(False) for childNode in childList: boolVal = childNode.isMonitored() if boolVal != False: print("test 6: failed :-(") return None print("test 6: success!")
def test6(): tree = xmlTree("tests/test2.xml") root = tree.getRoot() firstChild = root.getChild(0) childList = firstChild.getChildren() for childNode in childList: childNode.setMonitor(False) for childNode in childList: boolVal = childNode.isMonitored() if boolVal != False : print("test 6: failed :-(") return None print("test 6: success!")
def __init__(self, treeInstance=None, mytree=None, prep="plan", parent=None): # you can't have multiple __init__ functions in Python so we use mytree = None if mytree == None: #create a new tree instance with plan node as root self.treeInst = etree.Element("plan") from tree import xmlTree #tree instance new with plan as root self.myTree = xmlTree(None, self.treeInst) else: self.myTree = mytree self.treeInst = treeInstance self.parent = parent # monitor - boolean property, default-True self.monitor = True #node child list self.childList = [] #node probebility table self.probTable = [] # node distribution table for success and failure #distribution table - each entry points to a distribution self.distTableSucc = self._createDistTable("Successdistribution") self.distTableFail = self._createDistTable("Failuredistribution") #update probability table probString = self.getAttrib("probability") if probString != None: # self.probTable= self._parseString(probString) self.probTable = self._createProbTable(probString) else: self.probTable = None #node debuge child property #DEBUGchild - boolean value if we have a debug node in the sub-tree which was already debug- default- False self.DEBUGchild = False self._updateChildDebug() # DEBUG - list of two parameters first elem is boolean, second parm- is float self.DEBUG = self._setDebugFromXmlFile() #flag that indicates if this node was updated after debug self.reset = False #self.upperBound = [0]*node.parmetersInTheWorld #self.lowerBound = [0]*node.parmetersInTheWorld self.size = 1
def test20(): tree = xmlTree("tests/test3.xml") root = tree.getRoot() #this child is type- tsk child = root.getChild(0) ### create a new dist - and dist_succ = _createNormalDist(5, 2) dist_fail = _createNormalDist(4, 1) dist_fail1 = _createUniformDist(5, 8) #add to succ table child.addDistToSuccTable(dist_succ) #add to fail table/ child.addDistToFailTable(dist_fail) #get distribute from the node by it's index (p1,p2,p3..) dist_get_succ = child.getSuccDistAtIndex(0) dist_get_fail = child.getFailDistAtIndex(0) #check that it has the same parms #added by RAZ -- Adi, I made the tests a bit more complex, you should always have the tests as hard a possible, checking all possible cases. if (dist_get_succ != None and dist_get_succ.parmM == float(5) and dist_get_succ.parmG == float(2) and dist_get_fail != None and dist_get_fail.parmM == float(4) and dist_get_fail.parmG == float(1)): print("test 20.1: success!") else: ("test 20.1: failed :-(") # try to create computed dist. #added by RAZ -- Adi, I made the tests a bit more complex, you should always have the tests as hard a possible, checking all possible cases. dist = _createComputedDist() dist.setValueToTime(0.1, 1) dist.setValueToTime(0.1, dist.getCountByTime(0.1) + 1) dist.setValueToTime(0.2, 1) dist.setValueToTime(0.05, 1) dist.printMe() print dist.calcProb() print "-----------" dist_succ.printMe() print dist_succ.calcProb() dist_fail1.printMe() print dist_fail1.calcProb() if (dist.getCountByTime(0.1) == 2 and dist.getCountByTime(0.2) == 1 and dist.getCountByTime(0.05) == 1): print("test 20.2: success!") else: ("test 20.2: failed :-( - check computed dist")
def durLessThanT(fd, filePlanName, filePlanAttribName, T, samples): tree = xmlTree(filePlanName, None, filePlanAttribName) root = tree.getRoot() tree.createWrapperTreeMap("id") for j in range(node.parmetersInTheWorld): for i in range(int(samples)): root.runPlan(j) tmp = root.getChild(0).getLessThenTProb(j, float(T)) fd.write( "-------------------------------Astimated Duration-----------------------------------------\n" ) fd.write("Sampeling: # samples: " + str(samples) + " Prob: " + str(root.getChild(0).getProbAtIndex(j)) + " \n") fd.write("Sampeling: # samples: " + str(samples) + " T:" + str(T) + " Duration Distribution: " + str(tmp) + " \n") root.treeToXml(__location__ + "/output/testGUI.xml") return tree
def test10(): tree = xmlTree("tests/test3.xml") root = tree.getRoot() #this child is type- tsk child = root.getChild(0) ### create a new dist - and dist_succ = _createNormalDist(5,2) dist_fail = _createNormalDist(4,1) dist_fail1 = _createUniformDist(5, 8) #add to succ table child.addDistToSuccTable(dist_succ) #add to fail table/ child.addDistToFailTable(dist_fail) #get distribute from the node by it's index (p1,p2,p3..) dist_get_succ = child.getSuccDistAtIndex(0) dist_get_fail = child.getFailDistAtIndex(0) #check that it has the same parms #added by RAZ -- Adi, I made the tests a bit more complex, you should always have the tests as hard a possible, checking all possible cases. if (dist_get_succ != None and dist_get_succ.parmM == float(5) and dist_get_succ.parmG == float(2) and dist_get_fail != None and dist_get_fail.parmM == float(4) and dist_get_fail.parmG == float(1)): print ("test 10.1: success!") else: ("test 10.1: failed :-(") # try to create computed dist. #added by RAZ -- Adi, I made the tests a bit more complex, you should always have the tests as hard a possible, checking all possible cases. dist = _createComputedDist() dist.setValueToTime(0.1,1) dist.setValueToTime(0.1, dist.getCountByTime(0.1)+1 ) dist.setValueToTime(0.2,1) dist.setValueToTime(0.05,1) dist.printMe() print dist.calcProb() print "-----------" dist_succ.printMe() print dist_succ.calcProb() dist_fail1.printMe() print dist_fail1.calcProb() if (dist.getCountByTime(0.1) == 2 and dist.getCountByTime(0.2) == 1 and dist.getCountByTime(0.05) == 1): print ("test 10.2: success!") else: ("test 10.2: failed :-( - check computed dist")
def test29(): start = time.time() tree = xmlTree("tests/event3_no_tsk_attrib.xml", None, "tests/event3_tsk_attrib.xml") root = tree.getRoot() node.parmetersInTheWorld = 1 root.treeToXml("output/testE291.xml") print("test 29.1: success!") node.debugMode = False for i in range(100): root.runPlan(0) for i in range(100): root.runPlan(1) root.treeToXml("output/testE292.xml") print("test 29.2: success!") print "Success probability in offline mode: Clear sky = %f, Cloudy = %f" % ( root.getChild(0).getProbAtIndex(0), root.getChild(0).getProbAtIndex(1)) print "Average success time with clear sky = %f" % ( root.getChild(0).getAverageSuccTime(0)) print "Average success time when Cloudy = %f" % ( root.getChild(0).getAverageSuccTime(1)) elapsed = (time.time() - start) print "Time: %f" % elapsed print "-------Debug mode-------" node.debugMode = True for i in range(100): root.runPlan(0) for i in range(100): root.runPlan(1) root.treeToXml("output/testE293.xml") print("test 29.3: success!") print "Success probability in debug mode: Clear sky = %f, Cloudy = %f" % ( root.getChild(0).getProbAtIndex(0), root.getChild(0).getProbAtIndex(1)) print "Average success time in debug mode with clear sky = %f" % ( root.getChild(0).getAverageSuccTime(0)) print "Average success time in debug mode when Cloudy = %f" % ( root.getChild(0).getAverageSuccTime(1)) elapsed = (time.time() - start) elapsed = (time.time() - start) print "Time: %f" % elapsed
def test4(): tree = xmlTree("tests/test3.xml") #remember- root is alwayes type/tag- plan root = tree.getRoot() ans = [] ans.append(root.boolWhoAmI("plan")) firstChild = root.getChild(0) ans.append(firstChild.boolWhoAmI("seq")) ans.append((firstChild.getChild(0)).boolWhoAmI("seq")) ans.append((firstChild.getChild(1)).boolWhoAmI("seq")) ans.append((firstChild.getChild(2)).boolWhoAmI("loop")) ans.append((firstChild.getChild(3)).boolWhoAmI("par")) ans.append((firstChild.getChild(4)).boolWhoAmI("tsk")) ans.append((firstChild.getChild(5)).boolWhoAmI("sel")) for index in range(0,7): if ans[index] == False: print("test 4: failed :-(") print("test 4: success!")
def test4(): tree = xmlTree("tests/test3.xml") #remember- root is alwayes type/tag- plan root = tree.getRoot() ans = [] ans.append(root.boolWhoAmI("plan")) firstChild = root.getChild(0) ans.append(firstChild.boolWhoAmI("seq")) ans.append((firstChild.getChild(0)).boolWhoAmI("seq")) ans.append((firstChild.getChild(1)).boolWhoAmI("seq")) ans.append((firstChild.getChild(2)).boolWhoAmI("loop")) ans.append((firstChild.getChild(3)).boolWhoAmI("par")) ans.append((firstChild.getChild(4)).boolWhoAmI("tsk")) ans.append((firstChild.getChild(5)).boolWhoAmI("sel")) for index in range(0, 7): if ans[index] == False: print("test 4: failed :-(") print("test 4: success!")
def __init__(self, treeInstance=None, mytree=None, prep="plan", parent=None): # you can't have multiple __init__ functions in Python so we use mytree = None if mytree == None: # create a new tree instance with plan node as root self.treeInst = etree.Element("plan") from tree import xmlTree # tree instance new with plan as root self.myTree = xmlTree(None, self.treeInst) else: self.myTree = mytree self.treeInst = treeInstance self.parent = parent # monitor - boolean property, default-True self.monitor = True # node child list self.childList = [] # node probebility table self.probTable = [] # node distribution table for success and failure # distribution table - each entry points to a distribution self.distTableSucc = self.createDistTable("Successdistribution") self.distTableFail = self.createDistTable("Failuredistribution") # update probability table probString = self.getAttrib("probability") if probString != None: self.probTable = self._parseString(probString) else: self.probTable = None # node debuge child property # DEBUGchild - boolean value if we have a debug node in the sub-tree which was already debug- default- False self.DEBUGchild = False self._updateChildDebug() # DEBUG - list of two parameters first elem is boolean, second parm- is float self.DEBUG = self._setDebugFromXmlFile() # flag that indicates if this node was updated after debug self.reset = False
def test32(): start = time.time() tree = xmlTree("tests/skill4.xml", None, "tests/skill4_tsk_attribs.xml") root = tree.getRoot() node.parmetersInTheWorld = 1 root.treeToXml("output/skill4.xml") print("test 32.1: success!") node.debugMode = False for i in range(1000): root.runPlan(0) tree.createWrapperTreeMap("id") # monitorID = "param=9b82d340-6893-4e68-a676-4d1658aae8d0" # print monitorID.split("=")[1] monitordNode = tree.getWrappedNode("ae9c53ae-b42c-4f21-ba6a-7b1fa8741c2d") if monitordNode: print "Success probability in offline mode monitor: Mission: %f" % monitordNode.getProbAtIndex( 0) print "Average success time monitor: Mission= %f" % monitordNode.getAverageSuccTime( 0) print "SD success time monitor: Mission= %f" % monitordNode.getSDSuccTime( 0) monitordNode = tree.getWrappedNode("b9e18714-4869-422c-bc38-cb2dca88c530") if monitordNode: print "Success probability in offline mode monitor: ExitFromCar: %f" % monitordNode.getProbAtIndex( 0) print "Average success time monitor: ExitFromCar= %f" % monitordNode.getAverageSuccTime( 0) print "SD success time monitor: Mission= %f" % monitordNode.getSDSuccTime( 0) root.treeToXml("output/skill4_after_run.xml") print("test 32.2: success!") print "Success probability in offline mode - root: %f" % root.getChild( 0).getProbAtIndex(0) print "Average success time - root= %f" % root.getChild( 0).getAverageSuccTime(0) elapsed = (time.time() - start) print "Time: %f" % elapsed
def test12(): tree = xmlTree("tests/event1.xml") tree.treeToXml("output/test12.xml") print("test 12: success- check output/test12.xml file")