Skip to content

Commit

Permalink
constraint_solver: Fixup Java and .Net swig
Browse files Browse the repository at this point in the history
  • Loading branch information
Mizux committed Nov 15, 2024
1 parent cdfbb16 commit 8565641
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 30 deletions.
65 changes: 38 additions & 27 deletions ortools/constraint_solver/csharp/constraint_solver.i
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,11 @@ using System.Collections;
using System.Collections.Generic;
%}

%include "enumsimple.swg"

%include "exception.i"
%include "std_vector.i"
%include "std_common.i"
%include "std_string.i"

%include "ortools/base/base.i"
%include "ortools/util/csharp/absl_string_view.i"
%include "enumsimple.swg"
%import "ortools/util/csharp/absl_string_view.i"
%import "ortools/util/csharp/vector.i"
%include "ortools/util/csharp/proto.i"
%import "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
Expand Down Expand Up @@ -72,6 +66,16 @@ struct FailureProtect {
};
%}

%template(IntVector) std::vector<int>;
%template(IntVectorVector) std::vector<std::vector<int> >;
VECTOR_AS_CSHARP_ARRAY(int, int, int, IntVector);
JAGGED_MATRIX_AS_CSHARP_ARRAY(int, int, int, IntVectorVector);

%template(Int64Vector) std::vector<int64_t>;
%template(Int64VectorVector) std::vector<std::vector<int64_t> >;
VECTOR_AS_CSHARP_ARRAY(int64_t, int64_t, long, Int64Vector);
JAGGED_MATRIX_AS_CSHARP_ARRAY(int64_t, int64_t, long, Int64VectorVector);

/* allow partial c# classes */
%typemap(csclassmodifiers) SWIGTYPE "public partial class"

Expand Down Expand Up @@ -126,27 +130,9 @@ PROTECT_FROM_FAILURE(Solver::Fail(), arg1);

// ############ END DUPLICATED CODE BLOCK ############

%template(IntVector) std::vector<int>;
%template(IntVectorVector) std::vector<std::vector<int> >;
VECTOR_AS_CSHARP_ARRAY(int, int, int, IntVector);
JAGGED_MATRIX_AS_CSHARP_ARRAY(int, int, int, IntVectorVector);
//REGULAR_MATRIX_AS_CSHARP_ARRAY(int, int, int, IntVectorVector);

%template(Int64Vector) std::vector<int64_t>;
%template(Int64VectorVector) std::vector<std::vector<int64_t> >;
VECTOR_AS_CSHARP_ARRAY(int64_t, int64_t, long, Int64Vector);
JAGGED_MATRIX_AS_CSHARP_ARRAY(int64_t, int64_t, long, Int64VectorVector);
//REGULAR_MATRIX_AS_CSHARP_ARRAY(int64_t, int64_t, long, Int64VectorVector);

%apply int64_t * INOUT { int64_t * marker };
%apply int64_t * OUTPUT { int64_t *l, int64_t *u, int64_t *value };

// Since knapsack_solver.i and constraint_solver.i both need to
// instantiate the vector template, but their csharp_wrap.cc
// files end up being compiled into the same .dll, we must name the
// vector template differently.

// TupleSet depends on the previous typemaps
%include "ortools/util/csharp/tuple_set.i"

// Types in Proxy class:
Expand Down Expand Up @@ -301,6 +287,9 @@ namespace operations_research {
%ignore SequenceVarElement::LoadFromProto;
%ignore SequenceVarElement::WriteToProto;

// ModelVisitor
%unignore ModelVisitor;

// SolutionCollector
%feature("director") SolutionCollector;
%unignore SolutionCollector;
Expand Down Expand Up @@ -665,6 +654,12 @@ namespace operations_research {
// Methods:
%rename (SequenceVar) DisjunctiveConstraint::MakeSequenceVar;

// ModelCache
%unignore ModelCache;

// ObjectiveMonitor
%unignore ObjectiveMonitor;

// Pack
%unignore Pack;
%typemap(cscode) Pack %{
Expand Down Expand Up @@ -694,6 +689,12 @@ namespace operations_research {
%ignore PropagationBaseObject::EnqueueAll;
%ignore PropagationBaseObject::set_action_on_fail;

// PropagationMonitor
%unignore PropagationMonitor;

// RevPartialSequence
%unignore RevPartialSequence;

// SearchMonitor
%feature("director") SearchMonitor;
%unignore SearchMonitor;
Expand All @@ -704,6 +705,9 @@ namespace operations_research {
// Methods:
%rename (IsCrossed) SearchLimit::crossed;

// ImprovementSearchLimit
%unignore ImprovementSearchLimit;

// RegularLimit
%feature("director") RegularLimit;
%unignore RegularLimit;
Expand Down Expand Up @@ -731,6 +735,9 @@ namespace operations_research {
%unignore LocalSearchOperator::Reset;
%unignore LocalSearchOperator::Start;

// LocalSearchOperatorState
%unignore LocalSearchOperatorState;

// IntVarLocalSearchOperator
%feature("director") IntVarLocalSearchOperator;
%unignore IntVarLocalSearchOperator;
Expand Down Expand Up @@ -940,6 +947,10 @@ PROTO_INPUT(operations_research::CpModel,
PROTO2_RETURN(operations_research::CpModel,
Google.OrTools.ConstraintSolver.CpModel)

// Add needed import to operations_research_constraint_solver.cs
%pragma(csharp) moduleimports=%{
%}

namespace operations_research {
// Globals
// IMPORTANT(user): Global will be placed in operations_research_constraint_solver.cs
Expand Down
16 changes: 13 additions & 3 deletions ortools/constraint_solver/java/constraint_solver.i
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@

// TODO(user): Refactor this file to adhere to the SWIG style guide.

// Used for free functions.
%module(directors="1") operations_research;

%include "enumsimple.swg"
%include "exception.i"

Expand All @@ -22,6 +25,12 @@
%include "ortools/util/java/vector.i"
%include "ortools/util/java/proto.i"

// Make the SWIG-generated constructor public.
// This is necessary as it will be called from the routing package.
SWIG_JAVABODY_PROXY(/*PTRCTOR_VISIBILITY=*/public,
/*CPTR_VISIBILITY=*/public,
/*TYPE...=*/SWIGTYPE)

// Remove swig warnings
%warnfilter(473) operations_research::DecisionBuilder;
// TODO(user): Remove this warnfilter.
Expand Down Expand Up @@ -124,8 +133,6 @@ PROTECT_FROM_FAILURE(Solver::Fail(), arg1);

// ############ END DUPLICATED CODE BLOCK ############

%module(directors="1") operations_research;

%{
#include <setjmp.h>

Expand Down Expand Up @@ -1615,8 +1622,11 @@ PROTO_INPUT(operations_research::RegularLimitParameters,
PROTO2_RETURN(operations_research::RegularLimitParameters,
com.google.ortools.constraintsolver.RegularLimitParameters)
namespace operations_research {
// Add needed import to main.java
%pragma(java) moduleimports=%{
%}
namespace operations_research {
// Globals
// IMPORTANT(user): Globals will be placed in main.java
// i.e. use `import com.[...].constraintsolver.main`
Expand Down

0 comments on commit 8565641

Please sign in to comment.