From 576fb3fca565bd5c1964fc5942295c27d7a97491 Mon Sep 17 00:00:00 2001 From: Laurent Perron Date: Sat, 28 Jan 2023 12:38:26 +0100 Subject: [PATCH] fix examples/python/bazel; add time limit to example; remove jniutil; disable dump_vars_test on mac --- examples/python/BUILD.bazel | 2 - examples/python/bus_driver_scheduling_sat.py | 7 +- ortools/base/BUILD.bazel | 5 -- ortools/base/dump_vars_test.cc | 2 + ortools/base/jniutil.h | 68 -------------------- 5 files changed, 6 insertions(+), 78 deletions(-) delete mode 100644 ortools/base/jniutil.h diff --git a/examples/python/BUILD.bazel b/examples/python/BUILD.bazel index e063791d5f..044f4aa40d 100644 --- a/examples/python/BUILD.bazel +++ b/examples/python/BUILD.bazel @@ -83,8 +83,6 @@ code_sample_py("vendor_scheduling_sat") code_sample_py("wedding_optimal_chart_sat") -code_sample_py("weighted_latency_problem_sat") - code_sample_py("worker_schedule_sat") code_sample_py("zebra_sat") diff --git a/examples/python/bus_driver_scheduling_sat.py b/examples/python/bus_driver_scheduling_sat.py index b007649ab7..00f60afa81 100755 --- a/examples/python/bus_driver_scheduling_sat.py +++ b/examples/python/bus_driver_scheduling_sat.py @@ -33,9 +33,10 @@ from ortools.sat.python import cp_model _OUTPUT_PROTO = flags.DEFINE_string( 'output_proto', '', 'Output file to write the cp_model proto to.') -_PARAMS = flags.DEFINE_string('params', - 'num_search_workers:8,log_search_progress:true', - 'Sat solver parameters.') +_PARAMS = flags.DEFINE_string( + 'params', + 'num_search_workers:16,log_search_progress:true,max_time_in_seconds:45', + 'Sat solver parameters.') _INSTANCE = flags.DEFINE_integer('instance', 1, 'Instance to select (1, 2, 3).', 1, 3) diff --git a/ortools/base/BUILD.bazel b/ortools/base/BUILD.bazel index 0f241dfb02..bc64bd8725 100644 --- a/ortools/base/BUILD.bazel +++ b/ortools/base/BUILD.bazel @@ -596,8 +596,3 @@ cc_library( "@zlib", ], ) - -cc_library( - name = "jniutil", - hdrs = ["jniutil.h"], -) diff --git a/ortools/base/dump_vars_test.cc b/ortools/base/dump_vars_test.cc index 2f7525983e..54c7b37721 100644 --- a/ortools/base/dump_vars_test.cc +++ b/ortools/base/dump_vars_test.cc @@ -21,6 +21,7 @@ #include "gtest/gtest.h" +#if !defined(__APPLE__) namespace operations_research::base { namespace { @@ -161,3 +162,4 @@ TEST(DumpVars, TemporaryLifetime) { } // namespace } // namespace operations_research::base +#endif // !defined(__APPLE__) diff --git a/ortools/base/jniutil.h b/ortools/base/jniutil.h deleted file mode 100644 index 70e9967dd3..0000000000 --- a/ortools/base/jniutil.h +++ /dev/null @@ -1,68 +0,0 @@ -// Copyright 2010-2022 Google LLC -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#ifndef OR_TOOLS_BASE_JNIUTIL_H_ -#define OR_TOOLS_BASE_JNIUTIL_H_ - -#include - -#include - -#include "ortools/base/logging.h" - -class JNIUtil { - public: - // Creates a Java jstring from a null-terminated UTF-8 encoded C String. - // The caller must delete the jstring reference. - static jstring MakeJString(JNIEnv* env, const char* cstr) { - if (cstr == nullptr) return nullptr; - return env->NewStringUTF(cstr); - } - - // Creates a null-terminated UTF-8 encoded C string from a jstring. - // The returned string should be "delete[]"-ed when no longer needed. - static char* MakeCString(JNIEnv* env, jstring str) { - if (str == nullptr) return nullptr; - jsize length = env->GetStringUTFLength(str); - const char* src = env->GetStringUTFChars(str, nullptr); - char* dst = new char[length + 1]; - memcpy(dst, src, length); - dst[length] = '\0'; - env->ReleaseStringUTFChars(str, src); - return dst; - } - - // Creates a new char array from a jbyteArray. - // The caller must delete[] the returned array. - static char* MakeCharArray(JNIEnv* env, jbyteArray a, int* size) { - jsize n = env->GetArrayLength(a); - *size = n; - jbyte* jba = new jbyte[n]; - - env->GetByteArrayRegion(a, 0, n, jba); - // We make use of the fact that jbyte's are really just chars. - // If this changes (different VM, etc.) things will break. - return reinterpret_cast(jba); - } - - // Produces a jbyteArray from a char array. - static jbyteArray MakeJByteArray(JNIEnv* env, const char* a, int size) { - // Create empty array object - jbyteArray output = env->NewByteArray(size); - // Fill it - env->SetByteArrayRegion(output, 0, size, reinterpret_cast(a)); - return output; - } -}; - -#endif // OR_TOOLS_BASE_JNIUTIL_H_