6.9 Reading Index From External File

You can use data files when specifying indexes. Instead of the usual list of elements, enter the keyword INDEXFILE followed by a filename inside parentheses. If you use any characters in the filename, such as '-' and '#', that have special meaning to MPL, you can enter them by including the filename in double quotes (").

Example:

    INDEX
       product := INDEXFILE("product.dat");

The file is a free-format text file, in which the elements of the index are read in the order they appear. Separate the elements with commas or spaces. Everything inside curly braces and following an exclamation mark is treated as a comment.

Sometimes, the file you want to read the index elements from contains other columns of data. MPL allows you to specify which column is chosen for the index by adding a comma and a column number inside the parenthesis. For example, if the product index is stored in the first column of the product.dat file you would enter:


     INDEX
        product := INDEXFILE("product.dat", 1); 

Sample index file with one column for the product index and two data columns is shown below:


    prod1, 123.55, 245.90
    prod2, 347.00, 365.50
    prod3, 223.22, 389.60
    prod4, 439.50, 445.50 

Reading subset and multi-dimensional indexes from an index file is done in the same way as for normal indexes. The only difference is that each entry in the index file needs to contain the elements for each of the domain indexes. The entry in the model file is the same way as before.


     INDEX
        FactoryMachine[factory,machine] := INDEXFILE("factmach.dat");

Here is a sample index file with two columns, one for factory and one for machine:


    fac1, mach1,
    fac2, mach2,
    fac2, mach3,
    fac3, mach4,
    fac3, mach5, 

Back To Top | Maximal Home Page | Table of Contents | Previous Page | Next Page