Loads the solver parameters from a TOML file.
(cls, loc: str | pathlib.Path)
| 111 | |
| 112 | @classmethod |
| 113 | def from_file(cls, loc: str | pathlib.Path): |
| 114 | """ |
| 115 | Loads the solver parameters from a TOML file. |
| 116 | """ |
| 117 | with open(loc, "rb") as fh: |
| 118 | data = tomllib.load(fh) |
| 119 | |
| 120 | node_ops = NODE_OPERATORS |
| 121 | if "node_ops" in data: |
| 122 | node_ops = [getattr(pyvrp.search, op) for op in data["node_ops"]] |
| 123 | |
| 124 | route_ops = ROUTE_OPERATORS |
| 125 | if "route_ops" in data: |
| 126 | route_ops = [getattr(pyvrp.search, op) for op in data["route_ops"]] |
| 127 | |
| 128 | return cls( |
| 129 | IteratedLocalSearchParams(**data.get("ils", {})), |
| 130 | PenaltyParams(**data.get("penalty", {})), |
| 131 | NeighbourhoodParams(**data.get("neighbourhood", {})), |
| 132 | node_ops, |
| 133 | route_ops, |
| 134 | data.get("display_interval", 5.0), |
| 135 | PerturbationParams(**data.get("perturbation", {})), |
| 136 | ) |
| 137 | |
| 138 | |
| 139 | def solve( |