removed broken include
[libfirm] / ir / be / becopyilp.c
index ebcacb6..48a74c4 100644 (file)
 #include <malloc.h>
 #endif
 
+#define PATH_CONSTRAINTS_FOR_CLASSES
+#undef PRECOLOR_MAX_CLIQUE
 #undef NO_NULL_COLORS
 #undef NO_NULL_COLORS_EXTRA_CSTS
 #undef NO_NULL_COLORS_WITH_COSTS
-
 #if (defined(NO_NULL_COLORS_EXTRA_CSTS) || defined(NO_NULL_COLORS_WITH_COSTS)) && !defined(NO_NULL_COLORS)
 #error Chose your weapon!
 #endif
 
-#undef PRECOLOR_MAX_CLIQUE
-#define PATH_CONSTRAINTS_FOR_CLASSES
-
 #include "irprog.h"
 
 #include <lpp/lpp.h>
 #include <lpp/lpp_net.h>
-//#include <lpp/lpp_cplex.h>
+#include <lpp/lpp_cplex.h>
 #include <lpp/lpp_remote.h>
 #include "xmalloc.h"
 #include "pset.h"
@@ -598,8 +596,6 @@ static void check_ecc_and_add_cut(problem_instance_t *pi, ir_node **path, int le
                int cst_idx, var_idx, i, nnr1, nnr2;
                char buf[30];
 
-               printf("+++++++++++++++++++++++++++++++ PATH: %d\n", length);
-
                /* add cut to ilp */
                mangle_cst(buf, 'Q', pi->cst_counter++);
                cst_idx = lpp_add_cst(pi->curr_lp, buf, lpp_greater, 1);
@@ -845,10 +841,6 @@ static problem_instance_t *new_pi(const copy_opt_t *co) {
        pi_add_constr_preColoring(pi);
 #endif
 
-       FILE *out = fopen(pi->co->name, "wt");
-       lpp_dump_plain(pi->curr_lp, out);
-       fclose(out);
-
        return pi;
 }
 
@@ -896,9 +888,11 @@ static void pi_set_start_sol(problem_instance_t *pi) {
  */
 static void pi_solve_ilp(problem_instance_t *pi) {
        pi_set_start_sol(pi);
+       double lower_bound = co_get_lower_bound(pi->co) - co_get_inevit_copy_costs(pi->co);
+       lpp_set_bound(pi->curr_lp, lower_bound);
        lpp_solve_net(pi->curr_lp, LPP_HOST, LPP_SOLVER);
 //     lpp_solve_cplex(pi->curr_lp);
-//     printf("       SOLUTION TIME: %.2f\n", pi->curr_lp->sol_time);
+       DBG((dbg, LEVEL_1, "Solution time: %.2f\n", pi->curr_lp->sol_time));
 }
 
 /**
@@ -938,8 +932,8 @@ static void pi_set_simplicials(problem_instance_t *pi) {
  * Sets the colors of irns according to the values of variables
  * provided by the solution of the solver.
  */
-static void pi_apply_solution(problem_instance_t *pi) {
-       int i;
+static int pi_apply_solution(problem_instance_t *pi) {
+       int res = 1, i;
        double *sol;
        lpp_sol_state_t state;
        DBG((dbg, LEVEL_2, "Applying solution...\n"));
@@ -954,8 +948,9 @@ static void pi_apply_solution(problem_instance_t *pi) {
        sol = xmalloc((pi->last_x_var - pi->first_x_var + 1) * sizeof(*sol));
        state = lpp_get_solution(pi->curr_lp, sol, pi->first_x_var, pi->last_x_var);
        if (state != lpp_optimal) {
-               printf("Solution state is not 'optimal': %d\n", state);
+               printf("WARNING %s: Solution state is not 'optimal': %d\n", pi->co->name, state);
                assert(state >= lpp_feasible && "The solution should at least be feasible!");
+               res = 0;
        }
        for (i=0; i<pi->last_x_var - pi->first_x_var + 1; ++i) {
                int nnr, col;
@@ -971,9 +966,11 @@ static void pi_apply_solution(problem_instance_t *pi) {
                                assert(0 && "This should be a x-var");
                }
        }
+       return res;
 }
 
-void co_ilp_opt(copy_opt_t *co) {
+int co_ilp_opt(copy_opt_t *co, double time_limit) {
+       int res = 1;
        problem_instance_t *pi;
 
        dbg = firm_dbg_register("ir.be.copyoptilp");
@@ -989,9 +986,11 @@ void co_ilp_opt(copy_opt_t *co) {
                snprintf(buf, sizeof(buf), "%s.mps", co->name);
                lpp_dump(pi->curr_lp, buf);
 #endif
+               lpp_set_time_limit(pi->curr_lp, time_limit);
                pi_solve_ilp(pi);
-               pi_apply_solution(pi);
+               res = pi_apply_solution(pi);
                pi_set_simplicials(pi);
        }
        free_pi(pi);
+       return res;
 }