Virgil Stokes | 9 May 07:27
Picon
Picon
Favicon
Gravatar

Inventory simulation?

I would like to know if someone has used SimPy for inventory simulation.

--Thanks,
V. Stokes

-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference 
Don't miss this year's exciting event. There's still time to save $100. 
Use priority code J8TL2D2. 
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
Picon

"Activating function is not a generator (contains no 'yield')" error

Dear SimPy users or developers:

I am building a SimPy simulation in which my Process Execution method
is rather complex. I want to make that function call other functions
which will execute the "yield" statements. Apparently this is not
possible. As a very simple example of what I want to do, see the code
below. The execution fails with a "Activating function is not a
generator (contains no 'yield')" error.

What is the solution to this problem? Should I write big, monolithic
generator functions or is there any better way?

Best wishes,
Mario Orne DÍAZ ANADÓN
Imperial College London

********************************
from SimPy.Simulation import *

class Message(Process):
	""" a simple Process """
	def __init__(self,i,len):
		Process.__init__(self,name="Message"+str(i))
		self.i = i
		self.len = len

	def go(self):
		self.go2()
	def go2(self):
		print now(), self.i, "Starting"
(Continue reading)

kgmuller | 12 May 14:57
Picon
Picon
Favicon

Re: "Activating function is not a generator (contains no'yield')" error

Dear Mario,
No, you don't have to write big generator functions/PEMs.

Say you have the following code:

class Foo(Process):
    def PEM(self):
        ## Big, fat PEM
        ## The bla event
        bla
        bla
        bla
        (lots of code)
        bla
        bla
        yield (some action)
        ## The rhubarb event
        rhubarb
        rhubarb
        rhubarb
        rhubarb
        (even more code)
        rhubarb
        rhubarb
        yield (some other action)

You can transform this into:

class Foo(Process):
    def blaEvent(self):
(Continue reading)

Picon

Re: "Activating function is not a generator (contains no'yield')" error

Dear Klaus:

Thanks for your answer. I knew I could do the manipulation you
suggest, but it results in code repetion, less legibility and less
maintainability than the one I want to use.

I am using SimPy to simulate Wireless Sensor Networks in my PhD
thesis. I want to have a "transmit" function that incorporates the
delay of transmitting a packet (the "yield" part).I want to write
"yield" statements in the auxiliary functions called from the PEM. Am
I correct to say that is impossible to do?

Best wishes,
- Mario

On Mon, May 12, 2008 at 1:57 PM, kgmuller <kgmuller <at> xs4all.nl> wrote:
> Dear Mario,
>  No, you don't have to write big generator functions/PEMs.
>
>  Say you have the following code:
>
>  class Foo(Process):
>     def PEM(self):
>         ## Big, fat PEM
>         ## The bla event
>         bla
>         bla
>         bla
>         (lots of code)
>         bla
(Continue reading)

kgmuller | 12 May 18:49
Picon
Picon
Favicon

Re: "Activating function is not a generator (contains no'yield')" error

Dear Mario,
Every process object can only have one activated PEM at a time, so you can't
have yields outside the PEM/generator. SimPy is a process-oriented
simulation framework, and in a process, there is only one lifecycle (the
PEM). The PEM clearly shows the sequences of state change/event code (atomic
sections) and of synchronization commands. In most authors and users' views,
this gives better mapping between model and code, higher legibility and
better maintainability than e.g. event-based frameworks where events are
spread over different functions. But this is admittedly both a matter of
personal taste and experience.

I can't see any code repetition compared to your approach, BTW.

Your PhD thesis subject looks very interesting. If you ever need to have any
advice on SimPy internals or, better even, if you have any suggestions on
how to improve SimPy, please, contact me!

Best regards y saludos muy cordiales,

Klaus

> -----Original Message-----
> From: Mario Orne Díaz Anadón [mailto:ornediaz <at> gmail.com] 
> Sent: Monday, May 12, 2008 3:21 PM
> To: kgmuller
> Cc: simpy-users <at> lists.sourceforge.net
> Subject: Re: [Simpy-users] "Activating function is not a 
> generator (contains no'yield')" error
> 
> Dear Klaus:
(Continue reading)

Picon

Re: "Activating function is not a generator (contains no'yield')" error

Dear Klaus:
 Many thanks for your answer. Now I am clear that what I wanted to do
is impossible.

 Let me explain you why my approach would have saved me code repetition.

Example of what I wanted to do but it is impossible with SimPy:
 **************************
 class SensorNode:
     def transmit(self,packet):
         self.fun1()
         yield hold,self,t1
         self.fun2()
         yield hold,self,t2
         self.fun3()
    def PEM(self):
       some code
       if something:
             self.transmit(Packet1)
       some code
       if something:
           self.transmit(Packet2)
       while something:
              self.transmit(Packet3)

 *******************

With SimPy, every time I want to transmit a packet, instead of simply
writing "self.transmit(Packet)", I have to write the following:
        self.fun1()
(Continue reading)

Mark Elston | 12 May 19:50

Re: "Activating function is not a generator (contains no'yield')" error

Mario,

The SimPy docs say:

   Each PEM must contain at least one of the yield statements, described
   later, that make it a Python generator function.

A function that does not, itself, have a yield statement cannot be
a generator function.  This is right out of the documentation of the
yield statement in the Python docs.

So you need a yield in your PEM function for it to work.

You might try having your PEM hold on to the generator iterator of
the transmit function, yield'ing that iterator and calling next()
to get the behavior you want.  I haven't tried this and don't know
if it would work but it might be worth a try.

Mark

* Mario Orne Díaz Anadón wrote (on 5/12/2008 10:23 AM):
> Dear Klaus:
>  Many thanks for your answer. Now I am clear that what I wanted to do
> is impossible.
> 
>  Let me explain you why my approach would have saved me code repetition.
> 
> Example of what I wanted to do but it is impossible with SimPy:
>  **************************
>  class SensorNode:
(Continue reading)

Picon

Re: "Activating function is not a generator (contains no'yield')" error

Thanks Mark. Can you give me a simple example of how to implement your
suggestion of having the PEM hold on to the generator iterator of the
transmit function, yield'ing that iterator and calling next()?
- Mario.

On Mon, May 12, 2008 at 6:50 PM, Mark Elston <m.elston <at> advantest-ard.com> wrote:
> Mario,
>
>  The SimPy docs say:
>
>   Each PEM must contain at least one of the yield statements, described
>   later, that make it a Python generator function.
>
>  A function that does not, itself, have a yield statement cannot be
>  a generator function.  This is right out of the documentation of the
>  yield statement in the Python docs.
>
>  So you need a yield in your PEM function for it to work.
>
>  You might try having your PEM hold on to the generator iterator of
>  the transmit function, yield'ing that iterator and calling next()
>  to get the behavior you want.  I haven't tried this and don't know
>  if it would work but it might be worth a try.
>
>  Mark
>
>  * Mario Orne Díaz Anadón wrote (on 5/12/2008 10:23 AM):
>
>
>
(Continue reading)

Harri Vartiainen | 12 May 20:23
Picon
Picon
Favicon

Re: "Activating function is not a generator (contains no'yield')" error

 Try something like this:

class SensorNdoe:
     def transmit(self,packet):
         self.fun1()
         yield hold,self,t1
         self.fun2()
         yield hold,self,t2
         self.fun3()

    def PEM(self):
       some code
       if something:
             for a,b c in self.transmit(Packet1):
                yield a, b, c
       some code
       if something:
             for a,b c in self.transmit(Packet2):
                yield a, b, c
       while something:
             for a,b c in self.transmit(Packet1):
                yield a, b, c

On Mon, May 12, 2008 at 8:23 PM, Mario Orne Díaz Anadón
<ornediaz <at> gmail.com> wrote:
> Dear Klaus:
>  Many thanks for your answer. Now I am clear that what I wanted to do
> is impossible.
>
>  Let me explain you why my approach would have saved me code repetition.
(Continue reading)

Anselmo Pitombeira | 12 May 20:23
Picon
Favicon

Re: Inventory simulation?

Hi, V. Stokes,

I've built some supply chain models. Thus, I had to model the warehouses 
and distribution centers which comprise the chain. I think it is quite 
possible to use SimPy to do inventory simulation, but you should pay 
attention to what types you choose for your simulation objects. For 
example, in my models I found it unsuitable to represent a stock keeping 
unit (sku) as an instance of a Process class, since the model would get 
populated by an overwhelming amount of SimPy processes, what would eat 
up a big chunk of computer's memory and processing time. I think it is 
better to define a  "canonical" class (which doesn't derive from 
Process) for your sku's, and use Process-based classes whose instances 
will guide the material flow throughout a warehouse or whole supply 
chain. A further reason for using this approach is that it is easier to 
implement the just-in-time logic typical of inventory systems (as 
discrete-event simulation is highly influenced by the Queuing Theory 
view of push flow, sometimes you have to do some trick to model JIT 
policies).

Good luck

Anselmo Pitombeira

> Message: 4
> Date: Fri, 09 May 2008 07:27:58 +0200
> From: Virgil Stokes <vs <at> it.uu.se>
> Subject: [Simpy-users] Inventory simulation?
> To: simpy-users <at> lists.sourceforge.net
> Message-ID: <4823E0DE.7010108 <at> it.uu.se>
> Content-Type: text/plain; charset=ISO-8859-1; format=flowed
(Continue reading)


Gmane