def perf(self, prog_t, prog_r): prog_t_text = LangUtil.dicts_to_text(prog_t) prog_r_text = LangUtil.dicts_to_text(prog_r) running_time_diff = self.analyzer.find_running_time(prog_r_text)\ - self.analyzer.find_running_time(prog_t_text) collision_penalty = self.collisions( prog_r_text) * self.COLLISION_PENALTY return running_time_diff + collision_penalty
def change_instr(self, line_num): d = self.prog_rp[line_num] if d['instr'] == 'moveTo': d['instr'] = 'travel' elif d['instr'] == 'travel': d['instr'] = 'moveTo' d = LangUtil.update_dict_statement(d)
def change_line(self, line_num): d = self.prog_rp[line_num] instrs = ['moveTo', 'travel', 'sleep'] d['instr'] = instrs[randint(0, 2)] if d['instr'] == 'moveTo' or d['instr'] == 'travel': d['x'] = randint(0, self.analyzer.X_LIM) d['y'] = randint(0, self.analyzer.Y_LIM) d['r'] = randint(1, 2) if d['instr'] == 'sleep': # TODO: either use canned immediates or constraint s operand # to total time taken d['s'] = randint(0, 10) d['r'] = randint(1, 2) d = LangUtil.update_dict_statement(d)
def change_operand(self, line_num): d = self.prog_rp[line_num] if d['instr'] == 'moveTo' or d['instr'] == 'travel': op_num = randint(0, 2) if op_num == 0: d['x'] = randint(0, self.analyzer.X_LIM) if op_num == 1: d['y'] = randint(0, self.analyzer.Y_LIM) if op_num == 2: d['r'] = randint(1, 2) if d['instr'] == 'sleep': op_num = randint(0, 1) if op_num == 0: # TODO: either use canned immediates or constraint s operand # to total time taken d['s'] = randint(0, 10) if op_num == 1: d['r'] = randint(1, 2) d = LangUtil.update_dict_statement(d)
def __init__(self, prog_t): self.prog_t_text = prog_t self.prog_r_text = prog_t[:] self.prog_rp_text = prog_t[:] prog_t_stats = LangUtil.prog_text_to_statements(self.prog_t_text) prog_r_stats = LangUtil.prog_text_to_statements(self.prog_r_text) prog_rp_stats = LangUtil.prog_text_to_statements(self.prog_rp_text) self.prog_t = LangUtil.statements_to_dicts(prog_t_stats) self.prog_r = LangUtil.statements_to_dicts(prog_r_stats) self.prog_rp = LangUtil.statements_to_dicts(prog_rp_stats) self.RANDOM_SEED = 5373171 self.COLLISION_PENALTY = 100 self.BETA = 2 seed(self.RANDOM_SEED) self.analyzer = Analyzer((300, 300), (0, 0), (300, 0))
def eq(self, prog_t, prog_r): prog_t_text = LangUtil.dicts_to_text(prog_t) prog_r_text = LangUtil.dicts_to_text(prog_r) return self.analyzer.check_equivalent_nosmt(prog_t_text, prog_r_text)
def curr_rewrite(self): return LangUtil.dicts_to_text(self.prog_rp)