def run(self): file_ext = self.file file_ext.write("Number of suppliers is " + str(len(self.netw.graph.nodes())-1) + "\n" + "\n" + "Time Manufacturer Suppliers " + "\n" + "t ") for i in range(0, len(self.netw.graph.nodes())): if i < 10: file_ext.write(" " + str(i)) elif i < 100: file_ext.write(" " + str(i)) else: file_ext.write(" " + str(i)) file_ext.write("\n") #file = open("storytelling.txt", 'w') file = 0 # does not mean anything but for not to many files open mynodes = self.netw.mynodes self.indextrack.append(startmysimul(self.netw, self.track, self.seed, self.plot)) while True: # Write the beginning of the line if env.now < 10: file_ext.write(str(env.now) +" ") elif env.now > 99: file_ext.write(str(env.now)) else: file_ext.write(str(env.now) +" ") for i in range(0, len(mynodes)): # Write the delay of the node node = mynodes[i] if node.delay < 10: file_ext.write(" " + str(node.delay)) elif node.delay < 100: file_ext.write(" " + str(node.delay)) else: file_ext.write(" " + str(node.delay)) if node.label != 0 and node.state: # If node disrupted and not manuf newdelay = amplifyDis(node, self.delays) recovery_time = start_my_code.recovery_time(node.rating) time_since_started = self.locations[node.label] if time_since_started >= recovery_time or newdelay == 0: # If has receovered of if new dealy is zero self.locations[node.label] = 0 node.state = False node.delay = 0 if self.plot: print "Disruption solved at time", self.env.now, "at location", node.label #file.write("Disruption solved at time " + str(self.env.now) + " at location " + str(node.label)+"\n") if self.track and self.indextrack.count(node.label) > 0: self.indextrack.remove(node.label) else: self.locations[node.label] += 1 node.delay = newdelay if time_since_started > 0 and time_since_started % 5 == 0: #node.lead_time propagateDis(node, self.netw, file, self.delays, newdelay, self.track, self.indextrack, self.seed, self.plot) if self.env.now == start_my_code.TIME_SIMUL-1 : #print "done, final delays manuf", self.delays[0] file_ext.close() if self.plot: Graph_Plot.plotprettydis(self.netw.graph, self.delays, self.name) yield self.env.timeout(1) file_ext.write("\n") file_ext.close()