How to remove records from a table using values in a parameter

I have a table where the rows are types of foods and the columns are various nutrients found in those foods. I would like to trim this table to remove types of foods that are specified in a parameter. How does one do this in GAMS? Do I have to set up some sort of loop?

As you can tell, I am new to GAMS.

Hi eisenhee,

No problem about being new to GAMS! It’s important to note that a table and a parameter are the same thing… just a slightly different syntax for entry. Tables are really helpful for 2D data, but can get a bit messy with higher dimensional data. I have gotten in the habit of just using “flat” parameters i.e.,

SET food / pizza, fish /;
SET nutrient / sat_fat, calories /;

PARAMETER nutrient_values(food,nutrient) /
‘pizza’.‘sat_fat’ 100,
‘pizza’.‘calories’ 3000,
‘fish’.‘sat_fat’ 30,
‘fish’.‘calories’ 100 /;

If you wanted to trim out the values from nutrient_values based on some other parameter you could do it this way:

PARAMETER other_parameter(food,nutrient) /
‘fish’.‘sat_fat’ 100 /;

nutrient_values(food,nutrient)$(other_parameter(food,nutrient) <> 0) = 0;
display nutrient_values;

the $ is a conditional statement is a boolean test for non-zero values of ‘other_parameter’ and sets the value of ‘nutrient_values’ to zero when the condition is TRUE.

While there are always very good reasons to modify the input data, you might also want to explore just using set operations to pull out the values you want from a parameter. Say you want to put a subset of the data contained in nutrient_values into a new parameter called ‘seafood_nutrient_values’:

SET seafood(food) / fish /;
PARAMETER seafood_nutrient_values(food,nutrient);

seafood_nutrient_values(food,nutrient)$seafood(food) = nutrient_values(food,nutrient)
display seafood_nutrient_values;

hope that’s helpful

best,
adam