Graph data structure representing proof state.
| 91 | |
| 92 | |
| 93 | class Graph: |
| 94 | """Graph data structure representing proof state.""" |
| 95 | |
| 96 | def __init__(self): |
| 97 | self.type2nodes = { |
| 98 | Point: [], |
| 99 | Line: [], |
| 100 | Segment: [], |
| 101 | Circle: [], |
| 102 | Direction: [], |
| 103 | Length: [], |
| 104 | Angle: [], |
| 105 | Ratio: [], |
| 106 | Measure: [], |
| 107 | Value: [], |
| 108 | } |
| 109 | self._name2point = {} |
| 110 | self._name2node = {} |
| 111 | |
| 112 | self.rconst = {} # contains all constant ratios |
| 113 | self.aconst = {} # contains all constant angles. |
| 114 | |
| 115 | self.halfpi, _ = self.get_or_create_const_ang(1, 2) |
| 116 | self.vhalfpi = self.halfpi.val |
| 117 | |
| 118 | self.atable = ar.AngleTable() |
| 119 | self.dtable = ar.DistanceTable() |
| 120 | self.rtable = ar.RatioTable() |
| 121 | |
| 122 | # to quick access deps. |
| 123 | self.cache = {} |
| 124 | |
| 125 | self._pair2line = {} |
| 126 | self._triplet2circle = {} |
| 127 | |
| 128 | def copy(self) -> Graph: |
| 129 | """Make a copy of self.""" |
| 130 | p, definitions = self.build_def |
| 131 | |
| 132 | p = p.copy() |
| 133 | for clause in p.clauses: |
| 134 | clause.nums = [] |
| 135 | for pname in clause.points: |
| 136 | clause.nums.append(self._name2node[pname].num) |
| 137 | |
| 138 | g, _ = Graph.build_problem(p, definitions, verbose=False, init_copy=False) |
| 139 | |
| 140 | g.build_clauses = list(getattr(self, 'build_clauses', [])) |
| 141 | return g |
| 142 | |
| 143 | def _create_const_ang(self, n: int, d: int) -> None: |
| 144 | n, d = ar.simplify(n, d) |
| 145 | ang = self.aconst[(n, d)] = self.new_node(Angle, f'{n}pi/{d}') |
| 146 | ang.set_directions(None, None) |
| 147 | self.connect_val(ang, deps=None) |
| 148 | |
| 149 | def _create_const_rat(self, n: int, d: int) -> None: |
| 150 | n, d = ar.simplify(n, d) |