rework structure of everything
This commit is contained in:
parent
dcc4d6436c
commit
941d3e01df
64 changed files with 3819 additions and 3559 deletions
108
inire/tests/test_api.py
Normal file
108
inire/tests/test_api.py
Normal file
|
|
@ -0,0 +1,108 @@
|
|||
from shapely.geometry import box
|
||||
|
||||
from inire import (
|
||||
CongestionOptions,
|
||||
DiagnosticsOptions,
|
||||
LockedRoute,
|
||||
NetSpec,
|
||||
ObjectiveWeights,
|
||||
Port,
|
||||
RefinementOptions,
|
||||
RoutingOptions,
|
||||
RoutingProblem,
|
||||
SearchOptions,
|
||||
route,
|
||||
)
|
||||
from inire.geometry.components import Straight
|
||||
|
||||
|
||||
def test_route_problem_smoke() -> None:
|
||||
problem = RoutingProblem(
|
||||
bounds=(0, 0, 100, 100),
|
||||
nets=(NetSpec("net1", Port(10, 50, 0), Port(90, 50, 0), width=2.0),),
|
||||
)
|
||||
|
||||
run = route(problem)
|
||||
|
||||
assert set(run.results_by_net) == {"net1"}
|
||||
assert run.results_by_net["net1"].is_valid
|
||||
|
||||
|
||||
def test_route_problem_supports_configs_and_debug_data() -> None:
|
||||
problem = RoutingProblem(
|
||||
bounds=(0, 0, 100, 100),
|
||||
nets=(NetSpec("net1", Port(10, 10, 0), Port(90, 90, 0), width=2.0),),
|
||||
static_obstacles=(box(40, 0, 60, 70),),
|
||||
)
|
||||
options = RoutingOptions(
|
||||
search=SearchOptions(
|
||||
bend_radii=(10.0,),
|
||||
node_limit=50000,
|
||||
greedy_h_weight=1.2,
|
||||
),
|
||||
objective=ObjectiveWeights(
|
||||
bend_penalty=50.0,
|
||||
sbend_penalty=150.0,
|
||||
),
|
||||
congestion=CongestionOptions(warm_start=None),
|
||||
refinement=RefinementOptions(enabled=True),
|
||||
diagnostics=DiagnosticsOptions(capture_expanded=True),
|
||||
)
|
||||
|
||||
run = route(problem, options=options)
|
||||
|
||||
assert run.results_by_net["net1"].reached_target
|
||||
assert run.expanded_nodes
|
||||
assert run.metrics.nodes_expanded > 0
|
||||
|
||||
|
||||
def test_route_problem_locked_routes_become_static_obstacles() -> None:
|
||||
locked = (Straight.generate(Port(10, 50, 0), 80.0, 2.0, dilation=1.0),)
|
||||
problem = RoutingProblem(
|
||||
bounds=(0, 0, 100, 100),
|
||||
nets=(NetSpec("crossing", Port(50, 10, 90), Port(50, 90, 90), width=2.0),),
|
||||
locked_routes={"locked": LockedRoute.from_path(locked)},
|
||||
)
|
||||
options = RoutingOptions(
|
||||
congestion=CongestionOptions(max_iterations=1, warm_start=None),
|
||||
refinement=RefinementOptions(enabled=False),
|
||||
)
|
||||
|
||||
run = route(problem, options=options)
|
||||
result = run.results_by_net["crossing"]
|
||||
|
||||
assert not result.is_valid
|
||||
|
||||
|
||||
def test_locked_routes_enable_incremental_requests_without_sessions() -> None:
|
||||
problem_a = RoutingProblem(
|
||||
bounds=(0, -50, 100, 50),
|
||||
nets=(NetSpec("netA", Port(10, 0, 0), Port(90, 0, 0), width=2.0),),
|
||||
)
|
||||
options = RoutingOptions(search=SearchOptions(bend_radii=(10.0,)))
|
||||
results_a = route(problem_a, options=options)
|
||||
assert results_a.results_by_net["netA"].is_valid
|
||||
|
||||
problem_b = RoutingProblem(
|
||||
bounds=(0, -50, 100, 50),
|
||||
nets=(NetSpec("netB", Port(50, -20, 90), Port(50, 20, 90), width=2.0),),
|
||||
locked_routes={"netA": results_a.results_by_net["netA"].as_locked_route()},
|
||||
)
|
||||
results_b = route(problem_b, options=options)
|
||||
|
||||
assert results_b.results_by_net["netB"].is_valid
|
||||
|
||||
|
||||
def test_route_results_metrics_are_snapshots() -> None:
|
||||
problem = RoutingProblem(
|
||||
bounds=(0, 0, 100, 100),
|
||||
nets=(NetSpec("net1", Port(10, 50, 0), Port(90, 50, 0), width=2.0),),
|
||||
)
|
||||
options = RoutingOptions()
|
||||
run1 = route(problem, options=options)
|
||||
first_metrics = run1.metrics
|
||||
run2 = route(problem, options=options)
|
||||
|
||||
assert first_metrics == run1.metrics
|
||||
assert run1.metrics is not run2.metrics
|
||||
assert first_metrics.nodes_expanded > 0
|
||||
Loading…
Add table
Add a link
Reference in a new issue