## Choosing heuristic for A* algorithm where cost is less than absolute distance

Looking for information on choosing a heuristic for instances where the cost of traversing an edge can be less than one.

For example, say movement is allowed in the cardinal directions. Should all edge costs be at least one, then I would consider diagonal distance. However, if costs can be less than one, this could lead to an instance where diagonal distance will be an overestimate and thus is not an admissible heuristic.

My thought on the matter is perhaps to find the smallest possible cost and figure out a constant to divide diagonal distance by to guarantee it will never overestimate?

Would appreciate some guidance or some resources to look further into this.

## I am looking for VPS (low cost) in Israel

Hi,

I am looking for low cost VPS in Israel. Any lead?… | Read the rest of http://www.webhostingtalk.com/showthread.php?t=1748436&goto=newpost

## Why is the cost of film going up?

Two years ago 25 sheets of Ilford Delta 100 4×5 B&W cost just over \$ 25. My last purchase last fall it was ~\$ 35. Now it’s \$ 46. That’s a steep rise! What’s driving these rising film prices and can we expect them to drop again some day?

## Low cost server to buy for hosting a blog

I am looking for a low cost server to buy for hosting a blog and there are two hosts which are to my liking: kvchosting.net and hostsailor.com, so what should I do?

## Algorithm to simplify 2D convex hull at the cost of extra area

Are there any algorithms related to the following problem that could be usefull for solving it?

I have a convex hull built on some point set. I would like to simplify it (reduce number of points) by still keeping its perimiter (or area) as small as possible. New simplified polygon should not intersect the original hull.

The basic idea I am trying to implement is to calculate for each point of a polygon perimeter added by removal of this point. And then remove the cheapest point (which removal adds minimum value to the perimiter).

So we keep iterating and removing points while added perimiter or area value is suitable and passes some creteria.

Here comes the problem:

When removing point p1 we introduce a new edge formed by previous point p0 and the next point p2. This new edge can be non-optimal or invalid (intersecting the original hull). So I would like to adjust points p0 and p2 along their edges to keep perimeter valid and small as possible.

How can I find these adjusted positions of p0 and p2 ?

## Low Cost Unlimited Dedicated Servers – Budget Dedicated Servers – Hostpoco.com!

Hostpoco was formed to offer premium quality hosting services at affordable prices. Our dedicated server lineup offers unparalleled performance at the lowest prices in the market! Our Unmanaged Dedicated Servers are perfect for any size business. High performance, fully redundant and reliable Singapore based servers to meet and exceed your business needs.

If you need full authority and extensive control over your business environment and business sites then Dedicated servers is the most…

Low Cost Unlimited Dedicated Servers – Budget Dedicated Servers – Hostpoco.com!

## Algorithm to fit nodes in a graph minimizing the cost function

There are N nodes, where each node represents a person:

• name
• age
• # of parents
• # of children
• # of siblings
• # of spouses

The task is to fit all these nodes into families by minimizing the number of unfulfilled connections and the number of families.

My current thinking is to construct all possible graphs and then find the one where cost function is minimal. However the computational complexity is O(N!) in the worst case.

I believe it should be possible to cut off the whole branches of possible solutions by noticing early that they either will repeat already computed or are guaranteed to be worse.

Is there an algorithm (or algorithmic framework) that could assist in bringing the number of

## Iterate over the solutions for minimum cost matching

I implemented this paper, more specifically the bipartite graph case in numpy.

The whole code is available on github.

The file `munkres.py` comes from scipy.

Some variables seem poorly named but they respect the definitions of the paper.

I pasted the main file below. If you want to read it with line numbers and syntax coloring, it is also on github.

``__all__ = ["cost_matrix_without_inf", "linear_sum_assignment_iter"]  from heapq import heappush, heappop import numpy as np  from .munkres import linear_sum_assignment   def cost_matrix_without_inf(cost_matrix):     """     Replaces inf with a value that yield the same assignment.     inf means that an edge should not be used.     """     cost_matrix = np.asarray(cost_matrix).copy()     if not np.issubdtype(cost_matrix.dtype, np.floating):         return cost_matrix     if np.isneginf(cost_matrix).any():         raise ValueError("matrix contains -inf")      values = cost_matrix[~np.isinf(cost_matrix)]     m = values.min()     M = values.max()     n = min(cost_matrix.shape)     # strictly positive constant even when added     # to elements of the cost matrix     positive = n * (M - m + np.abs(M) + np.abs(m) + 1)     place_holder = (M + (n - 1) * (M - m)) + positive     cost_matrix[np.isposinf(cost_matrix)] = place_holder     return cost_matrix   def _coords_to_index(x):     if not x:         return np.array([], dtype=int), np.array([], dtype=int)     a, b = zip(*x)     return np.array(a), np.array(b)   def _index_to_coords(x):     return list(zip(*x))   def _second_best_assignment(cost_matrix, M, I, O):     """Returns the second best solution to the assignment problem     defined by ``cost_matrix`` with the constraints:      - all edges from ``I`` must be used     - the edges from ``O`` are forbidden      ``M`` is the best solution to this problem.      If the solution does not exist, returns None     """     cost_matrix = cost_matrix.copy()      # select a boolean mask to discard the     # rows and columns of already chosed assignments     select = np.ones_like(cost_matrix, dtype=bool)     i1, i2 = _coords_to_index(I)     select[i1, :] = False     select[:, i2] = False      # put an infinite weight to forbidden edges     cost_matrix[_coords_to_index(O)] = np.inf      # the theorem only works for perfect matchings     n, m = cost_matrix.shape     assert n == m      # build the graph     distance = np.tile(np.inf, (2 * n, 2 * n))     distance[:n, n:][select] = cost_matrix[select]     distance[M[0], n + M[1]] = np.inf     distance[n + M[1], M[0]] = np.where(         np.isposinf(cost_matrix[M]), cost_matrix[M], -cost_matrix[M]     )     backtrack = np.tile(np.arange(2 * n), (2 * n, 1))      # Floyd–Warshall algorithm     for k in range(2 * n):         for i in range(2 * n):             for j in range(2 * n):                 if distance[i, k] + distance[k, j] < distance[i, j]:                     distance[i, j] = distance[i, k] + distance[k, j]                     backtrack[i, j] = backtrack[i, k]      # restricting to the first n values should not be necessary     # but not doing it can fail some tests like this one:     # list(     #     linear_sum_assignment_iter(     #         [     #             [-319.77581059, -426.02257358, 129.91680618],     #             [201.86064154, float("inf"), 483.324417],     #             [434.94794501, -324.91883433, 204.60857852],     #         ]     #     )     # )      # no solution is possible     if np.isposinf(np.diagonal(distance)[:n].min()):         return      # compute the symetric difference of M and the cycle     matching = set(_index_to_coords(M))     target = np.diagonal(distance)[:n].argmin()     next_vertex = lambda i: backtrack[i, target]     i, j = target, next_vertex(target)     while True:         matching.add((i, j - n))         i, j = j, next_vertex(j)         matching.remove((j, i - n))         if j == target:             break         i, j = j, next_vertex(j)      return _coords_to_index(sorted(matching))   def _choose_in_difference(M, N):     return next(         eM for (eM, eN) in zip(_index_to_coords(M), _index_to_coords(N)) if eM != eN     )   def linear_sum_assignment_iter(cost_matrix: np.ndarray):     """Iterate over the solutions to the linear sum assignment problem     in increasing order of cost      The method used for the first solution is the Hungarian algorithm,     also known as the Munkres or Kuhn-Munkres algorithm.      The method used to find the second best solution and iterate over     the solutions is described in [1]_, but is implemented in a slightly     different, Dijkstra-like way. The states are represented as      .. math: (cost(N_k), r, M_k, N_k, I_k, O_k)      with :math:``r`` a random number used to avoid comparing the assignments.      This function can also solve a generalization of the classic assignment     problem where the cost matrix is rectangular. If it has more rows than     columns, then not every row needs to be assigned to a column, and vice     versa.     It supports infinite weights to represent edges that must never be     used.      Parameters     ----------     cost_matrix : array         The cost matrix of the bipartite graph.      Yields     -------     row_ind, col_ind : array         An array of row indices and one of corresponding column indices giving         the optimal assignment. The cost of the assignment can be computed         as ``cost_matrix[row_ind, col_ind].sum()``. The row indices will be         sorted; in the case of a square cost matrix they will be equal to         ``numpy.arange(cost_matrix.shape[0])``.      Examples     --------     >>> cost = np.array([[4, 1, 3], [2, 0, float("inf")], [3, 2, 2]])     >>> from matchmaker import linear_sum_assignment_iter     >>> it = linear_sum_assignment_iter(cost)     >>> row_ind, col_ind = next(it)     >>> col_ind     array([1, 0, 2])     >>> cost[row_ind, col_ind].sum()     5.0     >>> row_ind, col_ind = next(it)     >>> col_ind     array([0, 1, 2])     >>> cost[row_ind, col_ind].sum()     6.0      References     ----------      .. [1] Chegireddy, Chandra R., and Horst W. Hamacher. "Algorithms for finding     k-best perfect matchings." Discrete applied mathematics 18, no. 2     (1987): 155-165.      """     cost_matrix = np.asarray(cost_matrix)      # make the cost_matrix square as the algorithm only works     # for perfect matchings     # any value other than 0 would work     # see <https://cstheory.stackexchange.com/a/42168/43172>     n, m = cost_matrix.shape     if n < m:         cost_matrix = np.concatenate(             (cost_matrix, np.zeros((m - n, m), dtype=cost_matrix.dtype)), axis=0         )     elif n > m:         cost_matrix = np.concatenate(             (cost_matrix, np.zeros((n, n - m), dtype=cost_matrix.dtype)), axis=1         )      def transform(a, b):         """transforms a solution assignment (a, b)         back to the original matrix         """         mask = (a < n) & (b < m)         return a[mask], b[mask]      cost = lambda assignment: cost_matrix[assignment].sum()      # linear_sum_assignment doesn't require the matrix to be square,     # but second_best_assignment needs the best solution for a square matrix     M1 = linear_sum_assignment(cost_matrix_without_inf(cost_matrix))     if not np.isposinf(cost(M1)):         yield transform(*M1)     else:         return      # from now, use a copy of cost_matrix     # with dtype float     cost_matrix = cost_matrix.astype(float)      I1 = []     O1 = []     N1 = _second_best_assignment(cost_matrix, M1, I1, O1)     if N1 is None:         return     Q = [(cost(N1), np.random.rand(), M1, N1, I1, O1)]     while Q:         _, _, M, N, I, O = heappop(Q)         yield transform(*N)          e = _choose_in_difference(M, N)          Ip, Op = I + [e], O         Np = _second_best_assignment(cost_matrix, M, Ip, Op)         if Np is not None:             heappush(Q, (cost(Np), np.random.rand(), M, Np, Ip, Op))          Ik, Ok = I, O + [e]         Nk = _second_best_assignment(cost_matrix, N, Ik, Ok)         if Nk is not None:             heappush(Q, (cost(Nk), np.random.rand(), N, Nk, Ik, Ok)) ``

## Having difficulty understanding how to find the maximum volume with cost constraint.

We have $$1000 to buy the materials to build a box whose base length is seven times the base width and has no top. If the material for the sides cost$$10/cm2 and the material for the bottom cost \$ 15/cm2 determine the dimensions of the box that will maximize the enclosed volume.

## find all paths from source to destinations and then calculate the path with minimum cost

I am trying to solve one problem. Please refer complete problem statement before proceeding.

You are given a road network, with N cities and M bi-directional roads. Each road has some positive amount of tax associated to it,meaning if there is a road connecting cities A and B with tax C, you will need to pay C rupees to the government every time when you use this road.

but you have a wildcard which can be used at most K times and when you use wildcard while using a road, you do not need to pay tax associated with the road.

You are planning to visit one city this weekend, due to limited budged you want to estimate minimum passible cost from you home-city to every other city, so that you can choose the destination according to the budget, your home-city is a city numbered with 1.

For solving above problem I am Following this approach. Step 1) Calculate all the path between vertices u,v. Step 2) For a Path p=[i-j-k-l] do following

``   for(int i=0;i<k;i++){            int weight=findEdgeWithMaxWeight(p);      cost of path p=cost of path-weight;     } ``

I am repeating this step2 for all the paths for u,v and at last I am choosing the path with minimum weight. As my answer.

Consider following diagram to visualize my approach.

But problem with above approach is that I am have to calulate all the path between u,v to get the answer. Is there any way to get the optimal path with out calculating all the paths?

Edit: Hope Problem is bit clearer now.