def image_op_solver(figures, solutions, problem): operation = determine_single_image_op(figures) horizontal_tester = transformation.op_transform(figures[6], figures[7], operation) vertical_tester = transformation.op_transform(figures[2], figures[5], operation) horizontal_scores = [] vertical_scores = [] for i, solution in enumerate(solutions): x = algorithm.calc_rms(horizontal_tester, solution) horizontal_scores.append((i, x)) for i, solution in enumerate(solutions): x = algorithm.calc_rms(vertical_tester, solution) vertical_scores.append((i, x)) m_horizontal = min(horizontal_scores, key=lambda t: t[1]) m_vertical = min(vertical_scores, key=lambda t: t[1]) if m_horizontal[0] == m_vertical[ 0] or operation == 'modified-subtract-horizontal': scores = utility.get_score(m_horizontal, problem) return scores else: # need to determine which one to choose ? scores = utility.get_score(m_vertical, problem) return scores
def Solve(self, problem): figures, solutions = setup(problem) scores = [] # compare diagonals if problem.problemType == '3x3' and transformation.equality(figures[0], figures[4]) \ and transformation.equality(figures[1], figures[5]) \ and transformation.equality(figures[3], figures[7]): print('diagonal production rule chosen') m = comparison.compare_diagonal(scores, figures, solutions, problem) scores = utility.get_score(m, problem) elif comparison.compare_top_corners(figures) and comparison.compare_bottom_bc_ef(figures): print('top shape / bottom shape production rule chosen') m = comparison.compare_top_bottom(scores, figures, solutions, problem) scores = utility.get_score(m, problem) elif 'E' in problem.name.split(' ')[2]: print('xor, union, intersect solver') scores = image_op_solver(figures, solutions, problem) # standard generate and test else: print('generate & test solver') # generate our initial semantic network to test against init_network = create_semantic_network(figures, problem) scores = generate_and_test(init_network, scores, figures, solutions, problem) given = scores.index(max(scores)) + 1 actual = problem.checkAnswer(scores) print('given answer: ' + str(given)) print('actual answer: ' + str(actual)) print() return scores
def image_op_solver(figures, solutions, problem): operation = determine_single_image_op(figures) horizontal_tester = transformation.op_transform(figures[6], figures[7], operation) vertical_tester = transformation.op_transform(figures[2], figures[5], operation) horizontal_scores = [] vertical_scores = [] for i, solution in enumerate(solutions): x = algorithm.calc_rms(horizontal_tester, solution) horizontal_scores.append( (i, x) ) for i, solution in enumerate(solutions): x = algorithm.calc_rms(vertical_tester, solution) vertical_scores.append( (i, x) ) m_horizontal = min(horizontal_scores, key=lambda t: t[1]) m_vertical = min(vertical_scores, key=lambda t: t[1]) if m_horizontal[0] == m_vertical[0] or operation == 'modified-subtract-horizontal': scores = utility.get_score(m_horizontal, problem) return scores else: # need to determine which one to choose ? scores = utility.get_score(m_vertical, problem) return scores
def generate_and_test(init_network, scores, figures, solutions, problem): for i, solution in enumerate(solutions): if problem.problemType == '3x3': # compare init_network with generated solutions H_A = create_relationship_diagram([figures[6], figures[7]], 'horizontal') H_B = create_relationship_diagram([figures[7], solution], 'horizontal') H = utility.union(H_A, H_B) V_A = create_relationship_diagram([figures[2], figures[5]], 'vertical') V_B = create_relationship_diagram([figures[5], solution], 'vertical') V = utility.union(V_A, V_B) D = create_relationship_diagram([figures[4], solution], 'diagonal') else: H = create_relationship_diagram([figures[2], solution], 'horizontal', '2x2') V = create_relationship_diagram([figures[1], solution], 'vertical', '2x2') D = None score = agent_compare(init_network, H, V, D, problem, i + 1) scores.append(score) scores = utility.normalize_scores(scores, problem) print(scores) if 1.0 not in scores: if problem.problemType == '3x3': m_diagonal = comparison.compare_diagonal(scores, figures, solutions, problem) print('comparing diagonals to finalize score') possible_scores = [m_diagonal] m = min(possible_scores, key=lambda t: t[1]) scores = utility.get_score(m, problem) else: m_union = comparison.compare_union(scores, figures, solutions, problem) print('comparing union to finalize score') possible_scores = [m_union] m = min(possible_scores, key=lambda t: t[1]) scores = utility.get_score(m, problem) return scores
def Solve(self, problem): figures, solutions = setup(problem) scores = [] # compare diagonals if problem.problemType == '3x3' and transformation.equality(figures[0], figures[4]) \ and transformation.equality(figures[1], figures[5]) \ and transformation.equality(figures[3], figures[7]): print('diagonal production rule chosen') m = comparison.compare_diagonal(scores, figures, solutions, problem) scores = utility.get_score(m, problem) elif comparison.compare_top_corners( figures) and comparison.compare_bottom_bc_ef(figures): print('top shape / bottom shape production rule chosen') m = comparison.compare_top_bottom(scores, figures, solutions, problem) scores = utility.get_score(m, problem) elif 'E' in problem.name.split(' ')[2]: print('xor, union, intersect solver') scores = image_op_solver(figures, solutions, problem) # standard generate and test else: print('generate & test solver') # generate our initial semantic network to test against init_network = create_semantic_network(figures, problem) scores = generate_and_test(init_network, scores, figures, solutions, problem) given = scores.index(max(scores)) + 1 actual = problem.checkAnswer(scores) print('given answer: ' + str(given)) print('actual answer: ' + str(actual)) print() return scores