• Gurobi Staff

Could you please share what you tried so far and try to explain in more detail what you mean by

it but gives strange results by violating the constraints

Best regards,
Jaromił

Hi Jaromił,

Thanks for your response, please see the below formulation, I implemented it on the Gurobi Python API, but It gives an optimal solution with violation in constraints.

Here decision variables are 'x', 'x^k', and 'w' are the free variables, 'y' is binary, and 't' and 'z' have non-negative values to be taken.

The input I use is matrix 'a'.

\epsilon = 1e-4.

The output I got has a violation of one of the constraints,

How to fix this issue?

I use several parameters including FeasibilityTol=1e-6, Presolve=0, and NumericFocus=3 but the violation remains...

Regard, Arslan

Moreover, when given a fixed bound to 'x^k', e.g. -1e6 to 1e6, (26) constraint is violated which absolute value constraint and performs this strange behavior:

t_2_1 should be |xp_2_1| but it gives a strange value, how to fix it?

• Gurobi Staff

How to fix this issue?

A constraint violation of ~2e-11 is nothing to be worried about. Note that Gurobi uses numerical algorithm so it is basically impossible to achieve a 0 violation for models with continuous variables.

There is no fix to this issue. You should rather take the optimal solution point and check whether it is good enough for your application. If not, you could try to polish it yourself, i.e., round some variable values while pertaining feasibility of the model.

Moreover, when given a fixed bound to 'x^k', e.g. -1e6 to 1e6, (26) constraint is violated which absolute value constraint and performs this strange behavior:

This may happen for (absolute value) general constraints, because variable bounds are used to reformulate the absolute value constraints in a MIP fashion. To avoid this, you can do the following in the ordering given

1. You should try tightening the bounds of $$x^k$$ as much as possible.
2. You could try experimenting with the PreSOS1BigM and PreSOS2BigM parameters.
3. You could also try tightening the FeasibilityTol and IntFeasTol parameters to tighten feasibility tolerances.

Note that even with tighter bounds and tolerances, it may be inevitable that a small violation persists, e.g., $$x^p_{21} = -10^{-8}, t_{21} = 2\cdot 10^{-8}$$. As mentioned above, this is unavoidable due to machine precision and the numerical algorithms involved and the best way is to polish the optimal solution point after the optimization process is finished.

Best regards,
Jaromił

Hi Jaromił,

There is no fix to this issue. You should rather take the optimal solution point and check whether it is good enough for your application. If not, you could try to polish it yourself, i.e., round some variable values while pertaining feasibility of the model.

The optimal value is correct but the variable values that are taken for optimal solution by model are not satisfying. Also, how to set the variable precision that is to be taken up to 7 decimal places.

I have to find set zero violations for better results and the results I got have some numerical issues, so how to handle precision and use precise variable values when solving the model?

Thanks, Arslan

• Gurobi Staff

The optimal value is correct but the variable values that are taken for optimal solution by model are not satisfying. Also, how to set the variable precision that is to be taken up to 7 decimal places.

As I pointed out in my previous comment

1. You should try tightening the bounds of as much as possible.
2. You could try experimenting with the PreSOS1BigM and PreSOS2BigM parameters.
3. You could also try tightening the FeasibilityTol and IntFeasTol parameters to tighten feasibility tolerances.

Additionally, you might want to experiment with the NumericFocus and IntegralityFocus parameters.

I have to find set zero violations for better results and the results I got have some numerical issues, so how to handle precision and use precise variable values when solving the model?

This will not be possible as long as your model has continuous variables (unless you get very lucky). The only way is to use the solution point provided by Gurobi and try to manually polish it, i.e., try to perturb some variable values to reduce the violation, while maintaining feasibility and optimality. However, since the violation is so small, I cannot imagine that this is an easy task.

I used the parameters that you mentioned but NO change in the solution, even though I tried tight bounds.

Can I put the bound on the precision of the variable so that it only takes the desired values after the decimal places for solving the model? e.g x= 2.9001000000000015 but if I have to allow this to take only up to 7 decimal places, like x = 2.9001001? can it be possible to set the precision of the variable in Gurobi?

Regards, Arslan

• Gurobi Staff

Hi Arslan,

Can I put the bound on the precision of the variable so that it only takes the desired values after the decimal places for solving the model? e.g x= 2.9001000000000015 but if I have to allow this to take only up to 7 decimal places, like x = 2.9001001? can it be possible to set the precision of the variable in Gurobi?

Unfortunately, it is currently not possible to set individual variable tolerances.

You could try the following:

1. Solve the model and extract the solution point
2. Manually polish the solution point, e.g., round 2.9001000000000015 to 2.9001
3. Collect all constraints that have a too large violation
4. For each violated constraint, fix some of the variables to their polished solution value
5. Re-optimize and check whether constraint violations improved without degrading the optimal solution value
6. Re-iterate with different variables if needed

As already mentioned, there is no good way to reduce constraint violation way below a 1e-10 threshold by just adjusting parameters or tightening bounds. It is in the nature of numerical algorithms that they are inaccurate up to some digits. May I ask why you need a such high precision solution?

You could also try the Quad parameter but I doubt that it will help.

Best regards,
Jaromił

• Gurobi Staff

You could also share the model you generated so I can take a closer look. Note that uploading files in the Community Forum is not possible but we discuss an alternative in Posting to the Community Forum.