chore: Setup tox+appveyor, refomat python code, prepare rust code to add branch pruning to search
This commit is contained in:
parent
865889712e
commit
2636ecbdb9
35 changed files with 1245 additions and 926 deletions
BIN
icon/icon.ico
Normal file
BIN
icon/icon.ico
Normal file
Binary file not shown.
After Width: | Height: | Size: 368 KiB |
115
icon/make.py
Normal file
115
icon/make.py
Normal file
|
@ -0,0 +1,115 @@
|
|||
import svgwrite
|
||||
import random
|
||||
import time
|
||||
from math import factorial
|
||||
from itertools import permutations
|
||||
import tsp as m_tsp
|
||||
|
||||
def dist(p1,p2):
|
||||
return dist2(p1,p2)**0.5
|
||||
|
||||
|
||||
def dist2(p1,p2):
|
||||
diff=0
|
||||
for a,b in zip(p1,p2):
|
||||
diff+=(a-b)**2
|
||||
return diff
|
||||
|
||||
|
||||
def tsp(points):
|
||||
res=[]
|
||||
for idx in m_tsp.tsp(points)[1]:
|
||||
res.append(points[idx])
|
||||
return res
|
||||
|
||||
|
||||
def make_points(n,size,min_dist=0):
|
||||
min_dist*=min_dist
|
||||
points=[]
|
||||
while len(points)<n:
|
||||
px,py=random.random(),random.random()
|
||||
px*=size/2
|
||||
py*=size/2
|
||||
px+=70
|
||||
py+=70
|
||||
valid=True
|
||||
for p in points:
|
||||
if dist2(p,(px,py))<min_dist:
|
||||
valid=False
|
||||
break
|
||||
if valid:
|
||||
points.append((px,py))
|
||||
print("{}/{}".format(len(points),n))
|
||||
return points
|
||||
def generate(seed,name=None,small=False):
|
||||
sd=1
|
||||
if small:
|
||||
sd=2
|
||||
random.seed(seed)
|
||||
w=2
|
||||
max_rings=3
|
||||
num_points=10
|
||||
min_dist=10+10+20*(max_rings+1)
|
||||
base_r=10
|
||||
ring_step=lambda v:10+v*10
|
||||
size=1000
|
||||
if name is None:
|
||||
name=seed
|
||||
dwg=svgwrite.Drawing(filename="out/{}.svg".format(name))
|
||||
dwg.defs.add(dwg.style(".background { fill: #222; }"))
|
||||
dwg.add(dwg.rect(size=('100%','100%'), class_='background'))
|
||||
print("Generating points...")
|
||||
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
|
||||
x2/=sd
|
||||
y1/=sd
|
||||
y2/=sd
|
||||
line=dwg.add(dwg.line((x1,y1),(x2,y2),stroke_width=w,stroke=color))
|
||||
|
||||
for (px,py) in pos:
|
||||
base_r=3
|
||||
if small:
|
||||
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:
|
||||
dwg.add(dwg.circle((px,py),r=base_r+random.random()*base_r,stroke_width=w,stroke=color)).fill(color)
|
||||
r=base_r
|
||||
for _ in range(random.randint(1,max_rings)):
|
||||
if small:
|
||||
random.random()
|
||||
random.random()
|
||||
continue
|
||||
r+=ring_step(random.random())
|
||||
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))
|
||||
circ.fill(color,opacity=0)
|
||||
|
||||
dwg.save()
|
||||
|
||||
|
||||
|
||||
seed=0
|
||||
generate(seed,"icon_1",small=False)
|
||||
generate(seed,"icon_1_small",small=True)
|
2
icon/out/icon_1.svg
Normal file
2
icon/out/icon_1.svg
Normal file
File diff suppressed because one or more lines are too long
After Width: | Height: | Size: 5.8 KiB |
2
icon/out/icon_1_small.svg
Normal file
2
icon/out/icon_1_small.svg
Normal file
|
@ -0,0 +1,2 @@
|
|||
<?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>
|
After Width: | Height: | Size: 2.8 KiB |
Loading…
Add table
Add a link
Reference in a new issue