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
|
|
@ -155,6 +155,7 @@ The specification of the semantics of the Atomic DEVS blocks is entirely determi
|
|||
<li>The generated CSV- and SVG-files</li>
|
||||
</ul>
|
||||
</li>
|
||||
<li>Deadline: Sunday 5 December 2025, 23:59</li>
|
||||
</ol>
|
||||
|
||||
<h2 id="attention">Attention!</h2>
|
||||
|
|
@ -198,7 +199,7 @@ The specification of the semantics of the Atomic DEVS blocks is entirely determi
|
|||
|
||||
<h2>Extra Material</h2>
|
||||
<ul>
|
||||
<li>This assignment was inspired by the queueuing example, which you can in <tt>examples/queueing</tt>.</li>
|
||||
<li>This assignment was inspired by the <a href="https://msdl.uantwerpen.be/git/jexelmans/joeriPDEVS/src/mosis24/examples/queueing">queueuing example</a>.</li>
|
||||
</ul>
|
||||
|
||||
</body>
|
||||
|
|
|
|||
|
|
@ -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}
|
||||
|
|
|
|||
|
|
@ -3,3 +3,6 @@ class Job:
|
|||
# Jobs have a size and creation_time parameter
|
||||
self.size = size
|
||||
self.creation_time = creation_time
|
||||
|
||||
def __repr__(self):
|
||||
return f"Job(size={self.size},creation_time={self.creation_time})"
|
||||
|
|
@ -29,20 +29,6 @@ class Queue(AtomicDEVS):
|
|||
self.in_event = self.addInPort("in_event")
|
||||
self.in_finish = self.addInPort("in_finish")
|
||||
|
||||
def intTransition(self):
|
||||
# Is only called when we are outputting an event
|
||||
# Pop the first idle processor and clear processing event
|
||||
self.state.idle_procs.pop(0)
|
||||
if self.state.queue and self.state.idle_procs:
|
||||
# There are still queued elements, so continue
|
||||
self.state.processing = self.state.queue.pop(0)
|
||||
self.state.remaining_time = self.processing_time
|
||||
else:
|
||||
# No events left to process, so become idle
|
||||
self.state.processing = None
|
||||
self.state.remaining_time = float("inf")
|
||||
return self.state
|
||||
|
||||
def extTransition(self, inputs):
|
||||
# Update the remaining time of this job
|
||||
self.state.remaining_time -= self.elapsed
|
||||
|
|
@ -73,3 +59,17 @@ class Queue(AtomicDEVS):
|
|||
# Output the event to the processor
|
||||
port = self.out_proc[self.state.idle_procs[0]]
|
||||
return {port: self.state.processing}
|
||||
|
||||
def intTransition(self):
|
||||
# Is only called when we are outputting an event
|
||||
# Pop the first idle processor and clear processing event
|
||||
self.state.idle_procs.pop(0)
|
||||
if self.state.queue and self.state.idle_procs:
|
||||
# There are still queued elements, so continue
|
||||
self.state.processing = self.state.queue.pop(0)
|
||||
self.state.remaining_time = self.processing_time
|
||||
else:
|
||||
# No events left to process, so become idle
|
||||
self.state.processing = None
|
||||
self.state.remaining_time = float("inf")
|
||||
return self.state
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue