stub code to get sat/java interface

This commit is contained in:
Laurent Perron
2018-08-01 14:10:19 -07:00
parent 80694b8513
commit 5e2a5d1d86
6 changed files with 134 additions and 1 deletions

View File

@@ -173,6 +173,13 @@ $(GEN_DIR)/ortools/linear_solver/linear_solver_java_wrap.cc: \
| $(GEN_DIR)/ortools/linear_solver $(GEN_DIR)/com/google/ortools/linearsolver
$(SWIG_BINARY) $(SWIG_INC) -I$(INC_DIR) -c++ -java -o $(GEN_PATH)$Sortools$Slinear_solver$Slinear_solver_java_wrap.cc -package com.google.ortools.linearsolver -module operations_research_linear_solver -outdir $(GEN_PATH)$Scom$Sgoogle$Sortools$Slinearsolver $(SRC_DIR)$Sortools$Slinear_solver$Sjava$Slinear_solver.i
$(GEN_DIR)/ortools/sat/sat_java_wrap.cc: \
$(SRC_DIR)/ortools/sat/java/sat.i \
$(SRC_DIR)/ortools/base/base.i \
$(SAT_DEPS) \
| $(GEN_DIR)/ortools/sat $(GEN_DIR)/com/google/ortools/sat
$(SWIG_BINARY) -I$(INC_DIR) -c++ -java -o $(GEN_PATH)$Sortools$Ssat$Ssat_java_wrap.cc -package com.google.ortools.sat -module operations_research_sat -outdir $(GEN_PATH)$Scom$Sgoogle$Sortools$Ssat $(SRC_DIR)$Sortools$Ssat$Sjava$Ssat.i
$(OBJ_DIR)/swig/linear_solver_java_wrap.$O: \
$(GEN_DIR)/ortools/linear_solver/linear_solver_java_wrap.cc \
$(LP_DEPS) \
@@ -185,6 +192,12 @@ $(OBJ_DIR)/swig/graph_java_wrap.$O: \
| $(OBJ_DIR)/swig
$(CCC) $(JNIFLAGS) $(JAVA_INC) -c $(GEN_PATH)$Sortools$Sgraph$Sgraph_java_wrap.cc $(OBJ_OUT)$(OBJ_DIR)$Sswig$Sgraph_java_wrap.$O
$(OBJ_DIR)/swig/sat_java_wrap.$O: \
$(GEN_DIR)/ortools/sat/sat_java_wrap.cc \
$(SAT_DEPS) \
| $(OBJ_DIR)/swig
$(CCC) $(JNIFLAGS) $(JAVA_INC) -c $(GEN_PATH)$Sortools$Ssat$Ssat_java_wrap.cc $(OBJ_OUT)$(OBJ_DIR)$Sswig$Ssat_java_wrap.$O
$(GEN_DIR)/com/google/ortools/constraintsolver/SearchLimitProtobuf.java: \
$(SRC_DIR)/ortools/constraint_solver/search_limit.proto \
| $(GEN_DIR)/com/google/ortools/constraintsolver
@@ -205,6 +218,16 @@ $(GEN_DIR)/com/google/ortools/constraintsolver/RoutingEnums.java: \
| $(GEN_DIR)/com/google/ortools/constraintsolver
$(PROTOC) --proto_path=$(SRC_DIR) --java_out=$(GEN_PATH) $(SRC_DIR)$Sortools$Sconstraint_solver$Srouting_enums.proto
$(GEN_DIR)/com/google/ortools/sat/CpModel.java: \
$(SRC_DIR)/ortools/sat/cp_model.proto \
| $(GEN_DIR)/com/google/ortools/sat
$(PROTOC) --proto_path=$(SRC_DIR) --java_out=$(GEN_PATH) $(SRC_DIR)$Sortools$Ssat$Scp_model.proto
$(GEN_DIR)/com/google/ortools/sat/SatParameters.java: \
$(SRC_DIR)/ortools/sat/sat_parameters.proto \
| $(GEN_DIR)/com/google/ortools/sat
$(PROTOC) --proto_path=$(SRC_DIR) --java_out=$(GEN_PATH) $(SRC_DIR)$Sortools$Ssat$Ssat_parameters.proto
$(LIB_DIR)/protobuf.jar: dependencies/install/lib/protobuf.jar | $(LIB_DIR)
$(COPY) dependencies$Sinstall$Slib$Sprotobuf.jar $(LIB_DIR)
@@ -217,12 +240,16 @@ $(LIB_DIR)/com.google.ortools.jar: \
$(GEN_DIR)/com/google/ortools/constraintsolver/SolverParameters.java \
$(GEN_DIR)/com/google/ortools/constraintsolver/SearchLimitProtobuf.java \
$(GEN_DIR)/com/google/ortools/constraintsolver/RoutingParameters.java \
$(GEN_DIR)/com/google/ortools/constraintsolver/RoutingEnums.java | \
$(GEN_DIR)/com/google/ortools/constraintsolver/RoutingEnums.java \
$(GEN_DIR)/com/google/ortools/sat/SatParameters.java \
$(GEN_DIR)/com/google/ortools/sat/CpModel.java | \
$(CLASS_DIR)/com/google/ortools
$(JAVAC_BIN) -d $(CLASS_DIR) \
-cp $(LIB_DIR)$Sprotobuf.jar \
$(SRC_DIR)$Sortools$Scom$Sgoogle$Sortools$Sconstraintsolver$S*.java \
$(SRC_DIR)$Sortools$Scom$Sgoogle$Sortools$Ssat$S*.java \
$(GEN_PATH)$Scom$Sgoogle$Sortools$Sconstraintsolver$S*.java \
$(GEN_PATH)$Scom$Sgoogle$Sortools$Ssat$S*.java \
$(GEN_PATH)$Scom$Sgoogle$Sortools$Salgorithms$S*.java \
$(GEN_PATH)$Scom$Sgoogle$Sortools$Sgraph$S*.java \
$(GEN_PATH)$Scom$Sgoogle$Sortools$Slinearsolver$S*.java
@@ -233,12 +260,14 @@ $(LIB_DIR)/$(LIB_PREFIX)jniortools.$(JNI_LIB_EXT): \
$(OBJ_DIR)/swig/knapsack_solver_java_wrap.$O \
$(OBJ_DIR)/swig/graph_java_wrap.$O \
$(OBJ_DIR)/swig/linear_solver_java_wrap.$O \
$(OBJ_DIR)/swig/sat_java_wrap.$O \
$(OR_TOOLS_LIBS)
$(DYNAMIC_LD) $(LD_OUT)$(LIB_DIR)$S$(LIB_PREFIX)jniortools.$(JNI_LIB_EXT) \
$(OBJ_DIR)$Sswig$Sconstraint_solver_java_wrap.$O \
$(OBJ_DIR)$Sswig$Sknapsack_solver_java_wrap.$O \
$(OBJ_DIR)$Sswig$Sgraph_java_wrap.$O \
$(OBJ_DIR)$Sswig$Slinear_solver_java_wrap.$O \
$(OBJ_DIR)$Sswig$Ssat_java_wrap.$O \
$(OR_TOOLS_LNK) \
$(OR_TOOLS_LDFLAGS)
@@ -291,6 +320,7 @@ clean_java:
-$(DEL) $(GEN_PATH)$Sortools$Sconstraint_solver$S*java_wrap*
-$(DEL) $(GEN_PATH)$Sortools$Sgraph$S*java_wrap*
-$(DEL) $(GEN_PATH)$Sortools$Slinear_solver$S*java_wrap*
-$(DEL) $(GEN_PATH)$Sortools$Ssat$S*java_wrap*
-$(DEL) $(OBJ_DIR)$Sswig$S*_java_wrap.$O
-$(DEL) $(LIB_DIR)$S$(LIB_PREFIX)jni*.$(JNI_LIB_EXT)
-$(DEL) $(LIB_DIR)$S*.jar

View File

@@ -0,0 +1,14 @@
package com.google.ortools.sat;
import com.google.ortools.sat.CpModelProto;
public class CpModel {
public CpModel() {
builder_ = CpModelProto.newBuilder();
}
public CpModelProto Model() { return builder_.build(); }
public int Negated(int index) { return -index - 1; }
private CpModelProto.Builder builder_;
}

View File

@@ -15,6 +15,9 @@
syntax = "proto3";
option java_package = "com.google.ortools.sat";
option java_multiple_files = true;
option java_outer_classname = "CpModelProtobuf";
option csharp_namespace = "Google.OrTools.Sat";
package operations_research.sat;

70
ortools/sat/java/sat.i Normal file
View File

@@ -0,0 +1,70 @@
// Copyright 2010-2017 Google
// 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.
// This .i file exposes the sat cp_model API.
%include "ortools/base/base.i"
%include "ortools/util/java/proto.i"
%{
#include "ortools/sat/cp_model.pb.h"
#include "ortools/sat/sat_parameters.pb.h"
#include "ortools/sat/swig_helper.h"
%}
%module(directors="1") operations_research_sat
PROTO_INPUT(operations_research::sat::CpModelProto,
com.google.ortools.sat.CpModelProto,
model_proto);
PROTO_INPUT(operations_research::sat::SatParameters,
com.google.ortools.sat.SatParameters,
parameters);
PROTO2_RETURN(
operations_research::sat::CpSolverResponse,
com.google.ortools.sat.CpSolverResponse);
%ignoreall
%unignore operations_research;
%unignore operations_research::sat;
%unignore operations_research::sat::SatHelper;
%unignore operations_research::sat::SatHelper::Solve;
%unignore operations_research::sat::SatHelper::SolveWithParameters;
// We use the director version of the API.
%unignore operations_research::sat::SatHelper::SolveWithParametersAndSolutionCallback;
// --------- Include the swig helpers file to create the director classes ------
// We cannot use %ignoreall/%unignoreall as this is not compatible with nested
// swig files.
%feature("director") operations_research::sat::SolutionCallback;
%unignore operations_research::sat::SolutionCallback;
%unignore operations_research::sat::SolutionCallback::NumBinaryPropagations;
%unignore operations_research::sat::SolutionCallback::NumBooleans;
%unignore operations_research::sat::SolutionCallback::NumBranches;
%unignore operations_research::sat::SolutionCallback::NumConflicts;
%unignore operations_research::sat::SolutionCallback::NumIntegerPropagations;
%unignore operations_research::sat::SolutionCallback::ObjectiveValue;
%unignore operations_research::sat::SolutionCallback::OnSolutionCallback;
%unignore operations_research::sat::SolutionCallback::SolutionBooleanValue;
%unignore operations_research::sat::SolutionCallback::SolutionIntegerValue;
%unignore operations_research::sat::SolutionCallback::UserTime;
%unignore operations_research::sat::SolutionCallback::WallTime;
%include "ortools/sat/swig_helper.h"
%unignoreall

View File

@@ -13,6 +13,10 @@
syntax = "proto2";
option java_package = "com.google.ortools.sat";
option java_multiple_files = true;
package operations_research.sat;
// Contains the definitions for all the sat algorithm parameters and their

View File

@@ -116,6 +116,18 @@ class SatHelper {
return SolveCpModel(model_proto, &model);
}
static operations_research::sat::CpSolverResponse
SolveWithParametersAndSolutionCallback(
const operations_research::sat::CpModelProto& model_proto,
const operations_research::sat::SatParameters& parameters,
SolutionCallback* callback) {
Model model;
model.Add(NewSatParameters(parameters));
model.Add(NewFeasibleSolutionObserver(
[callback](const CpSolverResponse& r) { return callback->Run(r); }));
return SolveCpModel(model_proto, &model);
}
static operations_research::sat::CpSolverResponse
SolveWithStringParametersAndSolutionObserver(
const operations_research::sat::CpModelProto& model_proto,