Reading from .txt without converting in .csv

194 views
Skip to first unread message

Luis Fernández Ruiz

unread,
Apr 25, 2016, 8:00:18 AM4/25/16
to AIMMS - The Modeling System
Hi,

I have one doubt in reading .txt.
In one project, I receive files in .xlsx and .txt. In other occasions, I usually converted this .txt into a .csv and then I read it as a .xlsx, but now I can´t do it this way because of the way the client send files to me.

I would be very grateful if you could help me with this problem. I have attached one example of the .txt that I receive.

Kind regards!

Luis
Test.txt

Marcel Hunting

unread,
Apr 25, 2016, 10:35:53 AM4/25/16
to AIMMS - The Modeling System
Hi,

AIMMS cannot read in that text file directly. You have to do some programming yourself to read this file in AIMMS. See for example the CFLP example which can be found here.

Best regards,

Marcel Hunting
AIMMS Optimization Specialist

André Gâmbaro

unread,
Apr 27, 2016, 1:26:24 PM4/27/16
to ai...@googlegroups.com
Hi Luis,
Your file looks like a CSV which could be converted... 
Anyway once I had to deal with many input files, each in a different format (one for deliveries inputs, other for vehicles data, and so on etc). 
At that time I wrote a generic text file processor in AIMMS, and then for each type of file a used a procedure to save specific data in aimms.

Basically 
1) I read all text file to a String parameter: Ps_FileData := FileRead( Ps_filename ); 
2) One auxiliary procedure breaks it in many lines; saving it to a string parameter indexed in a integer set (Set_NumberOfLines).
3) Loop at each line:
3.1) An auxiliary procedure breaks the current line looking for the valid separators, saving each field in another string parameter indexed in a integer set (Set_FieldsCount), which count how many fields we have in that line;
3.2) save each field in a relevant AIMMS parameter, converting to number when necessary.
example:
P_X(Cliente) := P_TMP_Parametros('2');
P_Y(Cliente) := P_TMP_Parametros('3');


Overall it was not so slow. 
One problem: It seems that each text file should fit the string parameter at once (don't know how big...)

Hope it helps

André Gambaro




--
You received this message because you are subscribed to the Google Groups "AIMMS - The Modeling System" group.
To unsubscribe from this group and stop receiving emails from it, send an email to aimms+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Luis Fernández Ruiz

unread,
Apr 28, 2016, 6:03:38 AM4/28/16
to AIMMS - The Modeling System
Hi, 

Thanks to your help, I think I can figure out one way to read this files properly.

Thank you very much to both of you!

Luis 
Reply all
Reply to author
Forward
0 new messages