# Gurobi and Highs solver helpppp

**URL:** https://discuss.ampl.com/t/gurobi-and-highs-solver-helpppp/1079
**Category:** Support
**Tags:** solvers
**Created:** [April 29, 2024, 6:08pm UTC](https://discuss.ampl.com/t/gurobi-and-highs-solver-helpppp/1079 "2024-04-29T18:08:46Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![Firdevs\_Uykun](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.ampl.com/firdevs_uykun/32/528_2.png) [@Firdevs\_Uykun](https://discuss.ampl.com/u/Firdevs_Uykun)
#### Post date: [April 29, 2024, 6:08pm UTC](https://discuss.ampl.com/t/gurobi-and-highs-solver-helpppp/1079/1 "2024-04-29T18:08:46Z")

</div>

Hi,I build optimizations and solve with these solvers but In my optimization problem there is no randomness.I set up two different optimization problems they are used separately.I realize every time I rerun the python(close my computer and open and run) they solve different objectives,but in the same python opening window if I rerun they give same solution means no randomness in that opening.I couldn’t understand.

---

<div class="post-metadata">

### Author: ![marcos](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.ampl.com/marcos/32/154_2.png) [@marcos](https://discuss.ampl.com/u/marcos)
#### Post date: [April 29, 2024, 11:01pm UTC](https://discuss.ampl.com/t/gurobi-and-highs-solver-helpppp/1079/2 "2024-04-29T23:01:31Z")

</div>

Hi,

Gurobi and Highs are MIP solvers, so they are able to solve mixed-integer linear problems, which are convex, so you should expect them to find the optimal solution (and the optimal value is unique).

You can also run the `expand;` command in ampl to [see](https://ampl.com/wp-content/uploads/Chapter-12-Display-Commands-AMPL-Book.pdf) the model. Is it the same model in both problems?

If you are changing the data and you still get the same solution, it might be due to that data not affecting the solution. Maybe we could help if you give some more detail about how do you load data into your optimization problem.

---

<div class="post-metadata">

### Author: ![Firdevs\_Uykun](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.ampl.com/firdevs_uykun/32/528_2.png) [@Firdevs\_Uykun](https://discuss.ampl.com/u/Firdevs_Uykun)
#### Post date: [April 30, 2024, 5:26am UTC](https://discuss.ampl.com/t/gurobi-and-highs-solver-helpppp/1079/3 "2024-04-30T05:26:30Z")

</div>

I used Gurobi for quadratic optimization and Highs for linear optimization,gurobi for mean variance portfolio optimization and highs for mean-CVaR optimization problems.I used same data for both only issue is when I close my computer and open jupyter again solvers give me different objective values so results are also different like  
HiGHS 1.6.0:HiGHS 1.6.0: optimal solution; objective -0.07161774363  
162 simplex iterations  
0 barrier iterations

My return:0.0015850270437580668

HiGHS 1.6.0:HiGHS 1.6.0: optimal solution; objective -0.07161778293  
162 simplex iterations  
0 barrier iterations

My return: 0.00158591030001598  
For Highs, can I control randomness, my data is the matrix format,pandas, stock values data.  
For example,I read that gurobi is deterministic, but no, I have a similar issue.

---

<div class="post-metadata">

### Author: ![Firdevs\_Uykun](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.ampl.com/firdevs_uykun/32/528_2.png) [@Firdevs\_Uykun](https://discuss.ampl.com/u/Firdevs_Uykun)
#### Post date: [April 30, 2024, 5:47am UTC](https://discuss.ampl.com/t/gurobi-and-highs-solver-helpppp/1079/4 "2024-04-30T05:47:26Z")

</div>

I guess it is related with tolerance value or inner randomness ,I read document of Highs but not exist a random seed type of thing.

---

<div class="post-metadata">

### Author: ![marcos](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.ampl.com/marcos/32/154_2.png) [@marcos](https://discuss.ampl.com/u/marcos)
#### Post date: [May 1, 2024, 12:53am UTC](https://discuss.ampl.com/t/gurobi-and-highs-solver-helpppp/1079/5 "2024-05-01T00:53:19Z")

</div>

Hi,

There could be many reasons for this difference.

I would bet that when you rerun the solver, different values are being sent or retrieved by the solver. You can write the nl file that it’s being sent to the solver, and check if it is the same in the two situations.  
`write gmodel;` generates a file called “model.nl”, so you would need to write two different nl files. If you are using amplpy, something like `model.eval("write gf1;")` and `model.eval("write gf2;")` before your two solve statements to generate the two files.

Are you reusing the same ampl object for the two problems?

---

<div class="post-metadata">

### Author: ![Firdevs\_Uykun](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.ampl.com/firdevs_uykun/32/528_2.png) [@Firdevs\_Uykun](https://discuss.ampl.com/u/Firdevs_Uykun)
#### Post date: [May 2, 2024, 6:44am UTC](https://discuss.ampl.com/t/gurobi-and-highs-solver-helpppp/1079/6 "2024-05-02T06:44:49Z")

</div>

Same ampl object,if it runs in the opening in a jupyter it gave me same solution when I rerun in the same window solution was same,only difference is when I close my computer a week than run the jupyter optimal value give me this difference.

---

<div class="post-metadata">

### Author: ![marcos](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.ampl.com/marcos/32/154_2.png) [@marcos](https://discuss.ampl.com/u/marcos)
#### Post date: [May 6, 2024, 10:01am UTC](https://discuss.ampl.com/t/gurobi-and-highs-solver-helpppp/1079/7 "2024-05-06T10:01:44Z")

</div>

Hi,

Were you able to reproduce the issue? Time should not affect the jupyter notebook, solvers, or ampl itself, so there should be a way to reproduce the issue without waiting a week.

I could take a look at your script if you want ([support@ampl.com](mailto:support@ampl.com), [marcos@ampl.com](mailto:marcos@ampl.com)), but it seems that your data could be changing, or there is some kind of small precision issue when rerunning the problem with a different solver.
