in reply to Re: GLPK integration
in thread GLPK integration

Took a look at the sources of PDL::Opt::GLPK once again. There is glpk_aio.c, which is the mentioned copy from the Octave sources. This is the wrapper I utilized to link PDL to GLPK. It has a single C function that orchestrates the GLPK API calls and which is the interface that PDL::Opt::GLPK::glpk actually calls. In PDL::Opt::GLPK, the XS code to access it is generated from PD. You might use it in self-written XS code as well.

At least you might use it as a blueprint for your own code.

Greetings,
🐻

$gryYup$d0ylprbpriprrYpkJl2xyl~rzg??P~5lp2hyl0p$

Replies are listed 'Best First'.
Re^3: GLPK integration
by bliako (Abbot) on Jan 17, 2026 at 15:28 UTC

    ok thanks, your code demystifies how it is done. I will investigate how a MathProg translates to these matrices. Then passing the matrices to this convenient function will do the trick.

      Out of curiosity:
      What would be a use case to solve a linear program in MathProg format within a Perl program? My thoughts about it:

      If I had an LP in MathProg format, I'd use glpsol.
      Why would I want to feed it to a Perl wrapper?

      If I had some Perl data representing an LP, I could transform it into a format accepted by an LP solver and run the solver.
      Why would I want to convert it to MathProg instead?

      BTW: GLPK has a builtin MathProg generator. Just call the solver - it will generate the respective MathProg on request.

      Greetings,
      🐻

      $gryYup$d0ylprbpriprrYpkJl2xyl~rzg??P~5lp2hyl0p$
        Out of curiosity: What would be a use case to solve a linear program in MathProg format within a Perl program?

        I have a simple mathprog program which is run on hundreds of data items of the same form (a 3-vector). The data is entered by the user into the webserver and then results are html'ed and served through the webserver. The choice I have is to shell out to pglsol as many times as data items. Or shell out once with a shell script (this can be parallelised with gnu-parallel!) containing all the glpsol commands. I understand that transforming my MathProg to vectors/matrices your glpk() understands is the way to go. Just 1) I am experimenting still with the subject-to clauses and it is easier to do that in high-level MathProg, and 2) it's way more appealing for novices to write MathProg (or copy paste one) than filling out those cryptically-named vectors/matrices. BTW, for my use-case, all 1500 data items (i.e. running the same MathProg for 1500 different data items) are solved in less than a second, so speed is not an issue.

        glpsol has a function which reads a MathProg from a filehandle. I tried to convert it to using a string. But I did not persist much.