20 template<
typename T>
class SwigValueWrapper {
21 struct SwigMovePointer {
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; }
27 SwigValueWrapper& operator=(
const SwigValueWrapper<T>& rhs);
28 SwigValueWrapper(
const SwigValueWrapper<T>& rhs);
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; }
36 template <
typename T> T SwigValueInit() {
47 #ifndef SWIGTEMPLATEDISAMBIGUATOR
48 # if defined(__SUNPRO_CC) && (__SUNPRO_CC <= 0x560)
49 # define SWIGTEMPLATEDISAMBIGUATOR template
50 # elif defined(__HP_aCC)
53 # define SWIGTEMPLATEDISAMBIGUATOR template
55 # define SWIGTEMPLATEDISAMBIGUATOR
61 # if defined(__cplusplus) || (defined(__GNUC__) && !defined(__STRICT_ANSI__))
62 # define SWIGINLINE inline
70 # if defined(__GNUC__)
71 # if !(defined(__cplusplus)) || (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4))
72 # define SWIGUNUSED __attribute__ ((__unused__))
77 # define SWIGUNUSED __attribute__ ((__unused__))
83 #ifndef SWIG_MSC_UNSUPPRESS_4505
84 # if defined(_MSC_VER)
85 # pragma warning(disable : 4505)
89 #ifndef SWIGUNUSEDPARM
91 # define SWIGUNUSEDPARM(p)
93 # define SWIGUNUSEDPARM(p) p SWIGUNUSED
99 # define SWIGINTERN static SWIGUNUSED
103 #ifndef SWIGINTERNINLINE
104 # define SWIGINTERNINLINE SWIGINTERN SWIGINLINE
108 #if defined(__GNUC__)
109 # if (__GNUC__ >= 4) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
110 # ifndef GCC_HASCLASSVISIBILITY
111 # define GCC_HASCLASSVISIBILITY
117 # if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__)
118 # if defined(STATIC_LINKED)
121 # define SWIGEXPORT __declspec(dllexport)
124 # if defined(__GNUC__) && defined(GCC_HASCLASSVISIBILITY)
125 # define SWIGEXPORT __attribute__ ((visibility("default")))
134 # if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__)
135 # define SWIGSTDCALL __stdcall
142 #if !defined(SWIG_NO_CRT_SECURE_NO_DEPRECATE) && defined(_MSC_VER) && !defined(_CRT_SECURE_NO_DEPRECATE)
143 # define _CRT_SECURE_NO_DEPRECATE
147 #if !defined(SWIG_NO_SCL_SECURE_NO_DEPRECATE) && defined(_MSC_VER) && !defined(_SCL_SECURE_NO_DEPRECATE)
148 # define _SCL_SECURE_NO_DEPRECATE
152 #if defined(__APPLE__) && !defined(__ASSERT_MACROS_DEFINE_VERSIONS_WITHOUT_UNDERSCORES)
153 # define __ASSERT_MACROS_DEFINE_VERSIONS_WITHOUT_UNDERSCORES 0
161 #ifdef __INTEL_COMPILER
162 # pragma warning disable 592
167 #if defined(__GNUC__) && !defined(__INTEL_COMPILER)
168 typedef long long __int64;
172 #if defined(__x86_64)
199 const char *java_exception;
220 while (except_ptr->
code != code && except_ptr->
code)
223 jenv->ExceptionClear();
226 jenv->ThrowNew(excep, msg);
232 #define SWIG_contract_assert(nullreturn, expr, msg) if (!(expr)) {SWIG_JavaThrowException(jenv, SWIG_JavaIllegalArgumentException, msg); return nullreturn; } else
238 #define SWIGWORDSIZE64
242 #if (__WORDSIZE == 32) || (LONG_MAX == INT_MAX)
243 # error "SWIG wrapped code invalid in 32 bit architecture, regenerate code using -DSWIGWORDSIZE32"
267 std::string error_message;
268 self->LoadModelFromProto(input_model, &error_message);
269 return error_message;
272 std::unordered_set<std::string> names;
273 for (
const auto var : input_model.variable()) {
274 if (!
var.name().empty() && !names.insert(
var.name()).second) {
275 LOG(FATAL) <<
"found duplicated variable names " +
var.name();
278 std::string error_message;
279 self->LoadModelFromProtoWithUniqueNamesOrDie(input_model, &error_message);
280 return error_message;
284 self->ExportModelToProto(&
model);
289 self->FillSolutionResponseProto(&
response);
293 return self->LoadSolutionFromProto(
response).ok();
302 self->ExportModelToProto(&
model);
307 self->ExportModelToProto(&
model);
311 if (variables.size() != values.size()) {
312 LOG(FATAL) <<
"Different number of variables and values when setting "
315 std::vector<std::pair<const operations_research::MPVariable*, double> >
316 hint(variables.size());
317 for (
int i = 0; i < variables.size(); ++i) {
318 hint[i] = std::make_pair(variables[i], values[i]);
323 return self->SetNumThreads(num_theads).ok();
337 jresult = (jint)result;
349 jresult = (jint)result;
361 jresult = (jint)result;
373 jresult = (jint)result;
385 jresult = (jint)result;
397 jresult = (jint)result;
409 jresult = (jint)result;
421 jresult = (jint)result;
433 jresult = (jint)result;
445 jresult = (jint)result;
457 jresult = (jint)result;
469 jresult = (jint)result;
481 jresult = (jint)result;
493 jresult = (jint)result;
500 std::string *arg1 = 0 ;
510 const char *arg1_pstr = (
const char *)jenv->GetStringUTFChars(jarg1, 0);
511 if (!arg1_pstr)
return 0;
512 std::string arg1_str(arg1_pstr);
514 jenv->ReleaseStringUTFChars(jarg1, arg1_pstr);
534 std::string *arg1 = 0 ;
543 const char *arg1_pstr = (
const char *)jenv->GetStringUTFChars(jarg1, 0);
544 if (!arg1_pstr)
return 0;
545 std::string arg1_str(arg1_pstr);
547 jenv->ReleaseStringUTFChars(jarg1, arg1_pstr);
555 jboolean jresult = 0 ;
563 jresult = (jboolean)result;
569 jboolean jresult = 0 ;
578 jresult = (jboolean)result;
604 jresult = (jint)result;
610 jobjectArray jresult = 0 ;
612 std::vector< operations_research::MPVariable * > *result = 0 ;
620 if (
nullptr == result)
622 std::string java_class_path =
"com/google/ortools/linearsolver" "/""MPVariable";
623 jclass object_class = jenv->FindClass(java_class_path.c_str());
624 if (
nullptr == object_class)
626 jresult = jenv->NewObjectArray(result->size(), object_class, 0);
627 jmethodID ctor = jenv->GetMethodID(object_class,
"<init>",
"(JZ)V");
628 for (
int i = 0; i < result->size(); ++i) {
631 jobject elem = jenv->NewObject(object_class, ctor, obj_ptr,
false);
632 jenv->SetObjectArrayElement(jresult, i, elem);
642 std::string *arg2 = 0 ;
653 const char *arg2_pstr = (
const char *)jenv->GetStringUTFChars(jarg2, 0);
654 if (!arg2_pstr)
return 0;
655 std::string arg2_str(arg2_pstr);
657 jenv->ReleaseStringUTFChars(jarg2, arg2_pstr);
670 std::string *arg5 = 0 ;
677 arg2 = (double)jarg2;
678 arg3 = (double)jarg3;
679 arg4 = jarg4 ? true :
false;
684 const char *arg5_pstr = (
const char *)jenv->GetStringUTFChars(jarg5, 0);
685 if (!arg5_pstr)
return 0;
686 std::string arg5_str(arg5_pstr);
688 jenv->ReleaseStringUTFChars(jarg5, arg5_pstr);
700 std::string *arg4 = 0 ;
707 arg2 = (double)jarg2;
708 arg3 = (double)jarg3;
713 const char *arg4_pstr = (
const char *)jenv->GetStringUTFChars(jarg4, 0);
714 if (!arg4_pstr)
return 0;
715 std::string arg4_str(arg4_pstr);
717 jenv->ReleaseStringUTFChars(jarg4, arg4_pstr);
729 std::string *arg4 = 0 ;
736 arg2 = (double)jarg2;
737 arg3 = (double)jarg3;
742 const char *arg4_pstr = (
const char *)jenv->GetStringUTFChars(jarg4, 0);
743 if (!arg4_pstr)
return 0;
744 std::string arg4_str(arg4_pstr);
746 jenv->ReleaseStringUTFChars(jarg4, arg4_pstr);
756 std::string *arg2 = 0 ;
767 const char *arg2_pstr = (
const char *)jenv->GetStringUTFChars(jarg2, 0);
768 if (!arg2_pstr)
return 0;
769 std::string arg2_str(arg2_pstr);
771 jenv->ReleaseStringUTFChars(jarg2, arg2_pstr);
788 jresult = (jint)result;
794 jobjectArray jresult = 0 ;
796 std::vector< operations_research::MPConstraint * > *result = 0 ;
804 if (
nullptr == result)
806 std::string java_class_path =
"com/google/ortools/linearsolver" "/""MPConstraint";
807 jclass object_class = jenv->FindClass(java_class_path.c_str());
808 if (
nullptr == object_class)
810 jresult = jenv->NewObjectArray(result->size(), object_class, 0);
811 jmethodID ctor = jenv->GetMethodID(object_class,
"<init>",
"(JZ)V");
812 for (
int i = 0; i < result->size(); ++i) {
815 jobject elem = jenv->NewObject(object_class, ctor, obj_ptr,
false);
816 jenv->SetObjectArrayElement(jresult, i, elem);
826 std::string *arg2 = 0 ;
837 const char *arg2_pstr = (
const char *)jenv->GetStringUTFChars(jarg2, 0);
838 if (!arg2_pstr)
return 0;
839 std::string arg2_str(arg2_pstr);
841 jenv->ReleaseStringUTFChars(jarg2, arg2_pstr);
859 arg2 = (double)jarg2;
860 arg3 = (double)jarg3;
887 std::string *arg4 = 0 ;
894 arg2 = (double)jarg2;
895 arg3 = (double)jarg3;
900 const char *arg4_pstr = (
const char *)jenv->GetStringUTFChars(jarg4, 0);
901 if (!arg4_pstr)
return 0;
902 std::string arg4_str(arg4_pstr);
904 jenv->ReleaseStringUTFChars(jarg4, arg4_pstr);
914 std::string *arg2 = 0 ;
925 const char *arg2_pstr = (
const char *)jenv->GetStringUTFChars(jarg2, 0);
926 if (!arg2_pstr)
return 0;
927 std::string arg2_str(arg2_pstr);
929 jenv->ReleaseStringUTFChars(jarg2, arg2_pstr);
958 jresult = (jint)result;
973 jresult = (jint)result;
995 jresult = (jint)result;
1001 jdoubleArray jresult = 0 ;
1003 std::vector< double > result;
1011 const std::vector<double>& vec = result;
1012 jresult = jenv->NewDoubleArray(vec.size());
1013 jenv->SetDoubleArrayRegion(jresult, 0, vec.size(),
reinterpret_cast<const jdouble*
>(vec.data()));
1020 jboolean jresult = 0 ;
1030 arg2 = (double)jarg2;
1031 arg3 = jarg3 ? true :
false;
1033 jresult = (jboolean)result;
1050 jboolean jresult = 0 ;
1059 jresult = (jboolean)result;
1065 jboolean jresult = 0 ;
1067 std::string *arg2 = 0 ;
1078 const char *arg2_pstr = (
const char *)jenv->GetStringUTFChars(jarg2, 0);
1079 if (!arg2_pstr)
return 0;
1080 std::string arg2_str(arg2_pstr);
1082 jenv->ReleaseStringUTFChars(jarg2, arg2_pstr);
1083 result = (bool)(arg1)->SetSolverSpecificParametersAsString((std::string
const &)*arg2);
1084 jresult = (jboolean)result;
1096 jresult = (jint)result;
1102 jdouble jresult = 0 ;
1108 jresult = (jdouble)result;
1120 (arg1)->EnableOutput();
1131 (arg1)->SuppressOutput();
1145 jresult = (jlong)result;
1160 jresult = (jlong)result;
1166 jdouble jresult = 0 ;
1175 jresult = (jdouble)result;
1188 arg2 = (
int64)jarg2;
1189 (arg1)->set_time_limit(arg2);
1203 jresult = (jlong)result;
1209 std::string *arg1 = 0 ;
1217 const char *arg1_pstr = (
const char *)jenv->GetStringUTFChars(jarg1, 0);
1218 if (!arg1_pstr) return ;
1219 std::string arg1_str(arg1_pstr);
1221 jenv->ReleaseStringUTFChars(jarg1, arg1_pstr);
1227 jstring jresult = 0 ;
1239 std::unique_ptr<char[]> proto_buffer(
1241 bool parsed_ok = temp2.ParseFromArray(proto_buffer.get(), proto_size);
1245 "Unable to parse operations_research::MPModelProto protocol message.");
1250 jresult = jenv->NewStringUTF((&result)->c_str());
1256 jstring jresult = 0 ;
1268 std::unique_ptr<char[]> proto_buffer(
1270 bool parsed_ok = temp2.ParseFromArray(proto_buffer.get(), proto_size);
1274 "Unable to parse operations_research::MPModelProto protocol message.");
1279 jresult = jenv->NewStringUTF((&result)->c_str());
1285 jbyteArray jresult = 0 ;
1295 const long size = (&result)->ByteSizeLong();
1296 std::unique_ptr<char[]> buf(
new char[size]);
1297 (&result)->SerializeWithCachedSizesToArray(
reinterpret_cast<uint8*
>(buf.get()));
1305 jbyteArray jresult = 0 ;
1315 const long size = (&result)->ByteSizeLong();
1316 std::unique_ptr<char[]> buf(
new char[size]);
1317 (&result)->SerializeWithCachedSizesToArray(
reinterpret_cast<uint8*
>(buf.get()));
1325 jboolean jresult = 0 ;
1337 std::unique_ptr<char[]> proto_buffer(
1339 bool parsed_ok = temp2.ParseFromArray(proto_buffer.get(), proto_size);
1343 "Unable to parse operations_research::MPSolutionResponse protocol message.");
1348 jresult = (jboolean)result;
1354 jbyteArray jresult = 0 ;
1363 std::unique_ptr<char[]> proto_buffer(
1365 bool parsed_ok = temp1.ParseFromArray(proto_buffer.get(), proto_size);
1369 "Unable to parse operations_research::MPModelRequest protocol message.");
1375 const long size = (&result)->ByteSizeLong();
1376 std::unique_ptr<char[]> buf(
new char[size]);
1377 (&result)->SerializeWithCachedSizesToArray(
reinterpret_cast<uint8*
>(buf.get()));
1385 jstring jresult = 0 ;
1401 jresult = jenv->NewStringUTF((&result)->c_str());
1407 jstring jresult = 0 ;
1416 jresult = jenv->NewStringUTF((&result)->c_str());
1422 jstring jresult = 0 ;
1438 jresult = jenv->NewStringUTF((&result)->c_str());
1444 jstring jresult = 0 ;
1453 jresult = jenv->NewStringUTF((&result)->c_str());
1460 std::vector< operations_research::MPVariable * > *arg2 = 0 ;
1461 std::vector< double > *arg3 = 0 ;
1462 std::vector< operations_research::MPVariable * > result2 ;
1469 std::string java_class_path =
"com/google/ortools/linearsolver" "/""MPVariable";
1470 jclass object_class = jenv->FindClass(java_class_path.c_str());
1471 if (
nullptr == object_class)
1473 jmethodID method_id =
1474 jenv->GetStaticMethodID(
1475 object_class,
"getCPtr",
1476 std::string(
"(L" + java_class_path +
";)J").c_str());
1477 assert(method_id !=
nullptr);
1478 for (
int i = 0; i < jenv->GetArrayLength(jarg2); i++) {
1479 jobject elem = jenv->GetObjectArrayElement(jarg2, i);
1480 jlong ptr_value = jenv->CallStaticLongMethod(object_class, method_id, elem);
1489 arg3 =
new std::vector<double>;
1490 const int size = jenv->GetArrayLength(jarg3);
1491 arg3->reserve(size);
1492 jdouble *values = jenv->GetDoubleArrayElements((jdoubleArray)jarg3, NULL);
1493 for (
int i = 0; i < size; ++i) {
1494 arg3->emplace_back(values[i]);
1496 jenv->ReleaseDoubleArrayElements((jdoubleArray)jarg3, values, JNI_ABORT);
1511 jboolean jresult = 0 ;
1522 jresult = (jboolean)result;
1549 arg3 = (double)jarg3;
1555 jdouble jresult = 0 ;
1567 jresult = (jdouble)result;
1580 arg2 = (double)jarg2;
1581 (arg1)->SetOffset(arg2);
1586 jdouble jresult = 0 ;
1595 jresult = (jdouble)result;
1608 arg2 = jarg2 ? true :
false;
1609 (arg1)->SetOptimizationDirection(arg2);
1620 (arg1)->SetMinimization();
1631 (arg1)->SetMaximization();
1636 jboolean jresult = 0 ;
1645 jresult = (jboolean)result;
1651 jboolean jresult = 0 ;
1660 jresult = (jboolean)result;
1666 jdouble jresult = 0 ;
1675 jresult = (jdouble)result;
1681 jdouble jresult = 0 ;
1690 jresult = (jdouble)result;
1706 jstring jresult = 0 ;
1708 std::string *result = 0 ;
1715 jresult = jenv->NewStringUTF(result->c_str());
1728 arg2 = jarg2 ? true :
false;
1729 (arg1)->SetInteger(arg2);
1734 jdouble jresult = 0 ;
1743 jresult = (jdouble)result;
1758 jresult = (jint)result;
1764 jdouble jresult = 0 ;
1773 jresult = (jdouble)result;
1779 jdouble jresult = 0 ;
1788 jresult = (jdouble)result;
1801 arg2 = (double)jarg2;
1802 (arg1)->SetLB(arg2);
1814 arg2 = (double)jarg2;
1815 (arg1)->SetUB(arg2);
1828 arg2 = (double)jarg2;
1829 arg3 = (double)jarg3;
1830 (arg1)->SetBounds(arg2,arg3);
1835 jdouble jresult = 0 ;
1844 jresult = (jdouble)result;
1859 jresult = (jint)result;
1875 jstring jresult = 0 ;
1877 std::string *result = 0 ;
1884 jresult = jenv->NewStringUTF(result->c_str());
1900 arg3 = (double)jarg3;
1906 jdouble jresult = 0 ;
1918 jresult = (jdouble)result;
1924 jdouble jresult = 0 ;
1933 jresult = (jdouble)result;
1939 jdouble jresult = 0 ;
1948 jresult = (jdouble)result;
1961 arg2 = (double)jarg2;
1962 (arg1)->SetLB(arg2);
1974 arg2 = (double)jarg2;
1975 (arg1)->SetUB(arg2);
1988 arg2 = (double)jarg2;
1989 arg3 = (double)jarg3;
1990 (arg1)->SetBounds(arg2,arg3);
1995 jboolean jresult = 0 ;
2004 jresult = (jboolean)result;
2017 arg2 = jarg2 ? true :
false;
2018 (arg1)->set_is_lazy(arg2);
2032 jresult = (jint)result;
2038 jdouble jresult = 0 ;
2047 jresult = (jdouble)result;
2062 jresult = (jint)result;
2084 jresult = (jint)result;
2096 jresult = (jint)result;
2108 jresult = (jint)result;
2120 jresult = (jint)result;
2132 jresult = (jint)result;
2144 jresult = (jint)result;
2156 jresult = (jint)result;
2168 jresult = (jint)result;
2180 jresult = (jint)result;
2192 jresult = (jint)result;
2204 jresult = (jint)result;
2216 jresult = (jint)result;
2228 jresult = (jint)result;
2240 jresult = (jint)result;
2252 jresult = (jint)result;
2264 jresult = (jint)result;
2270 jdouble jresult = 0 ;
2276 jresult = (jdouble)result;
2282 jdouble jresult = 0 ;
2288 jresult = (jdouble)result;
2294 jdouble jresult = 0 ;
2300 jresult = (jdouble)result;
2312 jresult = (jint)result;
2324 jresult = (jint)result;
2351 arg3 = (double)jarg3;
2352 (arg1)->SetDoubleParam(arg2,arg3);
2367 (arg1)->SetIntegerParam(arg2,arg3);
2372 jdouble jresult = 0 ;
2383 jresult = (jdouble)result;
2400 jresult = (jint)result;
2435 arg2 = jarg2 ? true :
false;
2436 if (arg1) (arg1)->obfuscate = arg2;
2441 jboolean jresult = 0 ;
2449 result = (bool) ((arg1)->obfuscate);
2450 jresult = (jboolean)result;
2463 arg2 = jarg2 ? true :
false;
2464 if (arg1) (arg1)->log_invalid_names = arg2;
2469 jboolean jresult = 0 ;
2477 result = (bool) ((arg1)->log_invalid_names);
2478 jresult = (jboolean)result;
2491 arg2 = jarg2 ? true :
false;
2492 if (arg1) (arg1)->show_unused_variables = arg2;
2497 jboolean jresult = 0 ;
2505 result = (bool) ((arg1)->show_unused_variables);
2506 jresult = (jboolean)result;
2520 if (arg1) (arg1)->max_line_length = arg2;
2533 result = (int) ((arg1)->max_line_length);
2534 jresult = (jint)result;