def d3ize(self): from simplejson import dump edges = self.d3_edges() lkup = list(set(flatten([edge.d3_source(), edge.d3_target()] for edge in edges))) nodes = [ { 'name': node.d3_node_name() } for node in lkup ] edges = [ { 'source': lkup.index(edge.d3_source()), 'target': lkup.index(edge.d3_target()), 'attrs': edge.d3_attrs(), 'value': edge.d3_value() } for edge in edges ] data = { 'nodes': nodes, 'links': edges } with open('{0}/html/graph.json'.format(root_dir),'w') as fn: dump(data, fn, indent=2)
def con_ctm(self): return list(flatten([self.cr_geq(link.v_flow, 0), self.cr_leq(link.v_flow, link.fd.q_max), self.cr_leq(link.v_flow, link.fd.v * link.v_dens), self.cr_leq(link.v_flow, link.fd.w * (link.fd.rho_max - link.v_dens)), self.cr_geq(link.v_dens, 0), self.cr_leq(link.v_dens, link.fd.rho_max), ] for link in self.get_links()))
def check_feasible_constraints(): return list(flatten( [self.cr_geq(link.v_flow, link.state.flow), self.cr_geq(link.v_dens, link.state.density), self.cr_leq(link.v_flow, link.state.flow), self.cr_leq(link.v_dens, link.state.density)] for link in self.get_links() ))
def con_capacity(self): return list( flatten( [ self.cr_geq(link.v_flow, 0.0), self.cr_leq(link.v_flow, link.q_max) ] for link in self.get_links() ) )
def cache_props(self): """docstring for cache_props""" if not self.CACHE: return self.clear() [self.edgify(link) for link in self.links] self.sources = self._sources() self.sinks = self._sinks() self.junctions = set(flatten([link.up_junc, link.down_junc] for link in self.get_links())) self.od_routes = self.calc_od_routes() self.CACHE = False