Exemple #1
0
def testAngles():
    """
	tests the angle funciton for the roads..
	i.e. remove functions for graph
	"""
    # first, check if removing and adding gives the same result..
    a = (0, 0)
    b = (20, 0)
    c = (20, 20)
    d = (0, 20)
    e = (15, 10)
    nodes = [a, b, c, d, e]
    G = gr.ExtendedGraph(areaPoly=[(-5, -5), (50, -5), (50, 50), (-5, 50)])
    G.add_nodes_from(nodes)
    edges = [(a, b), (b, c), (c, d), (d, a), (a, e), (b, e), (c, e), (d, e)]
    G.add_edges_from(edges)
    a = G.areaCover
    assert abs(a - go.roadAreaCoverage(G)) < 1e-8
    G.remove_edges_from(edges)
    assert abs(G.areaCover - 0) < 1e-8
    for e in edges:
        G.add_edge(e[0], e[1])
    for i in range(200):  # many times
        for e in edges:
            G.remove_edge(e[0], e[1])
        for e in edges:
            G.add_edge(e[0], e[1])
    assert R.areaCover == a
    print "you passed the test.."
    G.draw(overlap=True)
Exemple #2
0
	def __init__(self, origin=None, globalOrigin=None,areaPoly=None, gridtype=None):
		if not areaPoly:
			raise Exception('areaPoly must be given.')
		if not origin:
			origin=(0,0)
		if not globalOrigin:
			globalOrigin=(596120, 6727530) #sweref99..located on map.. nice position.. use as default.
		self.areaPoly=areaPoly
		xmin,xmax,ymin,ymax=fun.polygonLim(areaPoly)
		side=10
		self.lim=np.array([xmin-0.5*side,xmax+0.5*side, ymin-0.5*side, ymax+0.5*side])
		self.A=fun.polygon_area(areaPoly)
		self.Ainv=1./self.A #used a lot.. faster to just compute this once.
		self.origin=origin
		self.globalOrigin=globalOrigin
		self.type=gridtype
		x,y,z=GIS.readTerrain(globalOrigin=globalOrigin , areaPoly=areaPoly)
		#get a list of how x and y varies.. strictly ascending
		xlist=x[:,0] #just the variations, not the 2D-matrix
		ylist=y[0,:]
		self.interpol=RectBivariateSpline(xlist, ylist, z) #used pretty much everytime we need the height of a specific point. Implemented in fortran and very fast

		nx.Graph.__init__(self)
		self.t_x=x
		self.t_y=y
		self.t_z=z
		self.roadWidth=4 #width of road
		self.overlap={} #will later be filled. A speedup thing
		self.weightFunction=normalizedPitchDist #reference to exter
		self.areaCover=go.roadAreaCoverage(self)
		self.moviefig=None #may be used for movies later
		self.cmdfolder=os.path.split(os.path.dirname(os.path.abspath(__file__)))[0]
Exemple #3
0
def findBugs(algList):
    """
	algorithms is a list of algorithms that should be tested
	"""
    while True:
        seed = int(random.uniform(0, 1000000))
        print "seed:", seed
        random.seed(seed)
        alg = random.choice(algList)
        print "chosen algorithm:", alg
        dx = random.uniform(-700, 700)
        globalOrigin = 596250 + dx, 6727996
        areaPoly = list(random.uniform(2, 3) * np.array([(0, 0), (48, 0), (73, 105), (0, 96)]))
        for i in range(len(areaPoly)):
            areaPoly[i] = tuple(areaPoly[i])
        R = gr.SqGridGraph(areaPoly=areaPoly, globalOrigin=globalOrigin)
        R = alg(R, aCap=0.2, anim=False)
    print "road area coverage:", go.roadAreaCoverage(R)
    print "internal evaluation of above:", R.areaCover
    print "total area:", fun.polygon_area(areaPoly)
    print "used total area:", R.A, R.Ainv
    print "total cost:", cf.totalCost(R)
Exemple #4
0
def tmp(areaPoly=None):
    globalOrigin = 596250, 6727996
    R = gr.SqGridGraph(areaPoly=areaPoly, globalOrigin=globalOrigin)
    simplified_bruteForce(R, aCap=0.2, anim=False)
    c = None
    for i in range(5):
        Rt = copy.deepcopy(R)
        Rt = simplified_bruteForce(Rt, aCap=0.2, anim=False)
        if c:
            assert c == Rt.cost
        c = Rt.cost

    R = simplified_bruteForce(R, aCap=0.2, anim=False)
    # R=stochastic(R,aCap=0.2)
    fig = plt.figure()
    ax = fig.add_subplot(111, aspect="equal")
    R.draw(ax)

    print "road area coverage:", go.roadAreaCoverage(R)
    print "internal evaluation of above:", R.areaCover
    print "total area:", fun.polygon_area(areaPoly)
    print "used total area:", R.A, R.Ainv
    print "total cost:", cf.totalCost(R)