## AMPL Session from Lecture 25, 11/12/2024 # We illustrate the use of 'read' command to read in data saved as # text files on the Killer Drugs LP example. # We have the Compos matrix parameter saved in a text file titled # Compos.txt, available in the present working directory along with # the model and data files. Just to ensure the data is read in # correctly, we change some of the values of Compos as listed in this # file: # 0.34 0.61 0.53 # 0.07 0.11 0.09 # 0.14 0.09 0.72 # 0.04 0.05 0.11 ampl: reset; model KillerDrugsDoozey.mod.txt; data KillerDrugsDoozey.dat.txt; ampl: display Compos; Compos := 1 A 0.04 1 B 0.08 1 C 0.03 2 A 0.07 2 B 0.11 2 C 0.09 3 A 0.14 3 B 0.09 3 C 0.12 4 A 0.04 4 B 0.05 4 C 0.11 ; # Note that these are the values originally listed in the data file # We now read in the data from Compos.txt: ampl: read {i in 1..nChem, j in Ingreds} Compos[i,j] < Compos.txt; ampl: close Compos.txt; # It's a good idea to "close" the file after reading from it is # finished---especially if you're going to read from a different file # afterward. ampl: display Compos; Compos := 1 A 0.34 1 B 0.61 1 C 0.53 2 A 0.07 2 B 0.11 2 C 0.09 3 A 0.14 3 B 0.09 3 C 0.72 4 A 0.04 4 B 0.05 4 C 0.11 ; ampl: