Ejemplo n.º 1
0
 def test_full_left_matching(self):
   g = [("a","b",1),
        ("c","b",2),
        ("y","z",10),
        ("y","zz",100)]
   matches = matching.full_left_match(g)
   self.assertTrue(("a","b") in matches)
   self.assertTrue(("c","b") in matches)
   self.assertTrue(("y","z") in matches)
Ejemplo n.º 2
0
  # -- Greate Graph Data --
  # create a connection from (provider -> recipient) if
  # their food types match and the delivery time from provider
  # to recipient is acceptable.
  G = {}
  for p in providers.values():
    for r in recipients.values():
      (can_deliver, dist) = can_deliver_timely(p, r)
      if has_food_overlap(p, r) and can_deliver and dist <= 15:
        G[(p["id"], r["id"])] = dist

  # convert graph data to flattened list of tuples form
  glist = [(p,r,d) for ((p,r), d) in G.items()]
  # perform matching on graph
  matches = full_left_match(glist)

  ##########################
  # -- generate outputs -- #
  ##########################

  #####################################################
  # Helper functions to create human readable outputs #
  #####################################################
  def bits2food(bs):
    # converts bits in the "foodtype" and "accepts" field
    # to a human readable string.
    ret = []
    for (ind, food) in enumerate(["Raw", "Prepared", "Dairy", "Packaged", "Baked", "Meat"]):
      if (bs & (2**ind)):
        ret.append(food)