Re: Loading matrix param from Excel table in GLPK

Heinrich Schuchardt <[email protected]>
Newsgroups gmane.comp.gnu.glpk
Message-ID <[email protected]>
Hello Rodolfo,

I guess it would be a better idea to format the CSV such that C1 and C2
values go into columns:

ITU,AGU,5
ITU,CEN,6
PMO,AGU,7
PMO,CEN,8

Otherwise use:

set D, dimen 3;
set C2;
set C1 := setof{(i,j,k) in D} i;
param traffic_st{i in C1, j in C2} >=0 :=
  if j = "AGU" then sum{(i,k,l) in D} k else sum{(i,k,l) in D} l;
table t1 IN "CSV" "foo.csv" :
D <- [IDX, AGU, CEN];
display traffic_st;
data;
set C2:=AGU CEN;
end;

with foo.csv:

IDX,AGU,CEN
ITU,5,6
PMO,7,8

Please, be aware that GLPK for Windows 4.61 comes with examples for
using the GLPK library with Visual Basic for Applications (VBA).

Best regards

Heinrich
On 03/10/2017 09:00 PM, Rodolfo Grosso wrote:
> Hi,
> 
> I want to pass matrix values contained in excel file or csv to a
> matrix parameter, for example, Excel table:
>          AGU    CEN
> ITU      5    6
> PMO   7    8
> 
> 
> 
> So that I can read  through the parameter traffic:
> 
> traffic[ITU,AGU]=5
> traffic[PMO,AGU]=7
> ...
> 
> In the real case there are many values.
> 
> For this, I made the following code, but it did not work:
> 
> set C1;
> set C2;
> param traffic_st{C1,C2} >=0;
> 
> table data IN "CSV" "traffic_st1.csv":
> [i ~ C1], {j in C2} <traffic_st[i,j] ~ (j)>;
> 
> and I define C2 in .dat file like:
> 
> set C2:=AGU CEN;
> 
> 
> Thank you in advance for your help
> 
> 
> Best regards.
> Rodolfo
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.