def roads_bipartite_match(): data = {key: value for key, value in request.args.iteritems()} query_json = data['query'] query = json.loads(query_json) inst = roadbm_json.RoadMatchInstance.from_json(query) S = inst.source_points() T = inst.target_points() roadmap = inst.get_roadmap() match = bm.ROADSBIPARTITEMATCH(S, T, roadmap) return jsonify(match)
def euclidean_roads_bipartite_match_svg(): data = {key: value for key, value in request.args.iteritems()} query_json = data['query'] query = json.loads(query_json) width = int(data.get('width')) height = int(data.get('height')) inst = roadbm_json.RoadMatchInstanceEuclidean.from_json(query) S = inst.source_points() T = inst.target_points() roadmap = inst.get_roadmap() layout = inst.get_layout() layout = {u: np.array(p) for u, p in layout.iteritems()} roadmap_ = euclidean_roadmap.euclidean_roadmap(roadmap, layout) match = bm.ROADSBIPARTITEMATCH(S, T, roadmap_) print roadmap_.edge interval_graph, layout_ = matchvis_util.INTERVAL_GRAPH( match, S, T, roadmap_, layout) print layout_ # turn it into an SVG! if False: graph_repr = [ '%s -> %s' % (repr(u), repr(v)) for u, v in interval_graph.edges_iter() ] other_pos_repr = {repr(u): repr(p) for u, p in layout_.iteritems()} return jsonify((graph_repr, other_pos_repr)) else: return draw_interval_graph(interval_graph, layout_, roadmap, layout, width, height)
('road 8', .05), ('road 10', .05), ] TT = [ ('road 6', .1), ('road 6', .15), ('road 8', .1), ('road 10', .1), ('road 10', .15), ('road 12', .1), ('road 13', .1), ] """ obtain the optimal matching """ import setiptah.roadbm.bm as roadbm opt_match = roadbm.ROADSBIPARTITEMATCH(SS, TT, roadmap) """ obtain an interval graph from the matching """ I_graph, I_pos = matchvis_util.INTERVAL_GRAPH(opt_match, SS, TT, roadmap, pos) # sometimes, there's still a cycle? """ make tikz animation """ def writeslide(k, mystr): f = open('slides/slide%d.tex' % k, 'w') f.write(mystr) f.close() f = open('slides/construction_animation.tex', 'w') SANITIZE(I_graph) INITIALIZE_BAGS(I_graph) match = []
roadnet.add_edge(1, 2, 'E', length=1.) roadnet.add_edge(2, 3, 'S', length=1.) roadnet.add_edge(3, 0, 'W', length=1.) sampler = roadbm.UniformDist(roadnet) Nmin, Nmax = 10, 10000 N = [int(n) for n in np.logspace(np.log10(Nmin), np.log10(Nmax), 10)] trials = 5 nt = [] cost = [] for n, t in itertools.product(N, range(trials)): PP = [sampler.sample() for i in xrange(n)] QQ = [sampler.sample() for i in xrange(n)] match = roadbm.ROADSBIPARTITEMATCH(PP, QQ, roadnet) #costs = MATCHCOSTS( match, PP, QQ, roadnet ) c = roadbm.ROADMATCHCOST(match, PP, QQ, roadnet) nt.append(n) cost.append(c) basis = [lambda n: n, lambda n: np.power(n, .5)] [alpha, kappa] = fit(nt, cost, basis) plt.scatter(nt, cost) interp = np.array([alpha * basis[0](n) + kappa * basis[1](n) for n in N]) plt.plot(N, interp, '--') plt.show()