Forum Discussion
FICO
8 years agoCommunity Manager
Sum duplicate entries from input data file
Is there a command to sum duplicate entries from an input data file in an "initializations from..." block?
For example, if I have a file input.dat:
Cost: [
(A) 1
(A) 2
(B) 5
]
and my Mosel code contains:
declarations
Materials: set of string
Cost: array(Materials) of real
end-declarations
initializations from "input.dat"
Cost
end-initializations
forall(m in Materials) writeln(m + " costs: " + Cost(m))
I'd like to see that Material "A" costs 3 ( = 1+2 ), but will instead see that it costs 2 (only the last duplicate value in the data file overwrites all previous duplicates). I understand that this is intended behavior, and that I could seek to do the summation on my data source, but is there an easy way to do this in Mosel?
1 Reply
- FICOCommunity Manager
The 'initializations' format does not allow you to use the same index multiple times for the same table. If you can distribute the multiple occurrences within your data into several tables you could read these into some temporary structures and later add them.
Otherwise, the only possibility I see for implementing this behaviour would be to write your own data reading routine, such as in these examples:
https://examples.xpress.fico.com/example.pl?id=readfile
FICO Xpress Optimization Examples Repository: Parsing a CSV-format data file (https://examples.xpress.fico.com/example.pl?id=readcsv)
Related Content
Related Content
?1030Error: Duplicate column names
I was adding some variables to the problem but is showed error telling there are duplicate columns in variable. I have created a small code to reproduce the error which is as follows. import xpress...4 years agoPlace FICO® Xpress Optimization ForumFICO® Xpress Optimization Forum1 unread comment1 unread0Views0likes1CommentData Input from Excel
Hello, I am having trouble reading the data from an excel spreadsheet into my model. I get the error message saying "wrong number of columns". I tried the following: It also didn't work wh...2 years agoPlace FICO® Xpress Optimization ForumFICO® Xpress Optimization Forum2 unread comments2 unread0Views0likes2Comments