Python: Rework RoutingModel::*Index typemap (Fix #1030)
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user