def get_problem(): # Initialize problem structure. p_a = Point('A') p_b = Point('B') p_c = Point('C') line_ab = Line('AB', end1=p_a, end2=p_b) line_bc = Line('BC', end1=p_b, end2=p_c) line_ac = Line('AC', end1=p_a, end2=p_c) angle_a = Angle('BAC', side1=line_ab, side2=line_ac, vertex=p_a) angle_b = Angle('ABC', side1=line_ab, side2=line_bc, vertex=p_b) angle_c = Angle('ACB', side1=line_ac, side2=line_bc, vertex=p_c) triangle = Triangle( 'ABC', vertex1=p_c, vertex2=p_a, vertex3=p_b, side1=line_ab, side2=line_bc, side3=line_ac, angle1=angle_c, angle2=angle_a, angle3=angle_b) entity = Entity('Basic test2') entity.add_entity(triangle) # Set target. target = Target(angle_c, 'angle') # Initialize conditions. conditions = [] conditions.append(AttributeValue(angle_a, angle=60)) conditions.append(AttributeValue(angle_b, angle=30)) return entity, target, conditions
def get_problem(): # Initialize problem structure. p_a = Point('A') p_b = Point('B') p_c = Point('C') p_d = Point('D') line_ac = Line('AC', end1=p_a, end2=p_c) line_bc = Line('BC', end1=p_b, end2=p_c) line_bd = Line('BD', end1=p_b, end2=p_d) line_cd = Line('CD', end1=p_c, end2=p_d) angle_acb = Angle('ACB', side1=line_ac, side2=line_bc, vertex=p_c) angle_acd = Angle('ACD', side1=line_ac, side2=line_cd, vertex=p_c) entity = Entity('Basic test5') entity.add_entity(p_a, p_b, p_c, p_d) entity.add_entity(line_ac, line_bc, line_bd, line_cd) entity.add_entity(angle_acb, angle_acd) # Initialize conditions. conditions = [] p = Perpendicular('AC_BD', line1=line_ac, line2=line_bd, foot_point=p_c) conditions.append(RelationshipBased(p)) # Set target. target = Target(angle_acd, 'angle') return entity, target, conditions
def get_problem(): # Initialize problem structure. p_a = Point('A') p_b = Point('B') p_c = Point('C') p_d = Point('D') line_ab = Line('AB', end1=p_a, end2=p_b) line_ac = Line('AC', end1=p_a, end2=p_c) line_ad = Line('AD', end1=p_a, end2=p_d) angle_bac = Angle('BAC', side1=line_ab, side2=line_ac, vertex=p_a) angle_cad = Angle('CAD', side1=line_ac, side2=line_ad, vertex=p_a) angle_bad = Angle('BAD', side1=line_ab, side2=line_ad, vertex=p_a) entity = Entity('Basic test3') entity.add_entity(p_a, p_b, p_c, p_d) entity.add_entity(line_ab, line_ac, line_ad) entity.add_entity(angle_bac, angle_bad, angle_cad) # Initialize conditions. conditions = [] conditions.append(AttributeValue(angle_bac, angle=60)) conditions.append(AttributeValue(angle_cad, angle=30)) cva = CommonVertexAngle('A_BCD', vertex=p_a, ends=[p_b, p_c, p_d]) r = RelationshipBased(cva) conditions.append(r) # Set target. target = Target(angle_bad, 'angle') return entity, target, conditions
def get_problem(): # Initialize problem structure. p_a = Point('A') p_b = Point('B') p_c = Point('C') p_d = Point('D') line_ac = Line('AC', end1=p_a, end2=p_c) line_bc = Line('BC', end1=p_b, end2=p_c) line_bd = Line('BD', end1=p_b, end2=p_d) line_cd = Line('CD', end1=p_c, end2=p_d) angle_acb = Angle('ACB', side1=line_ac, side2=line_bc, vertex=p_c) angle_acd = Angle('ACD', side1=line_ac, side2=line_cd, vertex=p_c) entity = Entity('Basic test4') entity.add_entity(p_a, p_b, p_c, p_d) entity.add_entity(line_ac, line_bc, line_bd, line_cd) entity.add_entity(angle_acb, angle_acd) # Initialize conditions. conditions = [] conditions.append(AttributeValue(angle_acb, angle=60)) sa = SupplementaryAngle('ACB_ACD', angle1=angle_acb, angle2=angle_acd) col = Collineation('BCD', points=[p_b, p_c, p_d]) conditions.append(RelationshipBased(sa)) conditions.append(RelationshipBased(col)) # Set target. target = Target(angle_acd, 'angle') return entity, target, conditions
def get_problem(): # Initialize problem structure. p_a = Point('A') p_b = Point('B') p_c = Point('C') p_d = Point('D') line_ab = Line('AB', end1=p_a, end2=p_b) line_ac = Line('AC', end1=p_a, end2=p_c) line_ad = Line('AD', end1=p_a, end2=p_d) angle_bac = Angle('BAC', side1=line_ab, side2=line_ac, vertex=p_a) angle_bad = Angle('BAD', side1=line_ab, side2=line_ad, vertex=p_a) angle_cad = Angle('CAD', side1=line_ac, side2=line_ad, vertex=p_a) entity = Entity('Basic test20') entity.add_entity(p_a, p_b, p_c, p_d) entity.add_entity(line_ab, line_ac, line_ad) entity.add_entity(angle_bac, angle_bad, angle_cad) # Set target. target = Target(angle_bad, 'angle') # Initialize conditions. conditions = [] conditions.append(AttributeValue(angle_bac, angle=30)) r = NAngleSector('BAD_AC', angle=angle_bad, split_line=line_ac, near_line=line_ab) conditions.append(RelationshipBased(r)) conditions.append(AttributeValue(r, ratio=0.25)) return entity, target, conditions
def get_problem(): """Test for line sum.""" # Initialize problem structure. p_a = Point('A') p_b = Point('B') p_c = Point('C') p_d = Point('D') p_e = Point('E') p_f = Point('F') p_g = Point('G') p_h = Point('H') line_ab = Line('AB', end1=p_a, end2=p_b) line_af = Line('AF', end1=p_a, end2=p_f) line_bf = Line('BF', end1=p_b, end2=p_f) line_cd = Line('CD', end1=p_c, end2=p_d) line_cg = Line('CG', end1=p_c, end2=p_g) line_dg = Line('DG', end1=p_d, end2=p_g) line_ef = Line('EF', end1=p_e, end2=p_f) line_eg = Line('EG', end1=p_e, end2=p_g) line_eh = Line('EH', end1=p_e, end2=p_h) line_fg = Line('FG', end1=p_f, end2=p_g) line_fh = Line('FH', end1=p_f, end2=p_h) line_gh = Line('GH', end1=p_g, end2=p_h) angle_afe = Angle('AFE', side1=line_af, side2=line_ef, vertex=p_f) angle_bfe = Angle('BFE', side1=line_bf, side2=line_ef, vertex=p_f) angle_afh = Angle('AFH', side1=line_af, side2=line_fh, vertex=p_f) angle_bfh = Angle('BFH', side1=line_bf, side2=line_fh, vertex=p_f) angle_cgh = Angle('CGH', side1=line_cg, side2=line_gh, vertex=p_g) angle_dgh = Angle('DGH', side1=line_dg, side2=line_gh, vertex=p_g) angle_cge = Angle('CGE', side1=line_cg, side2=line_eg, vertex=p_g) angle_dge = Angle('DGE', side1=line_dg, side2=line_eg, vertex=p_g) entity = Entity('Basic test14') for name, obj in locals().items(): if name.startswith(tuple(['p_', 'line_', 'angle_'])): entity.add_entity(obj) # Initialize conditions. conditions = [] conditions.append(AttributeValue(angle_afh, angle=60)) parallel = Parallel('AB_CD', line1=line_ab, line2=line_cd) r = RelationshipBased(parallel) conditions.append(r) conditions.append( RelationshipBased(Collineation('AFB', points=[p_a, p_f, p_b]))) conditions.append( RelationshipBased(Collineation('CGD', points=[p_c, p_g, p_d]))) conditions.append( RelationshipBased(Collineation('EFGH', points=[p_e, p_f, p_g, p_h]))) # Set target. target = Target(angle_cge, 'angle') return entity, target, conditions
def get_problem(): """Test for equality of opposite vertical angle.""" # Initialize problem structure. p_a = Point('A') p_b = Point('B') p_c = Point('C') p_d = Point('D') p_o = Point('O') line_ao = Line('AO', end1=p_a, end2=p_o) line_ad = Line('AD', end1=p_a, end2=p_d) line_do = Line('DO', end1=p_d, end2=p_o) line_bo = Line('BO', end1=p_b, end2=p_o) line_bc = Line('BC', end1=p_b, end2=p_c) line_co = Line('CO', end1=p_c, end2=p_o) angle_aob = Angle('AOB', side1=line_ao, side2=line_bo, vertex=p_o) angle_aoc = Angle('AOC', side1=line_ao, side2=line_co, vertex=p_o) angle_cod = Angle('COD', side1=line_co, side2=line_do, vertex=p_o) angle_bod = Angle('BOD', side1=line_bo, side2=line_do, vertex=p_o) entity = Entity('Basic test6') entity.add_entity(p_a, p_b, p_c, p_d, p_o) entity.add_entity(line_ao, line_ad, line_do, line_bo, line_bc, line_co) entity.add_entity(angle_aob, angle_aoc, angle_cod, angle_bod) # Initialize conditions. conditions = [] ova1 = OppositeVerticalAngle('AOB_COD', angle1=angle_aob, angle2=angle_cod, vertex=p_o) ova2 = OppositeVerticalAngle('AOC_BOD', angle1=angle_aoc, angle2=angle_bod, vertex=p_o) conditions.append(RelationshipBased(ova1)) conditions.append(RelationshipBased(ova2)) conditions.append(AttributeValue(angle_aob, angle=60)) # Set target. target = Target(angle_cod, 'angle') return entity, target, conditions
def get_problem(): # Initialize problem structure. p_a = Point('A') p_b = Point('B') p_c = Point('C') line_ab = Line('AB', end1=p_a, end2=p_b) line_bc = Line('BC', end1=p_b, end2=p_c) line_ac = Line('AC', end1=p_a, end2=p_c) angle_a = Angle('BAC', side1=line_ab, side2=line_ac, vertex=p_a) angle_b = Angle('ABC', side1=line_ab, side2=line_bc, vertex=p_b) angle_c = Angle('ACB', side1=line_ac, side2=line_bc, vertex=p_c) triangle = Triangle('ABC', vertex1=p_c, vertex2=p_a, vertex3=p_b, side1=line_ab, side2=line_bc, side3=line_ac, angle1=angle_c, angle2=angle_a, angle3=angle_b) entity = Entity('Basic test23') entity.add_entity(triangle) # Set target. target = Target(angle_c, 'angle') # Initialize conditions. conditions = [] conditions.append(AttributeValue(angle_b, angle=30)) r = ValueEquivalence('AB_AC', obj_list=[line_ab, line_ac], attr_list=['length', 'length']) conditions.append(RelationshipBased(r)) return entity, target, conditions
def get_problem(): # Initialize problem structure. p_a = Point('A') p_b = Point('B') p_c = Point('C') line_ab = Line('AB', end1=p_a, end2=p_b) line_bc = Line('BC', end1=p_b, end2=p_c) line_ac = Line('AC', end1=p_a, end2=p_c) angle_a = Angle('BAC', side1=line_ab, side2=line_ac, vertex=p_a) angle_b = Angle('ABC', side1=line_ab, side2=line_bc, vertex=p_b) angle_c = Angle('ACB', side1=line_ac, side2=line_bc, vertex=p_c) triangle_abc = Triangle('ABC', vertex1=p_c, vertex2=p_a, vertex3=p_b, side1=line_ab, side2=line_bc, side3=line_ac, angle1=angle_c, angle2=angle_a, angle3=angle_b) p_d = Point('D') p_e = Point('E') p_f = Point('F') line_de = Line('DE', end1=p_d, end2=p_e) line_ef = Line('EF', end1=p_e, end2=p_f) line_df = Line('DF', end1=p_d, end2=p_f) angle_d = Angle('EDF', side1=line_de, side2=line_df, vertex=p_d) angle_e = Angle('DEF', side1=line_de, side2=line_ef, vertex=p_e) angle_f = Angle('DFE', side1=line_df, side2=line_ef, vertex=p_f) triangle_def = Triangle('DEF', vertex1=p_f, vertex2=p_d, vertex3=p_e, side1=line_de, side2=line_ef, side3=line_df, angle1=angle_f, angle2=angle_d, angle3=angle_e) entity = Entity('Basic test19') entity.add_entity(triangle_abc) entity.add_entity(triangle_def) # Set target. target = Target(line_df, 'length') # Initialize conditions. conditions = [] conditions.append(AttributeValue(angle_a, angle=60)) conditions.append(AttributeValue(angle_b, angle=90)) conditions.append(AttributeValue(angle_c, angle=30)) conditions.append(AttributeValue(angle_d, angle=60)) conditions.append(AttributeValue(angle_e, angle=90)) conditions.append(AttributeValue(angle_f, angle=30)) conditions.append(AttributeValue(line_ab, length=1)) conditions.append(AttributeValue(line_ac, length=2)) conditions.append(AttributeValue(line_de, length=1)) return Problem(entity, conditions, target)
def get_problem(): # Initialize problem structure. p_a = Point('A') p_b = Point('B') p_c = Point('C') line_ab = Line('AB', end1=p_a, end2=p_b) line_bc = Line('BC', end1=p_b, end2=p_c) line_ac = Line('AC', end1=p_a, end2=p_c) angle_a = Angle('BAC', side1=line_ab, side2=line_ac, vertex=p_a) angle_b = Angle('ABC', side1=line_ab, side2=line_bc, vertex=p_b) angle_c = Angle('ACB', side1=line_ac, side2=line_bc, vertex=p_c) triangle_abc = Triangle('ABC', vertex1=p_c, vertex2=p_a, vertex3=p_b, side1=line_ab, side2=line_bc, side3=line_ac, angle1=angle_c, angle2=angle_a, angle3=angle_b) p_d = Point('D') p_e = Point('E') p_f = Point('F') line_de = Line('DE', end1=p_d, end2=p_e) line_ef = Line('EF', end1=p_e, end2=p_f) line_df = Line('DF', end1=p_d, end2=p_f) angle_d = Angle('EDF', side1=line_de, side2=line_df, vertex=p_d) angle_e = Angle('DEF', side1=line_de, side2=line_ef, vertex=p_e) angle_f = Angle('DFE', side1=line_df, side2=line_ef, vertex=p_f) triangle_def = Triangle('DEF', vertex1=p_f, vertex2=p_d, vertex3=p_e, side1=line_de, side2=line_ef, side3=line_df, angle1=angle_f, angle2=angle_d, angle3=angle_e) entity = Entity('Basic test17') entity.add_entity(triangle_abc) entity.add_entity(triangle_def) # Set target. target = Target(angle_f, 'angle') # Initialize conditions. conditions = [] conditions.append(AttributeValue(angle_a, angle=60)) conditions.append(AttributeValue(angle_b, angle=90)) st = SimilarTriangle('ABC_DEF', triangle_abc, triangle_def, cor_angle=[(angle_a, angle_d), (angle_b, angle_e), (angle_c, angle_f)]) conditions.append(RelationshipBased(st)) return entity, target, conditions
def parse_problem(self): """This function is used to generate entities automatically.""" entity = Entity('Entity container') target = None conditions = [] if self.problem is not None: return self.problem if self._shown: print('Using intelligent parser...') # Generate points. self.points = {pid: Point(pid) for pid in self._points} # Generate lines. self.lines = {} for lid in self._lines: lid = Parser._sort_string(lid) ends = [self.points[pid] for pid in lid] line = Line(lid, end1=ends[0], end2=ends[1]) length = self._look_up_length(lid) if length is not None: cond = AttributeValue(line, length=length) conditions.append(cond) self.lines[lid] = line # Generate angles. self.angles = {} for vertex, adj_nodes in self._adj_table.items(): n_adj = len(adj_nodes) for i in range(n_adj): for j in range(i + 1, n_adj): node1, node2 = adj_nodes[i], adj_nodes[j] node1 = self._line_alias[node1 + vertex][0] node2 = self._line_alias[vertex + node2][1] # Angle with zero degree if node1 == node2: continue # Flat angle if self._is_collineation(node1, vertex, node2): continue node1, node2 = sorted([node1, node2]) aid = ''.join([node1, vertex, node2]) line1 = self.find_line_by_ends(node1, vertex) line2 = self.find_line_by_ends(node2, vertex) sides = [line1, line2] angle = Angle(aid, side1=sides[0], side2=sides[1], vertex=self.points[vertex]) self.angles[aid] = angle degree = self._look_up_degree(aid) if degree is not None: cond = AttributeValue(angle, angle=degree) conditions.append(cond) # Generate triangle. self.triangles = {} triangle_ids = self._analyse_triangle() for tid in triangle_ids: t_vertexes = [self.points[v] for v in tid] t_side1 = self.find_line_by_ends(tid[0], tid[1]) t_side2 = self.find_line_by_ends(tid[1], tid[2]) t_side3 = self.find_line_by_ends(tid[0], tid[2]) t_sides = [t_side1, t_side2, t_side3] t_angle1 = self.find_angle_by_points(tid[0], tid[2], tid[1]) t_angle2 = self.find_angle_by_points(tid[1], tid[0], tid[2]) t_angle3 = self.find_angle_by_points(tid[0], tid[1], tid[2]) t_angles = [t_angle1, t_angle2, t_angle3] triangle = Triangle(tid, vertex1=t_vertexes[0], vertex2=t_vertexes[1], vertex3=t_vertexes[2], side1=t_sides[0], side2=t_sides[1], side3=t_sides[2], angle1=t_angles[0], angle2=t_angles[1], angle3=t_angles[2]) self.triangles[tid] = triangle if self._shown: print('points: ', sorted(self.points.keys())) print('lines', sorted(self.lines.keys())) print('angles: ', sorted(self.angles.keys())) print('triangles: ', sorted(self.triangles.keys())) # Generate relationships. collineations = {} for col in self._collineation_list: col_id = 'Collineation ' + ''.join([p for p in col]) ps = [self.points[pid] for pid in col] r = Collineation(col_id, points=ps) collineations[col_id] = r # Generate opposite vertival angles. opposite_angles = {} n_cols = len(self._collineation_list) for i in range(n_cols): for j in range(i + 1, n_cols): col1 = self._collineation_list[i] col2 = self._collineation_list[j] common = list(set(col1) & set(col2)) if len(common) != 1: continue vertex = common[0] if vertex in [col1[0], col1[-1], col2[0], col2[-1]]: continue angle1_1 = self.find_angle_by_points(col1[0], vertex, col2[0]) angle1_2 = self.find_angle_by_points(col1[-1], vertex, col2[-1]) rid = ' '.join(['OppositeAngle', angle1_1.id, angle1_2.id]) opposite_angles[rid] = OppositeVerticalAngle(rid, angle1=angle1_1, angle2=angle1_2, vertex=vertex) angle2_1 = self.find_angle_by_points(col1[0], vertex, col2[-1]) angle2_2 = self.find_angle_by_points(col1[-1], vertex, col2[0]) rid = ' '.join(['OppositeAngle', angle2_1.id, angle2_2.id]) opposite_angles[rid] = OppositeVerticalAngle(rid, angle1=angle2_1, angle2=angle2_2, vertex=vertex) # Generate supplementary angles. supplementary_angles = {} for col in self._collineation_list: for p in col[1:-1]: for adj_p in self._adj_table[p]: if adj_p in col: continue angle1 = self.find_angle_by_points(col[0], p, adj_p) angle2 = self.find_angle_by_points(col[-1], p, adj_p) rid = ' '.join( ['SupplementaryAngle', angle1.id, angle2.id]) supplementary_angles[rid] = \ SupplementaryAngle(rid, angle1=angle1, angle2=angle2) # Generate common vertex angles. common_vertex_angles = {} for v, arounds in self._common_vertex: vertex = self.points[v] ends = [self.points[pid] for pid in arounds] rid = ' '.join(['CommonVertexAngle', v, ''.join(arounds)]) r = CommonVertexAngle(rid, vertex=vertex, ends=ends) common_vertex_angles[rid] = r # Generate n angles sector. n_angles_sector = {} for aid, lid, ratio in self._angle_split: near_line = self.find_line_by_ends(*aid[:2]) angle_ = self.find_angle_by_points(*aid) line_ = self.find_line_by_ends(*lid) rid = ' '.join([angle_.id, line_.id, str(ratio), near_line.id]) r = NAngleSector(rid, angle=angle_, split_line=line_, near_line=near_line) cond = AttributeValue(r, ratio=ratio) conditions.append(cond) n_angles_sector[rid] = r # Generate n line sector. n_line_sector = {} for lid, pid, ratio in self._line_split: rid = ' '.join(['NLineSector', lid, pid, str(ratio)]) r = NLineSector(rid, line=self.find_line_by_ends(*lid), split_point=self.points[pid], near_point=self.points[lid[0]]) cond = AttributeValue(r, ratio=ratio) conditions.append(cond) n_line_sector[rid] = r # Generate perpendicular relationship. perpendiculars = {} for lid1, lid2 in self._perpendicular_pairs: rid = ' '.join(['Perpendicular', lid1, lid2]) r = Perpendicular(rid, line1=self.find_line_by_ends(*lid1), line2=self.find_line_by_ends(*lid2), foot_point=None) perpendiculars[rid] = r # Generate parallel relationship. parallels = {} for line_ids_tp in self._parallel_sets: line_ids = list(line_ids_tp) line_num = len(line_ids) for i in range(line_num): for j in range(i + 1, line_num): reverse = False if line_ids[i][0] > line_ids[i][1]: reverse = not reverse line_ids[i] = line_ids[i][::-1] if line_ids[j][0] > line_ids[j][1]: reverse = not reverse line_ids[j] = line_ids[j][::-1] line1 = self.lines[line_ids[i]] line2 = self.lines[line_ids[j]] rid = ' '.join(['Parallel', line_ids[i], line_ids[j]]) parallels[rid] = Parallel(rid, line1, line2, reverse=reverse) # Generate ValueEquivalence relationship. value_equivalence = {} for obj_list in self._angle_equivalent: obj_list = [ self.find_angle_by_points(*obj_id) for obj_id in obj_list ] rid = '='.join([obj.id for obj in obj_list]) r = ValueEquivalence(rid, obj_list=obj_list, attr_list=['angle'] * len(obj_list)) value_equivalence[rid] = r for obj_list in self._line_equivalent: obj_list = [self.find_line_by_ends(*obj_id) for obj_id in obj_list] rid = '='.join([obj.id for obj in obj_list]) r = ValueEquivalence(rid, obj_list=obj_list, attr_list=['length'] * len(obj_list)) value_equivalence[rid] = r # Generate equilateral triangle equilateral_triangles = {} for th_id in self._equilateral_triangle: std_th_id = ''.join(sorted(th_id)) th = self.triangles[std_th_id] r = IsEquilateralTriangle(std_th_id, th) equilateral_triangles[std_th_id] = r # Generate right triangle right_triangles = {} for th_id, aid in self._right_triangle: std_th_id = ''.join(sorted(th_id)) right_angle = self.find_angle_by_points(*aid) th = self.triangles[std_th_id] r = IsRightTriangle(std_th_id, th, right_angle) right_triangles[std_th_id] = r if self._shown: print('collineations: ', sorted(collineations.keys())) print('opposite angles: ', sorted(opposite_angles.keys())) print('supplementary angles: ', sorted(supplementary_angles.keys())) print('common vertex angles: ', sorted(common_vertex_angles.keys())) print('n angles sector: ', sorted(n_angles_sector.keys())) print('n line sector: ', sorted(n_line_sector.keys())) print('perpendiculars: ', sorted(perpendiculars.keys())) print('parallels: ', sorted(parallels.keys())) relationships = [] relationships += collineations.values() relationships += opposite_angles.values() relationships += supplementary_angles.values() relationships += common_vertex_angles.values() relationships += n_angles_sector.values() relationships += perpendiculars.values() relationships += n_line_sector.values() relationships += parallels.values() relationships += value_equivalence.values() relationships += equilateral_triangles.values() relationships += right_triangles.values() for r in relationships: conditions.append(RelationshipBased(r)) entity.add_entity(*(self.points.values())) entity.add_entity(*(self.lines.values())) entity.add_entity(*(self.angles.values())) entity.add_entity(*(self.triangles.values())) # Generate target. if self._target_triplet is None: raise NotImplementedError("Target not setted.") target_id = self._target_triplet[0] target_type = self._target_triplet[1] target_attr = self._target_triplet[2] target_obj = entity.find_child(target_id, target_type) target = Target(target_obj, target_attr) problem = Problem(entity, conditions, target) return problem