示例#1
0
文件: PM.py 项目: fiskpralin/Tota
	def __init__(self, G=None, vis=True, anim=False, mtype='2a', ttype='random'):
		SimExtend.__init__(self, G, vis, anim, animDelay=0.3) #animDelay==standard value for animations
		self.testvar=range(30000000)
		self.initialize()
		self.stats={'plant attempts':0, 'mound attempts':0, 'remound attempts':0, 'stumps in WA':None, 'stumps in WA sum diameter':0, 'immobile boulder struck':0, 'immobile vol sum':0, 'number of dibble disr stones in mound':0, 'dibble distr stone vol cum':0, 'queue percent':0,'work percent':0, 'work time':0,'rest time':0  }
		if not self.G.terrain:
			self.G.terrain=PlantMTerrain(G=self.G, ttype=ttype)
		tic=time.clock()
		if self.G.automatic=='undefined':
			if mtype[0:2]=='1a':
				self.G.automatic={'mound': False, 'plant': True, 'automove': False, 'micrositeSelection': False, 'moveToMicro': False,'haltMound':False, 'clearForOtherHead': False}
			else:
				self.G.automatic={'mound': True, 'plant': True, 'automove': True, 'micrositeSelection': False, 'moveToMicro': False, 'haltMound':True, 'clearForOtherHead': True}
		#self.test=testProcess1(name='sdf', sim=self)
		#self.activate(self.test, self.test.run())
		#self.simulate(until=5000)
		self.m=PlantMachine(name="planter", sim=self, G=self.G, mtype=mtype)
		self.activate(self.m,self.m.run())
		self.simulate(until=self.G.maxtime)
		return None
		#postprocessing
		self.productivity=len(self.m.treesPlanted)/(self.now()/3600.) #trees/hour
		print "result: %d trees in %d time, productivity: %f trees/hour"%(len(self.m.treesPlanted), self.now(), self.productivity)		
		self.setQueuePerc()
		print "stumps in WA sum diameter:", self.stats['stumps in WA sum diamater']
		print "number of remounds", self.stats['remound attempts']
		if self.p: #if we have a plotter instance
			self.p.terminate()
			plt.show() #nothing is processed in paralell with this, thus last:
示例#2
0
	def __init__(self, G=None, vis=True, anim=False, mtype='2a', ttype='random'):
		self.initialize()
		SimExtend.__init__(self, G, vis, anim, animDelay=0.3) #animDelay==standard value for animations
		if not self.G.simParam:
			self.G.simParam=paramsForSensAn()
			assert self.G.simParam
		self.stats={'plant attempts':0, 'mound attempts':0, 'remound attempts':0, 'stumps in WA':None, 'noStumps in WA':0,'stumps in WA sum diameter':0,'meanSurfBoulderDiamWA':0,'noSurfBouldersWA':0,'immobile boulder struck':0, 'immobile vol sum':0, 'number of dibble disr stones in mound':0, 'dibble distr stone vol cum':0, 'queue percent':0,'work percent':0, 'work time':0,'rest time':0, 'humus depths':[], 'inverting attempts':0, 'reinverting attempts':0}
		if not self.G.terrain:
			self.G.terrain=PlantMTerrain(ttype=ttype)
		else:
			if ttype!='random':
				raise Exception('Terrain is already specified. The input ttype is only used if G.terrain=None')
		self.stats['noSurfBoulders']=self.G.terrain.noSBoulders
	   	if self.stats['noSurfBoulders']==0: 
			self.stats['meanSurfBoulderDiam']=0
	   	else:
			self.stats['meanSurfBoulderDiam']=sum([2*sstone.radius for sstone in self.G.terrain.surfaceBoulders])/float(self.stats['noSurfBoulders']) #gives mean diameter
			print 'average surface boulder diameter in total area:',self.stats['meanSurfBoulderDiam']
		if self.G.automatic=='undefined':
			if mtype[0:2]=='1a':
				self.G.automatic={'mound': False, 'plant': True, 'automove': False, 'micrositeSelection': False, 'moveToMicro': False,'haltMound':False, 'clearForOtherHead': False}
			else:
				self.G.automatic={'mound': True, 'plant': True, 'automove': True, 'micrositeSelection': False, 'moveToMicro': False, 'haltMound':True, 'clearForOtherHead': True}
		self.m=PlantMachine(name="planter", sim=self, G=self.G, mtype=mtype)
		self.activate(self.m,self.m.run())
		self.simulate(until=self.G.maxtime)
		#postprocessing
		self.productivity=len(self.m.treesPlanted)/(self.now()/3600.) #trees/hour
		print "result: %d trees in %d time, productivity: %f trees/hour"%(len(self.m.treesPlanted), self.now(), self.productivity)		
		self.setQueuePerc()
		print "stumps in WA sum diameter:", self.stats['stumps in WA sum diameter']
		print 'Mean diameter of surfaceboulders in WA',self.stats['meanSurfBoulderDiamWA']
		print 'Number of SurfaceBoulders in WA',self.stats['noSurfBouldersWA']
		print "time to search for microsite", self.m.timeConsumption['searchTime']
		print "number of remounds", self.stats['remound attempts']
		if self.p: #if we have a plotter instance
			self.p.terminate()
			plt.show() #nothing is processed in parallell with this, thus last:
示例#3
0
文件: PM.py 项目: fiskpralin/Tota
class PlantmSim(SimExtend):
	"""
	class for a single simulation with a 1a or 2a plantmachine
	286
	"""
	def __init__(self, G=None, vis=True, anim=False, mtype='2a', ttype='random'):
		SimExtend.__init__(self, G, vis, anim, animDelay=0.3) #animDelay==standard value for animations
		self.testvar=range(30000000)
		self.initialize()
		self.stats={'plant attempts':0, 'mound attempts':0, 'remound attempts':0, 'stumps in WA':None, 'stumps in WA sum diameter':0, 'immobile boulder struck':0, 'immobile vol sum':0, 'number of dibble disr stones in mound':0, 'dibble distr stone vol cum':0, 'queue percent':0,'work percent':0, 'work time':0,'rest time':0  }
		if not self.G.terrain:
			self.G.terrain=PlantMTerrain(G=self.G, ttype=ttype)
		tic=time.clock()
		if self.G.automatic=='undefined':
			if mtype[0:2]=='1a':
				self.G.automatic={'mound': False, 'plant': True, 'automove': False, 'micrositeSelection': False, 'moveToMicro': False,'haltMound':False, 'clearForOtherHead': False}
			else:
				self.G.automatic={'mound': True, 'plant': True, 'automove': True, 'micrositeSelection': False, 'moveToMicro': False, 'haltMound':True, 'clearForOtherHead': True}
		#self.test=testProcess1(name='sdf', sim=self)
		#self.activate(self.test, self.test.run())
		#self.simulate(until=5000)
		self.m=PlantMachine(name="planter", sim=self, G=self.G, mtype=mtype)
		self.activate(self.m,self.m.run())
		self.simulate(until=self.G.maxtime)
		return None
		#postprocessing
		self.productivity=len(self.m.treesPlanted)/(self.now()/3600.) #trees/hour
		print "result: %d trees in %d time, productivity: %f trees/hour"%(len(self.m.treesPlanted), self.now(), self.productivity)		
		self.setQueuePerc()
		print "stumps in WA sum diameter:", self.stats['stumps in WA sum diamater']
		print "number of remounds", self.stats['remound attempts']
		if self.p: #if we have a plotter instance
			self.p.terminate()
			plt.show() #nothing is processed in paralell with this, thus last:
	def plotMoni(self, ax, number):
		"""
		defines the monitors that should be plotted.
		assumes that matplotlib axis ax and number \in {1,2,3} is given.
		"""
		if number==1: #plot driver activity
			driver=self.m.driver
			moni=driver.actMon
			if len(moni)>0:
				ax.plot(moni.tseries(),moni.yseries(), drawstyle='steps-post')
				ax.axis([-0.1, self.now(), -0.1, 1.2])
				ax.grid(True)
				ax.set_ylabel('Working pattern')
				ax.set_yticks((0,  1))#, ('idle', 'busy'))#, color = 'k')
		elif number==2: #plot driver waiting queue
			moni=self.m.driver.waitMon
			if len(moni)>0:
				maxt=int(max(moni.yseries()))
				ticks=[]
				for i in range(maxt+1): ticks.append(i)
				ax.set_yticks(tuple(ticks))
				ax.plot(moni.tseries(),moni.yseries(), drawstyle='steps-post')
				ax.axis([-0.1, self.now(), -0.1, max(moni.yseries())+0.1])
				ax.grid(True)
				ax.set_ylabel('Wait queue for driver.')
			"""moni=self.m.driver.waitMon
			if len(moni)>0:
				axt=int(max(moni.yseries()))
				ticks=[]
				for i in range(maxt+1): ticks.append(i)
				ax.set_yticks(tuple(ticks))
				ax.plot(moni.tseries(),moni.yseries(), drawstyle='steps-post')
				ax.axis([-0.1, m.sim.now(), -0.1, max(moni.yseries())+0.1])
				ax.grid(True)
				ax.set_ylabel('Wait queue for driver.')	"""
		elif number==3: #plot trees planted
			moni=self.m.treeMoni
			#trees planted
			if len(moni)>0:
				ax.plot(moni.tseries(),moni.yseries(), drawstyle='steps-post')
				ax.axis([-0.1, self.now(), -0.1, (max(moni.yseries())+1)])
				ax.grid(True)
				ax.set_xlabel('time(s)')
				ax.set_ylabel('trees planted')
		return ax
示例#4
0
class PlantmSim(SimExtend):
	"""
	class for a single simulation with a 1a or 2a plantmachine
	286
	"""
	def __init__(self, G=None, vis=True, anim=False, mtype='2a', ttype='random'):
		self.initialize()
		SimExtend.__init__(self, G, vis, anim, animDelay=0.3) #animDelay==standard value for animations
		if not self.G.simParam:
			self.G.simParam=paramsForSensAn()
			assert self.G.simParam
		self.stats={'plant attempts':0, 'mound attempts':0, 'remound attempts':0, 'stumps in WA':None, 'noStumps in WA':0,'stumps in WA sum diameter':0,'meanSurfBoulderDiamWA':0,'noSurfBouldersWA':0,'immobile boulder struck':0, 'immobile vol sum':0, 'number of dibble disr stones in mound':0, 'dibble distr stone vol cum':0, 'queue percent':0,'work percent':0, 'work time':0,'rest time':0, 'humus depths':[], 'inverting attempts':0, 'reinverting attempts':0}
		if not self.G.terrain:
			self.G.terrain=PlantMTerrain(ttype=ttype)
		else:
			if ttype!='random':
				raise Exception('Terrain is already specified. The input ttype is only used if G.terrain=None')
		self.stats['noSurfBoulders']=self.G.terrain.noSBoulders
	   	if self.stats['noSurfBoulders']==0: 
			self.stats['meanSurfBoulderDiam']=0
	   	else:
			self.stats['meanSurfBoulderDiam']=sum([2*sstone.radius for sstone in self.G.terrain.surfaceBoulders])/float(self.stats['noSurfBoulders']) #gives mean diameter
			print 'average surface boulder diameter in total area:',self.stats['meanSurfBoulderDiam']
		if self.G.automatic=='undefined':
			if mtype[0:2]=='1a':
				self.G.automatic={'mound': False, 'plant': True, 'automove': False, 'micrositeSelection': False, 'moveToMicro': False,'haltMound':False, 'clearForOtherHead': False}
			else:
				self.G.automatic={'mound': True, 'plant': True, 'automove': True, 'micrositeSelection': False, 'moveToMicro': False, 'haltMound':True, 'clearForOtherHead': True}
		self.m=PlantMachine(name="planter", sim=self, G=self.G, mtype=mtype)
		self.activate(self.m,self.m.run())
		self.simulate(until=self.G.maxtime)
		#postprocessing
		self.productivity=len(self.m.treesPlanted)/(self.now()/3600.) #trees/hour
		print "result: %d trees in %d time, productivity: %f trees/hour"%(len(self.m.treesPlanted), self.now(), self.productivity)		
		self.setQueuePerc()
		print "stumps in WA sum diameter:", self.stats['stumps in WA sum diameter']
		print 'Mean diameter of surfaceboulders in WA',self.stats['meanSurfBoulderDiamWA']
		print 'Number of SurfaceBoulders in WA',self.stats['noSurfBouldersWA']
		print "time to search for microsite", self.m.timeConsumption['searchTime']
		print "number of remounds", self.stats['remound attempts']
		if self.p: #if we have a plotter instance
			self.p.terminate()
			plt.show() #nothing is processed in parallell with this, thus last:
			
	def plotMoni(self, ax, number):
		"""
		defines the monitors that should be plotted.
		assumes that matplotlib axis ax and number \in {1,2,3} is given.
		"""
		if number==1: #plot driver activity
			driver=self.m.driver
			moni=driver.actMon
			if len(moni)>0:
				ax.plot(moni.tseries(),moni.yseries(), drawstyle='steps-post')
				ax.axis([-0.1, self.now(), -0.1, 1.2])
				ax.grid(True)
				ax.set_ylabel('Working pattern')
				ax.set_yticks((0,  1))#, ('idle', 'busy'))#, color = 'k')
		elif number==2: #plot driver waiting queue
			moni=self.m.driver.waitMon
			if len(moni)>0:
				maxt=int(max(moni.yseries()))
				ticks=[]
				for i in range(maxt+1): ticks.append(i)
				ax.set_yticks(tuple(ticks))
				ax.plot(moni.tseries(),moni.yseries(), drawstyle='steps-post')
				ax.axis([-0.1, self.now(), -0.1, max(moni.yseries())+0.1])
				ax.grid(True)
				ax.set_ylabel('Wait queue for driver.')
		elif number==3: #plot trees planted
			moni=self.m.treeMoni
			#trees planted
			if len(moni)>0:
				ax.plot(moni.tseries(),moni.yseries(), drawstyle='steps-post')
				ax.axis([-0.1, self.now(), -0.1, (max(moni.yseries())+1)])
				ax.grid(True)
				ax.set_xlabel('time(s)')
				ax.set_ylabel('trees planted')
		return ax