Search code examples
ampldataformat

Entering data in AMPL


I have a set such as:

set PRODUCTS  := p1 p2 p3 p4 p5 ;

Associated to this set I have some parameters, of the form:

param min_production {PRODUCTS} >= 0;
param max_production {PRODUCTS} >= 0;

I want to fill these params with a format where the set index is the col index, and the param name is the row index.

Something like this:

#Data                       p1   p2   p3   p4   p5
param min_production        20   10   20   20   30 ;
param max_production       120  110  120  120  150 ;
param min_stock_products    20   20   20   20   20 ;
param max_stock_products   100   80   80  120  120 ;
param price               6400 6000 5900 6250 6500 ;
param unit_cost            800 1000  400  500 1000 ;
param fixed_cost          1500 1500 1250 1500 1600 ;
param stock_cost_products   20   20   10   25   30 ;
param frac_demand_lost     0.4  0.4  0.4  0.4  0.4 ;

Is this possible? What is the syntax?


Solution

  • Section 9.2 of the AMPL Book offers a way to do something approximating this with set index as row, and param name as column. See p. 151, "Combined lists of sets and parameters".

    The format would look something like this:

    param: min_production max_production min_stock_products max_stock_products :=
    p1     20             120            20                 100
    p2     10             110            20                 80
    p3     20             120            20                 80
    ;
    

    The only way I know of that keeps products as the column index would be to create a second index set parameter_type that matches your model parameter names, and then define "model_parameters" as a param indexed on both products and parameter_type. You could then use the method shown in AMPL Book 9.3 of the same reference:

    param model_parameters: p1   p2   p3   p4   p5 :=
    min_production          20   10   20   20   30 
    max_production          120  110  120  120  150 
    min_stock_products      20   20   20   20   20 
    max_stock_products      100  80   80   120  120 
    ;