Determines the cost of moving from a given node to another given node.