code: def path(edges, source, sink, flavor="longest"):
      
      outgoing, incoming, nodes = node_to_edge(edges)
  
      nedges = len(edges)
      L = LPInstance()
  
      assert flavor in ("longest", "shortest")
  
      objective = MAXIMIZE if flavor == "longest" else MINIMIZE
      L.add_objective(edges, objective=objective)
  
      # Balancing constraint, incoming edges equal to outgoing edges except
      # source and sink
  
      constraints = []
      for v in nodes:
          incoming_edges = incoming[v]
          outgoing_edges = outgoing[v]
          icc = summation(incoming_edges)
          occ = summation(outgoing_edges)
  
          if v == source:
              if not outgoing_edges:
                  return None
              constraints.append("{0} = 1".format(occ))
          elif v == sink:
              if not incoming_edges:
                  return None
              constraints.append("{0} = 1".format(icc))
          else:
              # Balancing
              constraints.append("{0}{1} = 0".format(icc, occ.replace('+', '-')))
              # Simple path
              if incoming_edges:
                  constraints.append("{0} <= 1".format(icc))
              if outgoing_edges:
                  constraints.append("{0} <= 1".format(occ))
  
      L.constraints = constraints
      L.add_vars(nedges)
  
      selected, obj_val = L.lpsolve()
      results = sorted(x for i, x in enumerate(edges) if i in selected) \
          if selected else None
      results = edges_to_path(results)
  
      return results, obj_val
docs: Calculates shortest/longest path from list of edges in a graph
  
      >>> g = [(1,2,1),(2,3,9),(2,4,3),(2,5,2),(3,6,8),(4,6,10),(4,7,4)]
      >>> g += [(6,8,7),(7,9,5),(8,9,6),(9,10,11)]
      >>> path(g, 1, 8, flavor="shortest")
      ([1, 2, 4, 6, 8], 21)
      >>> path(g, 1, 8, flavor="longest")
      ([1, 2, 3, 6, 8], 25)