Tim Condit | 10 Jun 04:32
Picon

ending a simulation

Hi,

I've wondered about something, but so far have not had time to look more closely at it.  So I'm wondering if others have done something like this before.

I'm gathering statistics from a simulation of Taxis and Fares.  One of them is the span of time from Fare activation, until pickup by a Taxi.  The second is the span of time from when the Fare is picked up, until it is dropped off at its destination.  In every simulation, I wind up with three distinct groups of Fares: those that are picked up and taken to their destination, essentially completing the Fare's lifecycle; those that are picked up, but are still en'route when the simulation ends; and those that never get picked up at all, for one reason or another.

The problem I have (or maybe only imagine I have) is that this presents something of a dilemma when I'm trying to gather data with a Monitor.  I'm not sure how to report it!  Whatever I do with it at this point, it's a separate set (or sets) of data, that I'd like incorporated into the data for completed Fares.  So I'm thinking about using a sort of compound condition for terminating a simulation.  That would leave me with just the completed Fares and the waiting Fares, which is more manageable.  I tried this,

    simulate(until=(SIMTIME and len(Agents.waitingFares.theBuffer) == 0))

but it doesn't work, and I'm not sure why.  It almost seems to behave like I'm using a logical OR instead of AND in there.  The simulation starts up, and as the buffer is almost immediately emptied the simulation terminates, even though it's nowhere near SIMTIME.  Now I'm thinking about just calculating the time remaining for the en'route Fares to reach their destinations, and adding those Fares to the set of completed Fares, with a note to that effect.  But it's definitely a second choice.

Has anyone tried anything like this?  Had any success with it?  More generally, does anyone have strategies or pointers to documentation for dealing with these types of loose ends in data collection?

Thanks!
Tim

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Simpy-users mailing list
Simpy-users <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/simpy-users
Steven H. Rogers | 10 Jun 14:30
Favicon

Re: ending a simulation

Tim Condit wrote:
> Hi,
>
> I've wondered about something, but so far have not had time to look 
> more closely at it.  So I'm wondering if others have done something 
> like this before.
>
> I'm gathering statistics from a simulation of Taxis and Fares.  One of 
> them is the span of time from Fare activation, until pickup by a 
> Taxi.  The second is the span of time from when the Fare is picked up, 
> until it is dropped off at its destination.  In every simulation, I 
> wind up with three distinct groups of Fares: those that are picked up 
> and taken to their destination, essentially completing the Fare's 
> lifecycle; those that are picked up, but are still en'route when the 
> simulation ends; and those that never get picked up at all, for one 
> reason or another.
>
> The problem I have (or maybe only imagine I have) is that this 
> presents something of a dilemma when I'm trying to gather data with a 
> Monitor.  I'm not sure how to report it!  Whatever I do with it at 
> this point, it's a separate set (or sets) of data, that I'd like 
> incorporated into the data for completed Fares.  So I'm thinking about 
> using a sort of compound condition for terminating a simulation.  That 
> would leave me with just the completed Fares and the waiting Fares, 
> which is more manageable.  I tried this,
>
>     simulate(until=(SIMTIME and len(Agents.waitingFares.theBuffer) == 0))
>
> but it doesn't work, and I'm not sure why.  It almost seems to behave 
> like I'm using a logical OR instead of AND in there.  The simulation 
> starts up, and as the buffer is almost immediately emptied the 
> simulation terminates, even though it's nowhere near SIMTIME.  Now I'm 
> thinking about just calculating the time remaining for the en'route 
> Fares to reach their destinations, and adding those Fares to the set 
> of completed Fares, with a note to that effect.  But it's definitely a 
> second choice.
>
> Has anyone tried anything like this?  Had any success with it?  More 
> generally, does anyone have strategies or pointers to documentation 
> for dealing with these types of loose ends in data collection?

I believe that simulate expects a boolean argument, terminating when it 
evaluates to true.
Try something like:
simulate(until=((SimPy.Simulation.now() >= SIMTIME) and 
len(Agents.waitingFares.theBuffer) == 0))

# Steve

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
Steven H. Rogers | 10 Jun 14:52
Favicon

SimPy Book

What's the status of the SimPy book?  Also, while looking at the sample 
chapter on the web site I question the assert statement following the line:

yield Sim.request,self,ban.manager

It doesn't seem needed for the example, though it would be useful for a 
SimPy unit test.

Regards,
Steve

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
Tim Condit | 10 Jun 21:46
Picon

Re: ending a simulation

Thanks for the suggestion Steve.  Unfortunately, it terminates
prematurely in exactly the same way.

On 6/10/07, Steven H. Rogers <steve <at> shrogers.com> wrote:
> Tim Condit wrote:
> > Hi,
> >
> > I've wondered about something, but so far have not had time to look
> > more closely at it.  So I'm wondering if others have done something
> > like this before.
> >
> > I'm gathering statistics from a simulation of Taxis and Fares.  One of
> > them is the span of time from Fare activation, until pickup by a
> > Taxi.  The second is the span of time from when the Fare is picked up,
> > until it is dropped off at its destination.  In every simulation, I
> > wind up with three distinct groups of Fares: those that are picked up
> > and taken to their destination, essentially completing the Fare's
> > lifecycle; those that are picked up, but are still en'route when the
> > simulation ends; and those that never get picked up at all, for one
> > reason or another.
> >
> > The problem I have (or maybe only imagine I have) is that this
> > presents something of a dilemma when I'm trying to gather data with a
> > Monitor.  I'm not sure how to report it!  Whatever I do with it at
> > this point, it's a separate set (or sets) of data, that I'd like
> > incorporated into the data for completed Fares.  So I'm thinking about
> > using a sort of compound condition for terminating a simulation.  That
> > would leave me with just the completed Fares and the waiting Fares,
> > which is more manageable.  I tried this,
> >
> >     simulate(until=(SIMTIME and len(Agents.waitingFares.theBuffer) == 0))
> >
> > but it doesn't work, and I'm not sure why.  It almost seems to behave
> > like I'm using a logical OR instead of AND in there.  The simulation
> > starts up, and as the buffer is almost immediately emptied the
> > simulation terminates, even though it's nowhere near SIMTIME.  Now I'm
> > thinking about just calculating the time remaining for the en'route
> > Fares to reach their destinations, and adding those Fares to the set
> > of completed Fares, with a note to that effect.  But it's definitely a
> > second choice.
> >
> > Has anyone tried anything like this?  Had any success with it?  More
> > generally, does anyone have strategies or pointers to documentation
> > for dealing with these types of loose ends in data collection?
>
> I believe that simulate expects a boolean argument, terminating when it
> evaluates to true.
> Try something like:
> simulate(until=((SimPy.Simulation.now() >= SIMTIME) and
> len(Agents.waitingFares.theBuffer) == 0))
>
> # Steve
>
>
> -------------------------------------------------------------------------
> This SF.net email is sponsored by DB2 Express
> Download DB2 Express C - the FREE version of DB2 express and take
> control of your XML. No limits. Just data. Click to get it now.
> http://sourceforge.net/powerbar/db2/
> _______________________________________________
> Simpy-users mailing list
> Simpy-users <at> lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/simpy-users
>

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
Steven H. Rogers | 11 Jun 00:38
Favicon

Re: ending a simulation

Tim Condit wrote:
> Thanks for the suggestion Steve.  Unfortunately, it terminates
> prematurely in exactly the same way.
>
>   
Tim:

Sorry about that.  I looked at the Simulation.simulate code and it's 
expecting a number for until and defaults to 0.

Another thing to try is put a statement like this in your model() function.

If (SimPy.Simulation.now() >= SIMTIME) and len(Agents.waitingFares.theBuffer) == 0)):
    Simpy.Simulation.stopSimulation()

# Steve

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
Klaus Muller | 11 Jun 10:40
Picon
Picon
Favicon

Re: ending a simulation

Tim,
as you have been told by Steve Rogers already, "simulate" takes a numerical parameter.
 
As to the termination condition, is there a reason why you can't just stop producing fares at a certain time and set the endtime for simulate significantly later so that all fares which will ever be picked up get picked up? SimPy stops the moment there are no more events on the event list.
 
If this is not feasible for one reason or another, you could use a "yield waituntil" command in a process which stops the simulation when the condition is true. It slows the simulation down a bit, admittedly.
 
Klaus

From: simpy-users-bounces <at> lists.sourceforge.net [mailto:simpy-users-bounces <at> lists.sourceforge.net] On Behalf Of Tim Condit
Sent: Sunday, June 10, 2007 4:33 AM
To: simpy-users <at> lists.sourceforge.net
Subject: [Simpy-users] ending a simulation

Hi,

I've wondered about something, but so far have not had time to look more closely at it.  So I'm wondering if others have done something like this before.

I'm gathering statistics from a simulation of Taxis and Fares.  One of them is the span of time from Fare activation, until pickup by a Taxi.  The second is the span of time from when the Fare is picked up, until it is dropped off at its destination.  In every simulation, I wind up with three distinct groups of Fares: those that are picked up and taken to their destination, essentially completing the Fare's lifecycle; those that are picked up, but are still en'route when the simulation ends; and those that never get picked up at all, for one reason or another.

The problem I have (or maybe only imagine I have) is that this presents something of a dilemma when I'm trying to gather data with a Monitor.  I'm not sure how to report it!  Whatever I do with it at this point, it's a separate set (or sets) of data, that I'd like incorporated into the data for completed Fares.  So I'm thinking about using a sort of compound condition for terminating a simulation.  That would leave me with just the completed Fares and the waiting Fares, which is more manageable.  I tried this,

    simulate(until=(SIMTIME and len(Agents.waitingFares.theBuffer) == 0))

but it doesn't work, and I'm not sure why.  It almost seems to behave like I'm using a logical OR instead of AND in there.  The simulation starts up, and as the buffer is almost immediately emptied the simulation terminates, even though it's nowhere near SIMTIME.  Now I'm thinking about just calculating the time remaining for the en'route Fares to reach their destinations, and adding those Fares to the set of completed Fares, with a note to that effect.  But it's definitely a second choice.

Has anyone tried anything like this?  Had any success with it?  More generally, does anyone have strategies or pointers to documentation for dealing with these types of loose ends in data collection?

Thanks!
Tim
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Simpy-users mailing list
Simpy-users <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/simpy-users
Tim Condit | 12 Jun 22:23
Picon

Re: ending a simulation

Hi,
 
Sure, I can set the endtime later than when the last fare is created.  That's no problem.  I was looking for a solution that appealed to me aesthetically, but it's not blocking me. :)
 
Thanks again,
Tim
 
 
On 6/11/07, Klaus Muller <kgmuller <at> xs4all.nl > wrote:
Tim,
as you have been told by Steve Rogers already, "simulate" takes a numerical parameter.
 
As to the termination condition, is there a reason why you can't just stop producing fares at a certain time and set the endtime for simulate significantly later so that all fares which will ever be picked up get picked up? SimPy stops the moment there are no more events on the event list.
 
If this is not feasible for one reason or another, you could use a "yield waituntil" command in a process which stops the simulation when the condition is true. It slows the simulation down a bit, admittedly.
 
Klaus

From: simpy-users-bounces <at> lists.sourceforge.net [mailto: simpy-users-bounces <at> lists.sourceforge.net] On Behalf Of Tim Condit
Sent: Sunday, June 10, 2007 4:33 AM
To: simpy-users <at> lists.sourceforge.net
Subject: [Simpy-users] ending a simulation

 
Hi,

I've wondered about something, but so far have not had time to look more closely at it.  So I'm wondering if others have done something like this before.

I'm gathering statistics from a simulation of Taxis and Fares.  One of them is the span of time from Fare activation, until pickup by a Taxi.  The second is the span of time from when the Fare is picked up, until it is dropped off at its destination.  In every simulation, I wind up with three distinct groups of Fares: those that are picked up and taken to their destination, essentially completing the Fare's lifecycle; those that are picked up, but are still en'route when the simulation ends; and those that never get picked up at all, for one reason or another.

The problem I have (or maybe only imagine I have) is that this presents something of a dilemma when I'm trying to gather data with a Monitor.  I'm not sure how to report it!  Whatever I do with it at this point, it's a separate set (or sets) of data, that I'd like incorporated into the data for completed Fares.  So I'm thinking about using a sort of compound condition for terminating a simulation.  That would leave me with just the completed Fares and the waiting Fares, which is more manageable.  I tried this,

    simulate(until=(SIMTIME and len(Agents.waitingFares.theBuffer) == 0))

but it doesn't work, and I'm not sure why.  It almost seems to behave like I'm using a logical OR instead of AND in there.  The simulation starts up, and as the buffer is almost immediately emptied the simulation terminates, even though it's nowhere near SIMTIME.  Now I'm thinking about just calculating the time remaining for the en'route Fares to reach their destinations, and adding those Fares to the set of completed Fares, with a note to that effect.  But it's definitely a second choice.

Has anyone tried anything like this?  Had any success with it?  More generally, does anyone have strategies or pointers to documentation for dealing with these types of loose ends in data collection?

Thanks!
Tim

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Simpy-users mailing list
Simpy-users <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/simpy-users
Steven H. Rogers | 13 Jun 03:44
Favicon

Re: ending a simulation

Tim Condit wrote:
> Sure, I can set the endtime later than when the last fare is created.  
> That's no problem.  I was looking for a solution that appealed to me 
> aesthetically, but it's not blocking me. :)
It would be nice to have another optional parameter, say until_condition 
which could be a boolean expression or variable for Simulation.simulate().

# Steve

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
Klaus Muller | 15 Jun 10:04
Picon
Picon
Favicon

Re: ending a simulation

Steve,
Yes, this would be possible, but it would slow down the execution of SimPy,
as does any waiting for a general Boolean condition. If you want to
implement such terminating condition, you can use "yield waituntil" in
today's SimPy already.

Klaus Müller 

> -----Original Message-----
> From: Steven H. Rogers [mailto:steve <at> shrogers.com] 
> Sent: Wednesday, June 13, 2007 3:45 AM
> To: Tim Condit
> Cc: Klaus Muller; simpy-users
> Subject: Re: [Simpy-users] ending a simulation
> 
> Tim Condit wrote:
> > Sure, I can set the endtime later than when the last fare 
> is created.  
> > That's no problem.  I was looking for a solution that 
> appealed to me 
> > aesthetically, but it's not blocking me. :)
> It would be nice to have another optional parameter, say 
> until_condition which could be a boolean expression or 
> variable for Simulation.simulate().
> 
> # Steve
> 
> 

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
Klaus Muller | 15 Jun 10:19
Picon
Picon
Favicon

Saving and restarting SimPy simulations

All:
Python's pickle/cpickle does not support pickling generators (a stupid
omission, considering the power of generators). Simply saving the state of a
SimPy simulation by pickling is therefore not possible.

As quite a number of you have indicated a requirement for saving and
restarting SimPy simulations, I have written up an article giving recipes
and examples for making SimPy simulations saveable and restartable. You find
it at the SimPy website http://SimPy.Sourceforge.net.

The article gives a workaround approach, based on removing generators at
saving and reinstating them at restarting. Obviously, some programming is
required.

If you think that this is unnecessary programming overhead (as I do), lean
on Python's developers and ask for pickle or cpickle to be changed to
support the pickling of generators. They should make generators first class
Python citizens!

Klaus Müller

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/

Gmane