Skip to content

Commit

Permalink
added docstrings
Browse files Browse the repository at this point in the history
  • Loading branch information
obucklin committed Apr 24, 2024
1 parent 3e7e992 commit 5371cc6
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/compas_timber/planning/beam_nesting.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,34 @@


class Nester(object):
"""Class for nesting beams into a stock beam
Attributes
----------
stock_length : float
length of the stock beam in which to be nested
tolerance : float
tolerance for the nesting algorithm, if the remaining space in a bin is less than the tolerance, the bin is considered full
total_length : float
total length of all beams to be nested
"""

def __init__(self):
pass

def shuffle(self, lst):
random.shuffle(lst)

def space_remaining(self, bin):
"""returns the space remaining in a bin"""
if len(bin) == 0:
return self.stock_length
return self.stock_length - (sum([beam.blank_length for beam in bin]))

def sorted_dict(self, bin_dict):
"""sorts a dictionary of bins by space remaining in each bin"""
if len(bin_dict.items()) < 2:
return bin_dict
bin_list = sorted(bin_dict.values(), key=lambda x: self.space_remaining(x))
Expand All @@ -24,9 +40,11 @@ def sorted_dict(self, bin_dict):
return dict

def total_space(self, bin_dict):
"""returns the total space remaining in all bins, AKA total waste"""
return sum([self.space_remaining(bin) for bin in bin_dict.values()])

def get_initial_bins(self, beams):
"""returns a dictionary of bins with beams nested in them"""
bins = OrderedDict([(0, [])])
for beam in beams:
fits = False
Expand All @@ -41,6 +59,7 @@ def get_initial_bins(self, beams):
return bins

def fill_bins(self, bins, beams):
"""fills a partial bins dictionary with beams, returns a dictionary of bins with beams nested in them"""
for beam in beams:
fits = False
bins = self.sorted_dict(bins)
Expand All @@ -54,6 +73,7 @@ def fill_bins(self, bins, beams):
return bins

def parse_bins(self, bin_dict):
"""evaluates the success of the nesting, returns a dictionary with the results of the nesting process"""
dict_out = {"done": False}
dict_out["finished_bins"] = bin_dict
if self.total_space(bin_dict) < self.stock_length:
Expand All @@ -73,6 +93,21 @@ def parse_bins(self, bin_dict):
return dict_out

def get_bins(self, beams, stock_length, tolerance=1, iterations=10):
"""returns a dictionary of bins with beams nested in them
Parameters
----------
beams : list(:class:`compas_timber.parts.Beam`)
list of beams to be nested
stock_length : float
length of the stock beam in which to be nested
tolerance : float
tolerance for the nesting algorithm, if the remaining space in a bin is less than the tolerance, the bin is considered full
iterations : int
number of iterations to run the nesting algorithm, the algorithm will stop when the total waste is less than the stock length
"""

self.stock_length = stock_length
self.tolerance = tolerance
if tolerance is None:
Expand Down

0 comments on commit 5371cc6

Please sign in to comment.