fix examples/python/bazel; add time limit to example; remove jniutil; disable dump_vars_test on mac
This commit is contained in:
@@ -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")
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -596,8 +596,3 @@ cc_library(
|
||||
"@zlib",
|
||||
],
|
||||
)
|
||||
|
||||
cc_library(
|
||||
name = "jniutil",
|
||||
hdrs = ["jniutil.h"],
|
||||
)
|
||||
|
||||
@@ -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__)
|
||||
|
||||
@@ -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 <jni.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
#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<char*>(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<const jbyte*>(a));
|
||||
return output;
|
||||
}
|
||||
};
|
||||
|
||||
#endif // OR_TOOLS_BASE_JNIUTIL_H_
|
||||
Reference in New Issue
Block a user