# Need Assistance with AMPL Constraint Modeling

**URL:** <https://discuss.ampl.com/t/need-assistance-with-ampl-constraint-modeling/1127>\
**Category:** Support\
**Created:** [June 7, 2024, 6:22am UTC](https://discuss.ampl.com/t/need-assistance-with-ampl-constraint-modeling/1127 "2024-06-07T06:22:52Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![marcos](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.ampl.com/marcos/32/154_2.png) [@marcos](https://discuss.ampl.com/u/marcos)\
**Post date:** [June 10, 2024, 11:24am UTC](https://discuss.ampl.com/t/need-assistance-with-ampl-constraint-modeling/1127/4 "2024-06-10T11:24:42Z")

</div>

Hi @nolanmaris ,

The right way of writing indexed constraints in ampl is just specifying the index (there are no forall loops involved)

P\_{t} \leq D\_{t} + I\_{t-1} - I\_{t} + R\_{t}, \quad \forall t \in Time

```auto
subject to meet_demand {t in Time: t > 0}:
	prod[t] <= demand_forecast[t] + inventory[t-1] - inventory[t] + resource_availability[t];

```

I added the t \> 1 condition so you do not get an error for t = 0 (inventory[-1]?). It depends on what is the first time value you are considering.

You can use ordered sets to handle time in case it helps you:

```auto
set Time ordered := 1..100;
...
...
subject to meet_demand {t in Time: t != first(Time)}:
	prod[t] <= demand_forecast[t] + inventory[t-1] - inventory[t] + resource_availability[t];

```

---

_[View the full topic](https://discuss.ampl.com/t/need-assistance-with-ampl-constraint-modeling/1127)._
