Parameter Uncertainty and if-then statements in constraints

  • 3 November 2020
  • 4 replies

Dear All,


My name is Mohamad Khaled and for my university research project I am using AIMMS to model a 3-echelon Pharmaceutical Supply Chain model. The current model I’m trying to define and solve is a simple one compared to some of the models I have seen here. I have two issues with my current model:


The first issue is that the pharmaceutical products (AKA medication) has an uncertain demand which I am not able to properly define in the project despite indicating the index domain, using the uncertain option in the property setting and defining the box function with an upper and a lower value in the region area. (I attached a screenshot of the demand parameter with the descriptions and region and another screenshot of the current “nominal” data of the demand) 


The second issue is the wastage/expiration of the medication. I have defined a shelf-life variable and respective constraint, however, I couldn’t get the shelf-life variable to be used in the wastage constraint as the following warning message kept appearing: “Warning: Comparing elements of different sets is ambiguous. AIMMS will compare the elements based on the super set of the two sets. If this is not your intention, you can re-write the expression using the Ord function specifying the set explicitly. (see also the option warning_comparing_elements_different_sets).” What I am aiming to achieve is to incorporate and define the attached if-then formulas, which do work as they have been tested in a previous research study.

Note that for the wastage issue, I assigned a set called Medication_period, which refers to the time the medication was produced, to be a subset of the original time_period set.


I know that several users ask for your help, and that much more complex projects has been optimized by AIMMS, however I couldn’t find anything similar that would work for my model, which is why I’m asking for your help in this matter.


(Note: my supervisor suggested that a certain Add-on might be needed to be installed.)


Hope to hear from you soon,




Mohamad Khaled


Best answer by Marcel Hunting 9 November 2020, 10:13

View original

4 replies

Userlevel 5
Badge +4

Hi @kmohamad095. The definition of the uncertain parameter 'Medication_Demand' looks fine but uncertain parameters are only meaningful (in AIMMS) if they are used in combination with robust optimization, that is, if you use the function GMP::Instance::GenerateRobustCounterpart. See Chapter 20 in the Language Reference for more information. For an example, see: .


To get rid off the warning you should use

(p,m,t)|ord(m) < ord(t)

in the index domain of the constraints 'Shelf_Life_Constraint2'. (Your formulation is fine but AIMMS throws a warning which you can disable by switching off the option 'Warning comparing elements different sets’ as an alternative solution.)

Dear Mr. Marcel

I would like to thank you for your help and I am sorry for the late reply. I will take a look at the robust optimization link you provided for the uncertainty definition. For the Shelf_Life variable I want the data/results to be positive only, and even when using the non-negative range in defining the Shelf_Life variable, I’m not getting a result. I am getting a result only when the range is free.

I tried defining the Shelf_Life in a while-loop but I keep getting a message that says that “the term while is unexpected” (attached is an image of the message I’m getting). The problem is that I need to use the Shelf_Life variable to define the relationship of another variable.

From my limited experience in programming, I know that an if-then statement or a while-loop statement is the best thing for my research project, but I seem to be having an issue defining them properly despite following the manuals and their examples.

I appreciate your help and support, and would hope you could help me in this matter since I am not finding much material on Youtube or online to fix the error messages. 



Userlevel 5
Badge +4

You cannot use a while-loop inside a constraint definition. You should use the definition without the while part.

I would advise you to print the constraint listing and inspect it. The constraint listing will be printed in the listing file, inside the log folder, if you set the following options:

  • - Solvers General option 'Constraint Listing' to 'At every solve' (or 'At first solve');
  • - Solvers General option 'Constraint Listing Variable Values' to 'Print variable values';

Maybe AIMMS generates 

Shelf_Life(p,m,t) = - Medication_Decap(p)

for some (p,m,t) and that makes the model infeasible if Shelf_Life(p,m,t) is nonnegative and Medication_Decap(p) is positive. You can check this in the constraint listing.

Thank you Mr. Marcel for your reply, and I am sorry for constantly bothering you with questions. However, I am still facing issues with me model and I’m unable to solve them.

The first issue is the wastage portion of my model. In short, I created a set called manufacturing period (m) and made it a subset of the time period (t). After wards I used both sets to create the constraint for the medication shelf-life, which as you know will decline with time [attached is image#1 of the shelf-life constraint]. After getting the proper shelf-life values, despite the negative answers, I decided to use the shelf-life variable as a condition for the if-then statement to get the amount of wastage that will be produced from not selling that medication. Obviously, AIMMS reject having a variable be the subject of the if-then statement, despite giving me no errors when I check and commit the definition of the constraint [attached is image#2 of the wastage constraint]. When running the model I get the following message: “The definition of constraint 'Wastage_Constraint(1,1,1,1)' contains an if-then-else statement with a variable in the condition, which cannot be handled by BARON.”, which transforms the model into an MINLP one and makes defining the wastage amount extremely difficult. 

The second issue is the uncertainty of the model. I require that one parameter; the medication demand, be uncertain to make the model more realistic. However, despite following the model in the link you sent me in your first reply about parameter uncertainty, I am getting all sorts of error messages when I execute the Robust model procedure. The main error message is: “Warning: Generation of the robust counterpart failed because constraint 'Provider_Inventory_Constraint(1,1,1)' induces an infeasibility for uncertain parameter 'Medication_Demand(1,1)': an equality constraint containing an uncertain parameter can only be satisfied if a (non-adjustable) variable is multiplied by this parameter, or an adjustable variable depends on it.” I also tried to set a simple definition for the uncertainty, and all the constraints involved in with this uncertain parameter started showing errors saying that the left side of the constraint isn’t uncertain as well.


I am sorry for the very long reply, and appreciate any help you can provide. It may be too much to ask, but if you would be willing to have a video call through Zoom or MS Teams it would greatly help me in finishing this model for my thesis.


Mohamad Khaled Mtit 



Didn't find what you were looking for? Try searching on our documentation pages:

AIMMS Developer & PRO | AIMMS How-To | AIMMS SC Navigator