# AMPL Gurobi Define Variables Bounds

I am trying to define both upper and lower bounds for a vector of variables in AMPL (solver Gurobi). However, after solving to optimal solution, the variables violate the bounds. The only way these bounds work is defined as explicit constraint in AMPL through the 'subject to' clause. Any idea why AMPL doesn't accept the bounds defined in the first way? Thanks.

The first way:

var pi{t in 1..T} >= lb_pi[t] <= ub_pi[t];


The explicit way:

subject to C_pi_low{t in 1..T}:
pi[t] >= lb_pi[t];

subject to C_pi_up{t in 1..T}:
pi[t] <= ub_pi[t];

• The first way looks correct to me. What happens if you execute expand pi;? – RobPratt Dec 31 '20 at 5:38
• Missing comma between the bounds? – Erwin Kalvelagen Dec 31 '20 at 19:51

## 2 Answers

I am going to answer my own question. After I made the post, I realized the variable pi actually don't show up in the model though declared. It looks like this is the reason why the first way doesn't take effective in the 'solve' process while the second explicit way works.

• After presolve, these two formulations should result in the same variables with the same bounds being sent to the solver. It's very likely that there is a simple explanation for why you're getting a wrong solution with the first formulation, but it's not possible to find the explanation given only the information provided. In this situation, I recommend providing complete model and data files, so that pi's definition can be seen in context. – 4er Jan 15 at 14:17

According to section 14-1 of AMPL book:

For continuous variables, normally AMPL passes to solvers the first set of bounds, but you can instruct it to pass the second set by changing option var_bounds to 2 from its default value of 1. When active-set methods (like the simplex method) are applied, the second set tends to give rise to more degenerate variables, and hence more degenerate iterations that may impede progress toward a solution.

• I don't think this quote about original versus presolved bounds is relevant to the question. The variables should respect the lower and upper bounds whether they are specified in the VAR statement or via explicit constraints. – RobPratt Dec 31 '20 at 17:21
• Thanks @RobPratt but I think this is a way to define both upper and lower bounds for the variables if I understood the question correctly. – Oguz Toragay Dec 31 '20 at 17:27