OR-Tools  9.1
knapsack_solver_java_wrap.cc
Go to the documentation of this file.
1/* ----------------------------------------------------------------------------
2 * This file was automatically generated by SWIG (http://www.swig.org).
3 * Version 4.0.2
4 *
5 * This file is not intended to be easily readable and contains a number of
6 * coding conventions designed to improve portability and efficiency. Do not make
7 * changes to this file unless you know what you are doing--modify the SWIG
8 * interface file instead.
9 * ----------------------------------------------------------------------------- */
10
11
12#ifndef SWIGJAVA
13#define SWIGJAVA
14#endif
15
16
17
18#ifdef __cplusplus
19/* SwigValueWrapper is described in swig.swg */
20template<typename T> class SwigValueWrapper {
21 struct SwigMovePointer {
22 T *ptr;
23 SwigMovePointer(T *p) : ptr(p) { }
24 ~SwigMovePointer() { delete ptr; }
25 SwigMovePointer& operator=(SwigMovePointer& rhs) { T* oldptr = ptr; ptr = 0; delete oldptr; ptr = rhs.ptr; rhs.ptr = 0; return *this; }
26 } pointer;
27 SwigValueWrapper& operator=(const SwigValueWrapper<T>& rhs);
28 SwigValueWrapper(const SwigValueWrapper<T>& rhs);
29public:
30 SwigValueWrapper() : pointer(0) { }
31 SwigValueWrapper& operator=(const T& t) { SwigMovePointer tmp(new T(t)); pointer = tmp; return *this; }
32 operator T&() const { return *pointer.ptr; }
33 T *operator&() { return pointer.ptr; }
34};
35
36template <typename T> T SwigValueInit() {
37 return T();
38}
39#endif
40
41/* -----------------------------------------------------------------------------
42 * This section contains generic SWIG labels for method/variable
43 * declarations/attributes, and other compiler dependent labels.
44 * ----------------------------------------------------------------------------- */
45
46/* template workaround for compilers that cannot correctly implement the C++ standard */
47#ifndef SWIGTEMPLATEDISAMBIGUATOR
48# if defined(__SUNPRO_CC) && (__SUNPRO_CC <= 0x560)
49# define SWIGTEMPLATEDISAMBIGUATOR template
50# elif defined(__HP_aCC)
51/* Needed even with `aCC -AA' when `aCC -V' reports HP ANSI C++ B3910B A.03.55 */
52/* If we find a maximum version that requires this, the test would be __HP_aCC <= 35500 for A.03.55 */
53# define SWIGTEMPLATEDISAMBIGUATOR template
54# else
55# define SWIGTEMPLATEDISAMBIGUATOR
56# endif
57#endif
58
59/* inline attribute */
60#ifndef SWIGINLINE
61# if defined(__cplusplus) || (defined(__GNUC__) && !defined(__STRICT_ANSI__))
62# define SWIGINLINE inline
63# else
64# define SWIGINLINE
65# endif
66#endif
67
68/* attribute recognised by some compilers to avoid 'unused' warnings */
69#ifndef SWIGUNUSED
70# if defined(__GNUC__)
71# if !(defined(__cplusplus)) || (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4))
72# define SWIGUNUSED __attribute__ ((__unused__))
73# else
74# define SWIGUNUSED
75# endif
76# elif defined(__ICC)
77# define SWIGUNUSED __attribute__ ((__unused__))
78# else
79# define SWIGUNUSED
80# endif
81#endif
82
83#ifndef SWIG_MSC_UNSUPPRESS_4505
84# if defined(_MSC_VER)
85# pragma warning(disable : 4505) /* unreferenced local function has been removed */
86# endif
87#endif
88
89#ifndef SWIGUNUSEDPARM
90# ifdef __cplusplus
91# define SWIGUNUSEDPARM(p)
92# else
93# define SWIGUNUSEDPARM(p) p SWIGUNUSED
94# endif
95#endif
96
97/* internal SWIG method */
98#ifndef SWIGINTERN
99# define SWIGINTERN static SWIGUNUSED
100#endif
101
102/* internal inline SWIG method */
103#ifndef SWIGINTERNINLINE
104# define SWIGINTERNINLINE SWIGINTERN SWIGINLINE
105#endif
106
107/* exporting methods */
108#if defined(__GNUC__)
109# if (__GNUC__ >= 4) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
110# ifndef GCC_HASCLASSVISIBILITY
111# define GCC_HASCLASSVISIBILITY
112# endif
113# endif
114#endif
115
116#ifndef SWIGEXPORT
117# if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__)
118# if defined(STATIC_LINKED)
119# define SWIGEXPORT
120# else
121# define SWIGEXPORT __declspec(dllexport)
122# endif
123# else
124# if defined(__GNUC__) && defined(GCC_HASCLASSVISIBILITY)
125# define SWIGEXPORT __attribute__ ((visibility("default")))
126# else
127# define SWIGEXPORT
128# endif
129# endif
130#endif
131
132/* calling conventions for Windows */
133#ifndef SWIGSTDCALL
134# if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__)
135# define SWIGSTDCALL __stdcall
136# else
137# define SWIGSTDCALL
138# endif
139#endif
140
141/* Deal with Microsoft's attempt at deprecating C standard runtime functions */
142#if !defined(SWIG_NO_CRT_SECURE_NO_DEPRECATE) && defined(_MSC_VER) && !defined(_CRT_SECURE_NO_DEPRECATE)
143# define _CRT_SECURE_NO_DEPRECATE
144#endif
145
146/* Deal with Microsoft's attempt at deprecating methods in the standard C++ library */
147#if !defined(SWIG_NO_SCL_SECURE_NO_DEPRECATE) && defined(_MSC_VER) && !defined(_SCL_SECURE_NO_DEPRECATE)
148# define _SCL_SECURE_NO_DEPRECATE
149#endif
150
151/* Deal with Apple's deprecated 'AssertMacros.h' from Carbon-framework */
152#if defined(__APPLE__) && !defined(__ASSERT_MACROS_DEFINE_VERSIONS_WITHOUT_UNDERSCORES)
153# define __ASSERT_MACROS_DEFINE_VERSIONS_WITHOUT_UNDERSCORES 0
154#endif
155
156/* Intel's compiler complains if a variable which was never initialised is
157 * cast to void, which is a common idiom which we use to indicate that we
158 * are aware a variable isn't used. So we just silence that warning.
159 * See: https://github.com/swig/swig/issues/192 for more discussion.
160 */
161#ifdef __INTEL_COMPILER
162# pragma warning disable 592
163#endif
164
165
166/* Fix for jlong on some versions of gcc on Windows */
167#if defined(__GNUC__) && !defined(__INTEL_COMPILER)
168 typedef long long __int64;
169#endif
170
171/* Fix for jlong on 64-bit x86 Solaris */
172#if defined(__x86_64)
173# ifdef _LP64
174# undef _LP64
175# endif
176#endif
177
178#include <jni.h>
179#include <stdlib.h>
180#include <string.h>
181
182
183/* Support for throwing Java exceptions */
184typedef enum {
196
197typedef struct {
199 const char *java_exception;
201
202
203static void SWIGUNUSED SWIG_JavaThrowException(JNIEnv *jenv, SWIG_JavaExceptionCodes code, const char *msg) {
204 jclass excep;
205 static const SWIG_JavaExceptions_t java_exceptions[] = {
206 { SWIG_JavaOutOfMemoryError, "java/lang/OutOfMemoryError" },
207 { SWIG_JavaIOException, "java/io/IOException" },
208 { SWIG_JavaRuntimeException, "java/lang/RuntimeException" },
209 { SWIG_JavaIndexOutOfBoundsException, "java/lang/IndexOutOfBoundsException" },
210 { SWIG_JavaArithmeticException, "java/lang/ArithmeticException" },
211 { SWIG_JavaIllegalArgumentException, "java/lang/IllegalArgumentException" },
212 { SWIG_JavaNullPointerException, "java/lang/NullPointerException" },
213 { SWIG_JavaDirectorPureVirtual, "java/lang/RuntimeException" },
214 { SWIG_JavaUnknownError, "java/lang/UnknownError" },
215 { SWIG_JavaIllegalStateException, "java/lang/IllegalStateException" },
216 { (SWIG_JavaExceptionCodes)0, "java/lang/UnknownError" }
217 };
218 const SWIG_JavaExceptions_t *except_ptr = java_exceptions;
219
220 while (except_ptr->code != code && except_ptr->code)
221 except_ptr++;
222
223 jenv->ExceptionClear();
224 excep = jenv->FindClass(except_ptr->java_exception);
225 if (excep)
226 jenv->ThrowNew(excep, msg);
227}
228
229
230/* Contract support */
231
232#define SWIG_contract_assert(nullreturn, expr, msg) if (!(expr)) {SWIG_JavaThrowException(jenv, SWIG_JavaIllegalArgumentException, msg); return nullreturn; } else
233
234
235#include <cstdint>
236#include <string>
237#include <vector>
238
240
241
242#include <stdint.h> // Use the C99 official header
243
244
245#define SWIGWORDSIZE64
246#ifndef LONG_MAX
247#include <limits.h>
248#endif
249#if (__WORDSIZE == 32) || (LONG_MAX == INT_MAX)
250# error "SWIG wrapped code invalid in 32 bit architecture, regenerate code using -DSWIGWORDSIZE32"
251#endif
252
253
254#include <string>
255
256
258
259
260#ifdef __cplusplus
261extern "C" {
262#endif
263
265 jint jresult = 0 ;
267
268 (void)jenv;
269 (void)jcls;
271 jresult = (jint)result;
272 return jresult;
273}
274
275
277 jint jresult = 0 ;
279
280 (void)jenv;
281 (void)jcls;
283 jresult = (jint)result;
284 return jresult;
285}
286
287
289 jint jresult = 0 ;
291
292 (void)jenv;
293 (void)jcls;
295 jresult = (jint)result;
296 return jresult;
297}
298
299
301 jint jresult = 0 ;
303
304 (void)jenv;
305 (void)jcls;
307 jresult = (jint)result;
308 return jresult;
309}
310
311
313 jint jresult = 0 ;
315
316 (void)jenv;
317 (void)jcls;
319 jresult = (jint)result;
320 return jresult;
321}
322
323
324SWIGEXPORT jlong JNICALL Java_com_google_ortools_algorithms_mainJNI_new_1KnapsackSolver_1_1SWIG_10(JNIEnv *jenv, jclass jcls, jstring jarg1) {
325 jlong jresult = 0 ;
326 std::string *arg1 = 0 ;
328
329 (void)jenv;
330 (void)jcls;
331 if(!jarg1) {
333 return 0;
334 }
335 const char *arg1_pstr = (const char *)jenv->GetStringUTFChars(jarg1, 0);
336 if (!arg1_pstr) return 0;
337 std::string arg1_str(arg1_pstr);
338 arg1 = &arg1_str;
339 jenv->ReleaseStringUTFChars(jarg1, arg1_pstr);
340 result = (operations_research::KnapsackSolver *)new operations_research::KnapsackSolver((std::string const &)*arg1);
341 *(operations_research::KnapsackSolver **)&jresult = result;
342 return jresult;
343}
344
345
346SWIGEXPORT jlong JNICALL Java_com_google_ortools_algorithms_mainJNI_new_1KnapsackSolver_1_1SWIG_11(JNIEnv *jenv, jclass jcls, jint jarg1, jstring jarg2) {
347 jlong jresult = 0 ;
349 std::string *arg2 = 0 ;
351
352 (void)jenv;
353 (void)jcls;
355 if(!jarg2) {
357 return 0;
358 }
359 const char *arg2_pstr = (const char *)jenv->GetStringUTFChars(jarg2, 0);
360 if (!arg2_pstr) return 0;
361 std::string arg2_str(arg2_pstr);
362 arg2 = &arg2_str;
363 jenv->ReleaseStringUTFChars(jarg2, arg2_pstr);
364 result = (operations_research::KnapsackSolver *)new operations_research::KnapsackSolver(arg1,(std::string const &)*arg2);
365 *(operations_research::KnapsackSolver **)&jresult = result;
366 return jresult;
367}
368
369
370SWIGEXPORT void JNICALL Java_com_google_ortools_algorithms_mainJNI_delete_1KnapsackSolver(JNIEnv *jenv, jclass jcls, jlong jarg1) {
372
373 (void)jenv;
374 (void)jcls;
375 arg1 = *(operations_research::KnapsackSolver **)&jarg1;
376 delete arg1;
377}
378
379
380SWIGEXPORT void JNICALL Java_com_google_ortools_algorithms_mainJNI_KnapsackSolver_1init(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_, jlongArray jarg2, jobjectArray jarg3, jlongArray jarg4) {
382 std::vector< int64_t > *arg2 = 0 ;
383 std::vector< std::vector< int64_t > > *arg3 = 0 ;
384 std::vector< int64_t > *arg4 = 0 ;
385 std::vector< std::vector< int64_t > > result3 ;
386
387 (void)jenv;
388 (void)jcls;
389 (void)jarg1_;
390 arg1 = *(operations_research::KnapsackSolver **)&jarg1;
391
392 if(jarg2) {
393 arg2 = new std::vector<int64_t>;
394 const int size = jenv->GetArrayLength(jarg2);
395 arg2->reserve(size);
396 jlong *values = jenv->GetLongArrayElements((jlongArray)jarg2, NULL);
397 for (int i = 0; i < size; ++i) {
398 arg2->emplace_back(values[i]);
399 }
400 jenv->ReleaseLongArrayElements((jlongArray)jarg2, values, JNI_ABORT);
401 }
402 else {
404 return ;
405 }
406
407
408 if(jarg3) {
409 const int size = jenv->GetArrayLength(jarg3);
410 result3.clear();
411 result3.resize(size);
412 for (int index1 = 0; index1 < size; ++index1) {
413 jlongArray inner_array =
414 (jlongArray)jenv->GetObjectArrayElement(jarg3, index1);
415 const int inner_size = jenv->GetArrayLength(inner_array);
416 result3[index1].reserve(inner_size);
417 jlong * const values =
418 jenv->GetLongArrayElements((jlongArray)inner_array, NULL);
419 for (int index2 = 0; index2 < inner_size; ++index2) {
420 result3[index1].emplace_back(values[index2]);
421 }
422 jenv->ReleaseLongArrayElements((jlongArray)inner_array, values, JNI_ABORT);
423 jenv->DeleteLocalRef(inner_array);
424 }
425 arg3 = &result3;
426 }
427 else {
429 return ;
430 }
431
432
433 if(jarg4) {
434 arg4 = new std::vector<int64_t>;
435 const int size = jenv->GetArrayLength(jarg4);
436 arg4->reserve(size);
437 jlong *values = jenv->GetLongArrayElements((jlongArray)jarg4, NULL);
438 for (int i = 0; i < size; ++i) {
439 arg4->emplace_back(values[i]);
440 }
441 jenv->ReleaseLongArrayElements((jlongArray)jarg4, values, JNI_ABORT);
442 }
443 else {
445 return ;
446 }
447
448 (arg1)->Init((std::vector< int64_t > const &)*arg2,(std::vector< std::vector< int64_t > > const &)*arg3,(std::vector< int64_t > const &)*arg4);
449 {
450 delete arg2;
451 }
452 {
453 delete arg4;
454 }
455}
456
457
458SWIGEXPORT jlong JNICALL Java_com_google_ortools_algorithms_mainJNI_KnapsackSolver_1solve(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_) {
459 jlong jresult = 0 ;
461 int64_t result;
462
463 (void)jenv;
464 (void)jcls;
465 (void)jarg1_;
466 arg1 = *(operations_research::KnapsackSolver **)&jarg1;
467 result = (int64_t)(arg1)->Solve();
468 jresult = (jlong)result;
469 return jresult;
470}
471
472
473SWIGEXPORT jboolean JNICALL Java_com_google_ortools_algorithms_mainJNI_KnapsackSolver_1bestSolutionContains(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_, jint jarg2) {
474 jboolean jresult = 0 ;
476 int arg2 ;
477 bool result;
478
479 (void)jenv;
480 (void)jcls;
481 (void)jarg1_;
482 arg1 = *(operations_research::KnapsackSolver **)&jarg1;
483 arg2 = (int)jarg2;
484 result = (bool)((operations_research::KnapsackSolver const *)arg1)->BestSolutionContains(arg2);
485 jresult = (jboolean)result;
486 return jresult;
487}
488
489
490SWIGEXPORT jboolean JNICALL Java_com_google_ortools_algorithms_mainJNI_KnapsackSolver_1isSolutionOptimal(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_) {
491 jboolean jresult = 0 ;
493 bool result;
494
495 (void)jenv;
496 (void)jcls;
497 (void)jarg1_;
498 arg1 = *(operations_research::KnapsackSolver **)&jarg1;
499 result = (bool)((operations_research::KnapsackSolver const *)arg1)->IsSolutionOptimal();
500 jresult = (jboolean)result;
501 return jresult;
502}
503
504
505SWIGEXPORT jstring JNICALL Java_com_google_ortools_algorithms_mainJNI_KnapsackSolver_1getName(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_) {
506 jstring jresult = 0 ;
508 std::string result;
509
510 (void)jenv;
511 (void)jcls;
512 (void)jarg1_;
513 arg1 = *(operations_research::KnapsackSolver **)&jarg1;
514 result = ((operations_research::KnapsackSolver const *)arg1)->GetName();
515 jresult = jenv->NewStringUTF((&result)->c_str());
516 return jresult;
517}
518
519
520SWIGEXPORT jboolean JNICALL Java_com_google_ortools_algorithms_mainJNI_KnapsackSolver_1useReduction(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_) {
521 jboolean jresult = 0 ;
523 bool result;
524
525 (void)jenv;
526 (void)jcls;
527 (void)jarg1_;
528 arg1 = *(operations_research::KnapsackSolver **)&jarg1;
529 result = (bool)((operations_research::KnapsackSolver const *)arg1)->use_reduction();
530 jresult = (jboolean)result;
531 return jresult;
532}
533
534
535SWIGEXPORT void JNICALL Java_com_google_ortools_algorithms_mainJNI_KnapsackSolver_1setUseReduction(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_, jboolean jarg2) {
537 bool arg2 ;
538
539 (void)jenv;
540 (void)jcls;
541 (void)jarg1_;
542 arg1 = *(operations_research::KnapsackSolver **)&jarg1;
543 arg2 = jarg2 ? true : false;
544 (arg1)->set_use_reduction(arg2);
545}
546
547
548SWIGEXPORT void JNICALL Java_com_google_ortools_algorithms_mainJNI_KnapsackSolver_1setTimeLimit(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_, jdouble jarg2) {
550 double arg2 ;
551
552 (void)jenv;
553 (void)jcls;
554 (void)jarg1_;
555 arg1 = *(operations_research::KnapsackSolver **)&jarg1;
556 arg2 = (double)jarg2;
557 (arg1)->set_time_limit(arg2);
558}
559
560
561#ifdef __cplusplus
562}
563#endif
564
This library solves knapsack problems.
int64_t Solve()
Solves the problem and returns the profit of the optimal solution.
SolverType
Enum controlling which underlying algorithm is used.
@ KNAPSACK_MULTIDIMENSION_BRANCH_AND_BOUND_SOLVER
Generic Solver.
@ KNAPSACK_DYNAMIC_PROGRAMMING_SOLVER
Dynamic Programming approach for single dimension problems.
@ KNAPSACK_64ITEMS_SOLVER
Optimized method for single dimension small problems.
@ KNAPSACK_BRUTE_FORCE_SOLVER
Brute force method.
@ KNAPSACK_MULTIDIMENSION_CBC_MIP_SOLVER
CBC Based Solver.
SWIGEXPORT jint JNICALL Java_com_google_ortools_algorithms_mainJNI_KnapsackSolver_1KNAPSACK_1DYNAMIC_1PROGRAMMING_1SOLVER_1get(JNIEnv *jenv, jclass jcls)
SWIGEXPORT jboolean JNICALL Java_com_google_ortools_algorithms_mainJNI_KnapsackSolver_1isSolutionOptimal(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_)
SWIGEXPORT void JNICALL Java_com_google_ortools_algorithms_mainJNI_KnapsackSolver_1setUseReduction(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_, jboolean jarg2)
SWIGEXPORT jboolean JNICALL Java_com_google_ortools_algorithms_mainJNI_KnapsackSolver_1bestSolutionContains(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_, jint jarg2)
SWIGEXPORT jint JNICALL Java_com_google_ortools_algorithms_mainJNI_KnapsackSolver_1KNAPSACK_1MULTIDIMENSION_1BRANCH_1AND_1BOUND_1SOLVER_1get(JNIEnv *jenv, jclass jcls)
SWIGEXPORT jlong JNICALL Java_com_google_ortools_algorithms_mainJNI_KnapsackSolver_1solve(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_)
SWIGEXPORT jstring JNICALL Java_com_google_ortools_algorithms_mainJNI_KnapsackSolver_1getName(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_)
#define SWIGUNUSED
static void SWIGUNUSED SWIG_JavaThrowException(JNIEnv *jenv, SWIG_JavaExceptionCodes code, const char *msg)
@ SWIG_JavaArithmeticException
@ SWIG_JavaRuntimeException
@ SWIG_JavaNullPointerException
@ SWIG_JavaDirectorPureVirtual
@ SWIG_JavaOutOfMemoryError
@ SWIG_JavaIllegalStateException
@ SWIG_JavaIllegalArgumentException
@ SWIG_JavaIndexOutOfBoundsException
SWIGEXPORT void JNICALL Java_com_google_ortools_algorithms_mainJNI_KnapsackSolver_1init(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_, jlongArray jarg2, jobjectArray jarg3, jlongArray jarg4)
SWIGEXPORT jint JNICALL Java_com_google_ortools_algorithms_mainJNI_KnapsackSolver_1KNAPSACK_164ITEMS_1SOLVER_1get(JNIEnv *jenv, jclass jcls)
SWIGEXPORT jlong JNICALL Java_com_google_ortools_algorithms_mainJNI_new_1KnapsackSolver_1_1SWIG_10(JNIEnv *jenv, jclass jcls, jstring jarg1)
SWIGEXPORT void JNICALL Java_com_google_ortools_algorithms_mainJNI_KnapsackSolver_1setTimeLimit(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_, jdouble jarg2)
SWIGEXPORT jint JNICALL Java_com_google_ortools_algorithms_mainJNI_KnapsackSolver_1KNAPSACK_1MULTIDIMENSION_1CBC_1MIP_1SOLVER_1get(JNIEnv *jenv, jclass jcls)
SWIGEXPORT jboolean JNICALL Java_com_google_ortools_algorithms_mainJNI_KnapsackSolver_1useReduction(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_)
SWIGEXPORT void JNICALL Java_com_google_ortools_algorithms_mainJNI_delete_1KnapsackSolver(JNIEnv *jenv, jclass jcls, jlong jarg1)
#define SWIGEXPORT
SWIGEXPORT jint JNICALL Java_com_google_ortools_algorithms_mainJNI_KnapsackSolver_1KNAPSACK_1BRUTE_1FORCE_1SOLVER_1get(JNIEnv *jenv, jclass jcls)
SWIGEXPORT jlong JNICALL Java_com_google_ortools_algorithms_mainJNI_new_1KnapsackSolver_1_1SWIG_11(JNIEnv *jenv, jclass jcls, jint jarg1, jstring jarg2)
SWIG_JavaExceptionCodes code