RABINOVITCH Peter | 1 Feb 15:27
Favicon

Re: Question on queueing events to fire at specific times

Thanks to all who replied with suggestions. What follows is a sample
program that implements what I was trying to do.

Basically, a source generates a stream of jobs that go to a server to be
scheduled at specific times. When the time occurs, the job is 'popped'
and the server prints out some info. In the complete system, normal
server processing would continue on the popped job.

Thanks again,
Peter.

from SimPy.Simulation import *
from random import expovariate,Random
from datetime import datetime

class G:
    NextJobID=0
    EndTime=100.0
    Rnd=Random(7)

class Job(Process):
    def __init__(self):
        Process.__init__(self)
        self.id=G.NextJobID
        G.NextJobID+=1
        self.server=-1
    def popper(self,delay):
        yield hold,self,delay
        self.server.receivePopped(self)

(Continue reading)

carole depardieu | 13 Feb 16:59
Picon
Favicon

cpickle-ressources

Hello,

I need to pickle a liste of objects of type Ressources
using cPickle but that it impossible since there are
generators contained and cPickle can't do that.

It would be a great help for me if you could indicate
me what to do, I am about to work in a project and
having so little time at my disposal.

In all cases i do thank you and I am looking forward
hearing from you.

Carole Depardieu

	

	
		
___________________________________________________________________________ 
Découvrez une nouvelle façon d'obtenir des réponses à toutes vos questions ! 
Profitez des connaissances, des opinions et des expériences des internautes sur Yahoo!
Questions/Réponses 
http://fr.answers.yahoo.com

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier.
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
(Continue reading)

carole depardieu | 13 Feb 22:46
Picon

cpickle-Ressources

Hello,

I want to a lsit of Ressources using Python's module cPickle, but I am 
getting a message saying that it can't be done since cPickle can't save 
generators.

I am working on a project which must be finished quite soon, so I would 
appreciate any kind of help or indication .

I am looking forward to hear from you

Carole Depardieu

_________________________________________________________________
Avec Windows Live OneCare éliminez tous les virus de votre PC ! 
http://www.windowslive.fr/liveonecare/default.asp

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier.
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
Mark Anderson | 13 Feb 23:33
Picon

Re: cpickle-Ressources

This is something of a thorny problem, and if you are up against a tight deadline, there may not be an easy answer.
Because simpy relies heavily on python generators, and because generators cannot be pickled/unpickled, saving and restoring simulation state is a nontrivial task.  I have experienced some limited success with copying attributes from the generator based simpy objects to a non-simpy storage object (such as a dictionary) and pickling/unpickling that object.  That method has allowed me to save and restore simulation state for an extremely simple test model.  I have not progressed further than the prototype stage, however.

Good luck,
Mark Anderson

On 2/13/07, carole depardieu <carole_depardieu <at> hotmail.fr> wrote:
Hello,

I want to a lsit of Ressources using Python's module cPickle, but I am
getting a message saying that it can't be done since cPickle can't save
generators.

I am working on a project which must be finished quite soon, so I would
appreciate any kind of help or indication .

I am looking forward to hear from you

Carole Depardieu

_________________________________________________________________
Avec Windows Live OneCare éliminez tous les virus de votre PC !
http://www.windowslive.fr/liveonecare/default.asp


-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier.
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Simpy-users mailing list
Simpy-users <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/simpy-users

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier.
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Simpy-users mailing list
Simpy-users <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/simpy-users
Tony Vignaux | 13 Feb 23:42
Picon
Gravatar

Re: cpickle-Ressources

Carole,

Would there be some advantage in saving a snapshot only at instants when the resources are empty?

Tony



On 2/14/07, Mark Anderson <mnanderson <at> gmail.com> wrote:
This is something of a thorny problem, and if you are up against a tight deadline, there may not be an easy answer.
Because simpy relies heavily on python generators, and because generators cannot be pickled/unpickled, saving and restoring simulation state is a nontrivial task.  I have experienced some limited success with copying attributes from the generator based simpy objects to a non-simpy storage object (such as a dictionary) and pickling/unpickling that object.  That method has allowed me to save and restore simulation state for an extremely simple test model.  I have not progressed further than the prototype stage, however.

Good luck,
Mark Anderson


On 2/13/07, carole depardieu < carole_depardieu <at> hotmail.fr> wrote:
Hello,

I want to a lsit of Ressources using Python's module cPickle, but I am
getting a message saying that it can't be done since cPickle can't save
generators.

I am working on a project which must be finished quite soon, so I would
appreciate any kind of help or indication .

I am looking forward to hear from you

Carole Depardieu

_________________________________________________________________
Avec Windows Live OneCare éliminez tous les virus de votre PC !
http://www.windowslive.fr/liveonecare/default.asp


-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier.
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Simpy-users mailing list
Simpy-users <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/simpy-users


-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier.
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Simpy-users mailing list
Simpy-users <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/simpy-users




--
Prof Tony  Vignaux
Victoria University of Wellington
-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier.
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Simpy-users mailing list
Simpy-users <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/simpy-users
Tony Vignaux | 14 Feb 09:50
Picon
Gravatar

Re: cpickle-Ressources

I hope mine is not the only reply you have seen. Are you watching the mail list?  please send your replies to simpy-users <at> lists.sourceforge.net. Did you see Mark Anderson's reply though he repeated what Klaus Muller had thought.

I cannot see a solution to your problem immediately.

Is there some approximation you can think of? Does it matter to the remaining simulation which particular objects are queueing at the time of the snapshot? How many Resources are involved?


On 2/14/07, carole depardieu <carole_depardieu <at> hotmail.fr> wrote:
Good morning
Thank you so much for replying to me !


>
>Carole,
>
>Would there be some advantage in saving a snapshot only at instants when
>the
>resources are empty?


What I need is to have the state of the ressources at the end of my
simulation. And I can't force them to be empty since I need to know not only
the length od the queues but identifie those objects  too so as to be able
to recontinue and old simulation !

I had the a similar problem before when I was trying to pickle another
object, but then I could delete the function "expovariate"  before the "
dumping "and at the moment of loading i was including it again !
But now it is more complicated.






>
>Tony
>
>
>
>On 2/14/07, Mark Anderson <mnanderson <at> gmail.com> wrote:
>>
>>This is something of a thorny problem, and if you are up against a tight
>>deadline, there may not be an easy answer.
>>Because simpy relies heavily on python generators, and because generators
>>cannot be pickled/unpickled, saving and restoring simulation state is a
>>nontrivial task.  I have experienced some limited success with copying
>>attributes from the generator based simpy objects to a non-simpy storage
>>object (such as a dictionary) and pickling/unpickling that object.  That
>>method has allowed me to save and restore simulation state for an
>>extremely
>>simple test model.  I have not progressed further than the prototype
>>stage,
>>however.
>>
>>Good luck,
>>Mark Anderson
>>
>>On 2/13/07, carole depardieu <carole_depardieu <at> hotmail.fr > wrote:
>> >
>> > Hello,
>> >
>> > I want to a lsit of Ressources using Python's module cPickle, but I am
>> > getting a message saying that it can't be done since cPickle can't save
>> > generators.
>> >
>> > I am working on a project which must be finished quite soon, so I would
>> > appreciate any kind of help or indication .
>> >
>> > I am looking forward to hear from you
>> >
>> > Carole Depardieu
>> >
>> > _________________________________________________________________
>> > Avec Windows Live OneCare éliminez tous les virus de votre PC !
>> > http://www.windowslive.fr/liveonecare/default.asp
>> >
>> >
>> >
>> >
>>-------------------------------------------------------------------------
>> > Using Tomcat but need to do more? Need to support web services,
>> > security?
>> > Get stuff done quickly with pre-integrated technology to make your job
>> > easier.
>> > Download IBM WebSphere Application Server v.1.0.1 based on Apache
>> > Geronimo
>> >
>> http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
>> >
>> > _______________________________________________
>> > Simpy-users mailing list
>> > Simpy-users <at> lists.sourceforge.net
>> > https://lists.sourceforge.net/lists/listinfo/simpy-users
>> >
>>
>>
>>-------------------------------------------------------------------------
>>Using Tomcat but need to do more? Need to support web services, security?
>>Get stuff done quickly with pre-integrated technology to make your job
>>easier.
>>Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
>>http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
>>_______________________________________________
>>Simpy-users mailing list
>>Simpy-users <at> lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/simpy-users
>>
>>
>
>
>--
>Prof Tony  Vignaux
>Victoria University of Wellington

_________________________________________________________________
Personnalisez votre Messenger avec Live.com
http://www.windowslive.fr/livecom/




--
Prof Tony  Vignaux
Victoria University of Wellington
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Simpy-users mailing list
Simpy-users <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/simpy-users
carole depardieu | 14 Feb 10:24
Picon

FW: Re: cpickle-Ressources


>From: "Tony Vignaux" <vignaux <at> gmail.com>
>To: "Mark Anderson" <mnanderson <at> gmail.com>
>CC: "carole depardieu" <carole_depardieu <at> hotmail.fr>, 
>simpy-users <at> lists.sourceforge.net
>Subject: Re: [Simpy-users] cpickle-Ressources
>Date: Wed, 14 Feb 2007 11:42:05 +1300
>

_________________________________________________________________
Personnalisez votre Messenger avec Live.com 
http://www.windowslive.fr/livecom/
Carole,

Would there be some advantage in saving a snapshot only at instants when the
resources are empty?

Tony

On 2/14/07, Mark Anderson <mnanderson <at> gmail.com> wrote:
>
>This is something of a thorny problem, and if you are up against a tight
>deadline, there may not be an easy answer.
>Because simpy relies heavily on python generators, and because generators
>cannot be pickled/unpickled, saving and restoring simulation state is a
>nontrivial task.  I have experienced some limited success with copying
>attributes from the generator based simpy objects to a non-simpy storage
>object (such as a dictionary) and pickling/unpickling that object.  That
>method has allowed me to save and restore simulation state for an extremely
>simple test model.  I have not progressed further than the prototype stage,
>however.
>
>Good luck,
>Mark Anderson
>
>On 2/13/07, carole depardieu <carole_depardieu <at> hotmail.fr> wrote:
> >
> > Hello,
> >
> > I want to a lsit of Ressources using Python's module cPickle, but I am
> > getting a message saying that it can't be done since cPickle can't save
> > generators.
> >
> > I am working on a project which must be finished quite soon, so I would
> > appreciate any kind of help or indication .
> >
> > I am looking forward to hear from you
> >
> > Carole Depardieu
> >
> > _________________________________________________________________
> > Avec Windows Live OneCare éliminez tous les virus de votre PC !
> > http://www.windowslive.fr/liveonecare/default.asp
> >
> >
> >
> > 
>-------------------------------------------------------------------------
> > Using Tomcat but need to do more? Need to support web services,
> > security?
> > Get stuff done quickly with pre-integrated technology to make your job
> > easier.
> > Download IBM WebSphere Application Server v.1.0.1 based on Apache
> > Geronimo
> > http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
> >
> > _______________________________________________
> > Simpy-users mailing list
> > Simpy-users <at> lists.sourceforge.net
> > https://lists.sourceforge.net/lists/listinfo/simpy-users
> >
>
>
>-------------------------------------------------------------------------
>Using Tomcat but need to do more? Need to support web services, security?
>Get stuff done quickly with pre-integrated technology to make your job
>easier.
>Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
>http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
>_______________________________________________
>Simpy-users mailing list
>Simpy-users <at> lists.sourceforge.net
>https://lists.sourceforge.net/lists/listinfo/simpy-users
>
>

--
Prof Tony  Vignaux
Victoria University of Wellington

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Simpy-users mailing list
Simpy-users <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/simpy-users
carole depardieu | 14 Feb 10:25
Picon

FW: RE: cpickle-Ressources


>From: <RCRamsdell <at> gldd.com>
>To: <carole_depardieu <at> hotmail.fr>
>Subject: RE: [Simpy-users] cpickle-Ressources
>Date: Tue, 13 Feb 2007 16:35:50 -0600
>
>Hi Carole,
>
>There was some discussion of this in this thread a while back:
>
>http://sourceforge.net/mailarchive/message.php?msg_id=14032637
>
>There are few other mentions of the problem of saving a simulation state 
>(searhc the archives for pickle, or stackless)
>
>The short answer is that hgenerators cannot be pickled, I presume since 
>there is no way of saving the internal state of the function.  I suppose 
>that you could write your process/resource in such a way that the state 
>could be saved to a sub-class that is pickle-able.  Maybe have your Process 
>wrap another class without generators, and have the PEM call functions of 
>that class based on the state of the sub-class?  I suspect that this 
>approach would require pretty simple Processes.
>
>Robert
>
> > -----Original Message-----
> > From: simpy-users-bounces <at> lists.sourceforge.net
> > [mailto:simpy-users-bounces <at> lists.sourceforge.net] On Behalf
> > Of carole depardieu
> > Sent: Tuesday, February 13, 2007 3:47 PM
> > To: simpy-users <at> lists.sourceforge.net
> > Subject: [Simpy-users] cpickle-Ressources
> >
> > Hello,
> >
> > I want to a lsit of Ressources using Python's module cPickle,
> > but I am getting a message saying that it can't be done since
> > cPickle can't save generators.
> >
> > I am working on a project which must be finished quite soon,
> > so I would appreciate any kind of help or indication .
> >
> > I am looking forward to hear from you
> >
> > Carole Depardieu
> >
> > _________________________________________________________________
> > Avec Windows Live OneCare éliminez tous les virus de votre PC !
> > http://www.windowslive.fr/liveonecare/default.asp
> >
> >
> > --------------------------------------------------------------
> > -----------
> > Using Tomcat but need to do more? Need to support web
> > services, security?
> > Get stuff done quickly with pre-integrated technology to make
> > your job easier.
> > Download IBM WebSphere Application Server v.1.0.1 based on
> > Apache Geronimo
> > http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&
>dat=121642
> > _______________________________________________
> > Simpy-users mailing list
> > Simpy-users <at> lists.sourceforge.net
> > https://lists.sourceforge.net/lists/listinfo/simpy-users
> >

_________________________________________________________________
Avec Windows Live OneCare éliminez tous les virus de votre PC ! 
http://www.windowslive.fr/liveonecare/default.asp

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
carole depardieu | 14 Feb 10:25
Picon

FW: Re: cpickle-Ressources


>From: "Mark Anderson" <mnanderson <at> gmail.com>
>To: "carole depardieu" <carole_depardieu <at> hotmail.fr>
>CC: simpy-users <at> lists.sourceforge.net
>Subject: Re: [Simpy-users] cpickle-Ressources
>Date: Tue, 13 Feb 2007 17:33:07 -0500
>

_________________________________________________________________
Ten :  Messenger en illimité sur votre mobile !  
http://mobile.live.fr/messenger/ten/
This is something of a thorny problem, and if you are up against a tight
deadline, there may not be an easy answer.
Because simpy relies heavily on python generators, and because generators
cannot be pickled/unpickled, saving and restoring simulation state is a
nontrivial task.  I have experienced some limited success with copying
attributes from the generator based simpy objects to a non-simpy storage
object (such as a dictionary) and pickling/unpickling that object.  That
method has allowed me to save and restore simulation state for an extremely
simple test model.  I have not progressed further than the prototype stage,
however.

Good luck,
Mark Anderson

On 2/13/07, carole depardieu <carole_depardieu <at> hotmail.fr> wrote:
>
>Hello,
>
>I want to a lsit of Ressources using Python's module cPickle, but I am
>getting a message saying that it can't be done since cPickle can't save
>generators.
>
>I am working on a project which must be finished quite soon, so I would
>appreciate any kind of help or indication .
>
>I am looking forward to hear from you
>
>Carole Depardieu
>
>_________________________________________________________________
>Avec Windows Live OneCare éliminez tous les virus de votre PC !
>http://www.windowslive.fr/liveonecare/default.asp
>
>
>-------------------------------------------------------------------------
>Using Tomcat but need to do more? Need to support web services, security?
>Get stuff done quickly with pre-integrated technology to make your job
>easier.
>Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
>http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
>_______________________________________________
>Simpy-users mailing list
>Simpy-users <at> lists.sourceforge.net
>https://lists.sourceforge.net/lists/listinfo/simpy-users
>

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Simpy-users mailing list
Simpy-users <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/simpy-users
Klaus Muller | 15 Feb 15:41
Picon
Picon
Favicon

A solution for saving a SimPy simulation state by pickling

Dear Carole,
I worked on your problem (pickling a SimPy simulation state) and came up
with a workaround to Python's limitation of not being capable of pickling
generators.

Basically, one has to 

* maintain state in the PEMs (generator method) of the instances one wishes
to pickle,
* direct the program flow based on the initial state by "if state== . . . "
statements,
* for all restarted states, repeat the last yield statement executed before
the pickle
* pickle the interrupt (save) time,
* pickle the length of the Resource's activeQ (= the number of processes
holding a unit of that Resource)
* run through the activeQ of the Resource instance(s) with an index, say i:
  - make each process in the activeQ passive (set i._nextpoint=None and
i._nextTime=None). Then it is not
    a generator.
  - remove any reference to generators( set i._priority={})
  - pickle instance i 
* pickle the length of the Resource's waitQ (= the number of processes
waiting for that Resource)
* run through the waitQ of the Resource instance(s) with an index, say i:
  - remove any reference to generators( set i._priority={})
  - pickle instance i 

To reload and continue running the simulation,
* load the pickle time
* load the number of active processes
* generate that number of process instances and activate them at the
pickle/restart time
* load the number of waiting processes
* generate that number of process instances and activate them at the
pickle/restart time
* run the simulation

The attached file shows an adaptation of one of the models in the Bank
tutorial. It works!

PLEASE, comment!

Regards,

Klaus Müller

PS: We should all write to the Python developers and request that they
change pickle so that generators can be pickled. This requirement was
already raised in 1994, but no action so far!

 

#!/usr/bin/env python
""" bank08: A counter with a random service time"""
from SimPy.Simulation  import *
from random import expovariate, seed
import pickle as p

class Source(Process):
    """ Source generates customers randomly"""

    def generate(self,number,interval):       
        for i in range(number):
            c = Customer(name = "Customer%3.0f"%now())
            activate(c,c.visit(timeInBank=12.0))
            t = expovariate(1.0/interval)
            yield hold,self,t
normal=0
inQ=1
actif=2

class Customer(Process):
    """ Customer arrives, is served and leaves """

    def visit(self,timeInBank=0,state=normal): 
        if state==normal:
            self.state=state        
            self.arrive=now()
            print "%7.4f %s: Here I am     "%(now(),self.name)
            self.state=inQ
            yield request,self,counter
            self.state=actif
            wait=now()-self.arrive
            print "%7.4f %s: Waited %6.3f"%(now(),self.name,wait)
            self.tib = expovariate(1.0/timeInBank)           
            yield hold,self,self.tib                          
            yield release,self,counter
            print "%7.4f %s: Finished      "%(now(),self.name)
        elif self.state==inQ:
            yield request,self,counter
            self.state=actif
            wait=now()-self.arrive
            print "%7.4f %s: Waited %6.3f"%(now(),self.name,wait)
            self.tib = expovariate(1.0/timeInBank)            
            yield hold,self,self.tib                          
            yield release,self,counter
            print "%7.4f %s: Finished      "%(now(),self.name)
        elif self.state==actif:
            yield request,self,counter
            yield hold,self,self.tib-trestart
            yield release,self,counter
            print "%7.4f %s: Finished      "%(now(),self.name)            

class Pickler(Process):
    def picklesim(self):
        #open file for pickling
        f=open("pickle.dat","w")
        #pickle time
        p.dump(now(),f)
        #pickle Customer instances in activeQ
        #the number of instances in activeQ
        p.dump(len(counter.activeQ),f)
        #now the instances
        for i in counter.activeQ:
            i._nextpoint=None
            i._priority={} 
            i._nextTime=None            
            #print i.name
            p.dump(i,f)
        #pickle Customer instances in waitQ
        #the number of instances in waitQ
        p.dump(len(counter.waitQ),f)
        #now the instances
        for i in counter.waitQ:
            #i._nextpoint=None #remove generator
            i._priority={}
            p.dump(i,f)
        #close pickle file
        f.close()
        #end simulation
        stopSimulation()
        yield hold,self,0

def model(theseed,restart=False):                                   
    global counter,trestart
    if not restart: #initial run   
        seed(theseed)
        counter = Resource(name="Karen") 
        initialize()
        source = Source('Source')
        activate(source,source.generate(10,interval=10.0),0.0)
        tSimSave=250.    # time when simulation state is saved
        pick=Pickler()
        activate(pick,pick.picklesim(),at=tSimSave) 
        simulate(until=1000.0)
    else: #model restarted
        seed(2*theseed)
        f=open("pickle.dat")
        trestart=p.load(f)
        initialize()
        counter = Resource(name="Karen")
        #load the number of Customer instances in counter.activeQ
        nrActive=p.load(f)
        #regenerate the active Customer instances
        for i in range(nrActive):
            c=p.load(f)
            activate(c,c.visit(timeInBank=12.,state=c.state),at=trestart)            
        #load the number of Customer instances in counter.waitQ
        nrWaiting=p.load(f)
        #regenerate the active Customer instances
        for i in range(nrWaiting):
            c=p.load(f)
            activate(c,c.visit(timeInBank=12.,state=c.state),at=trestart)
        #the Source process (needs pickling as well, but not yet done)
        source = Source('Source')
        activate(source,source.generate(10,interval=10.0),at=trestart)
        simulate(until=1000.0)            

model(theseed=123456,restart=False)
print "\n**** After pickle and reload/restart of run (t=%s)"%now()
model(theseed=123456,restart=True)

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Simpy-users mailing list
Simpy-users <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/simpy-users

Gmane