jo37 has asked for the wisdom of the Perl Monks concerning the following question:

Hello nuns and monks!

Seemingly there is no Perl module that provides an interface to the GNU Linear Programming Kit (GLPK). Actually, its usage is not that easy as there lots of functions that have to be combined in the proper way. However, the Octave project managed to design an universal interface to GLPK in a single function.

So I thought about porting this interface to Perl and finally managed to implement it. The Octave implementation was a great help in this task as the core function that orchestrates the GLPK functions could be reused as-is. You can find my first attempt at GitHub.

I'd be glad to hear some opinions about this module, and I have a question: What is the policy for publishing a module on CPAN into an existing namespace hierarchy? I named the module PDL::Opt::GLPK, but I'm not sure if I need some consent to publish it.

Edit: Added GLPK link

Greetings,
🐻

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

Replies are listed 'Best First'.
Re: GLPK integration
by hippo (Archbishop) on Feb 16, 2024 at 16:43 UTC
    What is the policy for publishing a module on CPAN into an existing namespace hierarchy?

    I have done this before and my approach has been to contact the maintainer of the immediate parent in the hierarchy to solicit their views prior to publishing as it seems only polite. It has proven beneficial too in that they have suggested some changes to the proposed names for future-proofing, etc. I therefore recommend this approach to others thinking of doing the same.


    🦛

Re: GLPK integration
by jo37 (Curate) on Feb 22, 2024 at 12:10 UTC

    Published PDL::Opt::GLPK.

    Greetings,
    🐻

    $gryYup$d0ylprbpriprrYpkJl2xyl~rzg??P~5lp2hyl0p$
      Why not make a post here intended as "Perl News"? I think it's quite a big deal!
Re: GLPK integration
by etj (Priest) on Feb 20, 2024 at 12:52 UTC
    No consent is needed in PDL-land, but asking for thoughts is probably always a good idea.

    jo37 opened a GitHub issue last year doing exactly that, and I've followed up on it with thoughts based on this implementation: https://github.com/PDLPorters/pdl/issues/437

Re: GLPK integration
by bliako (Abbot) on Jan 15, 2026 at 14:32 UTC

    Hello jo37 a big thank you for porting GLPK to Perl/PDL.

    I was wondering whether it is possible as it is to specify the problem as a MathProg program (e.g. https://iuuk.mff.cuni.cz/~bohm/texts/mathprog_intro.html).

    I know there is examples/glpsol.c in the GLPK distribution which produces an executable which accepts a MathProg program and solves it. I guess it breaks down the program directives into GLPK API calls somehow, but it is too complex for me to decypher. I was wondering if you know if there is GLPK API call to do this.

    I have modified trivially examples/glpsol.c so as to provide glpsol(int argc, char **argv) which then I provide via XS to Perl (published here https://github.com/hadjiprocopis/perl-algorithm-glpk-glpsol). This is better than shelling out to glpsol executable but it is quite lame not only because it works like the executable, with a CLI params array but also it requires the program to be written to disk and it writes the solution to disk as well. So, I am looking for a better solution, namely a proper GLPK API function which reads in MathProg and outputs solution matrix.

    bw, bliako

      Hello bliako,

      first of all thank you for pointing to the POD errors. Just published a new release.

      I'm afraid I cannot answer your question as I'm not an expert on GLPK at all. Actually, I never used it directly. The module uses a copy of a C function from Octave's core to connect to GLPK. This way I could call GLPK from PDL without any knowledge of the former. Though the Octave-to-GLPK API has a lot of parameters, I found it much easier to use than GLPK itself.

      You may call it laziness, but isn't that one of a programmer's virtues? 😉

      Greetings,
      🐻

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

      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$

        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.