Use of measurements for enforcing the necessary conditions of optimality in the presence of constraints and uncertainty