From 2f0680127d68f5403641828951b5ded5cd71b20d Mon Sep 17 00:00:00 2001 From: Corentin Le Molgat Date: Wed, 13 Mar 2019 13:50:23 +0100 Subject: [PATCH] Backport from g3 to github --- ortools/algorithms/csharp/knapsack_solver.i | 2 + ortools/base/base.i | 1 + .../IntIntToLongFunction.java | 16 +- .../constraintsolver/LongTernaryOperator.java | 18 +-- .../LongTernaryPredicate.java | 40 ++--- .../csharp/IntArrayHelper.cs | 4 +- .../csharp/constraint_solver.i | 33 ---- .../java/constraint_solver.i | 67 +------- ortools/constraint_solver/java/routing.i | 4 - .../python/constraint_solver.i | 2 + .../samples/VrpInitialRoutes.java | 1 - ortools/graph/csharp/graph.i | 5 +- ortools/graph/java/graph.i | 8 +- ortools/sat/csharp/CpModel.cs | 4 +- ortools/sat/csharp/CpSolver.cs | 2 +- ortools/util/csharp/tuple_set.i | 1 - ortools/util/csharp/vector.i | 25 ++- ortools/util/java/tuple_set.i | 3 +- ortools/util/java/vector.i | 151 ++++++++++-------- 19 files changed, 148 insertions(+), 239 deletions(-) diff --git a/ortools/algorithms/csharp/knapsack_solver.i b/ortools/algorithms/csharp/knapsack_solver.i index a0110399ade..4e6aed67505 100644 --- a/ortools/algorithms/csharp/knapsack_solver.i +++ b/ortools/algorithms/csharp/knapsack_solver.i @@ -39,4 +39,6 @@ typedef uint64_t uint64; %rename (UseReduction) operations_research::KnapsackSolver::use_reduction; %rename (SetUseReduction) operations_research::KnapsackSolver::set_use_reduction; +// TODO(user): Replace with %ignoreall/%unignoreall +//swiglint: disable include-h-allglobals %include "ortools/algorithms/knapsack_solver.h" diff --git a/ortools/base/base.i b/ortools/base/base.i index b75088a0a8d..834c34e6456 100644 --- a/ortools/base/base.i +++ b/ortools/base/base.i @@ -10,6 +10,7 @@ // 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. + %{ #include #include diff --git a/ortools/com/google/ortools/constraintsolver/IntIntToLongFunction.java b/ortools/com/google/ortools/constraintsolver/IntIntToLongFunction.java index 6582ff77d10..78213e51e2d 100644 --- a/ortools/com/google/ortools/constraintsolver/IntIntToLongFunction.java +++ b/ortools/com/google/ortools/constraintsolver/IntIntToLongFunction.java @@ -25,12 +25,12 @@ */ @FunctionalInterface public interface IntIntToLongFunction { - /** - * Applies this function to the given arguments. - * - * @param left the first argument - * @param right the second argument - * @return the function result - */ - long applyAsLong(int left, int right); + /** + * Applies this function to the given arguments. + * + * @param left the first argument + * @param right the second argument + * @return the function result + */ + long applyAsLong(int left, int right); } diff --git a/ortools/com/google/ortools/constraintsolver/LongTernaryOperator.java b/ortools/com/google/ortools/constraintsolver/LongTernaryOperator.java index 34b10a680b4..e29989224b1 100644 --- a/ortools/com/google/ortools/constraintsolver/LongTernaryOperator.java +++ b/ortools/com/google/ortools/constraintsolver/LongTernaryOperator.java @@ -25,13 +25,13 @@ */ @FunctionalInterface public interface LongTernaryOperator { - /** - * Applies this operator to the given operands. - * - * @param left the first operand - * @param center the second operand - * @param right the third operand - * @return the operator result - */ - long applyAsLong(long left, long center, long right); + /** + * Applies this operator to the given operands. + * + * @param left the first operand + * @param center the second operand + * @param right the third operand + * @return the operator result + */ + long applyAsLong(long left, long center, long right); } diff --git a/ortools/com/google/ortools/constraintsolver/LongTernaryPredicate.java b/ortools/com/google/ortools/constraintsolver/LongTernaryPredicate.java index b33dfb118c8..c9b19fd5812 100644 --- a/ortools/com/google/ortools/constraintsolver/LongTernaryPredicate.java +++ b/ortools/com/google/ortools/constraintsolver/LongTernaryPredicate.java @@ -24,25 +24,25 @@ */ @FunctionalInterface public interface LongTernaryPredicate { - /** - * Evaluates this predicate on the given arguments. - * - * @param left the first operand - * @param center the second operand - * @param right the third operand - * @return {@code true} if the input argument matches the predicate, - * otherwise {@code false} - */ - boolean test(long left, long center, long right); + /** + * Evaluates this predicate on the given arguments. + * + * @param left the first operand + * @param center the second operand + * @param right the third operand + * @return {@code true} if the input argument matches the predicate, + * otherwise {@code false} + */ + boolean test(long left, long center, long right); - /** - * Returns a predicate that represents the logical negation of this - * predicate. - * - * @return a predicate that represents the logical negation of this - * predicate - */ - default LongTernaryPredicate negate() { - return (left, center, right) -> !test(left, center, right); - } + /** + * Returns a predicate that represents the logical negation of this + * predicate. + * + * @return a predicate that represents the logical negation of this + * predicate + */ + default LongTernaryPredicate negate() { + return (left, center, right) -> !test(left, center, right); + } } diff --git a/ortools/constraint_solver/csharp/IntArrayHelper.cs b/ortools/constraint_solver/csharp/IntArrayHelper.cs index ec6259036d6..3f5ec1caab2 100644 --- a/ortools/constraint_solver/csharp/IntArrayHelper.cs +++ b/ortools/constraint_solver/csharp/IntArrayHelper.cs @@ -105,7 +105,7 @@ public static implicit operator CpIntVectorVector(int[,] inVal) { return outVal; } - // cast from C# int[][] two-dimensional rray + // cast from C# int[][] two-dimensional array public static implicit operator CpIntVectorVector(int[][] inVal) { int x_size = inVal.GetLength(0); CpIntVectorVector outVal = new CpIntVectorVector(); @@ -173,7 +173,7 @@ public static implicit operator CpInt64VectorVector(long[,] inVal) { return outVal; } - // cast from C# long[][] two-dimensional rray + // cast from C# long[][] two-dimensional array public static implicit operator CpInt64VectorVector(long[][] inVal) { int x_size = inVal.GetLength(0); CpInt64VectorVector outVal = new CpInt64VectorVector(); diff --git a/ortools/constraint_solver/csharp/constraint_solver.i b/ortools/constraint_solver/csharp/constraint_solver.i index 00ebab3613c..35d3fac9d44 100644 --- a/ortools/constraint_solver/csharp/constraint_solver.i +++ b/ortools/constraint_solver/csharp/constraint_solver.i @@ -238,39 +238,6 @@ DEFINE_ARGS_TO_R_CALLBACK( #undef DEFINE_ARGS_TO_R_CALLBACK #undef DEFINE_VOID_TO_STRING_CALLBACK -// Convert in module_csharp_wrap.cc input argument (delegate marshaled in C function pointer) to original std::function<...> -//%typemap(in) Solver::DisplayCallback %{ -// $1 = [$input]() -> std::string { -// std::string result; -// return result.assign((*(char* (*)())$input)()); -// }; -//%} -// -//%typemap(in) Solver::IndexEvaluator1 %{ -// $1 = [$input](int64 u) -> int64 { -// return (*(int64 (*)(int64))$input)(u); -// }; -//%} -//%typemap(in) Solver::IndexEvaluator2 %{ -// $1 = [$input](int64 u, int64 v) -> int64 { -// return (*(int64 (*)(int64, int64))$input)(u, v);}; -//%} -//%typemap(in) Solver::IndexEvaluator3 %{ -// $1 = [$input](int64 u, int64 v, int64 w) -> int64 { -// return (*(int64 (*)(int64, int64, int64))$input)(u, v, w);}; -//%} -// -//%typemap(in) Solver::IndexFilter1 %{ -// $1 = [$input](int64 u) -> bool { -// return (*(bool (*)(int64))$input)(u);}; -//%} -//%typemap(in) Solver::ObjectiveWatcher %{ -// $1 = [$input](int64 u) -> void { -// return (*(void (*)(int64))$input)(u);}; -//%} - - - // Renaming namespace operations_research { diff --git a/ortools/constraint_solver/java/constraint_solver.i b/ortools/constraint_solver/java/constraint_solver.i index 02e44b8ab24..5e61b9ceee5 100644 --- a/ortools/constraint_solver/java/constraint_solver.i +++ b/ortools/constraint_solver/java/constraint_solver.i @@ -126,7 +126,10 @@ PROTECT_FROM_FAILURE(Solver::Fail(), arg1); #include "ortools/constraint_solver/constraint_solveri.h" %} +// Use to correctly wrap Solver::MakeScheduleOrPostpone. %apply int64 * INOUT { int64 *const marker }; +// Use to correctly wrap arguments otherwise SWIG will wrap them as +// SWIGTYPE_p_long_long opaque pointer. %apply int64 * OUTPUT { int64 *l, int64 *u, int64 *value }; // Types in Proxy class (e.g. Solver.java) e.g.: @@ -349,20 +352,17 @@ namespace operations_research { // Decision %feature("director") Decision; %unignore Decision; -// Methods: %rename (apply) Decision::Apply; %rename (refute) Decision::Refute; // DecisionBuilder %feature("director") DecisionBuilder; %unignore DecisionBuilder; -// Methods: %rename (nextWrap) DecisionBuilder::Next; // DecisionVisitor %feature("director") DecisionVisitor; %unignore DecisionVisitor; -// Methods: %rename (visitRankFirstInterval) DecisionVisitor::VisitRankFirstInterval; %rename (visitRankLastInterval) DecisionVisitor::VisitRankLastInterval; %rename (visitScheduleOrExpedite) DecisionVisitor::VisitScheduleOrExpedite; @@ -373,7 +373,6 @@ namespace operations_research { // ModelVisitor %unignore ModelVisitor; -// Methods: %rename (beginVisitConstraint) ModelVisitor::BeginVisitConstraint; %rename (beginVisitExtension) ModelVisitor::BeginVisitExtension; %rename (beginVisitIntegerExpression) ModelVisitor::BeginVisitIntegerExpression; @@ -398,14 +397,12 @@ namespace operations_research { // SymmetryBreaker %feature("director") SymmetryBreaker; %unignore SymmetryBreaker; -// Methods: %rename (addIntegerVariableEqualValueClause) SymmetryBreaker::AddIntegerVariableEqualValueClause; %rename (addIntegerVariableGreaterOrEqualValueClause) SymmetryBreaker::AddIntegerVariableGreaterOrEqualValueClause; %rename (addIntegerVariableLessOrEqualValueClause) SymmetryBreaker::AddIntegerVariableLessOrEqualValueClause; // ModelCache %unignore ModelCache; -// Methods: %rename (clear) ModelCache::Clear; %rename (findExprConstantExpression) ModelCache::FindExprConstantExpression; %rename (findExprExprConstantExpression) ModelCache::FindExprExprConstantExpression; @@ -436,7 +433,6 @@ namespace operations_research { // RevPartialSequence %unignore RevPartialSequence; -// Methods: %rename (isRanked) RevPartialSequence::IsRanked; %rename (numFirstRanked) RevPartialSequence::NumFirstRanked; %rename (numLastRanked) RevPartialSequence::NumLastRanked; @@ -445,7 +441,7 @@ namespace operations_research { %rename (size) RevPartialSequence::Size; // UnsortedNullableRevBitset -// TODO(corentinl) To removed from constraint_solveri.h (only use by table.cc) +// TODO(user): Remove from constraint_solveri.h (only use by table.cc) %ignore UnsortedNullableRevBitset; // Assignment @@ -528,12 +524,10 @@ namespace operations_research { %rename (unperformed) Assignment::Unperformed; // template AssignmentContainer<> -// Ignored: %ignore AssignmentContainer::MutableElement; %ignore AssignmentContainer::MutableElementOrNull; %ignore AssignmentContainer::ElementPtrOrNull; %ignore AssignmentContainer::elements; -// Methods: %rename (add) AssignmentContainer::Add; %rename (addAtPosition) AssignmentContainer::AddAtPosition; %rename (clear) AssignmentContainer::Clear; @@ -550,17 +544,14 @@ namespace operations_research { // AssignmentElement %unignore AssignmentElement; -// Methods: %rename (activate) AssignmentElement::Activate; %rename (deactivate) AssignmentElement::Deactivate; %rename (activated) AssignmentElement::Activated; // IntVarElement %unignore IntVarElement; -// Ignored: %ignore IntVarElement::LoadFromProto; %ignore IntVarElement::WriteToProto; -// Methods: %rename (reset) IntVarElement::Reset; %rename (clone) IntVarElement::Clone; %rename (copy) IntVarElement::Copy; @@ -577,10 +568,8 @@ namespace operations_research { // IntervalVarElement %unignore IntervalVarElement; -// Ignored: %ignore IntervalVarElement::LoadFromProto; %ignore IntervalVarElement::WriteToProto; -// Methods: %rename (clone) IntervalVarElement::Clone; %rename (copy) IntervalVarElement::Copy; %rename (durationMax) IntervalVarElement::DurationMax; @@ -618,10 +607,8 @@ namespace operations_research { // SequenceVarElement %unignore SequenceVarElement; -// Ignored: %ignore SequenceVarElement::LoadFromProto; %ignore SequenceVarElement::WriteToProto; -// Methods: %rename (backwardSequence) SequenceVarElement::BackwardSequence; %rename (clone) SequenceVarElement::Clone; %rename (copy) SequenceVarElement::Copy; @@ -638,7 +625,6 @@ namespace operations_research { // SolutionCollector %unignore SolutionCollector; -// Methods: %rename (add) SolutionCollector::Add; %rename (addObjective) SolutionCollector::AddObjective; %rename (backwardSequence) SolutionCollector::BackwardSequence; @@ -654,7 +640,6 @@ namespace operations_research { // SolutionPool %unignore SolutionPool; -// Methods: %rename (getNextSolution) SolutionPool::GetNextSolution; %rename (initialize) SolutionPool::Initialize; %rename (registerNewSolution) SolutionPool::RegisterNewSolution; @@ -789,7 +774,6 @@ import java.lang.Runnable; return array; } %} -// Ignored: %ignore Solver::SearchLogParameters; %ignore Solver::ActiveSearch; %ignore Solver::SetSearchContext; @@ -804,7 +788,6 @@ import java.lang.Runnable; %ignore Solver::MakeAtMost; %ignore Solver::demon_profiler; %ignore Solver::set_fail_intercept; -// Methods: %unignore Solver::Solver; %rename (acceptedNeighbors) Solver::accepted_neighbors; %rename (addBacktrackAction) Solver::AddBacktrackAction; @@ -1048,12 +1031,10 @@ import java.lang.Runnable; // BaseIntExpr %unignore BaseIntExpr; -// Methods: %rename (castToVar) BaseIntExpr::CastToVar; // IntExpr %unignore IntExpr; -// Methods: %rename (isVar) IntExpr::IsVar; %rename (range) IntExpr::Range; %rename (var) IntExpr::Var; @@ -1062,7 +1043,6 @@ import java.lang.Runnable; // IntVar %unignore IntVar; -// Methods: %rename (addName) IntVar::AddName; %rename (contains) IntVar::Contains; %rename (isDifferent) IntVar::IsDifferent; @@ -1083,14 +1063,12 @@ import java.lang.Runnable; // IntVarIterator %unignore IntVarIterator; -// Methods: %rename (init) IntVarIterator::Init; %rename (next) IntVarIterator::Next; %rename (ok) IntVarIterator::Ok; // BooleanVar %unignore BooleanVar; -// Methods: %rename (baseName) BooleanVar::BaseName; %rename (isDifferent) BooleanVar::IsDifferent; %rename (isEqual) BooleanVar::IsEqual; @@ -1108,7 +1086,6 @@ import java.lang.Runnable; // IntervalVar %unignore IntervalVar; -// Methods: %rename (cannotBePerformed) IntervalVar::CannotBePerformed; %rename (durationExpr) IntervalVar::DurationExpr; %rename (durationMax) IntervalVar::DurationMax; @@ -1154,17 +1131,14 @@ import java.lang.Runnable; // OptimizeVar %unignore OptimizeVar; -// Methods: %rename (applyBound) OptimizeVar::ApplyBound; %rename (print) OptimizeVar::Print; %rename (var) OptimizeVar::Var; // SequenceVar %unignore SequenceVar; -// Ignored: %ignore SequenceVar::ComputePossibleFirstsAndLasts; %ignore SequenceVar::FillSequence; -// Methods: %rename (rankFirst) SequenceVar::RankFirst; %rename (rankLast) SequenceVar::RankLast; %rename (rankNotFirst) SequenceVar::RankNotFirst; @@ -1175,7 +1149,6 @@ import java.lang.Runnable; // Constraint %unignore Constraint; -// Methods: %rename (initialPropagate) Constraint::InitialPropagate; %rename (isCastConstraint) Constraint::IsCastConstraint; %rename (postAndPropagate) Constraint::PostAndPropagate; @@ -1189,7 +1162,6 @@ import java.lang.Runnable; // see https://docs.oracle.com/javase/8/docs/api/java/util/function/LongBinaryOperator.html import java.util.function.LongBinaryOperator; %} -// Methods: %rename (makeSequenceVar) DisjunctiveConstraint::MakeSequenceVar; %rename (setTransitionTime) DisjunctiveConstraint::SetTransitionTime; %rename (transitionTime) DisjunctiveConstraint::TransitionTime; @@ -1204,7 +1176,6 @@ import java.util.function.LongUnaryOperator; // see https://docs.oracle.com/javase/8/docs/api/java/util/function/LongBinaryOperator.html import java.util.function.LongBinaryOperator; %} -// Methods: %rename (addCountAssignedItemsDimension) Pack::AddCountAssignedItemsDimension; %rename (addCountUsedBinDimension) Pack::AddCountUsedBinDimension; %rename (addSumVariableWeightsLessOrEqualConstantDimension) Pack::AddSumVariableWeightsLessOrEqualConstantDimension; @@ -1231,11 +1202,9 @@ import java.util.function.LongBinaryOperator; // PropagationBaseObject %unignore PropagationBaseObject; -// Ignored: %ignore PropagationBaseObject::ExecuteAll; %ignore PropagationBaseObject::EnqueueAll; %ignore PropagationBaseObject::set_action_on_fail; -// Methods: %rename (baseName) PropagationBaseObject::BaseName; %rename (enqueueDelayedDemon) PropagationBaseObject::EnqueueDelayedDemon; %rename (enqueueVar) PropagationBaseObject::EnqueueVar; @@ -1247,7 +1216,6 @@ import java.util.function.LongBinaryOperator; // SearchMonitor %feature("director") SearchMonitor; %unignore SearchMonitor; -// Methods: %rename (acceptDelta) SearchMonitor::AcceptDelta; %rename (acceptNeighbor) SearchMonitor::AcceptNeighbor; %rename (acceptSolution) SearchMonitor::AcceptSolution; @@ -1274,7 +1242,6 @@ import java.util.function.LongBinaryOperator; // SearchLimit %unignore SearchLimit; -// Ignored: %rename (check) SearchLimit::Check; %rename (copy) SearchLimit::Copy; %rename (init) SearchLimit::Init; @@ -1287,13 +1254,11 @@ import java.util.function.LongBinaryOperator; // see https://docs.oracle.com/javase/8/docs/api/java/util/function/Supplier.html import java.util.function.Supplier; %} -// Methods: %rename (maintain) SearchLog::Maintain; %rename (outputDecision) SearchLog::OutputDecision; // LocalSearchMonitor %unignore LocalSearchMonitor; -// Methods: %rename (beginAcceptNeighbor) LocalSearchMonitor::BeginAcceptNeighbor; %rename (beginFiltering) LocalSearchMonitor::BeginFiltering; %rename (beginFilterNeighbor) LocalSearchMonitor::BeginFilterNeighbor; @@ -1307,7 +1272,6 @@ import java.util.function.Supplier; // PropagationMonitor %unignore PropagationMonitor; -// Methods: %rename (beginConstraintInitialPropagation) PropagationMonitor::BeginConstraintInitialPropagation; %rename (beginDemonRun) PropagationMonitor::BeginDemonRun; %rename (beginNestedConstraintInitialPropagation) PropagationMonitor::BeginNestedConstraintInitialPropagation; @@ -1358,19 +1322,16 @@ import java.util.function.Supplier; // LocalSearchOperator %feature("director") LocalSearchOperator; %unignore LocalSearchOperator; -// Methods: %rename (nextNeighbor) LocalSearchOperator::MakeNextNeighbor; %rename (reset) LocalSearchOperator::Reset; %rename (start) LocalSearchOperator::Start; // VarLocalSearchOperator<> %unignore VarLocalSearchOperator; -// Ignored: %ignore VarLocalSearchOperator::Start; %ignore VarLocalSearchOperator::ApplyChanges; %ignore VarLocalSearchOperator::RevertChanges; %ignore VarLocalSearchOperator::SkipUnchanged; -// Methods: %rename (size) VarLocalSearchOperator::Size; %rename (value) VarLocalSearchOperator::Value; %rename (isIncremental) VarLocalSearchOperator::IsIncremental; @@ -1386,9 +1347,7 @@ import java.util.function.Supplier; // IntVarLocalSearchOperator %feature("director") IntVarLocalSearchOperator; %unignore IntVarLocalSearchOperator; -// Ignored: %ignore IntVarLocalSearchOperator::MakeNextNeighbor; -// Methods: %rename (size) IntVarLocalSearchOperator::Size; %rename (oneNeighbor) IntVarLocalSearchOperator::MakeOneNeighbor; %rename (value) IntVarLocalSearchOperator::Value; @@ -1405,7 +1364,6 @@ import java.util.function.Supplier; // BaseLns %feature("director") BaseLns; %unignore BaseLns; -// Methods: %rename (initFragments) BaseLns::InitFragments; %rename (nextFragment) BaseLns::NextFragment; %feature ("nodirector") BaseLns::OnStart; @@ -1418,35 +1376,29 @@ import java.util.function.Supplier; // ChangeValue %feature("director") ChangeValue; %unignore ChangeValue; -// Methods: %rename (modifyValue) ChangeValue::ModifyValue; // SequenceVarLocalSearchOperator %feature("director") SequenceVarLocalSearchOperator; %unignore SequenceVarLocalSearchOperator; -// Ignored: %ignore SequenceVarLocalSearchOperator::OldSequence; %ignore SequenceVarLocalSearchOperator::Sequence; %ignore SequenceVarLocalSearchOperator::SetBackwardSequence; %ignore SequenceVarLocalSearchOperator::SetForwardSequence; -// Methods: %rename (start) SequenceVarLocalSearchOperator::Start; // PathOperator %feature("director") PathOperator; %unignore PathOperator; %typemap(javaimports) PathOperator %{ -// Used to wrap start_empty_path_class -// see +// Used to wrap start_empty_path_class see: // https://docs.oracle.com/javase/8/docs/api/java/util/function/LongToIntFunction.html import java.util.function.LongToIntFunction; %} -// Ignored: %ignore PathOperator::Next; %ignore PathOperator::Path; %ignore PathOperator::SkipUnchanged; %ignore PathOperator::number_of_nexts; -// Methods: %rename (getBaseNodeRestartPosition) PathOperator::GetBaseNodeRestartPosition; %rename (initPosition) PathOperator::InitPosition; %rename (neighbor) PathOperator::MakeNeighbor; @@ -1456,14 +1408,12 @@ import java.util.function.LongToIntFunction; // PathWithPreviousNodesOperator %unignore PathWithPreviousNodesOperator; -// Methods: %rename (isPathStart) PathWithPreviousNodesOperator::IsPathStart; %rename (prev) PathWithPreviousNodesOperator::Prev; // LocalSearchFilter %feature("director") LocalSearchFilter; %unignore LocalSearchFilter; -// Methods: %rename (accept) LocalSearchFilter::Accept; %rename (getAcceptedObjectiveValue) LocalSearchFilter::GetAcceptedObjectiveValue; %rename (getSynchronizedObjectiveValue) LocalSearchFilter::GetSynchronizedObjectiveValue; @@ -1478,10 +1428,8 @@ import java.util.function.LongToIntFunction; // see https://docs.oracle.com/javase/8/docs/api/java/util/function/LongConsumer.html import java.util.function.LongConsumer; %} -// Ignored: %ignore IntVarLocalSearchFilter::FindIndex; %ignore IntVarLocalSearchFilter::IsVarSynced; -// Methods: %feature("nodirector") IntVarLocalSearchFilter::Synchronize; // Inherited. %rename (addVars) IntVarLocalSearchFilter::AddVars; // Inherited. %rename (injectObjectiveValue) IntVarLocalSearchFilter::InjectObjectiveValue; @@ -1502,7 +1450,6 @@ import java.util.function.LongConsumer; // Demon %unignore Demon; -// Methods: %rename (run) Demon::Run; %define CONVERT_VECTOR(CType, JavaType) @@ -1603,11 +1550,9 @@ PROTO2_RETURN(operations_research::SearchLimitParameters, namespace operations_research { // Globals -// IMPORTANT(corentinl): Global will be placed in main.java +// IMPORTANT(corentinl): Globals will be placed in main.java // i.e. use `import com.[...].constraintsolver.main` -// Ignored: %ignore FillValues; -// Functions: %rename (areAllBooleans) AreAllBooleans; %rename (areAllBound) AreAllBound; %rename (areAllBoundTo) AreAllBoundTo; diff --git a/ortools/constraint_solver/java/routing.i b/ortools/constraint_solver/java/routing.i index 890fdbe4b3a..561b904d266 100644 --- a/ortools/constraint_solver/java/routing.i +++ b/ortools/constraint_solver/java/routing.i @@ -62,7 +62,6 @@ import java.util.function.LongBinaryOperator; // see https://docs.oracle.com/javase/8/docs/api/java/util/function/LongUnaryOperator.html import java.util.function.LongUnaryOperator; %} -// Ignored: %ignore RoutingModel::AddDimensionDependentDimensionWithVehicleCapacity; %ignore RoutingModel::AddMatrixDimension( std::vector > values, @@ -89,7 +88,6 @@ import java.util.function.LongUnaryOperator; %ignore RoutingModel::TransitCallback; %ignore RoutingModel::StateDependentTransitCallback; %ignore RoutingModel::UnaryTransitCallbackOrNull; -// Methods: %rename (activeVar) RoutingModel::ActiveVar; %rename (addAllActive) RoutingModel::AddAllActive; %rename (addAtSolutionCallback) RoutingModel::AddAtSolutionCallback; @@ -225,7 +223,6 @@ import java.util.function.LongUnaryOperator; // see https://docs.oracle.com/javase/8/docs/api/java/util/function/LongBinaryOperator.html import java.util.function.LongBinaryOperator; %} -// Methods: %rename (cumulVar) RoutingDimension::CumulVar; %rename (fixedTransitVar) RoutingDimension::FixedTransitVar; %rename (getBreakIntervalsOfVehicle) RoutingDimension::GetBreakIntervalsOfVehicle; @@ -258,7 +255,6 @@ import java.util.function.LongBinaryOperator; // RoutingFilteredDecisionBuilder %unignore RoutingFilteredDecisionBuilder; -// Methods: %rename (getEndChainStart) RoutingFilteredDecisionBuilder::GetEndChainStart; %rename (getStartChainEnd) RoutingFilteredDecisionBuilder::GetStartChainEnd; %rename (initializeRoutes) RoutingFilteredDecisionBuilder::InitializeRoutes; diff --git a/ortools/constraint_solver/python/constraint_solver.i b/ortools/constraint_solver/python/constraint_solver.i index 45f1e3a6240..d2a7336a8c2 100644 --- a/ortools/constraint_solver/python/constraint_solver.i +++ b/ortools/constraint_solver/python/constraint_solver.i @@ -1922,6 +1922,8 @@ CONTAINERHELPER(IntVar, IntVarElement, IntContainer) CONTAINERHELPER(IntervalVar, IntervalVarElement, IntervalContainer) CONTAINERHELPER(SequenceVar, SequenceVarElement, SequenceContainer) +#undef CONTAINERHELPER + } // namespace operations_research // ================= constraint_solver.i API ===================== diff --git a/ortools/constraint_solver/samples/VrpInitialRoutes.java b/ortools/constraint_solver/samples/VrpInitialRoutes.java index 236486a6763..de17853edd9 100644 --- a/ortools/constraint_solver/samples/VrpInitialRoutes.java +++ b/ortools/constraint_solver/samples/VrpInitialRoutes.java @@ -20,7 +20,6 @@ import com.google.ortools.constraintsolver.RoutingSearchParameters; import com.google.ortools.constraintsolver.main; import java.util.logging.Logger; - // [END import] /** Minimal VRP. */ diff --git a/ortools/graph/csharp/graph.i b/ortools/graph/csharp/graph.i index 610d2189de2..d471e9a25e4 100644 --- a/ortools/graph/csharp/graph.i +++ b/ortools/graph/csharp/graph.i @@ -44,6 +44,8 @@ typedef uint64_t uint64; %unignore operations_research; %rename (MaxFlow) operations_research::SimpleMaxFlow; +%ignore operations_research::SimpleMaxFlow::GetSourceSideMinCut; // missing typemap for argument +%ignore operations_research::SimpleMaxFlow::GetSinkSideMinCut; // missing typemap for argument %unignore operations_research::SimpleMaxFlow::SimpleMaxFlow; %unignore operations_research::SimpleMaxFlow::~SimpleMaxFlow; %unignore operations_research::SimpleMaxFlow::AddArcWithCapacity; @@ -55,9 +57,6 @@ typedef uint64_t uint64; %unignore operations_research::SimpleMaxFlow::Capacity; %unignore operations_research::SimpleMaxFlow::OptimalFlow; %unignore operations_research::SimpleMaxFlow::Flow; -// Ignored: -%ignore operations_research::SimpleMaxFlow::GetSourceSideMinCut; // missing typemap for argument -%ignore operations_research::SimpleMaxFlow::GetSinkSideMinCut; // missing typemap for argument // Expose the "operations_research::SimpleMaxFlow::Status" enum. %unignore operations_research::SimpleMaxFlow::Status; diff --git a/ortools/graph/java/graph.i b/ortools/graph/java/graph.i index cd31cfc508a..c7786fa78fc 100644 --- a/ortools/graph/java/graph.i +++ b/ortools/graph/java/graph.i @@ -42,9 +42,6 @@ #include "ortools/graph/min_cost_flow.h" %} -typedef int64_t int64; -typedef uint64_t uint64; - // ############ max_flow.h ############ %ignoreall @@ -53,6 +50,8 @@ typedef uint64_t uint64; // MaxFlow %rename (MaxFlow) operations_research::SimpleMaxFlow; +%ignore operations_research::SimpleMaxFlow::GetSourceSideMinCut; // missing typemap for argument +%ignore operations_research::SimpleMaxFlow::GetSinkSideMinCut; // missing typemap for argument %unignore operations_research::SimpleMaxFlow::SimpleMaxFlow; %unignore operations_research::SimpleMaxFlow::~SimpleMaxFlow; %rename (addArcWithCapacity) operations_research::SimpleMaxFlow::AddArcWithCapacity; @@ -65,9 +64,6 @@ typedef uint64_t uint64; %rename (solve) operations_research::SimpleMaxFlow::Solve; %rename (getOptimalFlow) operations_research::SimpleMaxFlow::OptimalFlow; %rename (getFlow) operations_research::SimpleMaxFlow::Flow; -// Ignored: -%ignore operations_research::SimpleMaxFlow::GetSourceSideMinCut; // missing typemap for argument -%ignore operations_research::SimpleMaxFlow::GetSinkSideMinCut; // missing typemap for argument // To expose the Status enum's values (as constant integers), we must expose the enum // type itself. diff --git a/ortools/sat/csharp/CpModel.cs b/ortools/sat/csharp/CpModel.cs index c0f307c297a..a727023d6c9 100644 --- a/ortools/sat/csharp/CpModel.cs +++ b/ortools/sat/csharp/CpModel.cs @@ -16,9 +16,9 @@ namespace Google.OrTools.Sat using System; using System.Collections.Generic; -/// +/// /// Wrapper class around the cp_model proto. -/// +/// public class CpModel { public CpModel() diff --git a/ortools/sat/csharp/CpSolver.cs b/ortools/sat/csharp/CpSolver.cs index b055430a99f..fda26ba56ec 100644 --- a/ortools/sat/csharp/CpSolver.cs +++ b/ortools/sat/csharp/CpSolver.cs @@ -15,7 +15,7 @@ using System.Collections.Generic; namespace Google.OrTools.Sat -{ +{ public class CpSolver { diff --git a/ortools/util/csharp/tuple_set.i b/ortools/util/csharp/tuple_set.i index 2ed9dd14987..e1829751309 100644 --- a/ortools/util/csharp/tuple_set.i +++ b/ortools/util/csharp/tuple_set.i @@ -15,7 +15,6 @@ // TODO(user): Refactor this file to comply with the SWIG style guide. %include "ortools/base/base.i" - %include "ortools/util/csharp/vector.i" %{ diff --git a/ortools/util/csharp/vector.i b/ortools/util/csharp/vector.i index 6aaad22c034..09a211b7a53 100644 --- a/ortools/util/csharp/vector.i +++ b/ortools/util/csharp/vector.i @@ -27,9 +27,11 @@ #include "ortools/base/integral_types.h" %} -// Typemaps to represent const std::vector& arguments as arrays of -// CSHARPTYPE. +// Typemaps to represent arguments of types "const std::vector&" or +// "std::vector" as CSHARPTYPE[]. +// note: TYPE must be a primitive data type (PDT). %define VECTOR_AS_CSHARP_ARRAY(TYPE, CTYPE, CSHARPTYPE, ARRAYTYPE) +// This part is for const std::vector<>&. %typemap(cstype) const std::vector& %{ CSHARPTYPE[] %} %typemap(csin) const std::vector& %{ $csinput.Length, $csinput %} %typemap(imtype, out="global::System.IntPtr") const std::vector& %{ int length$argnum, CSHARPTYPE[] %} @@ -54,8 +56,7 @@ } return ret; } - -// Same, for std::vector +// Now, we do it for std::vector<>. %typemap(cstype) std::vector %{ CSHARPTYPE[] %} %typemap(csin) std::vector %{ $csinput.Length, $csinput %} %typemap(imtype, out="global::System.IntPtr") std::vector %{ int length$argnum, CSHARPTYPE[] %} @@ -81,13 +82,11 @@ } %enddef // VECTOR_AS_CSHARP_ARRAY -//VECTOR_AS_CSHARP_ARRAY(int, int, int); -//VECTOR_AS_CSHARP_ARRAY(int64, int64, long); -//VECTOR_AS_CSHARP_ARRAY(double, double, double); - -// Typemaps to represent const std::vector >& arguments as -// a CSharpType[][]. +// Typemaps to represent arguments of types "const std::vector>&" or +// "std::vector>*" as CSHARPTYPE[][]. +// note: TYPE must be a primitive data type (PDT). %define MATRIX_AS_CSHARP_ARRAY(TYPE, CTYPE, CSHARPTYPE, ARRAYTYPE) +// This part is for const std::vector>&. %typemap(cstype) const std::vector >& %{ CSHARPTYPE[][] %} %typemap(csin) const std::vector >& %{ $csinput.GetLength(0), @@ -117,8 +116,7 @@ $1 = &result; %} - -// Same, for std::vector>* +// Now, we do it for std::vector>*. %typemap(cstype) std::vector >* %{ CSHARPTYPE[][] %} %typemap(csin) std::vector >* %{ $csinput.GetLength(0), @@ -149,6 +147,3 @@ %} %enddef // MATRIX_AS_CSHARP_ARRAY -//MATRIX_AS_CSHARP_ARRAY(int, int, int); -//MATRIX_AS_CSHARP_ARRAY(int64, int64, long); -//MATRIX_AS_CSHARP_ARRAY(double, double, double); diff --git a/ortools/util/java/tuple_set.i b/ortools/util/java/tuple_set.i index 6a112940d05..a33444f313c 100644 --- a/ortools/util/java/tuple_set.i +++ b/ortools/util/java/tuple_set.i @@ -25,6 +25,7 @@ #include "ortools/util/tuple_set.h" %} +%ignore operations_research::IntTupleSet::RawData; // no typemap %rename (arity) operations_research::IntTupleSet::Arity; %rename (clear) operations_research::IntTupleSet::Clear; %rename (contains) operations_research::IntTupleSet::Contains; @@ -38,7 +39,5 @@ %rename (sortedByColumn) operations_research::IntTupleSet::SortedByColumn; %rename (sortedLexicographically) operations_research::IntTupleSet::SortedLexicographically; %rename (value) operations_research::IntTupleSet::Value; -// Ignored: -%ignore operations_research::IntTupleSet::RawData; // no typemap %include ortools/util/tuple_set.h diff --git a/ortools/util/java/vector.i b/ortools/util/java/vector.i index f8615da5029..3ac6fcd34a0 100644 --- a/ortools/util/java/vector.i +++ b/ortools/util/java/vector.i @@ -29,9 +29,12 @@ #include "ortools/base/integral_types.h" %} -// Typemaps to represent const std::vector& arguments as arrays of -// JavaType. +// Typemaps to represents arguments of types "const std::vector&" or +// "std::vector" as JavaType[] (Array). +// note: CType must be a primitive data type (PDT). +// ref: https://docs.oracle.com/javase/8/docs/technotes/guides/jni/spec/functions.html#Get_PrimitiveType_ArrayElements_routines %define VECTOR_AS_JAVA_ARRAY(CType, JavaType, JavaTypeName) +// This part is for const std::vector<>&. %typemap(jstype) const std::vector& #JavaType "[]" %typemap(javain) const std::vector& "$javainput" %typemap(jtype) const std::vector& #JavaType "[]" @@ -64,8 +67,7 @@ %typemap(javaout) const std::vector& { return $jnicall; } - -// Same, for std::vector +// Now, we do it for std::vector<>. %typemap(jstype) std::vector #JavaType "[]" %typemap(javain) std::vector "$javainput" %typemap(jtype) std::vector #JavaType "[]" @@ -101,9 +103,80 @@ VECTOR_AS_JAVA_ARRAY(int, int, Int); VECTOR_AS_JAVA_ARRAY(int64, long, Long); VECTOR_AS_JAVA_ARRAY(double, double, Double); -// Typemaps to represent const std::vector >& arguments as -// an ObjectArray of JavaTypeArrays. + +// Typemaps to represents arguments of types "const std::vector&" or +// "std::vector" as JavaType[] (ObjectArray). +// note: CType is NOT a primitive type. +// note: CastOp defines how to cast the output of CallStaticLongMethod to CType*; +// its first argument is CType, its second is the output of CallStaticLongMethod. +// ref: https://docs.oracle.com/javase/8/docs/technotes/guides/jni/spec/functions.html#GetObjectArrayElement +%define CONVERT_VECTOR_WITH_CAST(CType, JavaType, CastOp, JavaPackage) +// This part is for const std::vector&. +%typemap(jstype) const std::vector& "JavaType[]" +%typemap(javain) const std::vector& "$javainput" +%typemap(jtype) const std::vector& "JavaType[]" +%typemap(jni) const std::vector& "jobjectArray" +%typemap(in) const std::vector& (std::vector result) { + std::string java_class_path = #JavaPackage "/" #JavaType; + jclass object_class = jenv->FindClass(java_class_path.c_str()); + if (nullptr == object_class) + return $null; + jmethodID method_id = + jenv->GetStaticMethodID(object_class, + "getCPtr", + std::string("(L" + java_class_path + ";)J").c_str()); + assert(method_id != nullptr); + for (int i = 0; i < jenv->GetArrayLength($input); i++) { + jobject elem = jenv->GetObjectArrayElement($input, i); + jlong ptr_value = jenv->CallStaticLongMethod(object_class, method_id, elem); + result.push_back(CastOp(CType, ptr_value)); + } + $1 = &result; +} +%typemap(out) const std::vector& { + jclass object_class = jenv->FindClass("JavaPackage/JavaType"); + $result = jenv->NewObjectArray($1->size(), object_class, 0); + if (nullptr != object_class) { + jmethodID ctor = jenv->GetMethodID(object_class,"", "(JZ)V"); + for (int i = 0; i < $1->size(); ++i) { + jlong obj_ptr = 0; + *((CType **)&obj_ptr) = (*$1)[i]; + jobject elem = jenv->NewObject(object_class, ctor, obj_ptr, false); + jenv->SetObjectArrayElement($result, i, elem); + } + } +} +%typemap(javaout) const std::vector & { + return $jnicall; +} +// Now, we do it for std::vector. +%typemap(jstype) std::vector "JavaType[]" +%typemap(javain) std::vector "$javainput" +%typemap(jtype) std::vector "JavaType[]" +%typemap(jni) std::vector "jobjectArray" +%typemap(in) std::vector (std::vector result) { + jclass object_class = jenv->FindClass("JavaPackage/JavaType"); + if (nullptr == object_class) + return $null; + jmethodID method_id = jenv->GetStaticMethodID( + object_class, "getCPtr", "(LJavaPackage/JavaType;)J"); + assert(method_id != nullptr); + for (int i = 0; i < jenv->GetArrayLength($input); i++) { + jobject elem = jenv->GetObjectArrayElement($input, i); + jlong ptr_value = jenv->CallStaticLongMethod(object_class, method_id, elem); + $1.push_back(CastOp(CType, ptr_value)); + } +} +%enddef // CONVERT_VECTOR_WITH_CAST + + +// Typemaps to represents arguments of types "const std::vector>&" or +// "std::vector>*" as JavaType[][] (ObjectArray of JavaTypeArrays). +// note: CType must be a primitive data type (PDT). +// ref: https://docs.oracle.com/javase/8/docs/technotes/guides/jni/spec/functions.html#GetObjectArrayElement +// ref: https://docs.oracle.com/javase/8/docs/technotes/guides/jni/spec/functions.html#Get_PrimitiveType_ArrayElements_routines %define MATRIX_AS_JAVA_ARRAY(CType, JavaType, JavaTypeName) +// This part is for const std::vector>&. %typemap(jstype) const std::vector >& #JavaType "[][]" %typemap(javain) const std::vector >& "$javainput" %typemap(jtype) const std::vector >& #JavaType "[][]" @@ -134,8 +207,7 @@ VECTOR_AS_JAVA_ARRAY(double, double, Double); return $null; } %} - -// Same, for std::vector>* +// Now, we do it for std::vector>* %typemap(jstype) std::vector >* #JavaType "[][]" %typemap(javain) std::vector >* "$javainput" %typemap(jtype) std::vector >* #JavaType "[][]" @@ -180,69 +252,6 @@ MATRIX_AS_JAVA_ARRAY(int, int, Int); MATRIX_AS_JAVA_ARRAY(int64, long, Long); MATRIX_AS_JAVA_ARRAY(double, double, Double); -// Same, for std::vector, where CType is not a primitive type. -// CastOp defines how to cast the output of CallStaticLongMethod to CType*; -// its first argument is CType, its second is the output of -// CallStaticLongMethod. -%define CONVERT_VECTOR_WITH_CAST(CType, JavaType, CastOp, JavaPackage) -%typemap(jstype) const std::vector& "JavaType[]" -%typemap(javain) const std::vector& "$javainput" -%typemap(jtype) const std::vector& "JavaType[]" -%typemap(jni) const std::vector& "jobjectArray" -%typemap(in) const std::vector& (std::vector result) { - std::string java_class_path = #JavaPackage "/" #JavaType; - jclass object_class = jenv->FindClass(java_class_path.c_str()); - if (nullptr == object_class) - return $null; - jmethodID method_id = - jenv->GetStaticMethodID(object_class, - "getCPtr", - std::string("(L" + java_class_path + ";)J").c_str()); - assert(method_id != nullptr); - for (int i = 0; i < jenv->GetArrayLength($input); i++) { - jobject elem = jenv->GetObjectArrayElement($input, i); - jlong ptr_value = jenv->CallStaticLongMethod(object_class, method_id, elem); - result.push_back(CastOp(CType, ptr_value)); - } - $1 = &result; -} -%typemap(out) const std::vector& { - jclass object_class = jenv->FindClass("JavaPackage/JavaType"); - $result = jenv->NewObjectArray($1->size(), object_class, 0); - if (nullptr != object_class) { - jmethodID ctor = jenv->GetMethodID(object_class,"", "(JZ)V"); - for (int i = 0; i < $1->size(); ++i) { - jlong obj_ptr = 0; - *((CType **)&obj_ptr) = (*$1)[i]; - jobject elem = jenv->NewObject(object_class, ctor, obj_ptr, false); - jenv->SetObjectArrayElement($result, i, elem); - } - } -} -%typemap(javaout) const std::vector & { - return $jnicall; -} - -// Same, for std::vector -%typemap(jstype) std::vector "JavaType[]" -%typemap(javain) std::vector "$javainput" -%typemap(jtype) std::vector "JavaType[]" -%typemap(jni) std::vector "jobjectArray" -%typemap(in) std::vector (std::vector result) { - jclass object_class = jenv->FindClass("JavaPackage/JavaType"); - if (nullptr == object_class) - return $null; - jmethodID method_id = jenv->GetStaticMethodID( - object_class, "getCPtr", "(LJavaPackage/JavaType;)J"); - assert(method_id != nullptr); - for (int i = 0; i < jenv->GetArrayLength($input); i++) { - jobject elem = jenv->GetObjectArrayElement($input, i); - jlong ptr_value = jenv->CallStaticLongMethod(object_class, method_id, elem); - $1.push_back(CastOp(CType, ptr_value)); - } -} -%enddef - %define REINTERPRET_CAST(CType, ptr) reinterpret_cast(ptr) %enddef