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

2019-02-27 Thread Heinrich Schuchardt
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 

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

2019-02-27 Thread Huber, Jean-Christophe
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 = 1continuous variable
' GLP_IV = 2long variable
' GLP_BV = 3binary 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