OR-Tools  9.2
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#include <string>
246
247
249
250
251#ifdef __cplusplus
252extern "C" {
253#endif
254
256 jint jresult = 0 ;
258
259 (void)jenv;
260 (void)jcls;
262 jresult = (jint)result;
263 return jresult;
264}
265
266
268 jint jresult = 0 ;
270
271 (void)jenv;
272 (void)jcls;
274 jresult = (jint)result;
275 return jresult;
276}
277
278
280 jint jresult = 0 ;
282
283 (void)jenv;
284 (void)jcls;
286 jresult = (jint)result;
287 return jresult;
288}
289
290
292 jint jresult = 0 ;
294
295 (void)jenv;
296 (void)jcls;
298 jresult = (jint)result;
299 return jresult;
300}
301
302
304 jint jresult = 0 ;
306
307 (void)jenv;
308 (void)jcls;
310 jresult = (jint)result;
311 return jresult;
312}
313
314
315SWIGEXPORT jlong JNICALL Java_com_google_ortools_algorithms_mainJNI_new_1KnapsackSolver_1_1SWIG_10(JNIEnv *jenv, jclass jcls, jstring jarg1) {
316 jlong jresult = 0 ;
317 std::string *arg1 = 0 ;
319
320 (void)jenv;
321 (void)jcls;
322 if(!jarg1) {
324 return 0;
325 }
326 const char *arg1_pstr = (const char *)jenv->GetStringUTFChars(jarg1, 0);
327 if (!arg1_pstr) return 0;
328 std::string arg1_str(arg1_pstr);
329 arg1 = &arg1_str;
330 jenv->ReleaseStringUTFChars(jarg1, arg1_pstr);
331 result = (operations_research::KnapsackSolver *)new operations_research::KnapsackSolver((std::string const &)*arg1);
332 *(operations_research::KnapsackSolver **)&jresult = result;
333 return jresult;
334}
335
336
337SWIGEXPORT jlong JNICALL Java_com_google_ortools_algorithms_mainJNI_new_1KnapsackSolver_1_1SWIG_11(JNIEnv *jenv, jclass jcls, jint jarg1, jstring jarg2) {
338 jlong jresult = 0 ;
340 std::string *arg2 = 0 ;
342
343 (void)jenv;
344 (void)jcls;
346 if(!jarg2) {
348 return 0;
349 }
350 const char *arg2_pstr = (const char *)jenv->GetStringUTFChars(jarg2, 0);
351 if (!arg2_pstr) return 0;
352 std::string arg2_str(arg2_pstr);
353 arg2 = &arg2_str;
354 jenv->ReleaseStringUTFChars(jarg2, arg2_pstr);
355 result = (operations_research::KnapsackSolver *)new operations_research::KnapsackSolver(arg1,(std::string const &)*arg2);
356 *(operations_research::KnapsackSolver **)&jresult = result;
357 return jresult;
358}
359
360
361SWIGEXPORT void JNICALL Java_com_google_ortools_algorithms_mainJNI_delete_1KnapsackSolver(JNIEnv *jenv, jclass jcls, jlong jarg1) {
363
364 (void)jenv;
365 (void)jcls;
366 arg1 = *(operations_research::KnapsackSolver **)&jarg1;
367 delete arg1;
368}
369
370
371SWIGEXPORT void JNICALL Java_com_google_ortools_algorithms_mainJNI_KnapsackSolver_1init(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_, jlongArray jarg2, jobjectArray jarg3, jlongArray jarg4) {
373 std::vector< int64_t > *arg2 = 0 ;
374 std::vector< std::vector< int64_t > > *arg3 = 0 ;
375 std::vector< int64_t > *arg4 = 0 ;
376 std::vector< std::vector< int64_t > > result3 ;
377
378 (void)jenv;
379 (void)jcls;
380 (void)jarg1_;
381 arg1 = *(operations_research::KnapsackSolver **)&jarg1;
382
383 if(jarg2) {
384 arg2 = new std::vector<int64_t>;
385 const int size = jenv->GetArrayLength(jarg2);
386 arg2->reserve(size);
387 jlong *values = jenv->GetLongArrayElements((jlongArray)jarg2, NULL);
388 for (int i = 0; i < size; ++i) {
389 arg2->emplace_back(values[i]);
390 }
391 jenv->ReleaseLongArrayElements((jlongArray)jarg2, values, JNI_ABORT);
392 }
393 else {
395 return ;
396 }
397
398
399 if(jarg3) {
400 const int size = jenv->GetArrayLength(jarg3);
401 result3.clear();
402 result3.resize(size);
403 for (int index1 = 0; index1 < size; ++index1) {
404 jlongArray inner_array =
405 (jlongArray)jenv->GetObjectArrayElement(jarg3, index1);
406 const int inner_size = jenv->GetArrayLength(inner_array);
407 result3[index1].reserve(inner_size);
408 jlong * const values =
409 jenv->GetLongArrayElements((jlongArray)inner_array, NULL);
410 for (int index2 = 0; index2 < inner_size; ++index2) {
411 result3[index1].emplace_back(values[index2]);
412 }
413 jenv->ReleaseLongArrayElements((jlongArray)inner_array, values, JNI_ABORT);
414 jenv->DeleteLocalRef(inner_array);
415 }
416 arg3 = &result3;
417 }
418 else {
420 return ;
421 }
422
423
424 if(jarg4) {
425 arg4 = new std::vector<int64_t>;
426 const int size = jenv->GetArrayLength(jarg4);
427 arg4->reserve(size);
428 jlong *values = jenv->GetLongArrayElements((jlongArray)jarg4, NULL);
429 for (int i = 0; i < size; ++i) {
430 arg4->emplace_back(values[i]);
431 }
432 jenv->ReleaseLongArrayElements((jlongArray)jarg4, values, JNI_ABORT);
433 }
434 else {
436 return ;
437 }
438
439 (arg1)->Init((std::vector< int64_t > const &)*arg2,(std::vector< std::vector< int64_t > > const &)*arg3,(std::vector< int64_t > const &)*arg4);
440 {
441 delete arg2;
442 }
443 {
444 delete arg4;
445 }
446}
447
448
449SWIGEXPORT jlong JNICALL Java_com_google_ortools_algorithms_mainJNI_KnapsackSolver_1solve(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_) {
450 jlong jresult = 0 ;
452 int64_t result;
453
454 (void)jenv;
455 (void)jcls;
456 (void)jarg1_;
457 arg1 = *(operations_research::KnapsackSolver **)&jarg1;
458 result = (int64_t)(arg1)->Solve();
459 jresult = (jlong)result;
460 return jresult;
461}
462
463
464SWIGEXPORT jboolean JNICALL Java_com_google_ortools_algorithms_mainJNI_KnapsackSolver_1bestSolutionContains(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_, jint jarg2) {
465 jboolean jresult = 0 ;
467 int arg2 ;
468 bool result;
469
470 (void)jenv;
471 (void)jcls;
472 (void)jarg1_;
473 arg1 = *(operations_research::KnapsackSolver **)&jarg1;
474 arg2 = (int)jarg2;
475 result = (bool)((operations_research::KnapsackSolver const *)arg1)->BestSolutionContains(arg2);
476 jresult = (jboolean)result;
477 return jresult;
478}
479
480
481SWIGEXPORT jboolean JNICALL Java_com_google_ortools_algorithms_mainJNI_KnapsackSolver_1isSolutionOptimal(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_) {
482 jboolean jresult = 0 ;
484 bool result;
485
486 (void)jenv;
487 (void)jcls;
488 (void)jarg1_;
489 arg1 = *(operations_research::KnapsackSolver **)&jarg1;
490 result = (bool)((operations_research::KnapsackSolver const *)arg1)->IsSolutionOptimal();
491 jresult = (jboolean)result;
492 return jresult;
493}
494
495
496SWIGEXPORT jstring JNICALL Java_com_google_ortools_algorithms_mainJNI_KnapsackSolver_1getName(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_) {
497 jstring jresult = 0 ;
499 std::string result;
500
501 (void)jenv;
502 (void)jcls;
503 (void)jarg1_;
504 arg1 = *(operations_research::KnapsackSolver **)&jarg1;
505 result = ((operations_research::KnapsackSolver const *)arg1)->GetName();
506 jresult = jenv->NewStringUTF((&result)->c_str());
507 return jresult;
508}
509
510
511SWIGEXPORT jboolean JNICALL Java_com_google_ortools_algorithms_mainJNI_KnapsackSolver_1useReduction(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_) {
512 jboolean jresult = 0 ;
514 bool result;
515
516 (void)jenv;
517 (void)jcls;
518 (void)jarg1_;
519 arg1 = *(operations_research::KnapsackSolver **)&jarg1;
520 result = (bool)((operations_research::KnapsackSolver const *)arg1)->use_reduction();
521 jresult = (jboolean)result;
522 return jresult;
523}
524
525
526SWIGEXPORT void JNICALL Java_com_google_ortools_algorithms_mainJNI_KnapsackSolver_1setUseReduction(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_, jboolean jarg2) {
528 bool arg2 ;
529
530 (void)jenv;
531 (void)jcls;
532 (void)jarg1_;
533 arg1 = *(operations_research::KnapsackSolver **)&jarg1;
534 arg2 = jarg2 ? true : false;
535 (arg1)->set_use_reduction(arg2);
536}
537
538
539SWIGEXPORT void JNICALL Java_com_google_ortools_algorithms_mainJNI_KnapsackSolver_1setTimeLimit(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_, jdouble jarg2) {
541 double arg2 ;
542
543 (void)jenv;
544 (void)jcls;
545 (void)jarg1_;
546 arg1 = *(operations_research::KnapsackSolver **)&jarg1;
547 arg2 = (double)jarg2;
548 (arg1)->set_time_limit(arg2);
549}
550
551
552#ifdef __cplusplus
553}
554#endif
555
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