kgmuller | 3 Jun 06:18
Picon
Picon
Favicon

Re: cooperative multitasking with generators...

Glenn,
Yes, I had seen that. It makes interesting use of the 2.5 generator
expressions. 

Klaus Müller 

> -----Original Message-----
> From: simpy-users-bounces <at> lists.sourceforge.net 
> [mailto:simpy-users-bounces <at> lists.sourceforge.net] On Behalf 
> Of Glenn H Tarbox, PhD
> Sent: Thursday, May 29, 2008 8:51 AM
> To: simpy-users <at> lists.sourceforge.net
> Subject: [Simpy-users] cooperative multitasking with generators...
> 
> Looking at the design of SimPy, and its use of generators, I 
> wondered if anyone had come across the multitask package.  
> Its a clever use of python generators to provide fairly rich 
> cooperative constructs
> 
> http://o2s.csail.mit.edu/o2s-wiki/multitask
> 
> -glenn
> 
> --
> Glenn H. Tarbox, PhD || 206-494-0819 || glenn <at> tarbox.org 
> "Don't worry about people stealing your ideas. If your ideas 
> are any  good you'll have to ram them down peoples throats" 
> -- Howard Aiken
> 
> 
(Continue reading)

Travis Moulton | 12 Jun 23:43
Picon

yield request, hod, or release statements from nested functions

I believe it is possible to have yield work from a nested function.  In all the examples I have reviewed all yield request, yield hold, and yield release statements occur in the function called by the activate statement.  I would like the function called by the activate statement call other functions that would then execute the yield statements.  I've attached an example based roughly on the penny fab example from "Factory Physics" by Hopp and Spearman.  What I'm after here is the ability to easily code re-work sequences or a job shop environment where there are many different possible routes through a production line.

Travis

from SimPy.Simulation import *
from random import uniform

class pennyfab(Process):

    def __init__(self,name):
        self.start=0
        self.finish=0
        Process.__init__(self,name)

    def fab_punch(self):
        print self.name, ',request,1,punch,',now()
        yield request, self, punching
        print self.name, ',start,1,punch,',now()
        yield hold, self, 2+float(int(uniform(1,2/4*10)))/100
        yield release, self, punching
        print self.name,',finish,1,punch,',now()

    def fab_stamp(self):
        print self.name, ',request,1,stamp,',now()
        yield request, self, stamping
        print self.name, ',start,1,stamp,',now()
        yield hold, self, 4+float(int(uniform(1,4/4*10)))/100
        yield release, self, stamping
        print self.name,',finish,1,stamp,',now()

    def fab_rim(self):
        print self.name, ',request,1,rim,',now()
        yield request, self, rimming
        print self.name, ',start,1,rim,',now()
        yield hold, self, 10+float(int(uniform(1,10/4*10)))/100
        yield release, self, rimming
        print self.name,',finish,1,rim,',now()

    def fab_deburr(self):
        print self.name, ',request,1,deburr,',now()
        yield request, self, deburring
        print self.name, ',start,1,deburr,',now()
        yield hold, self, 3+float(int(uniform(1,3/4*10)))/100
        yield release, self, deburring
        print self.name,',finish,1,deburr,',now()

    def fab(self):
        yield request, self, wip
        self.start=now()

        self.fab_punch()
        if uniform(1,4)<2:
            self.fab_punch() # rework punch
        self.fab_stamp()
        if uniform(1,4)<2:
            self.fab_punch() # rework punch and stamp
            self.fab_stamp()
        self.fab_rim()
        self.fab_deburr()
        if uniform(1,4)<2:
            self.fab_stamp() # rework stamp and deburr
            self.fab_deburr()
       
        self.finish=now()
        yield release, self, wip
       

initialize()

punching=Resource(capacity=1,monitored=True,monitorType=Monitor)
stamping=Resource(capacity=2,monitored=True,monitorType=Monitor)
rimming=Resource(capacity=3,monitored=True,monitorType=Monitor)
deburring=Resource(capacity=1,monitored=True,monitorType=Monitor)
wip=Resource(capacity=6,monitored=True,monitorType=Monitor)                # implements CONWIP

   
penny=range(20)
for j in range(20):
    penny[j]=pennyfab(name='penny'+str(j))
    activate(penny[j],penny[j].fab())

simulate(until=500)

print ' '
print '*'*40
print '*'*11,' END SIMULATION ','*'*11
print '*'*40
print ' '

print 'Time history for WIP'
print '[time, activeQ]'
for item in wip.actMon:
    print item
print '-'*40

print 'Cycle Times'
average=0

for j in range(20):
    print penny[j].name,',',penny[j].finish-penny[j].start
    average=average+penny[j].finish-penny[j].start

print 'Average Cycle Time'
print average/20
print 'Lot Cycle Time'
print penny[19].finish-penny[0].start

print ' '
print '*'*40
print '*'*13,' END STATS ','*'*14
print '*'*40

-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
Simpy-users mailing list
Simpy-users <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/simpy-users
Travis Moulton | 13 Jun 00:41
Picon

Re: yield request, hod, or release statements from nested functions

Classic Newbie error, do your research first.

I just read [Simpy-users] "Activating function is not a generator (contains no 'yield')" error

and just modified my code to look like this:


from SimPy.Simulation import *
from random import uniform

class pennyfab(Process):

    def __init__(self,name):
        self.start=0
        self.finish=0
        Process.__init__(self,name)

    def fab_punch(self):
        print self.name, ',request,1,punch,',now()
        yield request, self, punching
        print self.name, ',start,1,punch,',now()
        yield hold, self, 2+float(int(uniform(1,2/4*10)))/100
        yield release, self, punching
        print self.name,',finish,1,punch,',now()

    def fab_stamp(self):
        print self.name, ',request,1,stamp,',now()
        yield request, self, stamping
        print self.name, ',start,1,stamp,',now()
        yield hold, self, 4+float(int(uniform(1,4/4*10)))/100
        yield release, self, stamping
        print self.name,',finish,1,stamp,',now()

    def fab_rim(self):
        print self.name, ',request,1,rim,',now()
        yield request, self, rimming
        print self.name, ',start,1,rim,',now()
        yield hold, self, 10+float(int(uniform(1,10/4*10)))/100
        yield release, self, rimming
        print self.name,',finish,1,rim,',now()

    def fab_deburr(self):
        print self.name, ',request,1,deburr,',now()
        yield request, self, deburring
        print self.name, ',start,1,deburr,',now()
        yield hold, self, 3+float(int(uniform(1,3/4*10)))/100
        yield release, self, deburring
        print self.name,',finish,1,deburr,',now()

    def fab(self):
        yield request, self, wip
        self.start=now()

        for i in self.fab_punch():
            yield i

        if uniform(1,4)<2:
            for i in self.fab_punch():
                yield i

        for i in self.fab_stamp():
            yield i

        if uniform(1,4)<2:
            for i in self.fab_punch():
                yield i
            for i in self.fab_stamp():
                yield i

        for i in self.fab_rim():
            yield i

        for i in self.fab_deburr():
            yield i

        if uniform(1,4)<2:
            for i in self.fab_stamp():
                yield i
            for i in self.fab_deburr():
                yield i

       
        self.finish=now()
        yield release, self, wip
       

initialize()

punching=Resource(capacity=1,monitored=True,monitorType=Monitor)
stamping=Resource(capacity=2,monitored=True,monitorType=Monitor)
rimming=Resource(capacity=3,monitored=True,monitorType=Monitor)
deburring=Resource(capacity=1,monitored=True,monitorType=Monitor)
wip=Resource(capacity=6,monitored=True,monitorType=Monitor) #implements CONWIP

   
penny=range(20)
for j in range(20):
    penny[j]=pennyfab(name='penny'+str(j))
    activate(penny[j],penny[j].fab())

simulate(until=500)

print ' '
print '*'*40
print '*'*11,' END SIMULATION ','*'*11
print '*'*40
print ' '

print 'Time history for WIP'
print '[time, activeQ]'
for item in wip.actMon:
    print item
print '-'*40


print 'Cycle Times'
average=0

for j in range(20):
    print penny[j].name,',',penny[j].finish-penny[j].start
    average=average+penny[j].finish-penny[j].start

print 'Average Cycle Time'
print average/20
print 'Lot Cycle Time'
print penny[19].finish-penny[0].start

print ' '
print '*'*40
print '*'*13,' END STATS ','*'*14
print '*'*40


On Thu, Jun 12, 2008 at 3:43 PM, Travis Moulton <tkmoult <at> gmail.com> wrote:
I believe it is possible to have yield work from a nested function.  In all the examples I have reviewed all yield request, yield hold, and yield release statements occur in the function called by the activate statement.  I would like the function called by the activate statement call other functions that would then execute the yield statements.  I've attached an example based roughly on the penny fab example from "Factory Physics" by Hopp and Spearman.  What I'm after here is the ability to easily code re-work sequences or a job shop environment where there are many different possible routes through a production line.

Travis

from SimPy.Simulation import *
from random import uniform

class pennyfab(Process):

    def __init__(self,name):
        self.start=0
        self.finish=0
        Process.__init__(self,name)

    def fab_punch(self):
        print self.name, ',request,1,punch,',now()
        yield request, self, punching
        print self.name, ',start,1,punch,',now()
        yield hold, self, 2+float(int(uniform(1,2/4*10)))/100
        yield release, self, punching
        print self.name,',finish,1,punch,',now()

    def fab_stamp(self):
        print self.name, ',request,1,stamp,',now()
        yield request, self, stamping
        print self.name, ',start,1,stamp,',now()
        yield hold, self, 4+float(int(uniform(1,4/4*10)))/100
        yield release, self, stamping
        print self.name,',finish,1,stamp,',now()

    def fab_rim(self):
        print self.name, ',request,1,rim,',now()
        yield request, self, rimming
        print self.name, ',start,1,rim,',now()
        yield hold, self, 10+float(int(uniform(1,10/4*10)))/100
        yield release, self, rimming
        print self.name,',finish,1,rim,',now()

    def fab_deburr(self):
        print self.name, ',request,1,deburr,',now()
        yield request, self, deburring
        print self.name, ',start,1,deburr,',now()
        yield hold, self, 3+float(int(uniform(1,3/4*10)))/100
        yield release, self, deburring
        print self.name,',finish,1,deburr,',now()

    def fab(self):
        yield request, self, wip
        self.start=now()

        self.fab_punch()
        if uniform(1,4)<2:
            self.fab_punch() # rework punch
        self.fab_stamp()
        if uniform(1,4)<2:
            self.fab_punch() # rework punch and stamp
            self.fab_stamp()
        self.fab_rim()
        self.fab_deburr()
        if uniform(1,4)<2:
            self.fab_stamp() # rework stamp and deburr
            self.fab_deburr()
       
        self.finish=now()
        yield release, self, wip
       

initialize()

punching=Resource(capacity=1,monitored=True,monitorType=Monitor)
stamping=Resource(capacity=2,monitored=True,monitorType=Monitor)
rimming=Resource(capacity=3,monitored=True,monitorType=Monitor)
deburring=Resource(capacity=1,monitored=True,monitorType=Monitor)
wip=Resource(capacity=6,monitored=True,monitorType=Monitor)                # implements CONWIP

   
penny=range(20)
for j in range(20):
    penny[j]=pennyfab(name='penny'+str(j))
    activate(penny[j],penny[j].fab())

simulate(until=500)

print ' '
print '*'*40
print '*'*11,' END SIMULATION ','*'*11
print '*'*40
print ' '

print 'Time history for WIP'
print '[time, activeQ]'
for item in wip.actMon:
    print item
print '-'*40

print 'Cycle Times'
average=0

for j in range(20):
    print penny[j].name,',',penny[j].finish-penny[j].start
    average=average+penny[j].finish-penny[j].start

print 'Average Cycle Time'
print average/20
print 'Lot Cycle Time'
print penny[19].finish-penny[0].start

print ' '
print '*'*40
print '*'*13,' END STATS ','*'*14
print '*'*40


-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
Simpy-users mailing list
Simpy-users <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/simpy-users

Gmane