diff options
| author | Bjoern Brandenburg <bbb@mpi-sws.org> | 2012-12-10 13:19:31 -0500 |
|---|---|---|
| committer | Bjoern Brandenburg <bbb@mpi-sws.org> | 2013-02-12 06:55:16 -0500 |
| commit | 7c79568606ee9bfdc22666954feac8d16fe37beb (patch) | |
| tree | c16507b8cfa1c65bda3c3f359b6e458d52a2106e /native/include/linprog | |
| parent | 96683d88c8c774bf75214438a6a4ea8955b329de (diff) | |
Refactor linprog_solve() into a proper function
Diffstat (limited to 'native/include/linprog')
| -rw-r--r-- | native/include/linprog/cplex.h | 6 | ||||
| -rw-r--r-- | native/include/linprog/glpk.h | 6 | ||||
| -rw-r--r-- | native/include/linprog/solver.h | 23 |
3 files changed, 25 insertions, 10 deletions
diff --git a/native/include/linprog/cplex.h b/native/include/linprog/cplex.h index 5e7addf..7c4f8b5 100644 --- a/native/include/linprog/cplex.h +++ b/native/include/linprog/cplex.h | |||
| @@ -1,7 +1,9 @@ | |||
| 1 | #ifndef LINPROG_CPLEX_H | 1 | #ifndef LINPROG_CPLEX_H |
| 2 | #define LINPROG_CPLEX_H | 2 | #define LINPROG_CPLEX_H |
| 3 | 3 | ||
| 4 | #include "linprog/solver.h" | 4 | #include "linprog/model.h" |
| 5 | |||
| 6 | class Solution; | ||
| 5 | 7 | ||
| 6 | // solve with CPLEX connected via the "Concert Technology" API | 8 | // solve with CPLEX connected via the "Concert Technology" API |
| 7 | Solution *cplex_solve(const LinearProgram& lp, unsigned int max_num_vars); | 9 | Solution *cplex_solve(const LinearProgram& lp, unsigned int max_num_vars); |
| @@ -9,4 +11,6 @@ Solution *cplex_solve(const LinearProgram& lp, unsigned int max_num_vars); | |||
| 9 | // solve with CPLEX connected via the plain, old C API | 11 | // solve with CPLEX connected via the plain, old C API |
| 10 | Solution *cpx_solve(const LinearProgram& lp, unsigned int max_num_vars); | 12 | Solution *cpx_solve(const LinearProgram& lp, unsigned int max_num_vars); |
| 11 | 13 | ||
| 14 | #include "linprog/solver.h" | ||
| 15 | |||
| 12 | #endif | 16 | #endif |
diff --git a/native/include/linprog/glpk.h b/native/include/linprog/glpk.h index fa2aec9..1b5fa1a 100644 --- a/native/include/linprog/glpk.h +++ b/native/include/linprog/glpk.h | |||
| @@ -1,8 +1,12 @@ | |||
| 1 | #ifndef LINPROG_GLPK_H | 1 | #ifndef LINPROG_GLPK_H |
| 2 | #define LINPROG_GLPK_H | 2 | #define LINPROG_GLPK_H |
| 3 | 3 | ||
| 4 | #include "linprog/solver.h" | 4 | #include "linprog/model.h" |
| 5 | |||
| 6 | class Solution; | ||
| 5 | 7 | ||
| 6 | Solution *glpk_solve(const LinearProgram& lp, unsigned int max_num_vars); | 8 | Solution *glpk_solve(const LinearProgram& lp, unsigned int max_num_vars); |
| 7 | 9 | ||
| 10 | #include "linprog/solver.h" | ||
| 11 | |||
| 8 | #endif | 12 | #endif |
diff --git a/native/include/linprog/solver.h b/native/include/linprog/solver.h index eb873b8..a15b9e0 100644 --- a/native/include/linprog/solver.h +++ b/native/include/linprog/solver.h | |||
| @@ -25,20 +25,27 @@ public: | |||
| 25 | }; | 25 | }; |
| 26 | 26 | ||
| 27 | #if defined(CONFIG_HAVE_CPLEX) | 27 | #if defined(CONFIG_HAVE_CPLEX) |
| 28 | |||
| 29 | #include "linprog/cplex.h" | 28 | #include "linprog/cplex.h" |
| 30 | #define linprog_solve(lp, vars) cpx_solve((lp), (vars)) | ||
| 31 | |||
| 32 | #elif defined(CONFIG_HAVE_GLPK) | 29 | #elif defined(CONFIG_HAVE_GLPK) |
| 33 | |||
| 34 | #include "linprog/glpk.h" | 30 | #include "linprog/glpk.h" |
| 35 | #define linprog_solve(lp, vars) glpk_solve((lp), (vars)) | ||
| 36 | |||
| 37 | #else | 31 | #else |
| 38 | |||
| 39 | #warning No LP solver available. | 32 | #warning No LP solver available. |
| 40 | #define linprog_solve(lp, vars) assert(0) | 33 | #endif |
| 41 | 34 | ||
| 35 | |||
| 36 | static inline Solution *linprog_solve( | ||
| 37 | const LinearProgram& lp, | ||
| 38 | unsigned int max_num_vars) | ||
| 39 | { | ||
| 40 | |||
| 41 | #if defined(CONFIG_HAVE_CPLEX) | ||
| 42 | return cpx_solve(lp, max_num_vars); | ||
| 43 | #elif defined(CONFIG_HAVE_GLPK) | ||
| 44 | return glpk_solve(lp, max_num_vars); | ||
| 45 | #else | ||
| 46 | assert(0); | ||
| 47 | return NULL; | ||
| 42 | #endif | 48 | #endif |
| 49 | } | ||
| 43 | 50 | ||
| 44 | #endif | 51 | #endif |
