def h4(solution, option): """ Combined weight of shortest path between supply and node * demand of node """ s = solution.step(option) v = s.vertices e = s.edges c = s.decisions #XXX generalize to many supplies [cc.clear() for cc in c] e_mst = mst(v, e) paths = dijkstra(v, e_mst, s.supplies[0]) result = sum([v[i].demand * paths[i] for i in range(len(v))]) [cc.restore() for cc in c] return result
def h2(solution, option): """ Measures unmet demand for each node, weighted by the minimum possible path weight to that node """ s = solution.step(option) v = s.vertices e = s.edges c = set(s.decisions) [cc.clear() for cc in c] #XXX generalize to many supplies paths = dijkstra(v, e, s.supplies[0]) result = sum([paths[i] * v[i].demand for i in range(len(v))]) [cc.restore() for cc in c] return result