Calculates the cost of traveling between two locations. The cost should be positive and non-negative.