X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ir%2Flpp%2Flpp_cplex.c;h=d24c8740f4cd94773c978ee3c9c0c4f4f7c27d2d;hb=7d61ad5fbb6a87bea369c8a01103a92d9ab79a48;hp=d6a1f3b421b97468be465752cf55f4e7ed60cdf3;hpb=780ca0cd82979273de26bd01971bc5547e7aa609;p=libfirm diff --git a/ir/lpp/lpp_cplex.c b/ir/lpp/lpp_cplex.c index d6a1f3b42..d24c8740f 100644 --- a/ir/lpp/lpp_cplex.c +++ b/ir/lpp/lpp_cplex.c @@ -1,43 +1,43 @@ +/* + * Copyright (C) 2005-2011 University of Karlsruhe. All right reserved. + * + * This file is part of libFirm. + * + * This file may be distributed and/or modified under the terms of the + * GNU General Public License version 2 as published by the Free Software + * Foundation and appearing in the file LICENSE.GPL included in the + * packaging of this file. + * + * Licensees holding valid libFirm Professional Edition licenses may use + * this file in accordance with the libFirm Commercial License. + * Agreement provided with the Software. + * + * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE + * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE. + */ + /** - * Author: Daniel Grund - * Date: 02.06.2005 - * Copyright: (c) Universitaet Karlsruhe - * Licence: This file protected by GPL - GNU GENERAL PUBLIC LICENSE. + * @file + * @author Daniel Grund */ +#include "config.h" +#ifdef WITH_CPLEX #include "lpp_cplex.h" #include #include - - -#ifdef _WIN32 -#include -#else -#include -#include -#endif - -#include "obst.h" - +#include #include -#include "assert.h" +#include "obst.h" +#include "stat_timing.h" #include "sp_matrix.h" static char cpx_cst_encoding[4] = "?ELG"; static char cpx_var_encoding[4] = "??CB"; -#define my_timersub(tvp, uvp, vvp) \ - do { \ - (vvp)->tv_sec = (tvp)->tv_sec - (uvp)->tv_sec; \ - (vvp)->tv_usec = (tvp)->tv_usec - (uvp)->tv_usec; \ - if ((vvp)->tv_usec < 0) { \ - (vvp)->tv_sec--; \ - (vvp)->tv_usec += 1000000; \ - } \ - } while (0) - typedef struct _cpx_t { lpp_t *lpp; CPXENVptr env; @@ -46,7 +46,8 @@ typedef struct _cpx_t { char buf[1024]; } cpx_t; -static void chk_cpx_err(cpx_t *cpx) { +static void chk_cpx_err(cpx_t *cpx) +{ if (cpx->status) { if (CPXgeterrorstring(cpx->env, cpx->status, cpx->buf)) printf("%s", cpx->buf); @@ -56,7 +57,8 @@ static void chk_cpx_err(cpx_t *cpx) { } } -static cpx_t *new_cpx(lpp_t *lpp) { +static cpx_t *new_cpx(lpp_t *lpp) +{ cpx_t *cpx = XMALLOCZ(cpx_t); cpx->lpp = lpp; cpx->env = CPXopenCPLEX(&cpx->status); @@ -70,7 +72,8 @@ static cpx_t *new_cpx(lpp_t *lpp) { return cpx; } -static void free_cpx(cpx_t *cpx) { +static void free_cpx(cpx_t *cpx) +{ CPXfreeprob(cpx->env, &cpx->prob); CPXcloseCPLEX(&cpx->env); free(cpx); @@ -80,7 +83,8 @@ static void free_cpx(cpx_t *cpx) { * Build CPLEX data structure from LPP matrix. * @note: The LPP matrix is freed after this step, to save memory. */ -static void cpx_construct(cpx_t *cpx) { +static void cpx_construct(cpx_t *cpx) +{ const matrix_elem_t *elem; int i, o, sv_cnt; int numcols, numrows, numentries; @@ -165,13 +169,15 @@ static void cpx_construct(cpx_t *cpx) { chk_cpx_err(cpx); obstack_free(&obst, NULL); - free_lpp_matrix(lpp); + lpp_free_matrix(lpp); } -static void cpx_solve(cpx_t *cpx) { +static void cpx_solve(cpx_t *cpx) +{ int i, CPX_state, numcols; double *values; - struct timeval tvb, tva, tvdiff; + timing_ticks_t tvb; + timing_ticks_t tva; lpp_t *lpp = cpx->lpp; numcols = CPXgetnumcols(cpx->env, cpx->prob); @@ -210,10 +216,13 @@ static void cpx_solve(cpx_t *cpx) { ? CPX_PARAM_OBJLLIM : CPX_PARAM_OBJULIM), lpp->bound); } + /* turn on the fancy messages :) */ + // CPXsetintparam (cpx->env, CPX_PARAM_SCRIND, CPX_ON); + /* solve */ - gettimeofday(&tvb, NULL); + timing_ticks(tvb); cpx->status = CPXmipopt(cpx->env, cpx->prob); - gettimeofday(&tva, NULL); + timing_ticks(tva); chk_cpx_err(cpx); /* get solution status */ @@ -255,14 +264,17 @@ static void cpx_solve(cpx_t *cpx) { CPXgetbestobjval(cpx->env, cpx->prob, &lpp->best_bound); /* get some statistics */ - my_timersub(&tva, &tvb, &tvdiff); - lpp->sol_time = tvdiff.tv_sec + tvdiff.tv_usec / 1e6; + timing_ticks_sub(tva, tvb); + lpp->sol_time = timing_ticks_dbl(tva); lpp->iterations = CPXgetmipitcnt(cpx->env, cpx->prob); } -void lpp_solve_cplex(lpp_t *lpp) { +void lpp_solve_cplex(lpp_t *lpp) +{ cpx_t *cpx = new_cpx(lpp); cpx_construct(cpx); cpx_solve(cpx); free_cpx(cpx); } + +#endif