Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed .hypothesis/examples/a40d01c034da88b1/64a58bdeba6666aa
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed .hypothesis/examples/eceffc5f24ea1d52/152b4186e83aa051
Binary file not shown.
Binary file removed .hypothesis/examples/eceffc5f24ea1d52/20a0fe39a85d6d45
Binary file not shown.
Binary file removed .hypothesis/examples/eceffc5f24ea1d52/32967d840a1e8096
Binary file not shown.
Binary file removed .hypothesis/examples/eceffc5f24ea1d52/3c453f9be77b3e8a
Binary file not shown.
Binary file removed .hypothesis/examples/eceffc5f24ea1d52/3f5231e170f31715
Binary file not shown.
Binary file removed .hypothesis/examples/eceffc5f24ea1d52/7308f95258218e43
Binary file not shown.
Binary file removed .hypothesis/examples/eceffc5f24ea1d52/7413e307d0be0208
Binary file not shown.
Binary file removed .hypothesis/examples/eceffc5f24ea1d52/8ed123916572b4ee
Binary file not shown.
Binary file removed .hypothesis/examples/eceffc5f24ea1d52/accb605f2057c9fd
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
4 changes: 3 additions & 1 deletion ciw/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@
from arrival_node import ArrivalNode
from exit_node import ExitNode
from node import Node
from import_params import load_parameters
from import_params import load_parameters

__version__ = '0.0.3'
53 changes: 29 additions & 24 deletions ciw/arrival_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,31 @@ def __init__(self, simulation):
"""
self.simulation = simulation
self.number_of_individuals = 0
self.next_event_dates_dict = {nd + 1:{cls:False for cls in range(self.simulation.parameters['Number_of_classes'])} for nd in range(self.simulation.number_of_nodes)}
self.initialise_next_event_dates_dict()
self.event_dates_dict = {nd + 1:{cls:False
for cls in range(self.simulation.parameters['Number_of_classes'])}
for nd in range(self.simulation.number_of_nodes)}
self.initialise_event_dates_dict()
self.find_next_event_date()

def initialise_next_event_dates_dict(self):
def __repr__(self):
"""
Initialises the next event dates dictionary with random times for each node and class
Representation of an arrival node.
"""
for nd in self.next_event_dates_dict:
for cls in self.next_event_dates_dict[nd]:
self.next_event_dates_dict[nd][cls] = self.simulation.inter_arrival_times[nd][cls]()
return 'Arrival Node'

def __repr__(self):
def find_next_event_date(self):
"""
Representation of a node::
Finds the time of the next event at this node.
"""
return 'Arrival Node'
times = [[self.event_dates_dict[nd+1][cls]
for cls in range(len(self.event_dates_dict[1]))]
for nd in range(len(self.event_dates_dict))]
mintimes = [min(obs) for obs in times]
nd = mintimes.index(min(mintimes))
cls = times[nd].index(min(times[nd]))
self.next_node = nd + 1
self.next_class = cls
self.next_event_date = self.event_dates_dict[self.next_node][self.next_class]

def have_event(self):
"""
Expand All @@ -39,29 +47,26 @@ def have_event(self):
next_node = self.simulation.transitive_nodes[self.next_node-1]
if len(next_node.individuals) < next_node.node_capacity:
next_node.accept(next_individual, self.next_event_date)
self.next_event_dates_dict[self.next_node][self.next_class] += self.sample_next_event_time(self.next_node, self.next_class)
self.event_dates_dict[self.next_node][self.next_class] += self.inter_arrival(self.next_node, self.next_class)
self.find_next_event_date()

def sample_next_event_time(self, nd, cls):
def initialise_event_dates_dict(self):
"""
Expovariate but omits zero
Initialises the next event dates dictionary
with random times for each node and class.
"""
return self.simulation.inter_arrival_times[nd][cls]()
for nd in self.event_dates_dict:
for cls in self.event_dates_dict[nd]:
self.event_dates_dict[nd][cls] = self.simulation.inter_arrival_times[nd][cls]()

def find_next_event_date(self):
def inter_arrival(self, nd, cls):
"""
Finds the time of the next event at this node
Samples the inter-arrival time for next class and node.
"""
times = [[self.next_event_dates_dict[nd+1][cls] for cls in range(len(self.next_event_dates_dict[1]))] for nd in range(len(self.next_event_dates_dict))]
mintimes = [min(obs) for obs in times]
nd = mintimes.index(min(mintimes))
cls = times[nd].index(min(times[nd]))
self.next_node = nd + 1
self.next_class = cls
self.next_event_date = self.next_event_dates_dict[self.next_node][self.next_class]
return self.simulation.inter_arrival_times[nd][cls]()

def update_next_event_date(self):
"""
Passes, updating next event happens at time of event
Passes, updating next event happens at time of event.
"""
pass
24 changes: 16 additions & 8 deletions ciw/data_record.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,34 @@ class DataRecord:
"""
A class for a data record
"""
def __init__(self, arrival_date, service_time, service_start_date, exit_date, node, destination, customer_class, queue_size_at_arrival, queue_size_at_departure):
def __init__(self,
arrival_date,
service_time,
service_start_date,
exit_date,
node,
destination,
customer_class,
queue_size_at_arrival,
queue_size_at_departure):
"""
An example of a data record instance.
"""
if exit_date < arrival_date:
raise ValueError('Arrival date should preceed exit date')

if service_time < 0:
raise ValueError('Service time should be positive')

self.arrival_date = arrival_date
self.service_time = service_time
self.service_start_date = service_start_date
self.exit_date = exit_date
self.customer_class = customer_class
self.queue_size_at_arrival = queue_size_at_arrival
self.queue_size_at_departure = queue_size_at_departure

self.service_end_date = service_start_date + service_time
self.wait = service_start_date - arrival_date
self.blocked = exit_date - self.service_end_date
self.node = node
self.destination = destination

def __repr__(self):
"""
Represents the Data Record
"""
return "Data Record"
1 change: 0 additions & 1 deletion ciw/import_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,4 @@ def load_parameters(directory_name):
parameter_file = open(parameter_file_name, 'r')
parameters = yaml.load(parameter_file)
parameter_file.close()

return parameters
Loading