def test_all_problems(policy=None, show_process_bar=False):
    problems = get_practical_problems(range(101, 131))

    total_trial = 0
    total_before_prune = 0
    total_after_prune = 0

    iter_obj = problems
    if show_process_bar:
        iter_obj = tqdm(iter_obj)
    for i, problem in enumerate(iter_obj):
        # print(i)
        solver = Solver(problem, policy)
        result = solver.solve(show_answer=False,
                              show_process=False,
                              show_graph=False,
                              prune=True)
        total_trial += result['trial_times']
        total_before_prune += result['solving_steps_before_prune']
        total_after_prune += result['solving_steps_after_prune']

    # print('Average trial times: {}'.format(total_trial / len(problems)))
    # print('Solving step before prune {}'.format(total_before_prune / len(problems)))
    # print('Solving step after prune {}'.format(total_after_prune / len(problems)))

    avg_trial = total_trial / len(problems)
    avg_before_prune = total_before_prune / len(problems)
    avg_after_prune = total_after_prune / len(problems)

    return avg_trial, avg_before_prune, avg_after_prune
def test_perpendicular():
    problem = create_problem()
    target = create_target(problem)
    solver = Solver(problem)
    solver.add_target(target)
    problem = solver.solve()
    assert problem.entity.find_child('BEC').angle == 90
Exemplo n.º 3
0
def test_simple_example4():
    problem = create_problem()
    target = create_target(problem)
    solver = Solver(problem)
    solver.add_target(target)
    problem = solver.solve()
    assert round(problem.entity.find_child('MN', type_=Line).length, 6) == 2.4
Exemplo n.º 4
0
def test_common_vertex_angle_relationship():
    problem = create_problem()
    target = create_target(problem)
    solver = Solver(problem)
    solver.add_target(target)
    problem = solver.solve()
    assert problem.entity.find_child('BAD').angle == 70
Exemplo n.º 5
0
def test_vertical_angle():
    problem = create_problem()
    target = create_target(problem)
    solver = Solver(problem)
    solver.add_target(target)
    problem = solver.solve()
    assert problem.entity.find_child('COD').angle == 40
def test_supplementary_angle():
    problem = create_problem()
    target = create_target(problem)
    solver = Solver(problem)
    solver.add_target(target)
    problem = solver.solve()
    assert problem.entity.find_child('CBD').angle == 130
def test_similar_triangle():
    problem = create_problem()
    target = create_target(problem)
    solver = Solver(problem)
    solver.add_target(target)
    problem = solver.solve()
    assert abs(problem.entity.find_child('EF', Line).length - 2) < 0.000001
Exemplo n.º 8
0
def test_parallel():
    problem = create_problem()
    target = create_target(problem)
    solver = Solver(problem)
    solver.add_target(target)
    problem = solver.solve()
    assert problem.entity.find_child('AEC').angle == 30
def test_simple_example1():
    problem = create_problem()
    target = create_target(problem)
    solver = Solver(problem)
    solver.add_target(target)
    problem = solver.solve()
    assert problem.entity.find_child('AEB', type_=Angle).angle == 75
Exemplo n.º 10
0
def test_collineation_relationship_reduction():
    problem = create_problem()
    target = create_target(problem)
    solver = Solver(problem)
    solver.add_target(target)
    problem = solver.solve()
    assert problem.entity.find_child('AC').length == 3
Exemplo n.º 11
0
def test_triangle_angle_reduction():
    problem = create_problem()
    target = create_target(problem)
    solver = Solver(problem)
    solver.add_target(target)
    problem = solver.solve()
    assert problem.entity.find_child('BAC', Angle).angle == 60
def test_simple_example2():
    problem = create_problem()
    target = create_target(problem)
    solver = Solver(problem)
    solver.add_target(target)
    problem = solver.solve()
    assert problem.entity.find_child(
        'DE', type_=Line).length - (3**(1 / 2) / 2) * 210 < 0.00001
Exemplo n.º 13
0
    def parse(self):
        problem = self.get_problem()

        solver = Solver(problem)

        print('Create a triangle successfully!')
        print(problem)

        # Add targets.
        for id_, type_, attr in self._target_dict:
            target = Target(TargetType.EVALUATION,
                            entity=problem.entity.find_child(id_, type_),
                            attr=attr)
            solver.add_target(target)

        solver.solve()

        return problem
Exemplo n.º 14
0
def test_simple_example():
    problem = create_problem()
    target1 = create_target1(problem)
    target2 = create_target2(problem)
    solver = Solver(problem)
    solver.add_target(target1)
    solver.add_target(target2)
    problem = solver.solve()
    assert problem.entity.find_child('CFE', type_=Angle).angle == 75
    assert problem.entity.find_child('BDC', type_=Angle).angle == 65
Exemplo n.º 15
0
def run_random_search(policy=None, show_process_bar=False):
    problems = get_practical_problems(range(1, 1 + all_problems))

    total_trial = np.zeros(all_problems)
    total_before_prune = np.zeros(all_problems)
    total_after_prune = np.zeros(all_problems)

    for i, problem in enumerate(tqdm(problems)):
        solver = Solver(problem, policy)
        result = solver.solve(show_answer=False,
                              show_process=False,
                              show_graph=False,
                              prune=True)
        total_trial[i] = result['trial_times']
        total_before_prune[i] = result['solving_steps_before_prune']
        total_after_prune[i] = result['solving_steps_after_prune']

    return total_trial, total_before_prune, total_after_prune
Exemplo n.º 16
0
def test_all_problems():
    problems = get_practical_problems(range(1, 131))

    total_trial = 0
    total_before_prune = 0
    total_after_prune = 0

    for problem in tqdm(problems):
        solver = Solver(problem)
        result = solver.solve(show_answer=False,
                              show_process=False,
                              show_graph=False,
                              prune=True)
        total_trial += result['trial_times']
        total_before_prune += result['solving_steps_before_prune']
        total_after_prune += result['solving_steps_after_prune']

    # print('Average trial times: {}'.format(total_trial / len(problems)))
    # print('Solving step before prune {}'.format(total_before_prune / len(problems)))
    # print('Solving step after prune {}'.format(total_after_prune / len(problems)))

    avg_trial_hist.append(total_trial / len(problems))
    avg_before_prune_hist.append(total_before_prune / len(problems))
    avg_after_prune_hist.append(total_after_prune / len(problems))
Exemplo n.º 17
0
def basic_test5():
    entity, target, conditions = get_problem()
    solver = Solver(entity=entity, target=target, conditions=conditions)
    solver.solve()
from geometry_solver import ProblemParser
from geometry_solver import Solver

parser = ProblemParser()
problem = parser.parse('/Users/nikoyou/Desktop/解题重构/dataset/114.txt')
solver = Solver(problem)
solver.solve()
import argparse

from geometry_solver import Solver

parser = argparse.ArgumentParser(description='ArgumentParser for test runner.')
parser.add_argument('--number', type=int)

args = parser.parse_args()

exec('from tests.practical_test.practical_test{} import practical_test{}'.format(
        args.number, args.number))
exec('problem = practical_test{}()'.format(args.number))

solver = Solver(problem)
result = solver.solve(show_answer=True, show_process=True, show_graph=True, prune=True)
print(result)

def basic_test22():
    entity, target, conditions = get_problem()
    solver = Solver(entity=entity, target=target, conditions=conditions)
    solver.solve(show_process=False)