Hello Jean-Christophe, the data you provide is insufficient for an analysis. What is needed is the actual problem or at least the relevant debug output of glp_simplex().
The term_hook() function in https://sourceforge.net/p/winglpk/code/HEAD/tree/trunk/examples/vba/glpk.bas is printing to the debug console. What is the output of glp_simplex when stalling? Inside the terminal hook function you could call glp_error() when a problem takes too long. This would allow you to gracefully terminate at least. Or call do_events in the terminal hook function to allow stopping via the debug controls. You could use function gpl_write_prob(), glp_write_lp(), glp_write_mps() to save the current problem to disk betore calling glp_simplex(). When a problem "stalls" try to run the saved file with glpsol to see if for this instance the problem is reproducible outside of your VBA program. Best regards Heinrich On 2/27/19 5:42 PM, Huber, Jean-Christophe wrote: > Dear GLPK users, > > > > I developed a model using GLPK v64 dll from VBA in Excel. This model is > mapping several initial conditions and thus launches the solver in many > successive “nodes” of initial conditions. > > For some of them, even if seldom, we have a stalling problem within the > dll itself. We first tried removing the scaling option as it removes > most these occurrence but this is also not 100% OK. > > > > Are there some ways to know why the simplex is stalling? Or any way to > facilitate solutions with some options? > > > > At the moment, the only options I use are similar to the VBA example > given in V64 package (see below) > > > > Many thanks for any hints or advice! > > > > Regards > > Jean-Christophe Huber > > > > > > ' ************************************ > > ' link with dll calculation > > ' ************************************ > > > > '-- Management of solver errors > > On Error GoTo error0 > > > > ' Register error hook function > > glp_error_hook AddressOf error_hook > > > > ' Register terminal hook function > > glp_term_hook AddressOf term_hook > > > > > > '-- Creation of the calculation object > > lp = glp_create_prob() > > Name = str2bytes("glpVBA") > > glp_set_prob_name lp, Name(0) > > > > glp_term_out GLP_OFF > > > > '-- Variables names and bounds, objective cost and integer option > > ' Set the number of variables > > glp_add_cols lp, NbVariables > > > > ' Define each variable > > For variable_index = 1 To NbVariables > > ' set variable name > > Name = str2bytes(Variable_name(variable_index)) > > glp_set_col_name lp, variable_index, Name(0) > > > > ' set variable kind > > ' kind of structural variable: > > ' GLP_CV = 1 continuous variable > > ' GLP_IV = 2 long variable > > ' GLP_BV = 3 binary variable > > ' glp_set_col_kind lp, #col, #kind > > > > ' set variable type of bound and bounds values > > ' Bounds Management > > 'GLPK_FR free variable: -inf < x[k] < +inf > > 'GLPK_LO lower bound: l[k] <= x[k] < +inf >> ">=" > > 'GLPK_UP upper bound: -inf < x[k] <= u[k] >> "<=" > > 'GLPK_DB double bound: l[k] <= x[k] <= u[k] > > 'GLPK_FX fixed variable: l[k] = x[k] = u[k] >> "=" > > Select Case Variable_BoundType(variable_index) > > Case "FX" > > glp_set_col_bnds lp, variable_index, GLP_FX, > Variable_LoBound(variable_index), Variable_UpBound(variable_index) > > Case "UP" > > glp_set_col_bnds lp, variable_index, GLP_UP, 0, > Variable_UpBound(variable_index) > > Case "LO" > > glp_set_col_bnds lp, variable_index, GLP_LO, > Variable_LoBound(variable_index), 0 > > Case "FR" > > glp_set_col_bnds lp, variable_index, GLP_FR, 0, 0 > > Case "DB" > > If Abs(Variable_LoBound(variable_index) - > Variable_UpBound(variable_index)) <= epsilon Then > > glp_set_col_bnds lp, variable_index, GLP_FX, > Variable_LoBound(variable_index), Variable_UpBound(variable_index) > > Else > > glp_set_col_bnds lp, variable_index, GLP_DB, > Variable_LoBound(variable_index), Variable_UpBound(variable_index) > > End If > > End Select > > > > ' set objective cost for each variable > > glp_set_obj_coef lp, variable_index, > Variable_ObjectiveCost(variable_index) > > Next > > > > > > '-- Constraints names and bounds > > ' Set the number of constraints > > glp_add_rows lp, NbConstraints > > > > ' Define each constraint > > For constraint_index = 1 To NbConstraints > > ' set constraint name > > Name = str2bytes(Constraint_name(constraint_index)) > > glp_set_row_name lp, constraint_index, Name(0) > > > > ' set constraint type of bound and bounds values > > ' Bounds Management > > 'GLPK_FR free variable: -inf < x[k] < +inf > > 'GLPK_LO lower bound: l[k] <= x[k] < +inf >> ">=" > > 'GLPK_UP upper bound: -inf < x[k] <= u[k] >> "<=" > > 'GLPK_DB double bound: l[k] <= x[k] <= u[k] > > 'GLPK_FX fixed variable: l[k] = x[k] = u[k] >> "=" > > Select Case Constraint_BoundType(constraint_index) > > Case "FX" > > glp_set_row_bnds lp, constraint_index, GLP_FX, > Constraint_LoBound(constraint_index), Constraint_UpBound(constraint_index) > > Case "UP" > > glp_set_row_bnds lp, constraint_index, GLP_UP, 0, > Constraint_UpBound(constraint_index) > > Case "LO" > > glp_set_row_bnds lp, constraint_index, GLP_LO, > Constraint_LoBound(constraint_index), 0 > > Case "FR" > > glp_set_row_bnds lp, constraint_index, GLP_FR, 0, 0 > > Case "DB" > > glp_set_row_bnds lp, constraint_index, GLP_DB, > Constraint_LoBound(constraint_index), Constraint_UpBound(constraint_index) > > End Select > > Next > > > > > > '-- Matrix A coefficients values > > matrix_index = 0 > > For constraint_index = 1 To NbConstraints > > For variable_index = 1 To NbVariables > > matrix_index = matrix_index + 1 > > ia(matrix_index) = constraint_index > > ja(matrix_index) = variable_index > > Ar(matrix_index) = Matrix_val(constraint_index, variable_index) > > Next > > Next > > ' set coefficients of the A matrix > > glp_load_matrix lp, NbConstraints * NbVariables, ia(0), ja(0), Ar(0) > > > > > > ' Setting objectives > > Name = str2bytes("Cost") > > glp_set_obj_name lp, Name(0) > > > > If MinBool Then > > glp_set_obj_dir lp, GLP_MIN > > Else > > glp_set_obj_dir lp, GLP_MAX > > End If > > > > ' Scaling options > > ' GLP_SF_GM = &H1 ' perform geometric mean scaling > > ' GLP_SF_EQ = &H10 ' perform equilibration scaling > > ' GLP_SF_2N = &H20 ' round scale factors to power of two > > ' GLP_SF_SKIP = &H40 ' skip if problem is well scaled > > ' GLP_SF_AUTO = &H80 ' choose scaling options automatically > > ' Note >> not yet linked to dll, to be tested with glp_scale_prob > lp, GLP_SF_AUTO > > 'glp_scale_prob lp, GLP_SF_AUTO > > > > ' Solve model > > ret = glp_init_smcp(smcp) > > ret = glp_simplex(lp, smcp) > > > > > > '-- Getting results and linking to subroutine outputs > > ' Objective cost > > optim_ObjCost = glp_get_obj_val(lp) > > ' Variable values > > For variable_index = 1 To NbVariables > > optim_VarVal(variable_index) = glp_get_col_prim(lp, variable_index) > > Next > > ' Solver status > > SolverStatus = glp_get_status(lp) > > Select Case SolverStatus > > Case GLP_OPT > > StatusText = "Optimal" > > Case GLP_FEAS > > StatusText = "Feasible" > > Case GLP_INFEAS > > StatusText = "Infeasible" > > Case GLP_NOFEAS > > StatusText = "No feasible" > > Case GLP_UNBND > > StatusText = "Unbounded" > > Case GLP_UNDEF > > StatusText = "Undefined" > > End Select > > > > '-- Close solver > > ' Free memory > > glp_delete_prob lp > > ' Deregister error hook function > > glp_error_hook 0, 0 > > > > > > > > > _______________________________________________ > Help-glpk mailing list > Help-glpk@gnu.org > https://lists.gnu.org/mailman/listinfo/help-glpk > _______________________________________________ Help-glpk mailing list Help-glpk@gnu.org https://lists.gnu.org/mailman/listinfo/help-glpk