solving optimization problem