function to calulate the cost of the solution has been added