Build a problem into a gr.Graph object.
(
cls,
pr: problem.Problem,
definitions: dict[str, problem.Definition],
verbose: bool = True,
init_copy: bool = True,
)
| 484 | |
| 485 | @classmethod |
| 486 | def build_problem( |
| 487 | cls, |
| 488 | pr: problem.Problem, |
| 489 | definitions: dict[str, problem.Definition], |
| 490 | verbose: bool = True, |
| 491 | init_copy: bool = True, |
| 492 | ) -> tuple[Graph, list[Dependency]]: |
| 493 | """Build a problem into a gr.Graph object.""" |
| 494 | check = False |
| 495 | g = None |
| 496 | added = None |
| 497 | if verbose: |
| 498 | logging.info(pr.url) |
| 499 | logging.info(pr.txt()) |
| 500 | while not check: |
| 501 | try: |
| 502 | g = Graph() |
| 503 | added = [] |
| 504 | plevel = 0 |
| 505 | for clause in pr.clauses: |
| 506 | adds, plevel = g.add_clause( |
| 507 | clause, plevel, definitions, verbose=verbose |
| 508 | ) |
| 509 | added += adds |
| 510 | g.plevel = plevel |
| 511 | |
| 512 | except (nm.InvalidLineIntersectError, nm.InvalidQuadSolveError): |
| 513 | continue |
| 514 | except DepCheckFailError: |
| 515 | continue |
| 516 | except (PointTooCloseError, PointTooFarError): |
| 517 | continue |
| 518 | |
| 519 | if not pr.goal: |
| 520 | break |
| 521 | |
| 522 | args = list(map(lambda x: g.get(x, lambda: int(x)), pr.goal.args)) |
| 523 | check = nm.check(pr.goal.name, args) |
| 524 | |
| 525 | g.url = pr.url |
| 526 | g.build_def = (pr, definitions) |
| 527 | for add in added: |
| 528 | g.add_algebra(add, level=0) |
| 529 | |
| 530 | return g, added |
| 531 | |
| 532 | def all_points(self) -> list[Point]: |
| 533 | """Return all nodes of type Point.""" |