Skip to content

Add type annotations and tidy some docstrings #268

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
57 changes: 28 additions & 29 deletions ciw/exactnode.py
Original file line number Diff line number Diff line change
@@ -1,39 +1,34 @@
from typing import List

from .node import Node
from .arrival_node import ArrivalNode
from decimal import Decimal, getcontext
from decimal import Decimal
from .server import Server


class ExactNode(Node):
"""
Inherits from the Node class, implements a more
precise version of addition to fix discrepencies
with floating point numbers.
"""Exact numerical precision node.

This class inherits from the Node class, and
implements a more precise version of addition to
fix discrepencies with floating point numbers.
"""

@property
def now(self):
"""
Gets the current time
"""
def now(self) -> Decimal:
"""Get the current time."""
return Decimal(self.simulation.current_time)

def create_starting_servers(self):
"""
Initialise the servers
"""
def create_starting_servers(self) -> List[Server]:
"""Initialise the servers at this node."""
return [Server(self, i + 1, Decimal("0.0")) for i in range(self.c)]

def increment_time(self, original, increment):
"""
Increments the original time by the increment
"""
def increment_time(self, original, increment) -> Decimal:
"""Increment the original time by the increment."""
return Decimal(str(original)) + Decimal(str(increment))

def get_service_time(self, ind):
"""
Returns a service time for the given customer class
"""
def get_service_time(self, ind) -> Decimal:
"""Return a service time for the given customer class."""
return Decimal(
str(
self.simulation.service_times[self.id_number][
Expand All @@ -44,21 +39,25 @@ def get_service_time(self, ind):


class ExactArrivalNode(ArrivalNode):
"""
"""Node with exact numerical time precision.

Inherits from the ArrivalNode class, implements a
more precise version of addition to fix discrepencies
with floating point numbers.
"""

def increment_time(self, original, increment):
"""
Increments the original time by the increment
"""
def increment_time(self, original, increment) -> Decimal:
"""Increment the original time by the increment."""
return Decimal(str(original)) + Decimal(str(increment))

def inter_arrival(self, nd, clss):
"""
Samples the inter-arrival time for next class and node.
def inter_arrival(self, nd, clss) -> Decimal:
"""Samples the inter-arrival time for next class and node.

Parameters
----------
nd (Node): Next node.
clss (Individual): Individual class to be selected next.

"""
return Decimal(
str(
Expand Down
Loading