From 91487e66ae515a9756e2c7c14f8c4e28b9985e3c Mon Sep 17 00:00:00 2001 From: Patrik Dufresne Date: Tue, 1 Jul 2014 18:52:05 -0400 Subject: [PATCH] Add a method to return bestSolution with single JNI call. To avoid multiple call to get the best solution of the linear problem, add a method to return a double[]. --- src/main/native/cbc4j.cpp | 4 ++++ src/main/native/cbc4j.hpp | 1 + src/main/native/cbc4j.i | 3 ++- 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main/native/cbc4j.cpp b/src/main/native/cbc4j.cpp index 9557187..3b6da91 100644 --- a/src/main/native/cbc4j.cpp +++ b/src/main/native/cbc4j.cpp @@ -39,6 +39,10 @@ double bestSolution(CbcModel& c, int colIndex){ return c.bestSolution()[colIndex]; } +const double* bestSolution(CbcModel& c){ + return c.bestSolution(); +} + void branchAndBound(CbcModel& c, int doStatistics){ c.branchAndBound(doStatistics); std::cout.flush(); diff --git a/src/main/native/cbc4j.hpp b/src/main/native/cbc4j.hpp index 8909436..cae05f2 100644 --- a/src/main/native/cbc4j.hpp +++ b/src/main/native/cbc4j.hpp @@ -13,6 +13,7 @@ using namespace std; void addCol(OsiClpSolverInterface& osi, int numberElements, const int *rows, const double *elements, const double collb, const double colub, const double obj); void addRow(OsiClpSolverInterface& osi, int numberElements, const int *columns, const double *element, const double rowlb, const double rowub); double bestSolution(CbcModel& c, int colIndex); +const double* bestSolution(CbcModel& c); void branchAndBound(CbcModel& c, int doStatistics = 0); void callCbc0 (CbcModel &m); int callCbc1 (int argc, const char *argv[], CbcModel & babSolver); diff --git a/src/main/native/cbc4j.i b/src/main/native/cbc4j.i index 87290cb..9ffe6b6 100644 --- a/src/main/native/cbc4j.i +++ b/src/main/native/cbc4j.i @@ -11,12 +11,13 @@ using namespace std; typedef std::string String; %typemap(out) const double* { -$result = SWIG_JavaArrayOutDouble(jenv, $1, arg1->getNumCols()); +$result = ($1) ? SWIG_JavaArrayOutDouble(jenv, $1, arg1->getNumCols()) : 0; } extern void addCol(OsiClpSolverInterface& osi, int numberElements, const int *rows, const double *elements, const double collb, const double colub, const double obj); extern void addRow(OsiClpSolverInterface& osi, int numberElements, const int *columns, const double *element, const double rowlb, const double rowub); extern double bestSolution(CbcModel& c, int colIndex); +extern const double* bestSolution(CbcModel& c); extern void branchAndBound(CbcModel& c, int doStatistics = 0); extern void callCbc0 (CbcModel &m); extern int callCbc1 (int argc, const char *argv[], CbcModel & babSolver); -- GitLab