Пример #1
0
	def setup(self, env):

		""" Create the factory architecture """
		machines = []
		machines.append(Machine(env, 1, self.worktime, self.num_stations, 3.0, self.remote_addr, ('10.10.0.101',0)))
		machines.append(Machine(env, 2, self.worktime, self.num_stations, 3.0, self.remote_addr, ('10.10.0.102',0)))
		machines.append(Machine(env, 3, self.worktime, self.num_stations, 3.0, self.remote_addr, ('10.10.0.103',0)))
		machines.append(Machine(env, 3, self.worktime, self.num_stations, 3.0, self.remote_addr, ('10.10.0.104',0)))

		# create the storage bin for product output
		output_store = simpy.resources.container.Container(env, capacity=self.output_store_sz)
		sfutils.loginfo(EventType.PART_ENTER_FACTORY, env, None, None, "output storage container created with size %d"%output_store.capacity)

		# Create more parts while the simulation is running
		part_id = 0
		while part_id < self.num_parts:
			
			# calculate wait time between parts
			scale = 0.2*self.t_inter # 20% of average 
			this_inter = self.t_inter + scale*(random.rand()-0.5) 
			yield env.timeout(this_inter)

			# produce new part on the line
			env.process(Part(env, part_id, machines, output_store))
			sfutils.loginfo(EventType.PART_ENTER_FACTORY, env, None, part_id, "part created")

			# increment to next part number
			part_id += 1	
Пример #2
0
def Part(env, part_id, machines, output_store):
	""" A part goes to each machine and requests work to be done.
		Work is done and part leaves to never come back """
	for mach in machines:
		with mach.station.request() as station_request:
			
			yield station_request
			mach.part_enters(part_id)
			
			yield env.process(mach.work(part_id))
			sfutils.loginfo(EventType.PART_EXIT_MACH, env, mach.mach_id, part_id, "part exits machine")
			
			with mach.rail.rail.request() as rail_request:
				
				yield rail_request
				sfutils.loginfo(EventType.PART_TRAVEL, env, mach.mach_id, part_id, "part in transit")
				
				yield env.process(mach.rail.travel(part_id))
	
	# store the product
	sfutils.loginfo(EventType.PRODUCT_STORED, env, None, part_id, "part stored as product")
	output_store.put(1)

	# tally the number of products in log file
	sfutils.loginfo(EventType.DIAGNOSTICS, env, None, None, "number of products " + str(output_store.level))
Пример #3
0
	def work(self, part_id):
		
		# calculate machine wait time for this iteration
		scale = 0.2*self.worktime # 20% of average work time for machine
		this_work_time = self.worktime + scale*(random.rand()-0.5) 

		# send msg that machine is working
		msg = SensorMessage(part_id=part_id, mach_id=self.mach_id, rail_id=0, msg_str="machine working")
		self.tcpclient.send_msg(msg)

		# TODO:  Wait for command from controller to start work TCP
		# left blank for now -- controller to be added later
		
		# do the work
		sfutils.loginfo(EventType.MACHINE_WORK, env, self.mach_id, part_id, "machine working")
		yield self.env.timeout(this_work_time)	

		# transmit that machine is done
		machine_done_str = "machine done" + \
			", work_time: " + str(this_work_time) + \
			", num_parts: " + str(self.num_parts)
		msg = SensorMessage(part_id=part_id, mach_id=self.mach_id, rail_id=0, msg_str=machine_done_str)
		self.tcpclient.send_msg(msg)
		sfutils.loginfo(EventType.MACHINE_DONE, env, self.mach_id, part_id, machine_done_str)
Пример #4
0
	def run(self, env):
		sfutils.loginfo(EventType.FACTORY_STARTED, env, None, None, "factory starting")		
		env.process(self.setup(env))
Пример #5
0
	def part_enters(self, part_id):
		sfutils.loginfo(EventType.PART_ENTER_MACH, env, self.mach_id, part_id, "part entered machine")
		msg = SensorMessage(part_id=part_id, mach_id=self.mach_id, rail_id=0, msg_str="part entered machine")
		self.tcpclient.send_msg(msg)