# Decomposition solution

**URL:** https://discuss.ampl.com/t/decomposition-solution/578
**Category:** Support
**Tags:** modeling
**Created:** [May 29, 2023, 11:25am UTC](https://discuss.ampl.com/t/decomposition-solution/578 "2023-05-29T11:25:42Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![andrea\_rosa](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.ampl.com/andrea_rosa/32/261_2.png) [@andrea\_rosa](https://discuss.ampl.com/u/andrea_rosa)
#### Post date: [May 29, 2023, 11:25am UTC](https://discuss.ampl.com/t/decomposition-solution/578/1 "2023-05-29T11:25:42Z")

</div>

Hi everyone! i have a model with a set aircraft:={1…N}, which describe an aircraft landing problem. My objective is to decompose the problem into subproblems that are easier to solve individually. I want to create subsets of aircraft, solving smaller subproblems separately and then combining the solutions, reducing the overall computational complexity and obtain good solutions more quickly. To do this, i have implemented this algorithm which iteratively generates the subsets ‘aircraft-relaxed’ and, for each subset, solve the new model ALP\_red (this model is equal to the initial one, but instead of set aircraft, it uses set aircraft\_red, for each variables and constraints). The problem is that AMPL gives me an error if i put the model ALP\_red inside the for cycle. How can I solve this problem, in order to achieve my goal?  
Attached the initial model ALP\_model, the new model ALP\_model\_red, and the file .run which represents my algorithm (decmat.run)  
Thank you for your help!  
Best regards, Andrea

Uploading: ALP\_model.mod…  
Uploading: alpdec.mod…  
[decmat.run](https://discuss.ampl.com/uploads/short-url/kUhenSc6DtL6zajBibs80mIWDXB.run) (1.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: [May 30, 2023, 3:50pm UTC](https://discuss.ampl.com/t/decomposition-solution/578/2 "2023-05-30T15:50:02Z")

</div>

AMPL will not let you execute `model` `alpdec.mod` inside your `for` loop. That would cause all of your model definition statements to be executed again at every pass though the loop — but AMPL only allows a `set`, `param`, `var`, etc. to be defined once.

Instead, you should move `model` `alpdec.mod` so that it comes before the loop, and then inside the loop you should only change the model’s set and param data.

If you still have trouble after you make this change, then upload all of your revised files here. (ALP\_model.mod and alpdec.mod did not upload properly, so even if you do not change them, you should try uploading them again.)

---

<div class="post-metadata">

### Author: ![andrea\_rosa](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.ampl.com/andrea_rosa/32/261_2.png) [@andrea\_rosa](https://discuss.ampl.com/u/andrea_rosa)
#### Post date: [May 31, 2023, 3:04pm UTC](https://discuss.ampl.com/t/decomposition-solution/578/3 "2023-05-31T15:04:45Z")

</div>

But if I put alpdec.mod outside the for loop I can’t solve cyclically the subproblems for each set aircraft\_red I generate. I need to resolve my model for each aircraft\_red and not for the initial aircraft set, and then combining the solutions to obtain good solutions more quickly. I uploaded the models in .run format but they are actually .mod files.  
Thank you for your help!

[ALP\_model.run](https://discuss.ampl.com/uploads/short-url/yg3hr01Aus4dxKOuXAnlGvCbz4r.run) (2.1 KB)  
[alpdec.run](https://discuss.ampl.com/uploads/short-url/ht2DKQ8iDOIePSG3jgpQ5RQHk36.run) (2.3 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: [June 2, 2023, 1:50am UTC](https://discuss.ampl.com/t/decomposition-solution/578/4 "2023-06-02T01:50:23Z")

</div>

You should read alpdec.mod before the loop. Then in each pass through the loop, because you compute new members for the set `aircraft_red`, AMPL will solve a new optimization problem.

There is maybe another problem that you are having. In decmat.run, you read ALP\_model.mod, and then later you read alpdec.mod. But there seems to be a lot of duplication between these model files:

- ALP\_model.mod has variables x, alfa, beta, etc. indexed over set aircraft, and then various objectives and constraints using set aircraft for indexing.

- alpdec.mod has variables x\_sub, alfa\_sub, beta\_sub etc. that are the same as the ones in ALP\_model.mod, except with indexing over set aircraft\_red. Also the objective and constraints are the same, except that they use the “\_sub” variables and they use aircraft\_red rather than aircraft.

It looks like you want to use just the set and param definitions from ALP\_model.mod, and just the variable, objective, and constraint definitions from alpdec.mod, along with the definition:

```auto
set aircraft_red within aircraft;

```
