使用lp slover的例子

lprec* lp;
uint64_t num = 6144570;
std::vector row(num+1, 0.0);
lp = make_lp(0,num);

set_add_rowmode(lp, FALSE);
for(int i=1; i<num; i++){
    row[i] = i;
}
row[num] = -1e10;
set_obj_fn(lp, &row.front());
set_maxim(lp);

for(int i=0; i<num; i++){
    row[i] = 1.0;
}
row[num] = 0.0;

set_add_rowmode(lp,TRUE);
add_constraint(lp,&row.front(),LE,num/4);
set_add_rowmode(lp,TRUE);
for(int i=0; i<num; i++){
    set_binary(lp, i, TRUE);
}
set_int(lp, num, TRUE);
set_add_rowmode(lp,FALSE);
set_verbose(lp, FULL);
static char kBfpConfigurationString[] = "bfp_LUSOL";     //求解solver
set_BFP(lp, kBfpConfigurationString);
set_scaling(lp, SCALE_CURTISREID);
// Example presolver call from lp_solve documentation.
set_presolve(
    lp, PRESOLVE_ROWS | PRESOLVE_COLS | PRESOLVE_LINDEP,
    get_presolveloops(lp));    //

// It seems NODE_RANGESELECT does to trick for the optimizer to realize it
// need to adapt the slack variable. Other flags are default ones for
// lp_solve.
set_bb_rule(
    lp,
    NODE_RANGESELECT | NODE_GREEDYMODE | NODE_DYNAMICMODE | NODE_RCOSTFIXING);

int ret = solve(lp);   //求解solver

printf("Objective value: %f\n", get_objective(lp));

REAL* variables_ptr;
get_ptr_variables(lp, &variables_ptr);
std::cout << "variables_ptr " << variables_ptr[0] << " " << variables_ptr[1] << " " << variables_ptr[2] << std::endl;
delete_lp(lp);
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值