text
stringlengths
0
828
4475,"def CreateVertices(self, points):
""""""
Returns a dictionary object with keys that are 2tuples
represnting a point.
""""""
gr = digraph()
for z, x, Q in points:
node = (z, x, Q)
gr.add_nodes([node])
return gr"
4476,"def CreateDirectedEdges(self, points, gr, layer_width):
""""""
Take each key (ie. point) in the graph and for that point
create an edge to every point downstream of it where the weight
of the edge is the tuple (distance, angle)
""""""
for z0, x0, Q0 in points:
for z1, x1, Q1 in points:
dz = z1 - z0 # no fabs because we check arrow direction
if dz > 0.0: # make sure arrow in right direction
if dz - layer_width < distance_threshold: # only adjacents
dx = math.fabs(x1 - x0)
if dx > 5 * bar_width:
continue
# Weights are negative to in order to use shortest path
# algorithms on the graph.
weight = -1 * math.hypot(dz, dx)
edge = ((z0, x0, Q0), (z1, x1, Q1))
gr.add_edge(edge, wt=weight)
# Ensure that it is already transitively reduced
assert len(critical.transitive_edges(gr)) == 0
return gr"
4477,"def GetFarthestNode(self, gr, node):
""""""node is start node""""""
# Remember: weights are negative
distance = minmax.shortest_path_bellman_ford(gr, node)[1]
# Find the farthest node, which is end of track
min_key = None
for key, value in distance.iteritems():
if min_key is None or value < distance[min_key]:
min_key = key
return min_key"
4478,"def on_success(self, fn, *args, **kwargs):
""""""
Call the given callback if or when the connected deferred succeeds.
""""""
self._callbacks.append((fn, args, kwargs))
result = self._resulted_in
if result is not _NOTHING_YET:
self._succeed(result=result)"
4479,"def _succeed(self, result):
""""""
Fire the success chain.
""""""
for fn, args, kwargs in self._callbacks:
fn(result, *args, **kwargs)
self._resulted_in = result"
4480,"def random_name(num_surnames=2):
""""""
Returns a random person name
Arguments:
num_surnames -- number of surnames
""""""
a = []
# Prefix
if random.random() < _PROB_PREF:
a.append(_prefixes[random.randint(0, len(_prefixes) - 1)])
# Forename
a.append(_forenames[random.randint(0, len(_forenames) - 1)])
# Surnames
for i in range(num_surnames):
a.append(_surnames[random.randint(0, len(_surnames) - 1)])
# Suffix
if random.random() < _PROB_SUFF:
a.append(_suffixes[random.randint(0, len(_suffixes) - 1)])
return "" "".join(a)"
4481,"def create_free_shipping_coupon(cls, free_shipping_coupon, **kwargs):
""""""Create FreeShippingCoupon