[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: requesting advice about creating a business model sim.

Charles Comstock

10/31/2004 4:02:00 AM

Chuck Brotman wrote:
>
> I envision an object oriented model (basically a queue based
> simulation) implemented in ruby. The purpose being to try tou nderstand how

<snip>
> A more specific question: Does anyone have any clever ideas (or design
> patterns, etc.) for keeping a simulation-time clock and dispatching the
> appropriate metods/objects on each tick?
>


I think the queue based simulation is the key, I believe the other
suggestion was for timer based, and that's bad for a simulation like
this. You don't want to step through a clock, you want an event queue
that you can shove items on and just have the simulation clock pull
things off of the event queue and do them in order that way. This makes
your performance dependent on the throughput of processing queue items
as opposed to an actual clock. As for appropriate what to with each
event? I would just have an event superclass that had an execute method
and a tick number on it. Then for each event just subclass from the
event class. You might also want some event factory or something to set
the parameters for each of the items.

class Event
attr :time
def execute
# do stuff
end
end

class PurchaseEvent < Event
def execute
purchase(100,:items, 10) # purchase 100 items in 10 ticks
end
end

class SaleEvent < Event
end

queue.pop.execute until(queue.empty?)

Anyhow that should get you started.

Charles Comstock