in reply to Re^2: GLPK integration
in thread GLPK integration

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.

Replies are listed 'Best First'.
Re^4: GLPK integration
by jo37 (Curate) on Jan 17, 2026 at 20:35 UTC

    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.

        I have a simple mathprog program which is run on hundreds of data items of the same form (a 3-vector).

        Ok, I understand. I assumed you were providing a general purpose module. Please ignore my hypercritical comments.

        Solving your task using PDL::Opt::GLPK might be easier than you think. If you provided a few examples that shall be solved simultaneously, I could write you a sub that solves these using the PDL module. You wouldn't have to deal with PDL at all elsewhere.

        Greetings,
        🐻

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