Hello,
I'm trying to use the function glp_ios_heur_sol in a python scrip (attached)
using the python-glpk module.
Unfortale I having troubles with the glp_iocp struct.

I would like to know if some one already do that and can send me a example.

Raniere Gaia Costa da Silva
from glpk.glpkpi import *

def bus_heu() :
    #Faco uma busca por solucoes inteiras factiveis via heuristica
    #Por simplicidade ja estou informando uma solucao
    size = 1000+1
    sol = doubleArray(size)
    sol[1] = 1.0
    sol[2] = 6.0
    return sol

def foo(tree, info) :
    #Modifica o funcionamento da GLPK para utilizar a solucao encontrar por heuristica
    if glp_ios_reason(tree) == GLP_IHEUR and glp_ios_curr_node(tree) == 1 :
        print "Introduzindo solucao"
        glp_ios_heur_sol(tree, info)
    return

#Aqui inicia a funcao principal
size = 1000+1
ia = intArray(size)
ja = intArray(size)
ar = doubleArray(size)
prob = glp_create_prob()

#Criacao do problema
glp_set_obj_dir(prob, GLP_MIN)
glp_add_rows(prob, 2)
glp_set_row_name(prob, 1, "p")
glp_set_row_bnds(prob, 1, GLP_UP, 0.0, 40.0)
glp_set_row_name(prob, 2, "q")
glp_set_row_bnds(prob, 2, GLP_UP, 0.0, 200.0)
glp_add_cols(prob, 2)
glp_set_col_name(prob, 1, "x1")
glp_set_col_kind(prob, 1, GLP_IV)
glp_set_col_bnds(prob, 1, GLP_LO, 0.0, 0.0)
glp_set_obj_coef(prob, 1, -10.0)
glp_set_col_name(prob, 2, "x2")
glp_set_col_kind(prob, 2, GLP_IV)
glp_set_col_bnds(prob, 2, GLP_LO, 0.0, 0.0)
glp_set_obj_coef(prob, 2, -15.0)
ia[1] = 1; ja[1] = 1; ar[1] =  8.0	# /* a[1,1] =  8 */
ia[2] = 1; ja[2] = 2; ar[2] =  4.0	# /* a[1,2] =  4 */
ia[3] = 2; ja[3] = 1; ar[3] = 15.0	# /* a[2,1] = 15 */
ia[4] = 2; ja[4] = 2; ar[4] = 30.0	# /* a[2,2] = 30 */

#Processo de solucao
glp_load_matrix(prob, 4, ia, ja, ar)
solve_lp = glp_simplex(prob, None)
if solve_lp == 0 and glp_get_status(prob) == GLP_OPT :
    sol = bus_heu()
    parm = glp_iocp()
    glp_init_iocp(parm)
    parm.cb_func = foo
    parm.cb_info = sol
    solve_mip = glp_intopt(prob, parm)
    #Leitura da solucao
    Z = glp_mip_obj_val(prob)
    x1 = glp_mip_col_val(prob, 1)
    x2 = glp_mip_col_val(prob, 2)
    print "\nZ = %g; x1 = %g; x2 = %g\n" %(Z, x1, x2)
del prob
_______________________________________________
Help-glpk mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/help-glpk

Reply via email to