[Python] GLPK sensitivty result parsing with PULP

Discussão em 'Python' iniciado por Stack, Agosto 3, 2025.

  1. Stack

    Stack Membro Participativo

    I am trying to figure out how to read the GLPK sensitivity results back into Python

    An example of how i am generating it:

    import pulp
    from pulp import LpStatus, value
    from glpk_sensitivity_parser import parse_sensitivity

    prob = pulp.LpProblem("TEST", pulp.LpMaximize)

    D = pulp.LpVariable("D", lowBound=0)
    P = pulp.LpVariable("P", lowBound=0)

    prob += 10 * D + 15 * P, "Objective"
    prob += 2 * D + 4 * P <= 100, "aluminium"
    prob += 3 * D + 2 * P <= 80, "steel"

    prob.solve()

    temp_file_name = f"sensitivity_LP_problem.sen"

    prob.solve(pulp.GLPK(options=['--ranges', f'{temp_file_name}']))


    This then generates a file which is humanly readable with 2 lines containing the bounds and sensitivities I need. Something like this:

    [​IMG]

    However... in my real problem, this becomes a 3 line problem like this:

    [​IMG] and its been a bit of a nightmare writing a parser (also like in the example, the first line has an empty entry but in the text file there is nothing there, so I have to know how many columns there are. It is all doable I guess but what if i eventually run this and its 4 or 5 lines all of a sudden due to some reason.

    I feel there must be a better/cleaner way of doing this than I am doing.

    So the question is, can i access the data before it gets put into this file format?

    Continue reading...

Compartilhe esta Página