# Running multiple instances of a Problem

**URL:** <https://discuss.ampl.com/t/running-multiple-instances-of-a-problem/679>\
**Category:** Support\
**Created:** [August 9, 2023, 9:01am UTC](https://discuss.ampl.com/t/running-multiple-instances-of-a-problem/679 "2023-08-09T09:01:40Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shuxue\_Jiaoshou](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.ampl.com/shuxue_jiaoshou/32/362_2.png) [@Shuxue\_Jiaoshou](https://discuss.ampl.com/u/Shuxue_Jiaoshou)\
**Post date:** [August 9, 2023, 9:01am UTC](https://discuss.ampl.com/t/running-multiple-instances-of-a-problem/679/1 "2023-08-09T09:01:40Z")

</div>

I want to run multiple instances of a problem by changing a single parameter w… But each time, I want to run it fresh (from scratch)… For example, when I run the model with ~ (w = 6), ~ I want a **fresh run** — that is, **not** use the optimal solution from the previous ~ (w = 5) ~ run as a starting solution… (This is due to the nature of my problem – I have to start from scratch every time.)

I can do this with a script written in C or Python or a UNIX shell script — but it appears impossible with AMPL commands… For example, if I write a for loop such as

```auto
for (T in 22..44) {
      model myModel.mod;
      let w := T;
      solve;
      display X;
      display Y;
      reset;
}

```

The reset command ~ “destroys” ~ the loop variable T — and so in the second run of the for loop, the statement ~ “`let w := T`” ~ is flagged as invalid (error).

Tried replacing “`let w:= T`” with “`let w := w + 1`” and replacing the “`for`” loop with  
“`for {22..44}`” — but this doesn’t work either.

I have tried the ~ “`reset data w`” ~ and ~ “`update`” ~ commands described in Chapter 11 of the AMPL book (the “Command Scripts” chapter) — but they all seem to use the optimal solutions from the previous ~w~ run (often resulting in **zero** iterations of the solver in the subsequent run).

Is there any way to do fresh “from scratch” runs with AMPL commands?

---

<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:** [August 9, 2023, 1:15pm UTC](https://discuss.ampl.com/t/running-multiple-instances-of-a-problem/679/2 "2023-08-09T13:15:27Z")

</div>

Set the AMPL option `reset_initial_guesses` to 1 to tell AMPL to ignore the previous optimal solution each time that the problem is solved. Also move your `model` statement outside of the loop, so that it is only executed once, and do not reset inside the loop:

```auto
model myModel.mod;
option reset_initial_guesses 1;

for {T in 22..44} {
      let w := T;
      solve;
      display X;
      display Y;
}

```

Here’s the description from the [AMPL Options](https://dev.ampl.com/ampl/options.html) listing:

> ### reset\_initial\_guesses _b_ (default 0)
> 
> Whether to send to the solver the current values of the variables. Values are sent when _b_ is at its default value of 0, and are reset to the initial values specified in the model if _b_ is set to 1.

---

<div class="post-metadata">

**Author:** ![Shuxue\_Jiaoshou](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.ampl.com/shuxue_jiaoshou/32/362_2.png) [@Shuxue\_Jiaoshou](https://discuss.ampl.com/u/Shuxue_Jiaoshou)\
**Post date:** [August 10, 2023, 6:03am UTC](https://discuss.ampl.com/t/running-multiple-instances-of-a-problem/679/3 "2023-08-10T06:03:48Z")

</div>

Thank you, but sorry, it doesn’t work… I am using MINOS as my solver… And in the model file (which contains a `data` section at the bottom), my options are:

```auto
option solver minos, reset_initial_guesses 1;

option minos_options 'superbasics_limit=10000 scale_option=2 solution=yes Major_iterations=200 timing=1';

```

I ran it for 50 values of w… In the first few runs, the **number of iterations** is non-zero… and then it is zero for the remaining 40+ runs.

---

<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:** [August 10, 2023, 3:04pm UTC](https://discuss.ampl.com/t/running-multiple-instances-of-a-problem/679/4 "2023-08-10T15:04:25Z")

</div>

Maybe for some values of `w`, MINOS doesn’t need any iterations. You can easily check: Pick a value of `w` for which MINOS reports zero iterations, and just solve for that one value of `w`. For example, if you are seeing zero iterations when you run in the loop and `w` is 53, do this test:

```auto
model myModel.mod;
option solver minos, reset_initial_guesses 1;
option minos_options 'superbasics_limit=10000 scale_option=2 solution=yes Major_iterations=200 timing=1';

let w := 53;
solve;

```

If MINOS still reports zero iterations, there is nothing wrong. But if instead in this test, MINOS reports a positive number of iterations, then upload your file(s) and I’ll take a closer look.

---

<div class="post-metadata">

**Author:** ![Shuxue\_Jiaoshou](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.ampl.com/shuxue_jiaoshou/32/362_2.png) [@Shuxue\_Jiaoshou](https://discuss.ampl.com/u/Shuxue_Jiaoshou)\
**Post date:** [August 11, 2023, 2:48am UTC](https://discuss.ampl.com/t/running-multiple-instances-of-a-problem/679/5 "2023-08-11T02:48:29Z")

</div>

I have uploaded the files… As you can see, besides the “`number of iterations`”, the solutions (the X values) and the values of “`integerCount`” are also different.

I had to change the names of file extensions (from “.txt” to “.dat”, then “.cmd” to “.run”, etc…) so that I could upload them.

[53-vertex-instance.mod](https://discuss.ampl.com/uploads/short-url/jLqxRtK5Hou9AnptaUT4qusLeu7.mod) (3.1 KB)  
[command-file-ampl-minos.run](https://discuss.ampl.com/uploads/short-url/qMsjwLGEQQhD0REqUwQ2fvbX8RX.run) (755 Bytes)  
[Local-ampl-script.dat](https://discuss.ampl.com/uploads/short-url/8hqN0vif1badcrqDt4BQnv0x0cN.dat) (869 Bytes)  
[Model-for-C-program.mod](https://discuss.ampl.com/uploads/short-url/AaeJUJ7N4k9tY7wtkyKX9l0yOVa.mod) (3.5 KB)  
[Result-C-program.dat](https://discuss.ampl.com/uploads/short-url/o0W8SvEBU9ePqX1cMYIaH6k3diO.dat) (20.8 KB)  
[Result-with-reset-guesses.dat](https://discuss.ampl.com/uploads/short-url/5M8EDAG8yxeXXRn0XWofMMwXYuB.dat) (21.5 KB)

---

<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:** [August 11, 2023, 5:23pm UTC](https://discuss.ampl.com/t/running-multiple-instances-of-a-problem/679/6 "2023-08-11T17:23:24Z")

</div>

After running some tests on your example, I realized that MINOS is a special case. Unlike most local nonlinear solvers, it can use 3 kinds of information from the previous solve:

- The optimal values of the variables.
- The optimal values of the dual variables.
- The statuses of the variables (basic, nonbasic, or superbasic) in the optimal solution.

You can tell MINOS to ignore all of this information, by setting the following options:

```auto
option solver minos, reset_initial_guesses 1, dual_initial_guesses 1, send_statuses 0;

```

When I make this change to the options and then run your example again, the number of iterations used by MINOS ranges from 156 to 171.

---

<div class="post-metadata">

**Author:** ![Shuxue\_Jiaoshou](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.ampl.com/shuxue_jiaoshou/32/362_2.png) [@Shuxue\_Jiaoshou](https://discuss.ampl.com/u/Shuxue_Jiaoshou)\
**Post date:** [August 12, 2023, 3:00am UTC](https://discuss.ampl.com/t/running-multiple-instances-of-a-problem/679/7 "2023-08-12T03:00:24Z")

</div>

The reason that I like this approach (rather than the C program approach) is that I can sometimes use NEOS… I can upload the model file and command file into NEOS and use their AMPL-MINOS platform… Thank you, I will try your suggestions and report back.

---

<div class="post-metadata">

**Author:** ![Shuxue\_Jiaoshou](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.ampl.com/shuxue_jiaoshou/32/362_2.png) [@Shuxue\_Jiaoshou](https://discuss.ampl.com/u/Shuxue_Jiaoshou)\
**Post date:** [August 15, 2023, 7:42am UTC](https://discuss.ampl.com/t/running-multiple-instances-of-a-problem/679/8 "2023-08-15T07:42:33Z")

</div>

Did some more testing… The number of iterations is now non-zero in each case… However, I still notice some interference from previous runs.

In one experiment, for [w = 0.0169], if I run the model in the range (0.0163 \le w \le 0.0172), the number of iterations for [w = 0.0169] is 13035… whereas if my range is (0.0164 \le w \le 0.0172), MINOS performs 20038 iterations for [w = 0.0169]… and the solutions returned are also different.

Anyway, I guess I will stop experimenting with this… Could be an issue with MINOS… Thanks for your help — let me continue my research using the C program method.
