Read data from .txt file

questions about GAMS' tools
Post Reply
perea@eio.upv.es
User
User
Posts: 9
Joined: 6 years ago

Read data from .txt file

Post by perea@eio.upv.es »

Hello!

Is there a way to read data from a .txt file, without having to transform such file into GAMS sintaxis?

For example, I want to read this instance of a scheduling problem

***********************
120 300 11 20
18 4 15 200 1000 2000 83 2 5 16 11 8 7
34 5 11 200 1000 2000 37 2 5 10 7 5 4
17 6 11 200 1000 2000 104 2 5 7 5 4 3
28 7 15 200 1000 2000 69 2 5 11 8 6 5
27 14 20 200 1000 2000 42 2 5 10 7 5 4
17 40 46 200 1000 2000 37 2 5 9 6 5 4
19 40 46 200 1000 2000 112 2 5 9 6 5 4
33 73 82 200 1000 2000 67 2 5 14 10 7 6
25 78 87 200 1000 2000 19 2 5 13 9 7 6
31 83 88 200 1000 2000 118 2 5 7 5 4 3
25 87 102 200 1000 2000 69 2 5 24 16 12 10
34 91 96 200 1000 2000 117 2 5 7 5 4 3
32 100 103 200 1000 2000 102 2 5 5 4 3 2
29 105 111 200 1000 2000 90 2 5 9 6 5 4
30 115 120 200 1000 2000 79 2 5 8 5 4 3
25 116 121 200 1000 2000 60 2 5 6 4 3 3
20 130 142 200 1000 2000 9 2 5 18 12 9 8
35 147 155 200 1000 2000 99 2 5 11 7 6 5
28 149 158 200 1000 2000 10 2 5 13 9 7 6
28 158 167 200 1000 2000 97 2 5 14 9 7 6
***************************
where

First line:
<quay_length> <time_horizon> <num_cranes> <num_vessels>

Remaining lines: in each line, the data of a vessel
<length> <estimated_arrival_time> <desired_departure_time> <cost_unit_deviation_from_desired_position> <cost_unit_wait> <cost_unit_delay> <desired_position> <min_num_cranes> <max_num_cranes> <handling_time_for_min_num_cranes> ... <handling_time_for_max_num_cranes>

Thanks in advance!

Fede
User avatar
Renger
Posts: 639
Joined: 7 years ago

Re: Read data from .txt file

Post by Renger »

Hi
You could just use an include file (See the discussion here here).
Or save the table as in Excel and use gdxxrw (see here ).
Cheers
Renger
____________________________________
Enjoy modeling even more: Read my blog on modeling at The lazy economist
Post Reply