#include "bemodule.h"
#include "error.h"
+#include "lpp.h"
+
#include "lc_opts.h"
#include "lc_opts_enum.h"
if (solve_log)
lpp_set_log(ienv->lp, stdout);
- lpp_solve_net(ienv->lp, options->ilp_server, options->ilp_solver);
+ lpp_solve(ienv->lp, options->ilp_server, options->ilp_solver);
//be_stat_ev_dbl("co_ilp_objval", ienv->lp->objval);
//be_stat_ev_dbl("co_ilp_best_bound", ienv->lp->best_bound);
0, /* try to omit frame pointer */
0, /* create PIC code */
BE_VERIFY_WARN, /* verification level: warn */
- "i44pc52.info.uni-karlsruhe.de", /* ilp server */
+ "", /* ilp server */
"cplex", /* ilp solver */
0, /* enable statistic event dumping */
"", /* print stat events */
#include "mps.h"
#include "lpp_t.h"
#include "lpp_comm.h"
+#include "lpp_solvers.h"
#define HASH_NAME_T(n) HASH_STR((n)->name, strlen((n)->name))
lpp->objval = lpp_readd(comm);
lpp->best_bound = lpp_readd(comm);
}
+
+void lpp_solve(lpp_t *lpp, const char* host, const char* solver)
+{
+ if (host == NULL || strlen(host) == 0) {
+ lpp_solver_func_t* f = lpp_find_solver(solver);
+ if (f != NULL)
+ f(lpp);
+ }
+
+ else {
+ lpp_solve_net(lpp, host, solver);
+ }
+}
+
*/
#define lpp_unset_bound(lpp) ((lpp)->set_bound = 0)
+/**
+ * Solve an ILP.
+ * @param lpp The problem.
+ * @param host The host to solve on.
+ * @param solver The solver to use.
+ */
+void lpp_solve(lpp_t *lpp, const char* host, const char* solver);
+
#endif /* _LPP_H */
? 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);
cpx->status = CPXmipopt(cpx->env, cpx->prob);
#include "lpp_t.h"
#include "lpp_comm.h"
-#include "lpp_cplex.h"
+#include "lpp_solvers.h"
#define MAX_JOBS 128
extern char** environ;
-typedef void (solver_func_t)(lpp_t *lpp);
-
typedef struct _job_t {
struct list_head list;
int id;
pthread_t session;
lpp_comm_t *comm;
lpp_t *lpp;
- solver_func_t *solver_func;
+ lpp_solver_func_t *solver_func;
time_t received;
int csock;
} job_t;
--title_length;
}
-static void job_init(job_t *job, lpp_comm_t *comm, lpp_t *lpp, solver_func_t *solver_func)
+static void job_init(job_t *job, lpp_comm_t *comm, lpp_t *lpp, lpp_solver_func_t *solver_func)
{
/* TODO MAXJOBS */
memset(job, 0, sizeof(job[0]));
return s;
}
-static void dummy_solver(lpp_t *lpp)
-{
- int i;
-
- for(i = 0; i < lpp->var_next; ++i) {
- lpp->vars[i]->value = i;
- lpp->vars[i]->value_kind = lpp_value_solution;
- }
-
- if(lpp->log)
- fprintf(lpp->log, "dummy solver exiting now.\n");
-
- sleep(1);
- lpp->sol_time = 0.0;
- lpp->iterations = 0;
- lpp->sol_state = lpp_optimal;
-}
-
-static void segv_solver(lpp_t *lpp)
-{
- int i;
-
- for(i = 0; i < lpp->var_next; ++i) {
- lpp->vars[i]->value = i;
- lpp->vars[i]->value_kind = lpp_value_solution;
- }
-
- if(lpp->log)
- fprintf(lpp->log, "segv dummy solver exiting now.\n");
-
- sleep(1);
- *((int *) 0) = 1;
-}
-
-#define DEFAULT_SOLVER lpp_solve_cplex
-
-struct {
- solver_func_t *solver;
- const char *name;
- int n_instances;
-} solvers[] = {
- { lpp_solve_cplex, "cplex", 1 },
- { dummy_solver, "dummy", 2 },
- { segv_solver, "segv", 2 },
-};
-
-
-static solver_func_t *find_solver(const char *name)
-{
- unsigned i;
-
- for(i = 0; i < sizeof(solvers) / sizeof(solvers[0]); ++i)
- if(strcmp(solvers[i].name, name) == 0)
- return solvers[i].solver;
-
- return NULL;
-}
-
static void *solver_thread(void * data)
{
job_t *job = data;
static void *session(int fd)
{
- solver_func_t *solver = DEFAULT_SOLVER;
- lpp_comm_t *comm = lpp_comm_new(fd, LPP_BUFSIZE);
+ lpp_solver_func_t *solver = lpp_find_solver("dummy");
+ lpp_comm_t *comm = lpp_comm_new(fd, LPP_BUFSIZE);
DBG((dbg, LEVEL_1, "starting session thread pid %d tid %d\n", getpid(), pthread_self()));
setproctitle("lpp_server [child]");
case LPP_CMD_SOLVER:
lpp_readbuf(comm, buf, sizeof(buf));
- solver = find_solver(buf);
+ solver = lpp_find_solver(buf);
DBG((dbg, LEVEL_2, "setting solver to: %s\n", buf));
//lpp_send_res(comm, solver != NULL, "could not find solver: %s", buf);
break;
case LPP_CMD_SOLVERS:
{
- int i, n = ARRAY_SIZE(solvers);
- lpp_writel(comm, n);
- for(i = 0; i < n; ++i)
- lpp_writes(comm, solvers[i].name);
+ int i;
+
+ for(i = 0; lpp_solvers[i].solver != NULL; i++);
+ lpp_writel(comm, i);
+
+ for(i = 0; lpp_solvers[i].solver != NULL; i++)
+ lpp_writes(comm, lpp_solvers[i].name);
lpp_flush(comm);
}
break;
--- /dev/null
+/**
+ * @file lpp_solvers.c
+ * @date 16.06.2011
+ * @author Sebastian Hack
+ *
+ * Copyright (C) 2011 Saarland University
+ * Released under the LGPL
+ */
+
+#include <unistd.h>
+
+#include "lpp_cplex.h"
+#include "lpp_solvers.h"
+
+static void dummy_solver(lpp_t *lpp)
+{
+ int i;
+
+ for(i = 0; i < lpp->var_next; ++i) {
+ lpp->vars[i]->value = i;
+ lpp->vars[i]->value_kind = lpp_value_solution;
+ }
+
+ if(lpp->log)
+ fprintf(lpp->log, "dummy solver exiting now.\n");
+
+ sleep(1);
+ lpp->sol_time = 0.0;
+ lpp->iterations = 0;
+ lpp->sol_state = lpp_optimal;
+}
+
+static void segv_solver(lpp_t *lpp)
+{
+ int i;
+
+ for(i = 0; i < lpp->var_next; ++i) {
+ lpp->vars[i]->value = i;
+ lpp->vars[i]->value_kind = lpp_value_solution;
+ }
+
+ if(lpp->log)
+ fprintf(lpp->log, "segv dummy solver exiting now.\n");
+
+ sleep(1);
+ *((int *) 0) = 1;
+}
+
+lpp_solver_t lpp_solvers[] = {
+ { lpp_solve_cplex, "cplex", 1 },
+ { dummy_solver, "dummy", 2 },
+ { segv_solver, "segv", 2 },
+ { NULL, NULL, 0 }
+};
+
+lpp_solver_func_t *lpp_find_solver(const char *name)
+{
+ int i;
+
+ for(i = 0; lpp_solvers[i].solver != NULL; i++)
+ if(strcmp(lpp_solvers[i].name, name) == 0)
+ return lpp_solvers[i].solver;
+
+ return NULL;
+}
+
+
--- /dev/null
+/**
+ * @file lpp_solvers.h
+ * @date 16.06.2011
+ * @author Sebastian Hack
+ *
+ * Copyright (C) 2011 Saarland University
+ * Released under the LGPL
+ */
+
+#ifndef LPP_SOLVER_H
+#define LPP_SOLVER_H
+
+#include "lpp.h"
+
+typedef void (lpp_solver_func_t)(lpp_t *lpp);
+
+typedef struct {
+ lpp_solver_func_t *solver;
+ const char *name;
+ int n_instances;
+} lpp_solver_t;
+
+extern lpp_solver_t lpp_solvers[];
+
+/**
+ * Find a solver for a given name.
+ */
+lpp_solver_func_t *lpp_find_solver(const char *name);
+
+#endif /* LPP_SOLVER_H */