# \[AMPL 24623\] Variables in the upper limit of the set

**URL:** <https://discuss.ampl.com/t/ampl-24623-variables-in-the-upper-limit-of-the-set/520>\
**Category:** Google Group Mirror\
**Created:** [April 28, 2023, 3:01pm UTC](https://discuss.ampl.com/t/ampl-24623-variables-in-the-upper-limit-of-the-set/520 "2023-04-28T15:01:00Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Liu\_Fan](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.ampl.com/liu_fan/32/229_2.png) [@Liu\_Fan](https://discuss.ampl.com/u/Liu_Fan)\
**Post date:** [April 28, 2023, 3:01pm UTC](https://discuss.ampl.com/t/ampl-24623-variables-in-the-upper-limit-of-the-set/520/1 "2023-04-28T15:01:00Z")

</div>

Dear Robert:  
I have a problem that I don’t know how to describe in ampl language.  
m[i,k] denotes the number of grids taken by vehicle i in the kth step, k ∈ {0,… ,K}, and I want to implement the constraint in ampl that the vehicle walks all the meshes in the least number of steps, A being the number of grids.  
when vehicle i walks through all the grids, i.e. sum{i in CARS, k in T[i]. .k\_x}m[i,k]=A, k\_x is minimum. But here k ∈ {T[i]. .k\_x} where k\_x is a variable and cannot be used as the upper limit of the set.  
Thank you very much for your time and assistance.  
Best regards.  
liufan

---

<div class="post-metadata">

**Author:** ![AMPL\_Google\_Group](https://avatars.discourse-cdn.com/v4/letter/a/9dc877/32.png) [@AMPL\_Google\_Group](https://discuss.ampl.com/u/AMPL_Google_Group)\
**Post date:** [May 1, 2023, 4:19pm UTC](https://discuss.ampl.com/t/ampl-24623-variables-in-the-upper-limit-of-the-set/520/2 "2023-05-01T16:19:21Z")

</div>

As you have observed, you cannot sum over {i in CARS, k in T[i]. .k\_x} where k\_x is a variable. You would need to reformulate this in some other way, most likely using some additional zero-one variables and additional constraints.

This is a general mathematical formulation problem rather than specifically an AMPL issue. Thus, to get help, I suggest that you ask your question on the [Operations Research StackExchange](https://or.stackexchange.com/) site, where there are many questions about formulating optimization problems, and usually they are answered pretty quickly.
