GLPK for Java中的输入/输出 [英] Input/output in GLPK for Java

查看:407
本文介绍了GLPK for Java中的输入/输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我找到了很多关于Java的GLPK示例,它们涉及如何为求解器指定模型(问题/约束)并从数据文件中读取参数,但是关于编程参数输入/输出的知识很少. 就我而言,我需要以编程方式向背包问题提交值(权重和值的数组),并对解决方案进行后处理(对找到的解决方案进行附加的数值检查),以便决定是否继续进行. 考虑一下相当于从数据文件读取param:行而无需调用glp_mpl_read_data或将解决方案的详细信息打印到文件而无需调用glp_print_mip/sol/itp的情况. 您可以提供示例代码还是将我指向正确的资源?

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?

推荐答案

这只是部分答案.我设法使用

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

功能如以下示例所示

    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.

这篇关于GLPK for Java中的输入/输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆