示例#1
0
文件: sfs3.py 项目: 2xR/legacy
class Worker(Process):
    IDLE = "idle"
    BUSY = "busy"
    
    def constructor(self):
        self.state = TSeries()
        self.current = None
        self.tasks = Deque()
        self.operation = None
        
    def status(self):
        return "(%s, %d tasks remaining) current=%s" % (self.state.last_value, 
                                                        len(self.tasks), self.current)
        
    def reset(self):
        self.state = TSeries(numeric=False, time_fnc=self.sim.clock.get)
        self.current = None
        self.tasks.clear()
        
    @Chain
    def initialize(self):
        self.state.collect(Worker.IDLE)
        while True:
            self.current = (yield self.operation.tasks.get()).result
            self.state.collect(Worker.BUSY)
            yield self.current # block until task is completed
            while len(self.tasks) > 0:
                self.current = self.tasks.popleft()
                yield self.current
            self.state.collect(Worker.IDLE)
            self.current = None
            
    def finalize(self):
        # repeat the last collected state to "close" the interval when ending a simulation
        self.state.repeat()
示例#2
0
文件: sfs1.py 项目: 2xR/legacy
class Machine(Process):
    IDLE = "idle"
    BUSY = "busy"
    
    current = None
    state = TSeries()
    
    def status(self):
        return "(%s) %s" % (self.state.last_value, self.current)
        
    def reset(self):
        self.state = TSeries(numeric=False, storing=True, time_fnc=self.sim.clock.get)
        self.current = None
        
    @Chain
    def initialize(self):
        while True:
            self.state.collect(Machine.IDLE)
            self.current = None
            self.current = (yield self.parent.queue.get()).result
            #yield self.prepare()
            yield self.process()
            self.current.action.succeed()
            
    @Chain
    def process(self):
        with self.current.history.add("process", machine=self.path):
            self.state.collect(Machine.BUSY)
            yield self.current.quantity * self.current.product.complexity[self.parent.name]
            
    def finalize(self):
        self.state.repeat()
        print self.path, self.state.report()
示例#3
0
文件: sfs3.py 项目: 2xR/legacy
class Machine(Process):
    IDLE = "idle"
    BUSY = "busy"
    
    def constructor(self):
        self.state = TSeries()
        self.current = None
        self.operation = None
        self.channel = None
        
    def status(self):
        return "(%s) %s" % (self.state.last_value, self.current)
        
    def reset(self):
        self.state = TSeries(numeric=False, time_fnc=self.sim.clock.get)
        self.current = None
        self.channel = Channel()
        
    @Chain
    def initialize(self):
        self.state.collect(Machine.IDLE)
        while True:
            lot = (yield self.operation.queue.get()).result # block until a lot is available
            load = LoadTask(lot, self)
            self.operation.tasks.append(load)
            yield load.observe() # block until operator finishes loading
            yield self.process()
            unload = UnloadTask(self)
            self.operation.tasks.append(unload)
            yield unload.observe() # block until operator finishes loading
            
    @Chain
    def process(self):
        yield self.channel.emit("Process started")
        self.state.collect(Machine.BUSY)
        duration = self.current.quantity * self.current.product.complexity[self.operation.path]
        self.process_delay = Delay(duration)
        yield self.process_delay
        self.state.collect(Machine.IDLE)
        yield self.channel.emit("Process finished")
        
    def finalize(self):
        # repeat the last collected state to "close" the interval when ending a simulation
        self.state.repeat()