# Change the solvers using loop

**URL:** <https://discuss.ampl.com/t/change-the-solvers-using-loop/512>\
**Category:** Support\
**Tags:** general, solvers\
**Created:** [April 23, 2023, 6:59am UTC](https://discuss.ampl.com/t/change-the-solvers-using-loop/512 "2023-04-23T06:59:22Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![sd1](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.ampl.com/sd1/32/256_2.png) [@sd1](https://discuss.ampl.com/u/sd1)\
**Post date:** [April 23, 2023, 6:59am UTC](https://discuss.ampl.com/t/change-the-solvers-using-loop/512/1 "2023-04-23T06:59:22Z")

</div>

Hope all is well.  
I want to compare the performances of a lot of different solvers, so I tried these commands in the console. However, it did not work. Is there any other way to avoid setting up the solver repeatedly?

set SOLVERS = {“minos”, “baron”, “gurobi”};  
model ‘ex1.mod’;  
data ‘ex1.dat’;  
for {i in SOLVERS}{  
option solver i;  
solve;  
display cost \>\> output.txt;  
}

Thanks!

---

<div class="post-metadata">

**Author:** ![4er](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.ampl.com/4er/32/530_2.png) [@4er](https://discuss.ampl.com/u/4er)\
**Post date:** [April 24, 2023, 5:02pm UTC](https://discuss.ampl.com/t/change-the-solvers-using-loop/512/2 "2023-04-24T17:02:14Z")

</div>

When your specify “option solver i;” AMPL sets option solver to the literal character string “i”. To instead set option solver to the _value_ of index i, use this command:

```auto
option solver (i);

```

The general rules for this situation are given in the subsection on [String expressions in AMPL commands](https://ampl.com/wp-content/uploads/Chapter-13-Command-Scripts-AMPL-Book.pdf#page=19) in Chapter 13 of the [AMPL book](https://ampl.com/learn/ampl-book/).

---

<div class="post-metadata">

**Author:** ![sd1](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.ampl.com/sd1/32/256_2.png) [@sd1](https://discuss.ampl.com/u/sd1)\
**Post date:** [April 24, 2023, 5:23pm UTC](https://discuss.ampl.com/t/change-the-solvers-using-loop/512/3 "2023-04-24T17:23:44Z")

</div>

This did work. Thank you very much!
