Restricting domain of a double summation

315 views
Skip to first unread message

Glen

unread,
Jul 16, 2014, 12:13:40 PM7/16/14
to ai...@googlegroups.com
Hello,

I am new to AIMMS and modeling in general, and am having trouble efficiently coding a simple model that I am working on as practice.

The basis of the model is to maximise Total Profit in planting a mixed-crop plan. There is a set of "Crops" with two indices "i" and "j" (necessary to describe interaction between two crops), and all elements of that set are "planted". Then, the crop that provides the least profit is removed from consideration and the model is run again. This is done until the final crop is reached and a comparison from all runs is done to determine which planting scheme yields the most profit. The equation for Total Profit includes a double summation over the two indices of the set Crops.

Currently, the crop selection is done manually. There are four elements to the set Crops (1,2,3,4). Initially, I plant all 4 crops. On the second run, I plant only crops 1, 2 and 3. And on the third run, I plant only crops 2 and 3. Therefore, I need to restrict the domain of the summation to the crops I wish to plant.

I have this working in a clumsy way. I defined two binary parameters, one for "i" and one for "j", which act as the domain restrictions for each summation. However, when I then remove a crop from consideration, I must go into both parameters and remove the crop. This works, but there must be a more concise way to achieve the same. Initially, I tried to restrict the summation over "j" with the binary parameter for "i", but this did not work.

What I then tried was to declare a second set, called "CropsToGrow", and made it a subset of "Crops". I then restricted the domain of both summations to this set. The goal was to make the elements of this set the crops I wish to grow. However, even in doing so, the summations still execute over all elements of the set "Crops".

Therefore, what I wish to do is restrict the domain of a double summation over different indices with a single parameter or set that does not depend on the specific index of summation.

Chris Kuip

unread,
Jul 18, 2014, 5:28:27 AM7/18/14
to ai...@googlegroups.com
Hi Glen,

There are several ways to tackle your modeling question. 
I will discuss three:

1) Use a binary parameter: isActiveCrop(i), which you initialize to 1 and set to 0 for crops no longer active.
   In your model you then use:
   sum( i | isActiveCrop(i), ... 
   or 
   sum( j | isActiveCrop(j), 
   or 
   sum( (i,j) | isActiveCrop(i) and isActiveCrop(j), ....
   
2) Slightly more elegant but essentially the same is to use a set activeCrops, subset of Crops:
   In your model you can then use:
   sum( i | i in activeCrops, ... 
   or 
   sum( j | j in activeCrops, 
   or 
   sum( (i,j) | (i in activeCrops) and (j in activeCrops), ....
  
3) The way I like to do it is again using a set of activeCrops, but also declaring indices in that set, say ai and aj.
   In your model you can then use:
   sum( ai, ...
   or 
   sum( aj, ....
   or
   sum( (ai,aj), ....
   
Hope this helps,

Chris Kuip
AIMMS Client Support.
   

Op woensdag 16 juli 2014 18:13:40 UTC+2 schreef Glen:

Glen

unread,
Jul 18, 2014, 10:56:01 AM7/18/14
to ai...@googlegroups.com
Hi Chris,

Thank you very much for your help. Method 2 is the one that worked for me.

Method 1 is what I already had working, but found it clumsy. It was okay for this simple model, with only two restrictions needing to be made, but needing to uncheck boxes in each parameter would become tedious if there were any more.

Method 2 was the approach I had tried, but I had my summations incorrectly defined as sum(i|ActiveCrops, . . . instead of including the necessary "i in ".

I could not make Method 3 work, as I have other parameters in the summations that rely on the "i" index, and it throws an error if I try to call them with the "ai" index. For example, there is a parameter "Profit(i)" that is multiplied by the number of crops grown. If I try to call a value from Profit(i) with the "ai" index, it tells me something along the lines of "ai is not associated with the set 'Crops'"

However, I am happy with Method 2, as it has the added benefit of clearly showing that the summation is restricted by a second set.

Thanks again for your help.

Glen
Reply all
Reply to author
Forward
0 new messages