help-glpk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Help-glpk] stalled GLPK when launching ret = glp_simplex in VBA


From: Huber, Jean-Christophe
Subject: [Help-glpk] stalled GLPK when launching ret = glp_simplex in VBA
Date: Thu, 21 Mar 2019 08:50:01 +0000

Dear GLPK helpers,

 

I come back to you as suggested by Heinrich, as I still experience cases where GLPK dll is cycling indefinitely instead of giving the info feasible/unfeasible.

 

Let me summarize:

- my routine is solving many times almost the same problem, only with very slightly modified coefficients in the matrix. This covers a "map" of conditions where each "cell" is a problem to be solved

- over the ranges of tested conditions, it is normal that some problems have no feasible solution (in short: we are calculating required materials to mix in liquid steel for obtaining a desired final analysis, and due to constraints in energy and mass balances, some targets are not possible), and some others are possible. We want to visualize on the "map" of conditions, the zones where there is no solution, and the zones where there is a solution, then identifying lowest cost inside the zones that are OK

- the problem I have is that in some cases, after solving already many cases (either with solution or without solution), the dll keeps stalling for a given set of initial conditions instead of completing with the status for the problem

 

What I have done:

- After removing some constraints that caused very large problem scales, I also tested with and without scaling options. It seems that depending on the choice "no scaling" / "scaling_default", the issue with GLPK stalling is not met with the same set of conditions (it happens apparently more easily when the problem is scaled)

- Stalling issue. In debug console I can see that this is linked to LP perturbation routine that is cycling indefinitely. See screenshot below

>> The last calculation (after “Testing slag Ratio: 0,14…”) is progressing very slowly : every 5-10 seconds the console is showing an additional line under “perturbing LP”. This keeps cycling without end (at least even after 30 min)

>>  I put the lp and prob files in attachment in case it helps: there in one set of problem (“_stalling”) where GLPK dll keeps cycling, and another (“_OK”) with only 1 coefficient difference in the matrix but where GLPK is running fine. In both cases the result should be “unfeasible problem” as expected.

>> The numerous calculations done before ran well (even if no primal feasible which is the info I need as an output of the solver, as can be seen in the part dedicated to “Testing slag ratio: 0.13 …”)

 

 

 

My questions:

  • Is there anything I should try to cope with the problem above (e.g. changing parameters of the solver, or scaling option…) that would help the solver to avoid cycling indefinitely ?
  • If not, and anyway it could be useful, I should at least implement a way to exit the dll in case of excessive time. I understood that I could use glp_error() or do_events but I could not find how to set such a control based on time. Are there any example I could use to adapt in my case?

 

Your support is much appreciated, I hope I’m not asking too much!

 

With best regards

Jean-Christophe

 

 

> 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

> 

>> address@hidden <mailto:address@hidden>

> 

>> https://urldefense.proofpoint.com/v2/url?u=https-3A__lists.gnu.org_ma

>> i

> 

>> lman_listinfo_help-2Dglpk&d=DwID-g&c=y5LGzd1hT50ruE_IlUH7x8VGgWz9W0tF

>> V

> 

>> WT6rSvPUKA&r=aJSMIq1T9WkhqQnBsLjUlPX3wypldBi_TyOebwAXhXiWH1DUyEEp515N

>> d

> 

>> TuWHS0X&m=tMoHcIEhFDNFxQLOgOzzODehhWfSZxezfYOeWMCzo1U&s=8TeiU4MmW-QdO

>> y

> 

>> BQ5COIoGZ1DQ4gIhStfYoeEsBDCpY&e=

> 

>> 

> 

> 

> 

 

Attachment: glpTrace_prob_OK.PROB
Description: glpTrace_prob_OK.PROB

Attachment: glpTrace_prob_stalling.prob
Description: glpTrace_prob_stalling.prob

Attachment: glpTrace_lp_OK.LP
Description: glpTrace_lp_OK.LP

Attachment: glpTrace_lp_stalling.lp
Description: glpTrace_lp_stalling.lp


reply via email to

[Prev in Thread] Current Thread [Next in Thread]