Reformat setup into levels of point constructions.
(
setup: list[problem.Dependency], existing_points: list[gm.Point]
)
| 26 | |
| 27 | |
| 28 | def point_levels( |
| 29 | setup: list[problem.Dependency], existing_points: list[gm.Point] |
| 30 | ) -> list[tuple[set[gm.Point], list[problem.Dependency]]]: |
| 31 | """Reformat setup into levels of point constructions.""" |
| 32 | levels = [] |
| 33 | for con in setup: |
| 34 | plevel = max([p.plevel for p in con.args if isinstance(p, gm.Point)]) |
| 35 | |
| 36 | while len(levels) - 1 < plevel: |
| 37 | levels.append((set(), [])) |
| 38 | |
| 39 | for p in con.args: |
| 40 | if not isinstance(p, gm.Point): |
| 41 | continue |
| 42 | if existing_points and p in existing_points: |
| 43 | continue |
| 44 | |
| 45 | levels[p.plevel][0].add(p) |
| 46 | |
| 47 | cons = levels[plevel][1] |
| 48 | cons.append(con) |
| 49 | |
| 50 | return [(p, c) for p, c in levels if p or c] |
| 51 | |
| 52 | |
| 53 | def point_log( |