I translated the program in C, and I am having the same trouble, so I
guess there is no problem with python-glpk.
#include <stdio.h>
#include <stdlib.h>
#include <glpk.h>

int main(int argc, char ** argv) {
    // PROBLEM
    glp_prob *prob;
    prob = glp_create_prob();
    glp_set_prob_name(prob, "mip");

    // VARIABLES
    glp_add_cols(prob, 3);
    // 0 <= x <= 4, continuous
    glp_set_col_name(prob, 1, "x");
    glp_set_col_bnds(prob, 1, GLP_DB, 0.0, 4.0);
    // -1 <= y <= 1, continuous
    glp_set_col_name(prob, 2, "y");
    glp_set_col_bnds(prob, 2, GLP_DB, -1.0, 1.0);
    // 0 <= z, integer
    glp_set_col_name(prob, 3, "z");
    glp_set_col_bnds(prob, 3, GLP_LO, 0.0, 0.0);
    glp_set_col_kind(prob, 3, GLP_IV);

    //OBJECTIVE
    glp_set_obj_coef(prob, 1, 1.0);
    glp_set_obj_coef(prob, 2, 4.0);
    glp_set_obj_coef(prob, 3, 9.0);

    // CONSTRAINTS
    glp_add_rows(prob, 3);
    // c1: x + y <= 5
    {
        int l = 2;
        int ind [l + 1];
        double val[l + 1];
        ind[1] = 1; ind[2] = 2;
        val[1] = 1.0; val[2] = 1.0;
        glp_set_mat_row(prob, 1, l, ind, val);
        glp_set_row_bnds(prob, 1, GLP_UP, 0.0, 5.0);
        glp_set_row_name(prob, 1, "c1");
    }
    // c2: x + z >= 10
    {
        int l = 2;
        int ind [l + 1];
        double val[l + 1];
        ind[1] = 1; ind[2] = 3;
        val[1] = 1.0; val[2] = 1.0;
        glp_set_mat_row(prob, 2, l, ind, val);
        glp_set_row_bnds(prob, 2, GLP_LO, 10.0, 0.0);
        glp_set_row_name(prob, 2, "c2");
    }
    // c3: -y + z == 7.5
    {
        int l = 2;
        int ind [l + 1];
        double val[l + 1];
        ind[1] = 2; ind[2] = 3;
        val[1] = -1.0; val[2] = 1.0;
        glp_set_mat_row(prob, 3, l, ind, val);
        glp_set_row_bnds(prob, 3, GLP_FX, 7.5, 7.5);
        glp_set_row_name(prob, 3, "c3");
    }

    //write problem
    glp_write_lp(prob, NULL, "obtained.lp");

    // delete it
    glp_delete_prob(prob);
    return 0;
}
_______________________________________________
Help-glpk mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/help-glpk

Reply via email to