removed C99 features
[libfirm] / ir / be / lpp_local.c
index 93ae091..362be3e 100644 (file)
@@ -4,21 +4,25 @@
  * Copyright:   (c) Universitaet Karlsruhe
  * Licence:     This file protected by GPL -  GNU GENERAL PUBLIC LICENSE.
  */
+#undef HAVE_CPLEX
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
 #endif
+#include "lpp_local.h"
+#include <stdio.h>
+
+#ifdef HAVE_CPLEX
 #include <alloca.h>
 #include <sys/time.h>
 
-#include "lpp_local.h"
 #include "xmalloc.h"
 #include "assert.h"
 #include "sp_matrix.h"
 #include "ilcplex/cplex.h"
 
-
-#define LOGFILE stdout
+#undef LOGFILE //stdout
+#define TIME_LIMIT 5*60 /* in sec. 0 for none */
 
 static char cpx_cst_encoding[4] = {'?', 'E', 'L', 'G'};
 static char cpx_var_encoding[4] = {'?', '?', 'C', 'B'};
@@ -50,8 +54,10 @@ static cpx_t *new_cpx(lpp_t *lpp) {
        chk_cpx_err(cpx);
        CPXchgobjsen(cpx->env, cpx->prob, (lpp->opt_type == minimize)?1:-1);
        chk_cpx_err(cpx);
+#ifdef LOGFILE
        if (CPXsetlogfile(cpx->env, LOGFILE))
                assert(0 && "Could not set logfile");
+#endif
        return cpx;
 }
 
@@ -61,7 +67,7 @@ static void free_cpx(cpx_t *cpx) {
        free(cpx);
 }
 
-void cpx_construct(cpx_t *cpx) {
+static void cpx_construct(cpx_t *cpx) {
        const matrix_elem_t *elem;
        int i, o, sv_cnt, numcols, numrows, numentries, objsen, *matbeg, *matcnt, *matind, *indices;
        double *obj, *rhs, *matval, *lb, *ub, *startv;
@@ -130,7 +136,7 @@ void cpx_construct(cpx_t *cpx) {
        chk_cpx_err(cpx);
 }
 
-void cpx_solve(cpx_t *cpx) {
+static void cpx_solve(cpx_t *cpx) {
        int i, CPX_state, numcols;
        double *values;
        struct timeval tvb, tva;
@@ -143,6 +149,8 @@ void cpx_solve(cpx_t *cpx) {
        CPXsetintparam(cpx->env, CPX_PARAM_MIPSTART, CPX_ON);
        CPXsetintparam(cpx->env, CPX_PARAM_MIPEMPHASIS, CPX_MIPEMPHASIS_BESTBOUND);
        CPXsetintparam(cpx->env, CPX_PARAM_VARSEL, CPX_VARSEL_STRONG);
+       if (TIME_LIMIT)
+               CPXsetdblparam(cpx->env, CPX_PARAM_TILIM, TIME_LIMIT);
 
        /* solve */
        gettimeofday(&tvb, NULL);
@@ -168,7 +176,7 @@ void cpx_solve(cpx_t *cpx) {
                case CPX_STAT_OPTIMAL:          lpp->sol_state = optimal; break;
                default:                                        lpp->sol_state = unknown;
        }
-       assert(lpp->sol_state == optimal);
+       assert(lpp->sol_state == optimal || lpp->sol_state == feasible);
 
        /* get variable solution values */
        values = alloca(numcols * sizeof(*values));
@@ -190,3 +198,10 @@ void lpp_solve_local(lpp_t *lpp) {
        cpx_solve(cpx);
        free_cpx(cpx);
 }
+
+#else
+
+void lpp_solve_local(lpp_t *lpp) {
+       fprintf(stderr, "CPLEX not available!\n");
+}
+#endif