Skip to content
Commits on Source (5)
# Prerequisites
- conda (miniconda/anaconda)
- Python:
- conda (miniconda/anaconda)
- tox (`conda install tox`)
- Inno Setup Compiler
- Download from [here](http://www.jrsoftware.org/isdl.php)
- or install via [scoop](https://scoop.sh/) `scoop install inno-setup`)
- Visual Studio 2019
- nightly rust compiler (`x86_64-pc-windows-msvc`)
# Testing
# Building an installer
```bash
conda create -n ed_lrr_gui_env python=3
conda activate ed_lrr_gui_env
python build_gui.py
pip install -e .
rs_gui_test
```
(Assuming `conda` is in your `PATH`)
1. Start a Visual Studio 2019 x64 command prompt
2. Run `tox`
3. Grab the installer from `installer/Output/`
# Installing
# Building
(Assuming `conda` is in your `PATH`)
```bash
conda create -n ed_lrr_gui_env python=3
conda activate ed_lrr_gui_env
1. Start a Visual Studio 2019 x64 command prompt
2. Run the following commands:
```
conda install pycrypto nuitka
pip install PyQt5 setuptools_rust
python build_gui.py
pip install setuptools_rust pyinstaller
pip install .
python setup.py build
python setup.py bdist_wheel
python setup.py sdist
mkdir exe
cd exe
pyinstaller --noupx --name ed_lrr_gui ../ed_lrr_gui/__main__.py
pyinstaller --noupx --onefile --name ed_lrr_gui ../ed_lrr_gui/__main__.py
cd ..
```
# Clean
```bash
rm -rfv _*.pyd *.pyc *.egg-info pip-wheel-metadata dist exe build __pycache__
cd rust
cargo clean
cargo clean --release
cd ..
```
then you can run `ed_lrr -h` from
# TODO
- integrate callbacks into the GUI: WIP
- QTimer pulls from queue updates UI (every 100ms)
# To do
- Implement progress dialog for preprocessor
- Finish implementing Dialog to display the computed route
\ No newline at end of file
import svgwrite
import random
import time
from math import factorial
from math import factorial,sin,cos,pi
from itertools import permutations
import tsp as m_tsp
......@@ -48,7 +48,7 @@ def generate(seed,name=None,small=False):
random.seed(seed)
w=2
max_rings=3
num_points=10
num_points=5
min_dist=10+10+20*(max_rings+1)
base_r=10
ring_step=lambda v:10+v*10
......@@ -62,17 +62,7 @@ def generate(seed,name=None,small=False):
color="#eee"
pos=make_points(num_points,size,min_dist=min_dist)
print("TSP...")
min_d=float('inf')
for p1 in pos:
for p2 in pos:
if p1==p2:
continue
min_d=min(min_d,dist(p1,p2))
print(min_d,min_dist)
pos=tsp(pos)
for (x1,y1),(x2,y2) in zip(pos,pos[1:]):
if small:
x1/=sd
......@@ -87,8 +77,6 @@ def generate(seed,name=None,small=False):
base_r=5
px/=sd
py/=sd
px=svgwrite.px(px)
py=svgwrite.px(py)
if random.random()>0.8:
dwg.add(dwg.circle((px,py),r=base_r+random.random()*base_r,stroke_width=w,stroke='#0ae')).fill('#0ae')
else:
......@@ -96,20 +84,26 @@ def generate(seed,name=None,small=False):
r=base_r
for _ in range(random.randint(1,max_rings)):
if small:
random.random()
random.random()
random.random()
continue
r+=ring_step(random.random())
ring_col=color
if random.random()>0.75:
circ=dwg.add(dwg.circle((px,py),r=r,stroke_width=w,stroke="#ea0"))
else:
circ=dwg.add(dwg.circle((px,py),r=r,stroke_width=w,stroke=color))
ring_col="#ea0"
circ=dwg.add(dwg.circle((px,py),r=r,stroke_width=w,stroke=ring_col))
circ.fill(color,opacity=0)
d=random.random()*pi*2
dx=cos(d)
dy=sin(d)
m=random.random()
moon=dwg.add(dwg.circle((px+dx*r,py+dy*r),r=2+2*m,stroke_width=w,stroke=ring_col))
moon.fill(ring_col)
dwg.save()
seed=0
seed=-4
generate(seed,"icon_1",small=False)
generate(seed,"icon_1_small",small=True)
<?xml version="1.0" encoding="utf-8" ?>
<svg baseProfile="full" height="100%" version="1.1" width="100%" xmlns="http://www.w3.org/2000/svg" xmlns:ev="http://www.w3.org/2001/xml-events" xmlns:xlink="http://www.w3.org/1999/xlink"><defs><style type="text/css"><![CDATA[.background { fill: #222; }]]></style></defs><rect class="background" height="100%" width="100%" x="0" y="0" /><line stroke="#eee" stroke-width="2" x1="492.2109257625241" x2="524.0564425976676" y1="448.9772014701512" y2="322.34342790869516" /><line stroke="#eee" stroke-width="2" x1="524.0564425976676" x2="461.8992945173863" y1="322.34342790869516" y2="221.6563630394637" /><line stroke="#eee" stroke-width="2" x1="461.8992945173863" x2="344.34965191779463" y1="221.6563630394637" y2="77.02085008200947" /><line stroke="#eee" stroke-width="2" x1="344.34965191779463" x2="280.2857904154225" y1="77.02085008200947" y2="199.45837514648167" /><line stroke="#eee" stroke-width="2" x1="280.2857904154225" x2="70.57140965721413" y1="199.45837514648167" y2="316.7889332326623" /><line stroke="#eee" stroke-width="2" x1="70.57140965721413" x2="210.91892219985192" y1="316.7889332326623" y2="447.90210207861196" /><line stroke="#eee" stroke-width="2" x1="210.91892219985192" x2="308.2984770761779" y1="447.90210207861196" y2="361.6910197275156" /><line stroke="#eee" stroke-width="2" x1="308.2984770761779" x2="308.50488827635854" y1="361.6910197275156" y2="502.65496388582005" /><line stroke="#eee" stroke-width="2" x1="308.50488827635854" x2="524.8731279841201" y1="502.65496388582005" y2="561.3927380188265" /><circle cx="492.2109257625241px" cy="448.9772014701512px" fill="#0ae" r="3.731732630661396" stroke="#0ae" stroke-width="2" /><circle cx="492.2109257625241px" cy="448.9772014701512px" fill="#eee" fill-opacity="0" r="20.036425461655202" stroke="#eee" stroke-width="2" /><circle cx="492.2109257625241px" cy="448.9772014701512px" fill="#eee" fill-opacity="0" r="39.2066151528047" stroke="#eee" stroke-width="2" /><circle cx="524.0564425976676px" cy="322.34342790869516px" fill="#0ae" r="3.4274831817264735" stroke="#0ae" stroke-width="2" /><circle cx="524.0564425976676px" cy="322.34342790869516px" fill="#eee" fill-opacity="0" r="17.479695714355703" stroke="#eee" stroke-width="2" /><circle cx="524.0564425976676px" cy="322.34342790869516px" fill="#eee" fill-opacity="0" r="30.68024176108116" stroke="#eee" stroke-width="2" /><circle cx="524.0564425976676px" cy="322.34342790869516px" fill="#eee" fill-opacity="0" r="50.00858000335023" stroke="#eee" stroke-width="2" /><circle cx="461.8992945173863px" cy="221.6563630394637px" fill="#eee" r="5.119684229600669" stroke="#eee" stroke-width="2" /><circle cx="461.8992945173863px" cy="221.6563630394637px" fill="#eee" fill-opacity="0" r="16.327505127673362" stroke="#ea0" stroke-width="2" /><circle cx="461.8992945173863px" cy="221.6563630394637px" fill="#eee" fill-opacity="0" r="28.359523652367695" stroke="#ea0" stroke-width="2" /><circle cx="461.8992945173863px" cy="221.6563630394637px" fill="#eee" fill-opacity="0" r="43.83182471736688" stroke="#eee" stroke-width="2" /><circle cx="344.34965191779463px" cy="77.02085008200947px" fill="#eee" r="5.393805057963009" stroke="#eee" stroke-width="2" /><circle cx="344.34965191779463px" cy="77.02085008200947px" fill="#eee" fill-opacity="0" r="18.756510141648885" stroke="#eee" stroke-width="2" /><circle cx="344.34965191779463px" cy="77.02085008200947px" fill="#eee" fill-opacity="0" r="30.650423427192447" stroke="#eee" stroke-width="2" /><circle cx="280.2857904154225px" cy="199.45837514648167px" fill="#eee" r="4.969978166968886" stroke="#eee" stroke-width="2" /><circle cx="280.2857904154225px" cy="199.45837514648167px" fill="#eee" fill-opacity="0" r="13.690852484838988" stroke="#eee" stroke-width="2" /><circle cx="280.2857904154225px" cy="199.45837514648167px" fill="#eee" fill-opacity="0" r="24.993096989884577" stroke="#eee" stroke-width="2" /><circle cx="70.57140965721413px" cy="316.7889332326623px" fill="#eee" r="3.2407449535617183" stroke="#eee" stroke-width="2" /><circle cx="70.57140965721413px" cy="316.7889332326623px" fill="#eee" fill-opacity="0" r="22.23082439820177" stroke="#eee" stroke-width="2" /><circle cx="70.57140965721413px" cy="316.7889332326623px" fill="#eee" fill-opacity="0" r="36.14378490054801" stroke="#eee" stroke-width="2" /><circle cx="70.57140965721413px" cy="316.7889332326623px" fill="#eee" fill-opacity="0" r="48.90012611366929" stroke="#ea0" stroke-width="2" /><circle cx="210.91892219985192px" cy="447.90210207861196px" fill="#0ae" r="5.685116902280026" stroke="#0ae" stroke-width="2" /><circle cx="210.91892219985192px" cy="447.90210207861196px" fill="#eee" fill-opacity="0" r="21.25263298673666" stroke="#eee" stroke-width="2" /><circle cx="210.91892219985192px" cy="447.90210207861196px" fill="#eee" fill-opacity="0" r="34.004741147184966" stroke="#eee" stroke-width="2" /><circle cx="210.91892219985192px" cy="447.90210207861196px" fill="#eee" fill-opacity="0" r="50.41670939300849" stroke="#eee" stroke-width="2" /><circle cx="308.2984770761779px" cy="361.6910197275156px" fill="#0ae" r="4.072102637940041" stroke="#0ae" stroke-width="2" /><circle cx="308.2984770761779px" cy="361.6910197275156px" fill="#eee" fill-opacity="0" r="19.127831050407124" stroke="#eee" stroke-width="2" /><circle cx="308.2984770761779px" cy="361.6910197275156px" fill="#eee" fill-opacity="0" r="35.429304454521855" stroke="#ea0" stroke-width="2" /><circle cx="308.50488827635854px" cy="502.65496388582005px" fill="#eee" r="5.194467662372544" stroke="#eee" stroke-width="2" /><circle cx="308.50488827635854px" cy="502.65496388582005px" fill="#eee" fill-opacity="0" r="20.05333115312908" stroke="#eee" stroke-width="2" /><circle cx="524.8731279841201px" cy="561.3927380188265px" fill="#eee" r="4.278393406031574" stroke="#eee" stroke-width="2" /><circle cx="524.8731279841201px" cy="561.3927380188265px" fill="#eee" fill-opacity="0" r="14.006075202160963" stroke="#eee" stroke-width="2" /></svg>
\ No newline at end of file
<svg baseProfile="full" height="100%" version="1.1" width="100%" xmlns="http://www.w3.org/2000/svg" xmlns:ev="http://www.w3.org/2001/xml-events" xmlns:xlink="http://www.w3.org/1999/xlink"><defs><style type="text/css"><![CDATA[.background { fill: #222; }]]></style></defs><rect class="background" height="100%" width="100%" x="0" y="0" /><line stroke="#eee" stroke-width="2" x1="188.02404486871725" x2="103.25754783979495" y1="121.5830171153579" y2="270.7955072425374" /><line stroke="#eee" stroke-width="2" x1="103.25754783979495" x2="528.9775215438594" y1="270.7955072425374" y2="470.2261757479043" /><line stroke="#eee" stroke-width="2" x1="528.9775215438594" x2="452.58130125271924" y1="470.2261757479043" y2="180.96408784515882" /><line stroke="#eee" stroke-width="2" x1="452.58130125271924" x2="338.3400040874068" y1="180.96408784515882" y2="208.34132172072512" /><circle cx="188.02404486871725" cy="121.5830171153579" fill="#eee" r="3.3185498772945903" stroke="#eee" stroke-width="2" /><circle cx="188.02404486871725" cy="121.5830171153579" fill="#eee" fill-opacity="0" r="22.429593602379832" stroke="#eee" stroke-width="2" /><circle cx="173.80179554276944" cy="104.23901834695114" fill="#eee" r="2.52050830126476" stroke="#eee" stroke-width="2" /><circle cx="103.25754783979495" cy="270.7955072425374" fill="#eee" r="3.4944547782059745" stroke="#eee" stroke-width="2" /><circle cx="103.25754783979495" cy="270.7955072425374" fill="#eee" fill-opacity="0" r="19.2697560241313" stroke="#eee" stroke-width="2" /><circle cx="115.03444741085107" cy="255.5433554690071" fill="#eee" r="3.7601015027223985" stroke="#eee" stroke-width="2" /><circle cx="103.25754783979495" cy="270.7955072425374" fill="#eee" fill-opacity="0" r="30.13693855048052" stroke="#eee" stroke-width="2" /><circle cx="89.02212054970202" cy="244.23260689141011" fill="#eee" r="3.0119075514208307" stroke="#eee" stroke-width="2" /><circle cx="528.9775215438594" cy="470.2261757479043" fill="#eee" r="4.420763662755435" stroke="#eee" stroke-width="2" /><circle cx="528.9775215438594" cy="470.2261757479043" fill="#eee" fill-opacity="0" r="22.44577790309402" stroke="#ea0" stroke-width="2" /><circle cx="549.9596596985477" cy="462.25354606049257" fill="#ea0" r="3.680925358835544" stroke="#ea0" stroke-width="2" /><circle cx="452.58130125271924" cy="180.96408784515882" fill="#eee" r="3.8758250081323116" stroke="#eee" stroke-width="2" /><circle cx="452.58130125271924" cy="180.96408784515882" fill="#eee" fill-opacity="0" r="21.8231723987879" stroke="#ea0" stroke-width="2" /><circle cx="430.78831758434035" cy="179.8166052191519" fill="#ea0" r="2.827892086263464" stroke="#ea0" stroke-width="2" /><circle cx="452.58130125271924" cy="180.96408784515882" fill="#eee" fill-opacity="0" r="37.812297120687795" stroke="#eee" stroke-width="2" /><circle cx="472.57653937753463" cy="213.0570818761791" fill="#eee" r="2.6102231928654778" stroke="#eee" stroke-width="2" /><circle cx="452.58130125271924" cy="180.96408784515882" fill="#eee" fill-opacity="0" r="55.938220307034" stroke="#eee" stroke-width="2" /><circle cx="506.1669380410402" cy="197.01600427617765" fill="#eee" r="3.252701491079807" stroke="#eee" stroke-width="2" /><circle cx="338.3400040874068" cy="208.34132172072512" fill="#eee" r="4.603865384638267" stroke="#eee" stroke-width="2" /><circle cx="338.3400040874068" cy="208.34132172072512" fill="#eee" fill-opacity="0" r="20.00878719559634" stroke="#eee" stroke-width="2" /><circle cx="329.11968037233845" cy="190.58358550160054" fill="#eee" r="2.132876938772122" stroke="#eee" stroke-width="2" /><circle cx="338.3400040874068" cy="208.34132172072512" fill="#eee" fill-opacity="0" r="39.144105385654704" stroke="#eee" stroke-width="2" /><circle cx="301.84139133159863" cy="222.48742554279568" fill="#eee" r="2.3674072974299003" stroke="#eee" stroke-width="2" /></svg>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8" ?>
<svg baseProfile="full" height="100%" version="1.1" width="100%" xmlns="http://www.w3.org/2000/svg" xmlns:ev="http://www.w3.org/2001/xml-events" xmlns:xlink="http://www.w3.org/1999/xlink"><defs><style type="text/css"><![CDATA[.background { fill: #222; }]]></style></defs><rect class="background" height="100%" width="100%" x="0" y="0" /><line stroke="#eee" stroke-width="2" x1="246.10546288126204" x2="262.0282212988338" y1="224.4886007350756" y2="161.17171395434758" /><line stroke="#eee" stroke-width="2" x1="262.0282212988338" x2="230.94964725869315" y1="161.17171395434758" y2="110.82818151973186" /><line stroke="#eee" stroke-width="2" x1="230.94964725869315" x2="172.17482595889732" y1="110.82818151973186" y2="38.51042504100474" /><line stroke="#eee" stroke-width="2" x1="172.17482595889732" x2="140.14289520771126" y1="38.51042504100474" y2="99.72918757324084" /><line stroke="#eee" stroke-width="2" x1="140.14289520771126" x2="35.28570482860707" y1="99.72918757324084" y2="158.39446661633116" /><line stroke="#eee" stroke-width="2" x1="35.28570482860707" x2="105.45946109992596" y1="158.39446661633116" y2="223.95105103930598" /><line stroke="#eee" stroke-width="2" x1="105.45946109992596" x2="154.14923853808895" y1="223.95105103930598" y2="180.8455098637578" /><line stroke="#eee" stroke-width="2" x1="154.14923853808895" x2="154.25244413817927" y1="180.8455098637578" y2="251.32748194291003" /><line stroke="#eee" stroke-width="2" x1="154.25244413817927" x2="262.43656399206003" y1="251.32748194291003" y2="280.6963690094133" /><circle cx="246.10546288126204px" cy="224.4886007350756px" fill="#0ae" r="6.21955438443566" stroke="#0ae" stroke-width="2" /><circle cx="262.0282212988338px" cy="161.17171395434758px" fill="#0ae" r="5.712471969544122" stroke="#0ae" stroke-width="2" /><circle cx="230.94964725869315px" cy="110.82818151973186px" fill="#eee" r="8.532807049334448" stroke="#eee" stroke-width="2" /><circle cx="172.17482595889732px" cy="38.51042504100474px" fill="#eee" r="8.989675096605016" stroke="#eee" stroke-width="2" /><circle cx="140.14289520771126px" cy="99.72918757324084px" fill="#eee" r="8.283296944948145" stroke="#eee" stroke-width="2" /><circle cx="35.28570482860707px" cy="158.39446661633116px" fill="#eee" r="5.401241589269531" stroke="#eee" stroke-width="2" /><circle cx="105.45946109992596px" cy="223.95105103930598px" fill="#0ae" r="9.475194837133376" stroke="#0ae" stroke-width="2" /><circle cx="154.14923853808895px" cy="180.8455098637578px" fill="#0ae" r="6.786837729900069" stroke="#0ae" stroke-width="2" /><circle cx="154.25244413817927px" cy="251.32748194291003px" fill="#eee" r="8.65744610395424" stroke="#eee" stroke-width="2" /><circle cx="262.43656399206003px" cy="280.6963690094133px" fill="#eee" r="7.1306556767192895" stroke="#eee" stroke-width="2" /></svg>
\ No newline at end of file
<svg baseProfile="full" height="100%" version="1.1" width="100%" xmlns="http://www.w3.org/2000/svg" xmlns:ev="http://www.w3.org/2001/xml-events" xmlns:xlink="http://www.w3.org/1999/xlink"><defs><style type="text/css"><![CDATA[.background { fill: #222; }]]></style></defs><rect class="background" height="100%" width="100%" x="0" y="0" /><line stroke="#eee" stroke-width="2" x1="94.01202243435863" x2="51.628773919897476" y1="60.79150855767895" y2="135.3977536212687" /><line stroke="#eee" stroke-width="2" x1="51.628773919897476" x2="264.4887607719297" y1="135.3977536212687" y2="235.11308787395214" /><line stroke="#eee" stroke-width="2" x1="264.4887607719297" x2="226.29065062635962" y1="235.11308787395214" y2="90.48204392257941" /><line stroke="#eee" stroke-width="2" x1="226.29065062635962" x2="169.1700020437034" y1="90.48204392257941" y2="104.17066086036256" /><circle cx="94.01202243435863" cy="60.79150855767895" fill="#eee" r="5.53091646215765" stroke="#eee" stroke-width="2" /><circle cx="51.628773919897476" cy="135.3977536212687" fill="#eee" r="6.358738772326545" stroke="#eee" stroke-width="2" /><circle cx="264.4887607719297" cy="235.11308787395214" fill="#0ae" r="9.400253756805997" stroke="#0ae" stroke-width="2" /><circle cx="226.29065062635962" cy="90.48204392257941" fill="#eee" r="6.236611100792434" stroke="#eee" stroke-width="2" /><circle cx="169.1700020437034" cy="104.17066086036256" fill="#eee" r="9.41158619939395" stroke="#eee" stroke-width="2" /></svg>
\ No newline at end of file
......@@ -21,5 +21,5 @@ Name: "{group}\Uninstall ED_LRR"; Filename: "{uninstallexe}"
;Name: modifypath; Description: Add application directory to PATH; Flags: unchecked
[Run]
Filename: "{app}\ED_LRR.exe"; Parameters: "download"; StatusMsg: "Downloading EDSM dumps..."; Description: "Download EDSM dumps"; Flags: postinstall
Filename: "{app}\ED_LRR.exe"; Description: "Launch ED_LRR"; Flags: postinstall nowait skipifsilent unchecked
; Filename: "{app}\ED_LRR.exe"; Parameters: "download"
This diff is collapsed.
[package]
name = "ed_lrr"
version = "0.1.0"
authors = ["Daniel Seiller <earthnuker@gmail.com>"]
edition = "2018"
repository = "https://gitlab.com/Earthnuker/ed_lrr.git"
license = "WTFPL"
[lib]
crate-type = ["cdylib"]
name = "_ed_lrr"
[dependencies]
pyo3 = { version = "0.8.0", features = ["extension-module"] }
csv = "1.1.1"
serde = { version = "1.0", features = ["derive"] }
rstar = "0.5.1"
humantime = "1.3.0"
permutohedron = "0.2.4"
serde_json = "1.0.40"
fnv = "1.0.6"
bincode = "1.1.4"
sha3 = "0.8.2"
byteorder = "1.3.2"
strsim = "0.9.2"
[package]
name = "ed_lrr"
version = "0.0.0"
authors = ["Daniel Seiller <earthnuker@gmail.com>"]
edition = "2018"
repository = "https://gitlab.com/Earthnuker/ed_lrr.git"
license = "WTFPL"
[lib]
crate-type = ["cdylib"]
name = "_ed_lrr"
[dependencies]
pyo3 = { version = "0.8.0", features = ["extension-module"] }
csv = "1.1.1"
serde = { version = "1.0.101", features = ["derive"] }
humantime = "1.3.0"
permutohedron = "0.2.4"
serde_json = "1.0.40"
fnv = "1.0.6"
bincode = "1.2.0"
sha3 = "0.8.2"
byteorder = "1.3.2"
strsim = "0.9.2"
rstar = "0.5.1"
......@@ -114,7 +114,7 @@ pub fn _ed_lrr(_py: Python, m: &PyModule) -> PyResult<()> {
py: Python<'static>,
hops: Vec<String>,
range: f32,
prune: Option<(usize,f64)>,
prune: Option<(usize, f32)>,
mode: String,
primary: bool,
permute: bool,
......
......@@ -57,7 +57,7 @@ pub struct RouteOpts {
pub keep_last: bool,
pub factor: Option<f32>,
pub mode: Mode,
pub prune: Option<(usize,f64)>,
pub prune: Option<(usize, f32)>,
pub systems: Vec<SysEntry>,
pub callback: Box<dyn Fn(&SearchState) -> PyResult<PyObject>>,
}
......@@ -193,8 +193,7 @@ pub struct Router {
range: f32,
primary_only: bool,
path: PathBuf,
prune: Option<(usize,f64)>,
prune_map: FnvHashMap<u32, (usize,f64)>,
prune: Option<(usize, f32)>,
callback: Box<dyn Fn(&SearchState) -> PyResult<PyObject>>,
}
......@@ -202,7 +201,7 @@ impl Router {
pub fn new(
path: &PathBuf,
range: f32,
prune: Option<(usize,f64)>,
prune: Option<(usize, f32)>,
primary_only: bool,
callback: Box<dyn Fn(&SearchState) -> PyResult<PyObject>>,
) -> Result<Self, String> {
......@@ -249,7 +248,6 @@ impl Router {
path: path.clone(),
callback,
prune,
prune_map: FnvHashMap::default()
};
println!(
"{} Systems loaded in {}",
......@@ -307,7 +305,6 @@ impl Router {
path,
callback,
prune: None,
prune_map: FnvHashMap::default()
},
))
}
......@@ -320,10 +317,9 @@ impl Router {
self.points_in_sphere(&sys.pos, sys.mult * r)
}
fn valid(&self, sys: &System, src: &System, dst: &System) -> bool {
fn valid(&self, sys: &System) -> bool {
let scoopable = self.scoopable.contains(&sys.id);
return scoopable;
// TODO: check prune map
}
pub fn best_multiroute(
......@@ -379,6 +375,14 @@ impl Router {
for pair in waypoints.windows(2) {
match pair {
[src, dst] => {
let d_total=dist(&src.pos,&dst.pos);
println!("Plotting route from [{}] to [{}]...", src.system, dst.system);
println!(
"Jump Range: {} Ly, Distance: {} Ly, Estimated Jumps: {}",
range,
d_total,
d_total / range
);
let block = match mode {
Mode::BFS => self.route_bfs(&src, &dst, range)?,
Mode::Greedy => self.route_greedy(&src, &dst, range)?,
......@@ -510,7 +514,7 @@ impl Router {
}
queue.extend(
self.neighbours(&sys, range)
.filter(|&nb| (self.valid(nb, &src, &dst) || (nb.id == goal_sys.id)))
.filter(|&nb| (self.valid(nb) || (nb.id == goal_sys.id)))
.filter(|&nb| seen.insert(nb.id))
.map(|nb| {
prev.insert(nb.id, sys);
......@@ -583,11 +587,11 @@ impl Router {
let mut prev = FnvHashMap::default();
let mut seen = FnvHashSet::default();
let mut found = false;
let mut queue: Vec<(f32, f32, usize, &System)> = Vec::new();
queue.push((-goal_sys.mult, start_sys.distp(goal_sys), 0, &start_sys));
let mut queue: Vec<(f32, usize, &System)> = Vec::new();
queue.push((start_sys.distp(goal_sys), 0, &start_sys));
seen.insert(start_sys.id);
while !(queue.is_empty() || found) {
while let Some((_, _, depth, sys)) = queue.pop() {
while let Some((_, depth, sys)) = queue.pop() {
if t_last.elapsed().as_millis() > 100 {
t_last = Instant::now();
state.depth = depth;
......@@ -611,7 +615,7 @@ impl Router {
}
queue.extend(
self.neighbours(&sys, range)
.filter(|&nb| (self.valid(nb, &src, &dst) || (nb.id == goal_sys.id)))
.filter(|&nb| (self.valid(nb) || (nb.id == goal_sys.id)))
.filter(|&nb| seen.insert(nb.id))
.map(|nb| {
prev.insert(nb.id, sys);
......@@ -619,10 +623,10 @@ impl Router {
if d_g < d_rem {
d_rem = d_g;
}
(-nb.mult, d_g, depth + 1, nb)
(d_g, depth + 1, nb)
}),
);
queue.sort_by(|a, b| fcmp(a.0, b.0).then(fcmp(a.1, b.1)));
queue.sort_by(|a, b| fcmp(a.0, b.0).then(a.1.cmp(&b.1)));
queue.reverse();
}
}
......@@ -786,6 +790,7 @@ impl Router {
range: f32,
) -> Result<Vec<System>, String> {
println!("Running BFS");
let min_improvement = self.prune.map(|v| (v.0,v.1*range)).unwrap_or_else(|| (0,0.0));
let src_name = start_sys.system.clone();
let dst_name = goal_sys.system.clone();
let d_total = dist(&start_sys.pos, &goal_sys.pos);
......@@ -804,15 +809,9 @@ impl Router {
system: start_sys.system.clone(),
body: start_sys.body.clone(),
};
println!("Plotting route from {} to {}...", src_name, dst_name);
println!(
"Jump Range: {} Ly, Distance: {} Ly, Estimated Jumps: {}",
range,
d_total,
d_total / range
);
let total = self.tree.size() as f32;
let mut prev = FnvHashMap::default();
let mut prev: FnvHashMap<u32, &System> = FnvHashMap::default();
let mut prune_map: FnvHashMap<u32, (usize, f32)> = FnvHashMap::default();
let mut seen = FnvHashSet::default();
let mut depth = 0;
let mut found = false;
......@@ -847,10 +846,24 @@ impl Router {
};
t_last = Instant::now();
}
if self.prune.is_some() {
let best_dist = if let Some(p_sys) = prev.get(&sys.id) {
dist2(&p_sys.pos, &goal_sys.pos).min(
prune_map
.get(&p_sys.id)
.map(|v| v.1)
.unwrap_or(std::f32::MAX),
)
} else {
dist2(&sys.pos, &goal_sys.pos)
};
prune_map.insert(sys.id, (depth, best_dist));
}
// TODO: check improvement, if too small: continue
queue_next.extend(
self.neighbours(&sys, range)
.filter(|&nb| {
(self.valid(nb, &start_sys, &goal_sys) || (nb.id == goal_sys.id))
(self.valid(nb) || (nb.id == goal_sys.id))
})
.filter(|&nb| seen.insert(nb.id))
.map(|nb| {
......