path = traceback(minnode) if (mileage == False): print("Path with minimum stops:") else: print("Path with least mileage:") pathstr = "" for n in path: pathstr+=n.value print(pathstr) if (mileage == False): print("Stops:",minnode.cost) else: print("Miles:",minnode.cost) print("Nodes expanded:", step) if __name__ == '__main__': Widget1 = inc.Widget("AEDCA") Widget2 = inc.Widget("BEACD") Widget3 = inc.Widget("BABCE") Widget4 = inc.Widget("DADBD") Widget5 = inc.Widget("BECBD") Widgets = [Widget1, Widget2, Widget3, Widget4, Widget5] # container for passing to function solve(Widgets) print() solve(Widgets,True)
# we don't want duplicates in a row q = random.randint(0,4) s+=chars[q] return s if __name__ == '__main__': minstep_nodes = [] minmile_nodes = [] x = [3,4,5,6,7,8] for N in x: print("N =",N) print() # generate the widgets Widget1 = inc.Widget(randstring(N)) Widget2 = inc.Widget(randstring(N)) Widget3 = inc.Widget(randstring(N)) Widget4 = inc.Widget(randstring(N)) Widget5 = inc.Widget(randstring(N)) Widgets = [Widget1, Widget2, Widget3, Widget4, Widget5] # container for passing to function # solve for minimum steps minstep_nodes.append(prog.solve(Widgets)) print() # solve for minimum mileage minmile_nodes.append(prog.solve(Widgets,True)) print() print()