help-glpk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-glpk] Generate data section files for model (in GNU MathProg o


From: glpk xypron
Subject: Re: [Help-glpk] Generate data section files for model (in GNU MathProg or other languages)
Date: Thu, 10 May 2012 08:09:42 +0200

Hello Tony,

> For the use of the "printf" command, the fact is that I find it not very
> flexible. Indeed, I have to write in plain text what I want to write as
> param. The syntax is different when the param is a simple list of records
> or when it is tabbing data.
See example:

# Outputing results as GMPL data file
# Save model file as test.mod
# 1st run: glpsol -m test.mod
# 2nd run: glpsol -m test.mod -d test.dat

param f, symbolic := "test.dat";
set S, dimen 3 := { (0, 0, 1), (0, 1, 0), (1, 0, 0), (1, 1, 1) };
param p{(i, j, k) in S} := i + 2 * j + 4 * k;

set T, dimen 3;
param q{T};
param r;

printf "data;\n" > f;
# Output simple parameter
printf "data;\n" > f;
printf "param r := %f;\n", card(S) >> f;

# Output set
printf "set T :=\n" >> f;
for {(i,j,k) in S} {
  printf "%d, %d, %d%s", i, j ,k,
  if card(setof{(l, m, n) in S : l > i or m > j or n > k }(l, m, n)) > 0
  then ","
  else ";" >> f;
  printf "\n" >> f;
}

# Output indexed parameter
printf "param q :=\n" >> f;
for {(i,j,k) in S} {
  printf "[%d, %d, %d] %f%s", i, j ,k, p[i, j, k],
  if card(setof{(l, m, n) in S : l > i or m > j or n > k }(l, m, n)) > 0
  then ","
  else ";" >> f;
  printf "\n" >> f;
}

printf "end;\n" >> f;

display T;
display q;
display r;
end;

> When you mention the use of a database and the table statement, isn't it
> when you have one model and you want to run the solver on one set of data?
Anyway you will need some loop that calls the GLPK solver repeatedly. In this 
loop you have to pass some parameter that can be used in the SQL statements to 
select the relevant data. See
http://en.wikibooks.org/wiki/GLPK/Scripting_plus_MathProg

Best regards

Xypron

-------- Original-Nachricht --------
> Datum: Wed, 9 May 2012 23:03:28 +0200
> Betreff: Re: [Help-glpk] Generate data section files for model (in GNU 
> MathProg or other languages)

> Hi,
> 
> Thanks for your answer!
> 
> For the use of the "printf" command, the fact is that I find it not very
> flexible. Indeed, I have to write in plain text what I want to write as
> param. The syntax is different when the param is a simple list of records
> or when it is tabbing data.
> 
> When you mention the use of a database and the table statement, isn't it
> when you have one model and you want to run the solver on one set of data?
> I am interesting in running the solver many times (with my c++ program)
> through many records of data with only on model.
> 
> The use of table statement here is limited because the table statement
> cannot be used in the data section (not as far as I know). Or in that
> case,
> I would have to generate as many models as the number of data that I want
> to use by only changing the part related to table statement.As I want to
> keep in very simple (that is being able to use the program on different
> computer without having to copy whole bunch of data structure like a
> database), maybe the use of a CSV file would be better. In that case, if I
> keep following this table-statement solution, I would have many .mod file
> with one last line which initializes data. The table statement would be
> different for each file in the sense that each .mod file will be linked to
> different .csv files (like table data1 in "CSV" "data1.csv" ... , table
> data2 in "CSV" "data2.csv" ... ). However, I found this option still not
> as
> flexible as I want (maybe either I don't get want you mean, I work with
> glpk for only a month and with the basic functions, or I am too exigent).
> 
> Regards,

-- 
Empfehlen Sie GMX DSL Ihren Freunden und Bekannten und wir
belohnen Sie mit bis zu 50,- Euro! https://freundschaftswerbung.gmx.de



reply via email to

[Prev in Thread] Current Thread [Next in Thread]