separate sorted_interval_list.i from sat.i in the python CP-SAT wrapping

This commit is contained in:
Laurent Perron
2019-05-08 11:05:33 +02:00
parent dc7899783e
commit beef2334cb
5 changed files with 104 additions and 25 deletions

View File

@@ -43,6 +43,7 @@ PYCP_LIBS = $(LIB_DIR)/_pywrapcp.$(SWIG_PYTHON_LIB_SUFFIX)
PYLP_LIBS = $(LIB_DIR)/_pywraplp.$(SWIG_PYTHON_LIB_SUFFIX)
PYSAT_LIBS = $(LIB_DIR)/_pywrapsat.$(SWIG_PYTHON_LIB_SUFFIX)
PYDATA_LIBS = $(LIB_DIR)/_pywraprcpsp.$(SWIG_PYTHON_LIB_SUFFIX)
PYSORTED_INTERVAL_LIST_LIBS = $(LIB_DIR)/_sorted_interval_list.$(SWIG_PYTHON_LIB_SUFFIX)
PYTHON_OR_TOOLS_LIBS = \
$(GEN_DIR)/ortools/__init__.py \
$(PYALGORITHMS_LIBS) \
@@ -50,7 +51,8 @@ PYTHON_OR_TOOLS_LIBS = \
$(PYCP_LIBS) \
$(PYLP_LIBS) \
$(PYSAT_LIBS) \
$(PYDATA_LIBS)
$(PYDATA_LIBS) \
$(PYSORTED_INTERVAL_LIST_LIBS)
# Main target
.PHONY: python # Build Python OR-Tools.
@@ -375,8 +377,6 @@ $(GEN_DIR)/ortools/sat/pywrapsat.py: \
-o $(GEN_PATH)$Sortools$Ssat$Ssat_python_wrap.cc \
-module pywrapsat \
$(SRC_DIR)/ortools/sat$Spython$Ssat.i
$(SED) -i -e 's/< long long >/< int64 >/g' \
$(GEN_PATH)$Sortools$Ssat$Ssat_python_wrap.cc
$(GEN_DIR)/ortools/sat/sat_python_wrap.cc: \
$(GEN_DIR)/ortools/sat/pywrapsat.py
@@ -455,6 +455,51 @@ else
cp $(PYDATA_LIBS) $(GEN_PATH)/ortools/data
endif
# sorted_interval_list
ifeq ($(PLATFORM),MACOSX)
PYSORTED_INTERVAL_LIST_LDFLAGS = -install_name @rpath/_sorted_interval_list.$(SWIG_PYTHON_LIB_SUFFIX) #
endif
$(GEN_DIR)/ortools/util/sorted_interval_list.py: \
$(SRC_DIR)/ortools/util/sorted_interval_list.h \
$(SRC_DIR)/ortools/base/base.i \
$(SRC_DIR)/ortools/util/python/vector.i \
$(SRC_DIR)/ortools/util/python/sorted_interval_list.i \
$(UTIL_DEPS) \
| $(GEN_DIR)/ortools/util
$(SWIG_BINARY) $(SWIG_INC) -I$(INC_DIR) -c++ -python $(SWIG_PYTHON3_FLAG) \
-o $(GEN_PATH)$Sortools$Sutil$Ssorted_interval_list_python_wrap.cc \
-module sorted_interval_list \
$(SRC_DIR)$Sortools$Sutil$Spython$Ssorted_interval_list.i
$(SED) -i -e 's/< long long >/< int64 >/g' \
$(GEN_PATH)$Sortools$Sutil$Ssorted_interval_list_python_wrap.cc
$(GEN_DIR)/ortools/util/sorted_interval_list_python_wrap.cc: \
$(GEN_DIR)/ortools/util/sorted_interval_list.py
$(OBJ_DIR)/swig/sorted_interval_list_python_wrap.$O: \
$(GEN_DIR)/ortools/util/sorted_interval_list_python_wrap.cc \
$(UTIL_DEPS) \
| $(OBJ_DIR)/swig
$(CCC) $(CFLAGS) $(PYTHON_INC) $(PYTHON3_CFLAGS) \
-c $(GEN_PATH)$Sortools$Sutil$Ssorted_interval_list_python_wrap.cc \
$(OBJ_OUT)$(OBJ_DIR)$Sswig$Ssorted_interval_list_python_wrap.$O
$(PYSORTED_INTERVAL_LIST_LIBS): $(OBJ_DIR)/swig/sorted_interval_list_python_wrap.$O $(OR_TOOLS_LIBS)
$(DYNAMIC_LD) \
$(PYSORTED_INTERVAL_LIST_LDFLAGS) \
$(LD_OUT)$(LIB_DIR)$S_sorted_interval_list.$(SWIG_PYTHON_LIB_SUFFIX) \
$(OBJ_DIR)$Sswig$Ssorted_interval_list_python_wrap.$O \
$(OR_TOOLS_LNK) \
$(SYS_LNK) \
$(PYTHON_LNK) \
$(PYTHON_LDFLAGS)
ifeq ($(SYSTEM),win)
copy $(LIB_DIR)$S_sorted_interval_list.$(SWIG_PYTHON_LIB_SUFFIX) $(GEN_PATH)\\ortools\\util\\_pywraputil.pyd
else
cp $(PYSORTED_INTERVAL_LIST_LIBS) $(GEN_PATH)/ortools/util
endif
#######################
## Python SOURCE ##
#######################
@@ -824,8 +869,8 @@ clean_python:
-$(DEL) ortools$Sutil$S*.pyc
-$(DELREC) ortools$Sutil$S__pycache__
-$(DEL) $(GEN_PATH)$Sortools$Sutil$S*_python_wrap.*
-$(DEL) $(GEN_PATH)$Sortools$Sutil$S_pywrap*
-$(DEL) $(LIB_DIR)$S_pywrap*.$(SWIG_PYTHON_LIB_SUFFIX)
-$(DEL) $(GEN_PATH)$Sortools$Sutil$S_*
-$(DEL) $(LIB_DIR)$S_*.$(SWIG_PYTHON_LIB_SUFFIX)
-$(DEL) $(OBJ_DIR)$Sswig$S*python_wrap.$O
-$(DELREC) temp_python*
@@ -1010,11 +1055,12 @@ $(PYPI_ARCHIVE_TEMP_DIR)/ortools/ortools/data: $(PYDATA_LIBS) | $(PYPI_ARCHIVE_T
$(COPY) $(GEN_PATH)$Sortools$Sdata$S*.py $(PYPI_ARCHIVE_TEMP_DIR)$Sortools$Sortools$Sdata
$(COPY) $(GEN_PATH)$Sortools$Sdata$S_pywraprcpsp.* $(PYPI_ARCHIVE_TEMP_DIR)$Sortools$Sortools$Sdata
$(PYPI_ARCHIVE_TEMP_DIR)/ortools/ortools/util: | $(PYPI_ARCHIVE_TEMP_DIR)/ortools/ortools
$(PYPI_ARCHIVE_TEMP_DIR)/ortools/ortools/util: $(PYUTIL_LIBS) | $(PYPI_ARCHIVE_TEMP_DIR)/ortools/ortools
-$(DELREC) $(PYPI_ARCHIVE_TEMP_DIR)$Sortools$Sortools$Sutil
-$(MKDIR) $(PYPI_ARCHIVE_TEMP_DIR)$Sortools$Sortools$Sutil
$(TOUCH) $(PYPI_ARCHIVE_TEMP_DIR)$Sortools$Sortools$Sutil$S__init__.py
$(COPY) $(GEN_PATH)$Sortools$Sutil$S*.py $(PYPI_ARCHIVE_TEMP_DIR)$Sortools$Sortools$Sutil
$(COPY) $(GEN_PATH)$Sortools$Sutil$S_sorted_interval_list.* $(PYPI_ARCHIVE_TEMP_DIR)$Sortools$Sortools$Sutil
$(PYPI_ARCHIVE_TEMP_DIR)/ortools/ortools/.libs: | $(PYPI_ARCHIVE_TEMP_DIR)/ortools/ortools
-$(DELREC) $(PYPI_ARCHIVE_TEMP_DIR)$Sortools$Sortools$S.libs

View File

@@ -25,7 +25,9 @@ from ortools.sat import cp_model_pb2
from ortools.sat import sat_parameters_pb2
from ortools.sat.python import cp_model_helper
from ortools.sat import pywrapsat
Domain = pywrapsat.Domain
from ortools.util import sorted_interval_list
Domain = sorted_interval_list.Domain
# The classes below allow linear expressions to be expressed naturally with the
# usual arithmetic operators +-*/ and with constant numbers, which makes the

View File

@@ -17,16 +17,17 @@
%include "ortools/base/base.i"
%include "ortools/util/python/proto.i"
%import "ortools/util/python/vector.i"
// std::function utilities.
%include "ortools/util/python/functions.i"
// Domain class.
%import "ortools/util/python/sorted_interval_list.i"
%{
#include "ortools/sat/cp_model.pb.h"
#include "ortools/sat/sat_parameters.pb.h"
#include "ortools/sat/swig_helper.h"
#include "ortools/util/sorted_interval_list.h"
%}
%pythoncode {
@@ -96,23 +97,7 @@ PY_PROTO_TYPEMAP(ortools.sat.sat_parameters_pb2,
%unignore operations_research::sat::SolutionCallback::WallTime;
%feature("nodirector") operations_research::sat::SolutionCallback::WallTime;
%unignore operations_research::Domain;
%unignore operations_research::Domain::Domain;
%unignore operations_research::Domain::AllValues;
%unignore operations_research::Domain::Complement;
%unignore operations_research::Domain::Contains;
%unignore operations_research::Domain::FlattenedIntervals;
%unignore operations_research::Domain::FromFlatIntervals;
%rename (FromIntervals) operations_research::Domain::FromVectorIntervals;
%unignore operations_research::Domain::FromValues;
%unignore operations_research::Domain::IsEmpty;
%unignore operations_research::Domain::Max;
%unignore operations_research::Domain::Min;
%unignore operations_research::Domain::Negation;
%unignore operations_research::Domain::Size;
%include "ortools/sat/swig_helper.h"
%include "ortools/util/sorted_interval_list.h"
%unignoreall

View File

@@ -0,0 +1,45 @@
// Copyright 2010-2018 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.
// This .i file exposes the sorted_interval_list API.
%include "stdint.i"
%include "ortools/base/base.i"
%import "ortools/util/python/vector.i"
%{
#include "ortools/util/sorted_interval_list.h"
%}
%ignoreall
%unignore operations_research;
%unignore operations_research::Domain;
%unignore operations_research::Domain::Domain;
%unignore operations_research::Domain::AllValues;
%unignore operations_research::Domain::Complement;
%unignore operations_research::Domain::Contains;
%unignore operations_research::Domain::FlattenedIntervals;
%unignore operations_research::Domain::FromFlatIntervals;
%rename (FromIntervals) operations_research::Domain::FromVectorIntervals;
%unignore operations_research::Domain::FromValues;
%unignore operations_research::Domain::IsEmpty;
%unignore operations_research::Domain::Max;
%unignore operations_research::Domain::Min;
%unignore operations_research::Domain::Negation;
%unignore operations_research::Domain::Size;
%include "ortools/util/sorted_interval_list.h"
%unignoreall

View File

@@ -56,6 +56,7 @@ setup(
'ortools.graph' : ['_pywrapgraph.dll'],
'ortools.algorithms' : ['_pywrapknapsack_solver.dll'],
'ortools.sat' : ['_pywrapsat.dll', '*.md'],
'ortools.util' : ['_sorted_interval_list.dll'],
DELETEWIN 'ortools' : ['.libs/*' DDDD]
},
include_package_data=True,