Commit 30d5842d authored by Justin Borromeo's avatar Justin Borromeo
Browse files

Fix some bugs

parent a28ebd22
......@@ -5,6 +5,7 @@ import time
import path_constant as pc
import packing_penalty as pp
from os import makedirs
from copy import deepcopy
class cma_approach(object):
def __init__(self,
......@@ -161,7 +162,8 @@ class cma_approach(object):
return latencies, max_latency_idx
"""
Decide partition sizes and evaluate.
Decide partition sizes and evaluate the soln. Should always return a
packable solution.
"""
def eva_hybrid_sq(self, layer):
# res is a list corresponding to each partition. res_step is the
......@@ -175,7 +177,10 @@ class cma_approach(object):
# Do a binary search to find the largest packable variable_max_res_unit.
search_upper_bound = self.max_res_unit
search_lower_bound = sum([r*r for r in res])
while not search_upper_bound >= search_lower_bound:
last_packable_res = []
last_packable_max_res_unit = 0
while search_upper_bound > search_lower_bound:
variable_max_res_unit = \
int((search_upper_bound + search_lower_bound)/2)
limit_reached = False
......@@ -189,6 +194,8 @@ class cma_approach(object):
res[max_idx] -= self.res_step
limit_reached = True
if pp.isPackable(res, self.max_pack_size):
last_packable_res = deepcopy(res)
last_packable_max_res_unit = variable_max_res_unit
# The desired max_res_unit value is greater than its current
# value.
search_lower_bound = variable_max_res_unit
......@@ -198,14 +205,13 @@ class cma_approach(object):
search_upper_bound = variable_max_res_unit
# Calculate latencies of final solution.
latencies, max_idx = self.find_max_latency(layer, res)
latencies, max_idx = self.find_max_latency(layer, last_packable_res)
# TODO we want to penalize based on how much we had to decrease
# variable_max_res_unit.
max_res_unit_decrease = self.max_res_unit - variable_max_res_unit
packing_penalty = pp.calculatePackingPenalty(max_res_unit_decrease)
return latencies[max_idx] + packing_penalty, latencies, res, layer
return latencies[max_idx] + packing_penalty, latencies, last_packable_res, layer
def evaluation_top_level(self, in_val):
pid, sampling = in_val
......@@ -304,35 +310,22 @@ class cma_approach(object):
layer = []
res = []
latencies = []
if not self.filter_layer(self.best_layer):
##print("RESULT NOT VALID")
##print("Layer:", self.best_layer, "sum: ", sum(self.best_layer))
#print(self.penalty_layer(self.best_layer))
if self.print_to_csv:
with open(pc.RESULT_CSV_PATH+'cma_logmore_sq.csv', 'a') as csvFile:
writer = csv.writer(csvFile, delimiter=',', lineterminator="\n")
writer.writerow([self.target_col,self.i,self.k, self.topology_file, 0, 0, 0, 0, 0, 0, 0, layer, res, self.end-self.start, self.es.sigma, self.seed_od,self.valid_sampling_percentage, self.trial, self.population_size, self.max_res_unit, self.seeding_type])
csvFile.close
if self.is_hybrid:
if not self.filter_layer(self.best_layer):
##print("RESULT NOT VALID")
##print("Layer:", self.best_layer, "sum: ", sum(self.best_layer))
#print(self.penalty_layer(self.best_layer))
if self.print_to_csv:
with open(pc.RESULT_CSV_PATH+'cma_logmore_sq.csv', 'a') as csvFile:
writer = csv.writer(csvFile, delimiter=',', lineterminator="\n")
writer.writerow([self.target_col,self.i,self.k, self.topology_file, 0, 0, 0, 0, 0, 0, 0, layer, res, self.end-self.start, self.es.sigma, self.seed_od,self.valid_sampling_percentage, self.trial, self.population_size, self.max_res_unit, self.seeding_type])
csvFile.close
result = [self.target_col,self.i,self.k, self.topology_file, 0, 0, 0, 0, 0, 0, 0, layer, res, self.end-self.start, self.es.sigma, self.seed_od,self.valid_sampling_percentage, self.trial, self.population_size, self.max_res_unit, self.seeding_type]
result = [self.target_col,self.i,self.k, self.topology_file, 0, 0, 0, 0, 0, 0, 0, layer, res, self.end-self.start, self.es.sigma, self.seed_od,self.valid_sampling_percentage, self.trial, self.population_size, self.max_res_unit, self.seeding_type]
return False, result
layer = self.regroup_layers(self.best_layer)
max_latency, latencies, res, _ = self.eva_hybrid_sq(layer)
else:
if not self.filter_res(self.best_res) and not self.filter_layer(self.best_layer):
#print("RESULT NOT VALID")
#print("Layer:", self.best_layer, "sum: ", sum(self.best_layer))
#print("Res:", self.best_res, "sum: ", sum(self.best_res))
return False
return False, result
layer = self.regroup_layers(self.best_layer)
res = self.best_res
latencies, max_idx = self.find_max_latency(layer, self.best_res)
max_latency = latencies[max_idx]
layer = self.regroup_layers(self.best_layer)
max_latency, latencies, res, _ = self.eva_hybrid_sq(layer)
# generate data for mapping the full array (129 * 129)
full_latency, full_max_idx = self.find_max_latency([self.layers], [129]*len(self.layers))
......@@ -363,12 +356,11 @@ class cma_approach(object):
directory_path = pc.RESULT_SCREENSHOT_PATH + \
str(self.topology_file.replace(".csv", "")) + "/" + \
"pack_size_" + str(self.max_pack_size) + "/" + \
"linear_penalty_constant_" + str(pp.PENALTY_CONSTANT) + "/"
"penalty_constant_" + str(pp.PENALTY_CONSTANT) + "/"
makedirs(directory_path, exist_ok = True)
pngFileName = "k=" + str(self.k) + "_max=" + str(self.max_res_unit) \
+ ".png"
packing_penalty = pp.packingPenalty(res, self.max_pack_size)
if packing_penalty == 0 and output_png:
if pp.isPackable(res, self.max_pack_size) and output_png:
bin_area = self.max_pack_size ** 2
packed_area = 0
for rect in res:
......
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