0

I've got many text (.txt) files that looks like this:

#camiones disponibles
set K:= 1 2 3;

#capacidades de camiones
param Q:=
1 20000
2 15000
3 10000
;

#demanda por tipo de leche
param D:=
26800
11700
2500

;

#costos de transporte
param c[*,*]
: 1000  1   2   3   4   5   6   7

1000    0   35  78  76  98  55  52  37
1   35  0   60  59  91  81  40  13
2   78  60  0   3   37  87  26  48
3   76  59  3   0   36  83  24  47
4   98  91  37  36  0   84  51  78
5   55  81  87  83  84  0   66  74
6   52  40  26  24  51  66  0   28
7   37  13  48  47  78  74  28  0

From my understanding this is an OPL Data file. Each one of these text files are an instance, and every one of them has the same variables. I need to read one text file at a time.

I'm trying to get each variable definition into a python variable, such as a numpy array or a pandas data frame.

  • are the files consistently formatted? is this a variable declaration param D:=, as well as set K:= 1 2 3;? – Captain Caveman Dec 09 '22 at 02:30
  • @CaptainCaveman yes, all files are formatted the same, and also yes. I should get an array for every variable, something like D=[26800,11700,2500] and K=[1,2,3] https://github.com/elimail/Gradual-Milk-Blending-Instances this is where I'm getting the data – Gonzalo Luarte Dec 09 '22 at 04:03

1 Answers1

1

This data file is Not opl format but ampl. So what you could do is use ampl to read the file and then from ampl Write that data in any Format you Need

https://portal.ampl.com/docs/archive/first-website/BOOK/CHAPTERS/15-display.pdf#page=33

Alex Fleischer
  • 9,276
  • 2
  • 12
  • 15