X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ir%2Flpp%2Flpp_gurobi.c;h=6b043e456bbf8dc3f1b2b358ced5774d0abb5024;hb=4f25f9ca1fd1d53303f277a140a1aa657782aeba;hp=b3dca0fb792cf44a5a14b68553c7e9e999845dc6;hpb=f75c5b35a105152cde5ffa13ebf918843c1b80c3;p=libfirm diff --git a/ir/lpp/lpp_gurobi.c b/ir/lpp/lpp_gurobi.c index b3dca0fb7..6b043e456 100644 --- a/ir/lpp/lpp_gurobi.c +++ b/ir/lpp/lpp_gurobi.c @@ -28,6 +28,7 @@ #include #include +#include #include "obst.h" @@ -42,6 +43,7 @@ static char gurobi_var_encoding[4] = { 0, 0, GRB_CONTINUOUS, GRB_BINARY }; typedef struct _gurobi_t { lpp_t *lpp; GRBenv *env; + GRBenv *modelenv; GRBmodel *model; } gurobi_t; @@ -69,16 +71,17 @@ static gurobi_t *new_gurobi(lpp_t *lpp) * The only thing gurobi sanely supports is giving a string with a filename * :-( ...so we use /tmp/firm_gurobi.log as a temporary measure... */ -#if 0 - error = GRBsetlogfile(grb->env, lpp->log); - check_gurobi_error(grb, error); -#endif + if (lpp->log != stdout && lpp->log != stderr) { + error = GRBsetintparam(grb->env, GRB_INT_PAR_OUTPUTFLAG, 0); + check_gurobi_error(grb, error); + } return grb; } static void free_gurobi(gurobi_t *grb) { + GRBfreemodel(grb->model); GRBfreeenv(grb->env); free(grb); } @@ -89,19 +92,18 @@ static void free_gurobi(gurobi_t *grb) */ static void gurobi_construct(gurobi_t *grb) { - const matrix_elem_t *elem; - int i, o; - //int sv_cnt; - //int *indices; - //double *startv; - int numcols, numrows, numentries; - int objsen, *matbeg, *matcnt, *matind; - double *obj, *rhs, *matval, *lb; - char *sense, *vartype; - char **colname, **rowname; - struct obstack obst; - lpp_t *lpp = grb->lpp; - int error; + int i, o; + //int sv_cnt; + //int *indices; + //double *startv; + int numcols, numrows, numentries; + int objsen, *matbeg, *matcnt, *matind; + double *obj, *rhs, *matval, *lb; + char *sense, *vartype; + char **colname, **rowname; + struct obstack obst; + lpp_t *lpp = grb->lpp; + int error; numcols = lpp->var_next-1; numrows = lpp->cst_next-1; @@ -135,14 +137,6 @@ static void gurobi_construct(gurobi_t *grb) colname[i] = (char*) curr_var->name; vartype[i] = gurobi_var_encoding[curr_var->type.var_type]; -#if 0 - if (curr_var->value_kind == lpp_value_start) { - panic("start values not supported in gurobi yet"); - indices[sv_cnt] = i; - startv[sv_cnt++] = curr_var->value; - } -#endif - matbeg[i] = o; matcnt[i] = 0; matrix_foreach_in_col(lpp->m, 1 + i, elem) { @@ -168,6 +162,7 @@ static void gurobi_construct(gurobi_t *grb) objsen, 0, obj, sense, rhs, matbeg, matcnt, matind, matval, lb, NULL, vartype, colname, rowname); check_gurobi_error(grb, error); + grb->modelenv = GRBgetenv(grb->model); obstack_free(&obst, NULL); lpp_free_matrix(lpp); @@ -183,40 +178,12 @@ static void gurobi_solve(gurobi_t *grb) double *values; double iterations; - /* set performance parameters */ - // CPXsetintparam(grb->env, CPX_PARAM_MIPSTART, CPX_ON); - //CPXsetintparam(grb->env, CPX_PARAM_MIPORDTYPE, CPX_MIPORDER_COST); - /* output every search tree node */ - // CPXsetintparam(grb->env, CPX_PARAM_MIPINTERVAL, 1); - - /* experimental switches */ - // CPXsetintparam(grb->env, CPX_PARAM_VARSEL, CPX_VARSEL_STRONG); - // CPXsetdblparam(grb->env, CPX_PARAM_BTTOL, 1.0); - // CPXsetintparam(grb->env, CPX_PARAM_BRDIR, CPX_BRDIR_UP); - /* Set the time limit appropriately */ if(lpp->time_limit_secs > 0.0) { - error = GRBsetdblparam(grb->env, GRB_DBL_PAR_TIMELIMIT, lpp->time_limit_secs); + error = GRBsetdblparam(grb->modelenv, GRB_DBL_PAR_TIMELIMIT, lpp->time_limit_secs); check_gurobi_error(grb, error); } - /* - * If we have enough time, we instruct cplex to imply some - * of its higher order magic to pursue the best solution - */ - if(lpp->emphasis) { - /* not implemented */ - } - - /* - * If a bound of the objective function is supplied, - * set it accordingly, dependign on minimization or maximization. - */ - if(lpp->set_bound) { - //panic("bound not implemented yet"); - fprintf(stderr, "Warning: gurobi bound not implemented yet\n"); - } - /* solve */ error = GRBoptimize(grb->model); check_gurobi_error(grb, error); @@ -250,7 +217,9 @@ static void gurobi_solve(gurobi_t *grb) check_gurobi_error(grb, error); error = GRBgetdblattr(grb->model , GRB_DBL_ATTR_OBJBOUND, &lpp->best_bound); - check_gurobi_error(grb, error); + if (error != 0) { + lpp->best_bound = FP_NAN; + } } /* get some statistics */