Need Assistance with AMPL Constraint Modeling

Hello ,

I hope you’re doing well. I am currently working on a project where I am utilizing AMPL for optimization modeling. I have faced a technical challenge related to modeling a specific constraint.

The issue I am facing revolves around incorporating time-dependent constraints into my optimization model. Specifically, I need to enforce constraints that vary dynamically based on temporal factors such as production schedules, resource availability, and demand fluctuations.

Even after many attempts and referring to the documentation, I am not able to devise a satisfactory solution. The constraint in question is crucial for my optimization problem, as it directly impacts the feasibility and efficiency of the proposed solutions.

If there are any recommended approaches for handling similar temporal issues, I would greatly appreciate the advice.

Thank you all ! :slightly_smiling_face:

Thank you
nolanmaris

The principles of a time-based formulation are described in section 4.2 A multiperiod production model of the AMPL book. But for help with your particular constraint, you will need to provide some more details:

  • The decision variables involved in your constraint.
  • A description in words of the restriction on the variables that your constraint needs to enforce.
  • A mathematical description of your constraint.
  • Your attempt at describing the constraint in AMPL, even though it is not fully correct.

Hi 4er,

Thanks for your reply . Below are the required information -

  1. Decision variables: Production quantities, resource allocations, and inventory levels.

  2. Description: Constraint ensures production meets demand, considering resource constraints and inventory policies, dynamically adjusting over time.

  3. Mathematical description: Pt≤Dt+It−1−It+RtP_{t} \leq D_{t} + I_{t-1} - I_{t} + R_{t}Pt≤Dt+It−1−It+Rt

  4. Attempt in AMPL:

subject to meet_demand { forall(t in forall(t Time) { production prod [t] <= demand_forecast[t] + inventory[t-1] - inventory[t] + resource_availability[t]; } }

Appreciate any further advice.

Thank you
nolanmaris

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

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:

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];