Skip to content

Commit

Permalink
Simantha master conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
m-hoff committed Dec 22, 2020
2 parents 456aaf7 + 49f07cf commit 8c932af
Show file tree
Hide file tree
Showing 25 changed files with 2,008 additions and 445 deletions.
37 changes: 13 additions & 24 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,31 +1,20 @@
**/.idea/
**/__pycache__/
**/.ipynb_checkpoints
*.pyc

*.vscode/

mow_demo2.ipynb

simpy_test.ipynb
validation/
logs/
simenv/

maintsim/test.ipynb
setup.py

*.csv
*.ipynb
!demo.ipynb
*.csv
*.html
*.pkl
*.pyc
*.txt
*.vscode/
*.xlsx

maintsim/.ipynb_checkpoints/test-checkpoint.ipynb
maintsim.py
simpy_test.ipynb
maintsim_example.html
maintsim_example.ipynb
mow_demo.ipynb
mow_demo2.ipynb
pm_reliability.ipynb
pmow_demo.ipynb
maintsim/concurrent downtime demo.ipynb
maintsim/degradation.py
maintsim/Simpy demo.ipynb
maintsim/system viz.ipynb
maintsim/demo.html
!requirements.txt
!LICENSE.txt
4 changes: 4 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
MIT License

<<<<<<< HEAD
Copyright (c) 2019 Michael Hoffman
=======
Copyright (c) 2020 Michael Hoffman
>>>>>>> dev

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
262 changes: 150 additions & 112 deletions README.md

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
scipy==1.5.2
31 changes: 31 additions & 0 deletions simantha/Asset.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import random

class Asset:
"""
Parent class for assets in the system. All objects should extend this class, and
there should be no instances.
"""
def __init__(self, name, selection_priority=1):
self.name = name
# assets with higher priority will be selected over those with lower priority
# when competing for resources or space.
self.selection_priority = selection_priority

self.upstream = []
self.downstream = []

def initialize(self):
pass

def get_candidate_givers(self, blocked=False):
"""
Returns a list of assets that can give a part to this asset from among the
upstream assets.
If 'blocked=True' then only return assets that are currently blocked.
"""
candidates = []
for candidate in self.upstream:
if blocked:
if candidate.blocked:
candidates.append(candidate)
93 changes: 93 additions & 0 deletions simantha/Buffer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
class Buffer:
def __init__(self, name='Buffer', capacity=float('inf'), initial_level=0):
self.name = name
self.capacity = capacity
self.initial_level = initial_level
self.level = initial_level

self.env = None

self.level_data = {'time': [0], 'level': [initial_level]}

self.pending_requests = []

def initialize(self):
self.level = self.initial_level

self.reserved_content = 0
self.reserved_vacancy = 0

if self.env.collect_data:
self.level_data = {'time': [0], 'level': [self.initial_level]}

def can_get_part(self):
return self.level + self.reserved_vacancy < self.capacity

def reserve_content(self, quantity=1):
self.reserved_content += 1

def get(self, quantity=1):
if not self.is_empty():
self.level -= quantity
self.reserved_content -= quantity

if self.env.collect_data:
self.level_data['time'].append(self.env.now)
self.level_data['level'].append(self.level)

else:
raise RuntimeError('Attempting to take more parts than available.')

def reserve_vacancy(self, quantity=1):
self.reserved_vacancy += 1

def put(self, quantity=1):
if not self.is_full():
self.level += quantity
self.reserved_vacancy -= 1

if self.env.collect_data:
self.level_data['time'].append(self.env.now)
self.level_data['level'].append(self.level)

else:
raise RuntimeError('Attempting to put part in full buffer.')

def is_empty(self):
#return self.level - self.reserved_content == 0
return self.level == 0

def is_full(self):
#return self.level + self.reserved_vacancy == self.capacity
return self.level == self.capacity

def can_give(self):
return self.level - self.reserved_content > 0

def can_receive(self):
return self.level + self.reserved_vacancy < self.capacity

# def get_available_space(self):
# return self.capacity - self.level

# def get_available_parts(self):
# return self.level

def define_routing(self, upstream=[], downstream=[]):
self.upstream = upstream
self.downstream = downstream

def get_candidate_givers(self, only_free=False, blocked=False):
if blocked:
# get only candidate givers that can give a part
return [obj for obj in self.get_candidate_givers() if obj.blocked]
else:
return [obj for obj in self.upstream if obj.can_give()]

def get_candidate_receivers(self, only_free=False, starved=False):
if starved:
return [obj for obj in self.get_candidate_receivers() if obj.starved]
else:
# get only candidate receivers that can accept a part
return [obj for obj in self.downstream if obj.can_receive()]

Loading

0 comments on commit 8c932af

Please sign in to comment.