From 27f9c4f95ef0359d8cee2b131a6d7aff62a2a7b8 Mon Sep 17 00:00:00 2001 From: Laurent Perron Date: Mon, 10 Dec 2018 12:57:27 +0100 Subject: [PATCH] support int64_t transition in c# --- makefiles/Makefile.dotnet.mk | 8 ++++++++ ortools/algorithms/csharp/knapsack_solver.i | 6 +++++- .../constraint_solver/csharp/constraint_solver.i | 14 ++++++++++---- ortools/graph/csharp/graph.i | 7 ++++++- ortools/linear_solver/csharp/linear_solver.i | 8 +++++++- ortools/sat/csharp/sat.i | 5 +++++ 6 files changed, 41 insertions(+), 7 deletions(-) diff --git a/makefiles/Makefile.dotnet.mk b/makefiles/Makefile.dotnet.mk index 2d8e5b1388..71a6cdda9d 100644 --- a/makefiles/Makefile.dotnet.mk +++ b/makefiles/Makefile.dotnet.mk @@ -195,6 +195,11 @@ $(GEN_DIR)/ortools/constraint_solver/constraint_solver_csharp_wrap.cc: \ $(SED) -i -e 's/CSharp_Constraint/CSharp_CpConstraint/g' \ $(GEN_PATH)$Sortools$Sconstraint_solver$S*cs \ $(GEN_PATH)$Sortools$Sconstraint_solver$Sconstraint_solver_csharp_wrap.* + $(SED) -i -e 's/< long long >/< int64 >/g' \ + $(GEN_PATH)$Sortools$Sconstraint_solver$Sconstraint_solver_csharp_wrap.cc + $(SED) -i -e 's/< long long,long long >/< int64, int64 >/g' \ + $(GEN_PATH)$Sortools$Sconstraint_solver$Sconstraint_solver_csharp_wrap.cc + $(OBJ_DIR)/swig/constraint_solver_csharp_wrap.$O: \ $(GEN_DIR)/ortools/constraint_solver/constraint_solver_csharp_wrap.cc \ @@ -216,6 +221,9 @@ $(GEN_DIR)/ortools/algorithms/knapsack_solver_csharp_wrap.cc: \ -dllimport "$(OR_TOOLS_NATIVE_ASSEMBLY_NAME).$(SWIG_DOTNET_LIB_SUFFIX)" \ -outdir $(GEN_PATH)$Sortools$Salgorithms \ $(SRC_DIR)$Sortools$Salgorithms$Scsharp$Sknapsack_solver.i + $(SED) -i -e 's/< long long >/< int64_t >/g' \ + $(GEN_PATH)$Sortools$Salgorithms$Sknapsack_solver_csharp_wrap.cc + $(OBJ_DIR)/swig/knapsack_solver_csharp_wrap.$O: \ $(GEN_DIR)/ortools/algorithms/knapsack_solver_csharp_wrap.cc \ diff --git a/ortools/algorithms/csharp/knapsack_solver.i b/ortools/algorithms/csharp/knapsack_solver.i index 54de53b410..a0a9c928df 100644 --- a/ortools/algorithms/csharp/knapsack_solver.i +++ b/ortools/algorithms/csharp/knapsack_solver.i @@ -13,6 +13,9 @@ // TODO(user): Refactor this file to adhere to the SWIG style guide. +%include +%include + %include "ortools/base/base.i" /* allow partial c# classes */ @@ -23,7 +26,8 @@ #include "ortools/algorithms/knapsack_solver.h" %} -%include "std_vector.i" +typedef int64_t int64; +typedef uint64_t uint64; // See the comment in // ../../constraint_solver/csharp/constraint_solver.i about naming diff --git a/ortools/constraint_solver/csharp/constraint_solver.i b/ortools/constraint_solver/csharp/constraint_solver.i index 14685eb1d7..ba8040c14a 100644 --- a/ortools/constraint_solver/csharp/constraint_solver.i +++ b/ortools/constraint_solver/csharp/constraint_solver.i @@ -19,12 +19,15 @@ using System.Runtime.InteropServices; using System.Collections; %} -%include "exception.i" -%include "std_vector.i" +%include +%include +%include +%include "ortools/base/base.i" %include "ortools/util/csharp/tuple_set.i" %include "ortools/util/csharp/functions.i" %include "ortools/util/csharp/proto.i" + // We need to forward-declare the proto here, so that PROTO_INPUT involving it // works correctly. The order matters very much: this declaration needs to be // before the %{ #include ".../constraint_solver.h" %}. @@ -78,6 +81,9 @@ struct FailureProtect { }; %} +typedef int64_t int64; +typedef uint64_t uint64; + /* allow partial c# classes */ %typemap(csclassmodifiers) SWIGTYPE "public partial class" @@ -137,9 +143,9 @@ PROTECT_FROM_FAILURE(Solver::Fail(), arg1); // files end up being compiled into the same .dll, we must name the // vector template differently. %template(CpIntVector) std::vector; -%template(CpInt64Vector) std::vector; +%template(CpInt64Vector) std::vector; %template(CpIntVectorVector) std::vector >; -%template(CpInt64VectorVector) std::vector >; +%template(CpInt64VectorVector) std::vector >; %define CS_TYPEMAP_STDVECTOR_OBJECT(CTYPE, TYPE) SWIG_STD_VECTOR_ENHANCED(operations_research::CTYPE*); diff --git a/ortools/graph/csharp/graph.i b/ortools/graph/csharp/graph.i index e6399363ec..67f16a694c 100644 --- a/ortools/graph/csharp/graph.i +++ b/ortools/graph/csharp/graph.i @@ -22,6 +22,8 @@ // - examples/csharp/assignment.cs // - examples/csharp/csflow.cs +%include + %include "ortools/base/base.i" %import "ortools/graph/ebert_graph.h" @@ -32,6 +34,9 @@ #include "ortools/graph/min_cost_flow.h" %} +typedef int64_t int64; +typedef uint64_t uint64; + // ############ max_flow.h ############ %ignoreall @@ -39,7 +44,7 @@ %unignore operations_research; %rename (MaxFlow) operations_research::SimpleMaxFlow; %unignore operations_research::SimpleMaxFlow::SimpleMaxFlow; -// %unignore operations_research::SimpleMaxFlow::~SimpleMaxFlow; +%unignore operations_research::SimpleMaxFlow::~SimpleMaxFlow; %unignore operations_research::SimpleMaxFlow::AddArcWithCapacity; %unignore operations_research::SimpleMaxFlow::Solve; %unignore operations_research::SimpleMaxFlow::NumNodes; diff --git a/ortools/linear_solver/csharp/linear_solver.i b/ortools/linear_solver/csharp/linear_solver.i index c99109fe67..30589db909 100644 --- a/ortools/linear_solver/csharp/linear_solver.i +++ b/ortools/linear_solver/csharp/linear_solver.i @@ -28,14 +28,20 @@ // - examples/csharp/cslinearprogramming.cs // - examples/csharp/csintegerprogramming.cs + +%include +%include + %include "ortools/base/base.i" -%include "std_vector.i" %{ #include "ortools/linear_solver/linear_solver.h" #include "ortools/linear_solver/linear_solver.pb.h" %} +typedef int64_t int64; +typedef uint64_t uint64; + // We need to forward-declare the proto here, so that the PROTO_* macros // involving them work correctly. The order matters very much: this declaration // needs to be before the %{ #include ".../linear_solver.h" %}. diff --git a/ortools/sat/csharp/sat.i b/ortools/sat/csharp/sat.i index ac73442fd2..005c54bff0 100644 --- a/ortools/sat/csharp/sat.i +++ b/ortools/sat/csharp/sat.i @@ -17,6 +17,8 @@ using System.Runtime.InteropServices; using System.Collections; %} +%include + %include "ortools/base/base.i" %include "ortools/util/csharp/proto.i" @@ -26,6 +28,9 @@ using System.Collections; #include "ortools/sat/swig_helper.h" %} +typedef int64_t int64; +typedef uint64_t uint64; + %module(directors="1") operations_research_sat PROTO_INPUT(operations_research::sat::CpModelProto,