58 lines
1.6 KiB
Markdown
58 lines
1.6 KiB
Markdown
|
# Python API
|
||
|
|
||
|
First the module needs to be imported
|
||
|
|
||
|
```python
|
||
|
from _ed_lrr import PyRouter, PyShip
|
||
|
```
|
||
|
|
||
|
Then we need to instantiate a route plotter
|
||
|
|
||
|
```python
|
||
|
# callback is passed a dict describing the current search state and progress
|
||
|
def callback(state):
|
||
|
print(state)
|
||
|
|
||
|
r=PyRouter(callback)
|
||
|
```
|
||
|
|
||
|
Optionally ship loadouts can be loaded from the Elite: Dangerous journal files
|
||
|
|
||
|
```python
|
||
|
ships = PyShip.from_journal()
|
||
|
```
|
||
|
|
||
|
To plot a route we need to load a list of star systems with coordinates
|
||
|
|
||
|
```python
|
||
|
r.load("./stars.csv")
|
||
|
```
|
||
|
|
||
|
After a list has been loaded we can resolve star systems to their IDs
|
||
|
|
||
|
```python
|
||
|
systems = [
|
||
|
# resolve by coordinates, needs to build an R*-Tree so uses a few GB of RAM
|
||
|
(0,0,0),
|
||
|
# resolve by name, does fuzzy search, has to scan the whole list of system names
|
||
|
"Colonia",
|
||
|
# resolve by ID, fairly fast, but the IDs are ed_lrr specific
|
||
|
3553323
|
||
|
]
|
||
|
systems = r.resolve_systems(*query) # this will return a dict mapping the input key to a dict
|
||
|
assert sorted(systems.keys())==sorted(query)
|
||
|
sys_ids = {k: v["id"] for k, v in systems.items()}
|
||
|
```
|
||
|
|
||
|
Once the system IDs are known we can compute a route
|
||
|
|
||
|
```python
|
||
|
route = r.route(
|
||
|
[sys_ids["Sol"], sys_ids["Colonia"]] # route hops, can be any number of systems (at least 2)
|
||
|
48.0, # jump range
|
||
|
beam_width=1<<12, # beam width to limit exploration (4096)
|
||
|
greedyness=0, # greedyness for A* (0=BFS,0.5 = A*, 1=Greedy)
|
||
|
max_dist=500, # maximum deviation from straight line (not yet implemented)
|
||
|
num_workers=0 # number of workers to distribute the search accross (0 -> serial mode, >=1 -> spawn worker pool)
|
||
|
)
|
||
|
```
|