Input/output in GLPK for Java

流过昼夜 提交于 2019-12-13 16:50:09

问题


I find a lot of GLPK for Java examples about how to specify the model (problem/constraints) to the solver and read parameters from a data file, but very little about programmatic parameter input/output. In my case I need to submit values (array of weights and values) to a knapsack problem programmatically and postprocess the solution as well (perform addtional numeric checks on the solution found) in order to decide whether to proceed or not. Think of the equivalent of reading a param: line from a data file without calling glp_mpl_read_data or printing details of a solution to a file without calling glp_print_mip/sol/itp. Can you provide example code or point me to the right resource?


回答1:


This is only a partial answer. I managed to solve the output part using the

GLPK.get_ipt_obj_val
GLPK.get_mip_obj_val
GLPK.get_ipt_col_val
GLPK.get_mip_col_val

functions as in the following example

    static void writeMipSolution(glp_prob lp) {

    String name = GLPK.glp_get_obj_name(lp);
    double val = GLPK.glp_mip_obj_val(lp);

    System.out.println(name + " = " + val);

    int n = GLPK.glp_get_num_cols(lp);

    for (int i = 1; i <= n; i++) {
        name = GLPK.glp_get_col_name(lp, i);
        val = GLPK.glp_mip_col_val(lp, i);
        System.out.println(name + " = " + val);
    }
}

Still investigating the input part, though.



来源:https://stackoverflow.com/questions/36158637/input-output-in-glpk-for-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!