Python: Rework RoutingModel::*Index typemap (Fix #1030)

This commit is contained in:
Corentin Le Molgat
2019-01-31 14:57:17 +01:00
parent 14875ce073
commit 719a2ba20a
3 changed files with 21 additions and 2 deletions

View File

@@ -36,6 +36,18 @@ class RoutingSearchParameters;
#include "ortools/util/optional_boolean.pb.h"
%}
DEFINE_INDEX_TYPE_TYPEDEF(
operations_research::RoutingCostClassIndex,
operations_research::RoutingModel::CostClassIndex);
DEFINE_INDEX_TYPE_TYPEDEF(
operations_research::RoutingDimensionIndex,
operations_research::RoutingModel::DimensionIndex);
DEFINE_INDEX_TYPE_TYPEDEF(
operations_research::RoutingDisjunctionIndex,
operations_research::RoutingModel::DisjunctionIndex);
DEFINE_INDEX_TYPE_TYPEDEF(
operations_research::RoutingVehicleClassIndex,
operations_research::RoutingModel::VehicleClassIndex);
%ignore operations_research::RoutingModel::AddMatrixDimension(
std::vector<std::vector<int64> > values,

View File

@@ -22,6 +22,11 @@
%{
#include "ortools/constraint_solver/routing_types.h"
template<typename IndexT>
inline PyObject* PyInt_FromIndexT(const IndexT i) {
return PyInt_FromLong(i.value());
}
%}
// This macro defines typemaps for IndexT, std::vector<IndexT> and
@@ -47,7 +52,7 @@ bool PyObjAs(PyObject *py, IndexT* i) {
return true;
}
%}
PY_LIST_OUTPUT_TYPEMAP(IndexT, PyInt_Check, PyInt_FromLong);
PY_LIST_OUTPUT_TYPEMAP(IndexT, PyInt_Check, PyInt_FromIndexT<IndexT>);
PY_LIST_LIST_INPUT_TYPEMAP(IndexT, PyInt_Check);
%enddef // DEFINE_INDEX_TYPE

View File

@@ -48,7 +48,7 @@
$1 = i == size;
}
}
%typemap(in) std::vector<type>(std::vector<type> temp) {
%typemap(in) std::vector<type> (std::vector<type> temp) {
if (!vector_input_helper($input, &temp, PyObjAs<type>)) {
if (!PyErr_Occurred())
SWIG_Error(SWIG_TypeError, "sequence(type) expected");
@@ -157,4 +157,6 @@ PY_LIST_OUTPUT_TYPEMAP(double, PyFloat_Check, PyFloat_FromDouble);
%enddef // PY_LIST_LIST_INPUT_TYPEMAP
PY_LIST_LIST_INPUT_TYPEMAP(int, PyInt_Check);
PY_LIST_LIST_INPUT_TYPEMAP(int64, SwigPyIntOrLong_Check);
PY_LIST_LIST_INPUT_TYPEMAP(double, PyFloat_Check);