in Bin Packing/src/baseline_sum_of_squares.py [0:0]
def get_action(state):
state = state['real_obs']
num_bins_level = state[:-1]
item_size = state[-1]
bag_capacity = len(state)-1
if item_size == bag_capacity:
return 0 # new bag
min_difference = bag_capacity
chosen_bin_index = 0 #default is new bag
for i, bins in enumerate(num_bins_level):
#skip new bag and levels for which bins don't exist
if bins == 0 or i == 0:
continue
#if item fits perfectly into the bag
elif (i + item_size) == bag_capacity:
# assuming full bins have count 0
if -bins < min_difference:
min_difference = -bins
chosen_bin_index = i
return chosen_bin_index
else:
continue
#item should fit in bag and should be at least of size 1
elif (i + item_size) > bag_capacity:
continue
#sum of squares difference that chooses the bin
if num_bins_level[i + item_size] - bins < min_difference:
chosen_bin_index = i
min_difference = num_bins_level[i + item_size] - bins
return chosen_bin_index