Hi,
I am trying to upload data from a csv file to define sets and parameters. I have a.mod and .run file that works to return max parameter volume when I have just one index column (Hour). But when I try to add another index column (Day) I get a syntax error. My goal is to have the set Day that is comprised of hourly parameters (consumption and insolation).
#Model code
set Day;
set Hour;
param consumption{Hour} >=0;
param max_consumption:= max{i in Hour} consumption[i];
#run code
model csvtest.mod;
table hourpour IN "amplcsv" "testload.csv": Day <-[Day], Hour <-[Hour], consumption;
read table hourpower;
display max_consumption;
The error message:
context: table hourpour IN "amplcsv" "testload.csv":
Day <-[Day], >>> Hour <<< <-[Hour], consumption;
Data is formatted with 4 columns Day Hour consumption and insolation. Day and hour are indices
Thank you and sorry for any formatting issues in this post!
For each d in Day and h in Hour, does your data have a value consumption[d,h] and a value insolation[d,h]? Then your data could be defined in the AMPL model like this:
set Day;
set Hour;
param consumption {Day,Hour} >= 0;
param insolation {Day,Hour} >= 0;
There’s a discussion of reading similar data, in this topic: Reading two sets and 2D data in matrix from one sheet in Excel. It refers to a “2D” spreadsheet table, but the same approach works just as well for a csv table with two index columns and two value columns, like you describe. The table statement would be set up something like this:
set DayHour dimen 2;
set Day = setof {(i,j) in DayHour} i;
set Hour = setof {(i,j) in DayHour} j;
param consumption {Day,Hour} >= 0;
param insolation {Day,Hour} >= 0;
table dayhour IN "amplcsv" "testload.csv":
DayHour <- [Day,Hour], consumption, insolation;
(If you want the data to be defined differently in AMPL, however, then please show the set and param statements that you have in mind.)