[Top][All Lists]

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

Re: [Help-glpk] CSV output?

From: glpk xypron
Subject: Re: [Help-glpk] CSV output?
Date: Mon, 26 Jul 2010 08:09:24 +0200

Hello Kevin,

you can write the solution in the postsolution phase using
the printf command,


printf "Row name,Status,Lower bound,Upper bound,Dual" > out.txt;
printf "cost,%i,%g,%g,%g",
  cost.status,, cost.ub, cost.dual >> out.txt;
printf{s in S} "supply[%s],%i,%g,%g,%g",
  s, supply[s].status, supply[s].lb, suppy[s].ub, supply[s].dual >> out.txt;

You can write the same information to a CSV files or to a SQL
data base using the table command.

If you want to reuse the solution in a separate program
I think using a SQL data base is the best solution, because
there will be no need to parse a flat file.


The output functionality you have been using is coded in
glpk-4.44/src/glpapi11.c in the following routines:
- glp_print_mip
- glp_print_ipt
- glp_print_sol

When thinking about a different output format please, have a
look at file formats that already exist like

CPLEX SOL file format

Best regards


-------- Original-Nachricht --------
> Datum: Sun, 25 Jul 2010 16:27:40 -0600
> Betreff: [Help-glpk] CSV output?

> Hello List,
> I'm attempting to programmatically parse the solution output from GLPK. 
>   From what I currently see, there's no way to unambiguously parse the 
> output because of a lack of delimiters.  The only "mostly correct" way 
> that I see is to use column indices.  The problem with this is if the 
> value exceeds the column width, parsing gets much more difficult.
> What I would like would be an unambiguous format like what CSV could 
> provide.  For example, the 1st example below could be unambiguously (and 
> much more easily) parsed if presented as a CSV:
> $ glpsol ... --output solution.soln
> $ cat solution.soln | grep -A3 'No.   Row name'
>     No.   Row name   St   Activity     Lower bound   Upper bound   
> Marginal
> ------ ------------ -- ------------- ------------- ------------- 
> -------------
>       1 cost         B        153.675
>       2 supply[Se]   B            300                         350
> $ glpsol ... --output_format csv --output solution.soln
> $ cat solution.soln | grep -A3 'No.,Row name'
> No.,Row name,St,Activity,Lower bound,Upper bound,Marginal
> 1,cost,B,153.675,,,
> 2,supply[Se],B,300,,350,
> (Please excuse the email formatting, if possible.  If not, I can resend 
> the output as an attachment so that it won't get muddled.)
> This also has the virtue of
>   - Creating a smaller output file
>   - The output can more easily be understood by a multitude of tools
>     and libraries (for instance, Excel/Calc, scripting CSV libraries,
>     etc.).  Less ad-hoc and specific parsing necessary.
>   - Making unambiguous output, for example, like what currently happens
>      - when row name exceeds 12 characters,
>      - if a string representation of a value exceeds the column width,
>      - or if a value is not specified (like index 2, lower bound)
>   - Keeping the "human readable" names of constraints and variables,
>     unlike the -w output format
> Is there another way to unambiguously represent the solution output?  If 
> not, and if CSV would be welcomed by the developers, I'm happy to create 
> a patch.
> Thanks,
> Kevin

GRATIS für alle GMX-Mitglieder: Die maxdome Movie-FLAT!
Jetzt freischalten unter

reply via email to

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