# Error executing "display" command

**URL:** <https://discuss.ampl.com/t/error-executing-display-command/584>\
**Category:** New to AMPL\
**Created:** [May 30, 2023, 4:49pm UTC](https://discuss.ampl.com/t/error-executing-display-command/584 "2023-05-30T16:49:56Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Samuele\_Viaro](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.ampl.com/samuele_viaro/32/178_2.png) [@Samuele\_Viaro](https://discuss.ampl.com/u/Samuele_Viaro)\
**Post date:** [May 30, 2023, 4:49pm UTC](https://discuss.ampl.com/t/error-executing-display-command/584/1 "2023-05-30T16:49:56Z")

</div>

Hello!! 🙂  
I am using AMPL+CPLEX along with C++…  
I’ve come across a bug and it would help me if I could visualize one of my sets named "setA "by displaying its values on a terminal (linux).  
I usually use the following:

_ampl.eval(“display setA;”);_

However, when I try to display this set I get the following error:

_terminate called after throwing an instance of ‘ampl::AMPLException’_

- what(): Error executing “display” command:\*  
_error processing set setB:_
- invalid subscript parC[4]\*

where setB is a copy of setA,  
and parC is a parameter defined as parC[setC], where set C is initialized and then modified in the code with

_ampl.eval(“let setC := setC diff setA”);_

I understand that they are “connected” but why can’t I simply see the values of a set with the display command??  
Knowing the values of the set would be helpful in understanding where the bug might be…

Hope I was clear enough… 😊

Thank you in advance  
Sam

---

<div class="post-metadata">

**Author:** ![fdabrandao](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.ampl.com/fdabrandao/32/63_2.png) [@fdabrandao](https://discuss.ampl.com/u/fdabrandao)\
**Post date:** [May 30, 2023, 6:44pm UTC](https://discuss.ampl.com/t/error-executing-display-command/584/2 "2023-05-30T18:44:56Z")

</div>

Hi @Samuele_Viaro,

Could you please provide the declarations of the three sets? From the error message `setA` seems to be defined in function of `setB` that seems to be defined in function of `parC`. Is that the case?

Nevertheless, from the “`let setC := setC diff setA;`” and the fact that `parC` is indexed over the set `setC`, that error happens because if you load the data for `parC` for all indices in `setC` initially, and then remove values from `setC`, you end up with data for invalid subscripts (data for deleted subscripts) in `parC`. You can clear the data for `parC` with `ampl.eval("reset data parC;");` when you update `setC`.

```cpp
ampl.eval("reset data parC; let setC := setC diff setA;")

```

---

<div class="post-metadata">

**Author:** ![Samuele\_Viaro](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.ampl.com/samuele_viaro/32/178_2.png) [@Samuele\_Viaro](https://discuss.ampl.com/u/Samuele_Viaro)\
**Post date:** [May 31, 2023, 5:34pm UTC](https://discuss.ampl.com/t/error-executing-display-command/584/3 "2023-05-31T17:34:15Z")

</div>

Hello!!  
in my .mod file I declare:  
_param parC[setC] \>= 0_  
_set setC default {1…N}_  
_set setA := {1}_

then in my C++ code:  
_ampl.readData(“./src/exec\_ampl/dataIn.dat”);_ //data for parC  
_ampl.eval(“redeclare set setA = {j in setD: MTX[j, parC[j]] \< X};”);_  
_ampl.eval(“set setB;”);_  
_ampl.getSet(“setB”).setValues(, .size());_  
_ampl.eval(“let setC := setC diff setA;”);_  
_ampl.eval(“reset data parC;”);_  
_ampl.eval(“redeclare param parC{setC} \>= 0;”);_

I am doing all these changes because at every simulation setA changes based on the results of the previous simulation.  
I basically have to update the values of the set based on the result of the previous simulation…  
Could it be that after I do reset data parC I have to add new

Thanks again

---

<div class="post-metadata">

**Author:** ![fdabrandao](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.ampl.com/fdabrandao/32/63_2.png) [@fdabrandao](https://discuss.ampl.com/u/fdabrandao)\
**Post date:** [June 2, 2023, 2:37pm UTC](https://discuss.ampl.com/t/error-executing-display-command/584/4 "2023-06-02T14:37:57Z")

</div>

Hi @Samuele_Viaro,

Since you load the data for parC from a data file, in order to avoid invalid indices in parC, you can just change its indexing set to be the original value of setC.

```auto
param parC{1..N} >= 0
set setC default {1…N}
set setA := {1}

```

Then you don’t need to worry about `parC` anymore as it will contain all the data, and by indexing using `setC` you will only access the elements that still exist in a given iteration.

---

<div class="post-metadata">

**Author:** ![Samuele\_Viaro](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.ampl.com/samuele_viaro/32/178_2.png) [@Samuele\_Viaro](https://discuss.ampl.com/u/Samuele_Viaro)\
**Post date:** [June 2, 2023, 4:43pm UTC](https://discuss.ampl.com/t/error-executing-display-command/584/5 "2023-06-02T16:43:59Z")

</div>

Hello!!  
Yes, this is what I was doing before.  
However, everytime I run a simulation I add values to setC, and the number of constraints and variables increase greatly with setC…  
At every simulation I reduce the size of setC removing values that I no longer need in order to reduce the size of the problem and decrease the computation time…

---

<div class="post-metadata">

**Author:** ![fdabrandao](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.ampl.com/fdabrandao/32/63_2.png) [@fdabrandao](https://discuss.ampl.com/u/fdabrandao)\
**Post date:** [June 2, 2023, 4:46pm UTC](https://discuss.ampl.com/t/error-executing-display-command/584/6 "2023-06-02T16:46:16Z")

</div>

Hi @Samuele_Viaro,

You can keep using setC for indexing in the rest of the model (variables and constraints). You just need to avoid using it in parameters like `parC` that will be holding data for all values.

---

<div class="post-metadata">

**Author:** ![Samuele\_Viaro](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.ampl.com/samuele_viaro/32/178_2.png) [@Samuele\_Viaro](https://discuss.ampl.com/u/Samuele_Viaro)\
**Post date:** [June 2, 2023, 4:56pm UTC](https://discuss.ampl.com/t/error-executing-display-command/584/7 "2023-06-02T16:56:00Z")

</div>

Ok, this I could try… 😊  
But, increasing the size of a parameter won’t affect the computation time?

---

<div class="post-metadata">

**Author:** ![fdabrandao](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.ampl.com/fdabrandao/32/63_2.png) [@fdabrandao](https://discuss.ampl.com/u/fdabrandao)\
**Post date:** [June 2, 2023, 4:58pm UTC](https://discuss.ampl.com/t/error-executing-display-command/584/8 "2023-06-02T16:58:37Z")

</div>

No, the only computation times relative to the parameter is essentially the time to load the data into it, and we need to do that anyways for the first iteration. After that the performance is mostly affected by variables and constraints.

---

<div class="post-metadata">

**Author:** ![Samuele\_Viaro](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.ampl.com/samuele_viaro/32/178_2.png) [@Samuele\_Viaro](https://discuss.ampl.com/u/Samuele_Viaro)\
**Post date:** [June 2, 2023, 6:24pm UTC](https://discuss.ampl.com/t/error-executing-display-command/584/9 "2023-06-02T18:24:37Z")

</div>

Great!!  
This helps a lot!! 🤗
