286 int idx = luaL_checkinteger( L, 2 );
287 const char *name = luaL_checkstring( L, 3 );
288 double coef = luaL_checknumber( L, 4 );
289 const char *skind = luaL_optstring( L, 5,
"real" );
290 int haslb = !lua_isnoneornil( L, 6 );
291 int hasub = !lua_isnoneornil( L, 7 );
292 double lb = luaL_optnumber( L, 6, 0.0 );
293 double ub = luaL_optnumber( L, 7, 0.0 );
294 int type = GLP_FR, kind = GLP_CV;
297 glp_set_col_name( lp->
prob, idx, name );
298 glp_set_obj_coef( lp->
prob, idx, coef );
301 if ( haslb && hasub ) {
302 if ( fabs( lb - ub ) < DOUBLE_TOL )
312 glp_set_col_bnds( lp->
prob, idx, type, lb, ub );
315 if ( strcmp( skind,
"real" ) == 0 )
317 else if ( strcmp( skind,
"integer" ) == 0 )
319 else if ( strcmp( skind,
"binary" ) == 0 )
322 return NLUA_ERROR( L, _(
"Unknown column kind '%s'!" ), skind );
323 glp_set_col_kind( lp->
prob, idx, kind );
385 luaL_checktype( L, 2, LUA_TTABLE );
386 luaL_checktype( L, 3, LUA_TTABLE );
387 luaL_checktype( L, 4, LUA_TTABLE );
390 n = lua_objlen( L, 2 );
392 if ( ( n != lua_objlen( L, 3 ) ) || ( n != lua_objlen( L, 4 ) ) )
393 return NLUA_ERROR( L, _(
"Table lengths don't match!" ) );
397 ia = calloc( n + 1,
sizeof(
int ) );
398 ja = calloc( n + 1,
sizeof(
int ) );
399 ar = calloc( n + 1,
sizeof(
double ) );
400 for (
size_t i = 1; i <= n; i++ ) {
401 lua_rawgeti( L, 2, i );
402 lua_rawgeti( L, 3, i );
403 lua_rawgeti( L, 4, i );
405 ia[i] = luaL_checkinteger( L, -3 );
406 ja[i] = luaL_checkinteger( L, -2 );
407 ar[i] = luaL_checknumber( L, -1 );
409 ia[i] = lua_tointeger( L, -3 );
410 ja[i] = lua_tointeger( L, -2 );
411 ar[i] = lua_tonumber( L, -1 );
417 glp_load_matrix( lp->
prob, n, ia, ja, ar );
648 Uint64 starttime = SDL_GetTicks64();
652 ismip = ( glp_get_num_int( lp->
prob ) > 0 );
653 glp_init_smcp( &parm_smcp );
654 parm_smcp.msg_lev = GLP_MSG_ERR;
657 glp_init_iocp( &parm_iocp );
658 parm_iocp.msg_lev = GLP_MSG_ERR;
663 if ( !lua_isnoneornil( L, 2 ) ) {
664 GETOPT_SMCP( meth, opt_meth, METH_DEF );
665 GETOPT_SMCP( pricing, opt_pricing, PRICING_DEF );
666 GETOPT_SMCP( r_test, opt_r_test, R_TEST_DEF );
667 GETOPT_SMCP( presolve, opt_onoff, PRESOLVE_DEF );
669 GETOPT_IOCP( br_tech, opt_br_tech, BR_TECH_DEF );
670 GETOPT_IOCP( bt_tech, opt_bt_tech, BT_TECH_DEF );
671 GETOPT_IOCP( pp_tech, opt_pp_tech, PP_TECH_DEF );
672 GETOPT_IOCP( sr_heur, opt_onoff, SR_HEUR_DEF );
673 GETOPT_IOCP( fp_heur, opt_onoff, FP_HEUR_DEF );
674 GETOPT_IOCP( ps_heur, opt_onoff, PS_HEUR_DEF );
675 GETOPT_IOCP( gmi_cuts, opt_onoff, GMI_CUTS_DEF );
676 GETOPT_IOCP( mir_cuts, opt_onoff, MIR_CUTS_DEF );
677 GETOPT_IOCP( cov_cuts, opt_onoff, COV_CUTS_DEF );
678 GETOPT_IOCP( clq_cuts, opt_onoff, CLQ_CUTS_DEF );
683 parm_smcp.meth = METH_DEF;
684 parm_smcp.pricing = PRICING_DEF;
685 parm_smcp.r_test = R_TEST_DEF;
686 parm_smcp.presolve= PRESOLVE_DEF;
688 parm_iocp.br_tech = BR_TECH_DEF;
689 parm_iocp.bt_tech = BT_TECH_DEF;
690 parm_iocp.pp_tech = PP_TECH_DEF;
691 parm_iocp.sr_heur = SR_HEUR_DEF;
692 parm_iocp.fp_heur = FP_HEUR_DEF;
693 parm_iocp.ps_heur = PS_HEUR_DEF;
694 parm_iocp.gmi_cuts = GMI_CUTS_DEF;
695 parm_iocp.mir_cuts = MIR_CUTS_DEF;
696 parm_iocp.cov_cuts = COV_CUTS_DEF;
697 parm_iocp.clq_cuts = CLQ_CUTS_DEF;
703 if ( !ismip || !parm_iocp.presolve ) {
704 ret = glp_simplex( lp->
prob, &parm_smcp );
705 if ( ( ret != 0 ) && ( ret != GLP_ETMLIM ) ) {
707 lua_pushstring( L, linopt_error( ret ) );
711 ret = glp_get_status( lp->
prob );
712 if ( ( ret != GLP_OPT ) && ( ret != GLP_FEAS ) ) {
714 lua_pushstring( L, linopt_status( ret ) );
719 ret = glp_intopt( lp->
prob, &parm_iocp );
720 if ( ( ret != 0 ) && ( ret != GLP_ETMLIM ) ) {
722 lua_pushstring( L, linopt_error( ret ) );
726 ret = glp_mip_status( lp->
prob );
727 if ( ( ret != GLP_OPT ) && ( ret != GLP_FEAS ) ) {
729 lua_pushstring( L, linopt_status( ret ) );
733 z = glp_get_obj_val( lp->
prob );
736 lua_pushnumber( L, z );
740 for (
int i = 1; i <= lp->
ncols; i++ ) {
742 z = glp_mip_col_val( lp->
prob, i );
744 z = glp_get_col_prim( lp->
prob, i );
745 lua_pushnumber( L, z );
746 lua_rawseti( L, -2, i );
751 for (
int i = 1; i <= lp->
nrows; i++ ) {
753 z = glp_mip_row_val( lp->
prob, i );
755 z = glp_get_row_prim( lp->
prob, i );
756 lua_pushnumber( L, z );
757 lua_rawseti( L, -2, i );
763 NLUA_WARN( L, _(
"glpk: too over 1 second to optimize!" ) );