+/*
+ * 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 <stdio.h>
#include <stdlib.h>
-
-#ifdef WITH_CPLEX
-
-
-#ifdef _WIN32
-#include <malloc.h>
-#else
-#include <sys/time.h>
-#include <alloca.h>
-#endif
-
-#include "obst.h"
-
+#include <assert.h>
#include <ilcplex/cplex.h>
-#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;
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);
}
}
-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);
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);
* 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) {
- const matrix_elem_t *elem;
- int i, o, sv_cnt;
- int numcols, numrows, numentries;
- int objsen, *matbeg, *matcnt, *matind, *indices;
- double *obj, *rhs, *matval, *lb, *ub, *startv;
- char *sense, *vartype;
- char **colname, **rowname;
- struct obstack obst;
- lpp_t *lpp = cpx->lpp;
+static void cpx_construct(cpx_t *cpx)
+{
+ int i, o, sv_cnt;
+ int numcols, numrows, numentries;
+ int objsen, *matbeg, *matcnt, *matind, *indices;
+ double *obj, *rhs, *matval, *lb, *ub, *startv;
+ char *sense, *vartype;
+ char **colname, **rowname;
+ struct obstack obst;
+ lpp_t *lpp = cpx->lpp;
numcols = lpp->var_next-1;
numrows = lpp->cst_next-1;
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);
? 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 */
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);