Example #1
0
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
Example #2
0
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
Example #3
0
def get_image_op(figures, orientation):

    xor = transformation.op_transform(figures[0], figures[1], 'xor')
    xor_similarity = ('xor', algorithm.calc_rms(xor, figures[2]))

    intersect = transformation.op_transform(figures[0], figures[1],
                                            'intersect')
    intersect_similarity = ('intersect',
                            algorithm.calc_rms(intersect, figures[2]))

    subtract = transformation.op_transform(figures[0], figures[1], 'subtract')
    subtract_similarity = ('subtract',
                           algorithm.calc_rms(subtract, figures[2]))

    union = transformation.op_transform(figures[0], figures[1], 'union')
    union_similarity = ('union', algorithm.calc_rms(union, figures[2]))

    modified_subtract = transformation.op_transform(
        figures[0], figures[1], 'modified-subtract-' + orientation)
    modified_subtract_similarity = ('modified-subtract-' + orientation,
                                    algorithm.calc_rms(modified_subtract,
                                                       figures[2]))

    comparisons = [
        xor_similarity, intersect_similarity, union_similarity,
        subtract_similarity, modified_subtract_similarity
    ]
    m = min(comparisons, key=lambda t: t[1])

    return m[0]
Example #4
0
def get_image_op(figures, orientation):

    xor = transformation.op_transform(figures[0], figures[1], 'xor')
    xor_similarity = ('xor', algorithm.calc_rms(xor, figures[2]))

    intersect = transformation.op_transform(figures[0], figures[1], 'intersect')
    intersect_similarity = ('intersect', algorithm.calc_rms(intersect, figures[2]))

    subtract = transformation.op_transform(figures[0], figures[1], 'subtract')
    subtract_similarity = ('subtract', algorithm.calc_rms(subtract, figures[2]))

    union = transformation.op_transform(figures[0], figures[1], 'union')
    union_similarity = ('union', algorithm.calc_rms(union, figures[2]))

    modified_subtract = transformation.op_transform(figures[0], figures[1], 'modified-subtract-' + orientation)
    modified_subtract_similarity = ('modified-subtract-' + orientation, algorithm.calc_rms(modified_subtract, figures[2]))

    comparisons = [xor_similarity, intersect_similarity, union_similarity, subtract_similarity, modified_subtract_similarity]
    m = min(comparisons, key=lambda t: t[1])

    return m[0]