Ejemplo n.º 1
0
  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)
Ejemplo n.º 2
0
 def con_ctm(self):
   return list(flatten([geq(link.v_flow, 0),
                        leq(link.v_flow, link.fd.q_max),
                        leq(link.v_flow, link.fd.v * link.v_dens),
                        leq(link.v_flow, link.fd.w * (link.fd.rho_max - link.v_dens)),
                        geq(link.v_dens, 0),
                        leq(link.v_dens, link.fd.rho_max),
                        ] for link in self.get_links()))
Ejemplo n.º 3
0
 def con_capacity(self):
   return list(
     flatten(
       [
         geq(link.v_flow, 0.0),
         leq(link.v_flow, link.q_max)
       ]
       for link in self.get_links()
     )
   )
Ejemplo n.º 4
0
 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
Ejemplo n.º 5
0
 def check_feasible_constraints(self):
   return list(flatten(
     [geq(link.v_flow, link.flow), geq(link.v_dens, link.rho),leq(link.v_flow, link.flow), leq(link.v_dens, link.rho)]
       for link in self.get_links()
   ))