add a function 'replaceCost' to the NonlinearProgramWConstraint, so that it can replace a given cost with the new one