java glpk,GLPK for Java中的输入/输出

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

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.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值