Advanced GMPL models for motivational examples

Advanced GMPL models of the motivational examples

We have already made the advanced model of for the Festivals example. In this practice session, try to do the same for the Fröccs example.

Advanced GMPL model for the fröccs example

First try to create a more general model, where the fröccs types are given as data. The very first step is to identify the necessary set and parameter definitions. Reveal set and parameter definitions

Mathematical notation GMPL code
Sets and parameters
\(F\)set FroccsTypes;
\(p_{f}\qquad f\in F\)param price{FroccsTypes};
\(s^{s}\)param soda_stock;
\(s^{w}\)param wine_stock;
\(c^{s}_{f}\qquad f\in F\)param soda_content{FroccsTypes};
\(c^{w}_{f}\qquad f\in F\)param wine_content{FroccsTypes};

The second step is to create the variables, constraints and objective function of the generic model. Reveal the generic model

Mathematical notation GMPL code
Variables
\(q_f\qquad f\in F\) var quantity{FroccsTypes}>=0;
Constraints
\(\displaystyle\sum_{f\in F} q_f \cdot c^s_f \le s^s\) s.t. SodaUsage: sum{f in FroccsTypes} quantity[f] * soda_content[f] <= soda_stock;
\(\displaystyle\sum_{f\in F} q_f \cdot c^w_f \le s^w\) s.t. WineUsage: sum{f in FroccsTypes} quantity[f] * wine_content[f] <= wine_stock;
Objective function
\(\displaystyle\sum_{f\in F} q_f \cdot p_f \to max\) maximize Income: sum{f in FroccsTypes} price[f] * quantity[f];

Last, but not least, provide data for the model in a data file Reveal data file

set FroccsTypes :=
  kisfroccs
  nagyfroccs
  hosszulepes
  hazmester
  vicehazmester
  krudyfroccs
  soherfroccs
  puskasfroccs
  ;

param price :=
  kisfroccs     110
  nagyfroccs    200
  hosszulepes   120
  hazmester     260
  vicehazmester 200
  krudyfroccs   800
  soherfroccs   200
  puskasfroccs  550
  ;
  

param soda_stock := 1500;
param wine_stock := 1000;

param soda_content :=
  kisfroccs     1
  nagyfroccs    1
  hosszulepes   2
  hazmester     2
  vicehazmester 3
  krudyfroccs   1
  soherfroccs   9
  puskasfroccs  3
  ;

  
param wine_content :=
  kisfroccs     1
  nagyfroccs    2
  hosszulepes   1
  hazmester     3
  vicehazmester 2
  krudyfroccs   9
  soherfroccs   1
  puskasfroccs  6
  ;

More general Product-mix model

We feel, that this model is still very specific to beverages made from soda and wine. If we were to have a problem instance with different products, that use given portions of certain raw materials, and given were all the price and stock data as well, the model would be very similar. So now, try to create a model, where it is not hardcoded to have two types of ingredients, but it would be given by a set. Reveal model file with data section

set Products;
set Ingredients;

param price{Products};
param stock{Ingredients};
param content{Products,Ingredients};

var quantity{Products}>=0;

s.t. IngredientUsage{i in Ingredients}:
  sum{p in Products} quantity[p] * content[p,i] <= stock[i];

maximize Income:
  sum{p in Products} price[p] * quantity[p];

data;

set Products :=
  kisfroccs
  nagyfroccs
  hosszulepes
  hazmester
  vicehazmester
  krudyfroccs
  soherfroccs
  puskasfroccs
  ;

set Ingredients :=
  soda
  wine
  ;

param price :=
  kisfroccs     110
  nagyfroccs    200
  hosszulepes   120
  hazmester     260
  vicehazmester 200
  krudyfroccs   800
  soherfroccs   200
  puskasfroccs  550
  ;
  

param stock :=
  soda 1500
  wine 1000
  ;


param content :
                soda  wine  :=
  kisfroccs     1     1  
  nagyfroccs    1     2
  hosszulepes   2     1
  hazmester     2     3
  vicehazmester 3     2
  krudyfroccs   1     9
  soherfroccs   9     1
  puskasfroccs  3     6
  ;

end;

More general Product-mix model

To test Your skills, try to make the generic model for a more sophisticated festival example. First, to warm-up, include the price of each festival, and make the objective to minimize the total cost instead of the number of festivals.

Secondly, define the dates of the festivals, and introduce a new constraint, that You can not be at two places at the same time.

Finally, try to extend the model with something on Your own, to make it more realistic.


Final notes

The main point of this practice session was to get used to generic models, and their syntax in GMPL.