update HTML + changes made to queueing example during tutorial
This commit is contained in:
parent
94b3b47e87
commit
7230fcf584
4 changed files with 37 additions and 24 deletions
|
|
@ -1,9 +1,17 @@
|
|||
from pypdevs.DEVS import AtomicDEVS
|
||||
from job import Job
|
||||
import random
|
||||
import dataclasses
|
||||
|
||||
# Define the state of the generator as a structured object
|
||||
@dataclasses.dataclass
|
||||
class GeneratorState:
|
||||
current_time: float
|
||||
remaining: float
|
||||
to_generate: int
|
||||
next_job: None
|
||||
random: random.Random
|
||||
|
||||
def __init__(self, gen_num, seed=0):
|
||||
# Current simulation time (statistics)
|
||||
self.current_time = 0.0
|
||||
|
|
@ -34,14 +42,22 @@ class Generator(AtomicDEVS):
|
|||
# Determine size of the event to generate
|
||||
size = max(1, int(self.state.random.gauss(self.size_param, 5)))
|
||||
# Calculate current time (note the addition!)
|
||||
creation = self.state.current_time + self.state.remaining
|
||||
creation = self.state.current_time
|
||||
# Update state
|
||||
self.state.next_job = Job(size, creation)
|
||||
self.state.remaining = self.state.random.expovariate(self.gen_param)
|
||||
|
||||
def timeAdvance(self):
|
||||
# Return remaining time; infinity when generated enough
|
||||
return self.state.remaining
|
||||
|
||||
def outputFnc(self):
|
||||
# Output the new event on the output port
|
||||
return {self.out_event: self.state.next_job}
|
||||
|
||||
def intTransition(self):
|
||||
# Update simulation time
|
||||
self.state.current_time += self.timeAdvance()
|
||||
self.state.current_time += self.state.remaining
|
||||
# Update number of generated events
|
||||
self.state.to_generate -= 1
|
||||
if self.state.to_generate == 0:
|
||||
|
|
@ -53,10 +69,3 @@ class Generator(AtomicDEVS):
|
|||
self.__nextJob()
|
||||
return self.state
|
||||
|
||||
def timeAdvance(self):
|
||||
# Return remaining time; infinity when generated enough
|
||||
return self.state.remaining
|
||||
|
||||
def outputFnc(self):
|
||||
# Output the new event on the output port
|
||||
return {self.out_event: self.state.next_job}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue