fix cost_from_cost_matrix