Commit 460e2549 authored by Justin Borromeo's avatar Justin Borromeo
Browse files

Kinda borked

parent 209c3705
......@@ -336,6 +336,7 @@ class cma_approach(object):
csvFile.close
png_file_name = ""
pack_result = None
if self.valid_sampling_percentage > 0:
directory_path = pc.RESULT_SCREENSHOT_PATH + \
str(self.topology_file.replace(".csv", "")) + "/" + \
......@@ -343,13 +344,17 @@ class cma_approach(object):
"bin_wastage_k_" + str(pp.BIN_WASTAGE_CONSTANT) + "/" \
"bin_overflow_k_" + str(pp.BIN_OVERFLOW_CONSTANT) + "/"
makedirs(directory_path, exist_ok = True)
png_file_name = "k=" + str(self.k) + "_max=" + str(self.max_res_unit) \
+ ".png"
png_file_name = "k=" + str(self.k) + ".png"
packing_penalty = pp.packingPenalty(res, self.max_pack_size)
if packing_penalty == 0 and output_png:
pp.printPNG(res,
self.max_pack_size,
directory_path + png_file_name)
self.max_pack_size,
directory_path + png_file_name)
pack_result = PackingResult(self.topology_file,
self.k,
png_file_name,
max_latency)
result = [self.target_col,
self.i,
......@@ -373,10 +378,6 @@ class cma_approach(object):
self.max_res_unit,
self.seeding_type]
pack_result = PackingResult(self.topology_file,
self.k,
png_file_name,
max_latency)
return True, result, pack_result
if __name__ == "__main__":
......
......@@ -14,33 +14,44 @@ def packingPenalty(partitions, full_array):
packer.pack()
# First and only bin
bin_area = packer[0].width * packer[0].height
# Calculate packed area.
packed_area = 0
for rect in packer[0]:
side_length = rect.width
square_area = side_length ** 2
packed_area += square_area
packed_area += side_length ** 2
# Calculate percentage of bin space wasted
percentage_bin_wasted = 100 * (bin_area - packed_area) / bin_area
if len(packer[0]) == len(partitions):
return 0 # Fully packed, no penalty
# Calculate total partition area.
total_partition_area = 0
for partition in partitions:
total_partition_area += partition ** 2
percentage_partition_area_unpacked = \
(1 - (total_partition_area - packed_area) / total_partition_area) * 100
# Small 0.0001 offset so a fully-packed bin with non-fully packed layers
# isn't treated as 0-penalty.
percentage_partition_area_packed = 0
return penaltyFunction(percentage_bin_wasted,
percentage_partition_area_packed) + 0.00001
percentage_partition_area_unpacked) + 0.00001
BIN_WASTAGE_CONSTANT = 40000
BIN_OVERFLOW_CONSTANT = 40000
BIN_OVERFLOW_CONSTANT = 0
"""
Returns a penalty float, which is a function of percentage of space wasted in
the bin and the percentage of the combined partition area packed.
"""
def penaltyFunction(percentage_wasted, percentage_partition_area_packed):
def penaltyFunction(percentage_wasted, percentage_partition_area_unpacked):
# 0 percent wasted -> 0 penalty
# 5 percent wasted -> 200000
return BIN_WASTAGE_CONSTANT * percentage_wasted + \
BIN_OVERFLOW_CONSTANT * percentage_partition_area_packed
BIN_OVERFLOW_CONSTANT * percentage_partition_area_unpacked
def printPNG(partitions, full_array, filename = "sth.png"):
# print(partitions, full_array)
......
......@@ -77,6 +77,9 @@ if __name__ == "__main__":
for evo in result:
writer = csv.writer(csvFile, delimiter=',', lineterminator="\n")
writer.writerow(evo)
if pack_result == None:
# Soln wasn't packable.
continue
packing_res_key = (pack_result.topology, pack_result.partition_count)
if packing_res_key in best_packing_results:
if best_packing_results[packing_res_key][0] < pack_result.latency:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment