From 1de1de33086b8bf679ae7a181868a2eff6b733af Mon Sep 17 00:00:00 2001 From: "lperron@google.com" Date: Thu, 5 Jan 2012 10:42:43 +0000 Subject: [PATCH] minor improvements from internal code --- Makefile | 3 +- algorithms/knapsack_solver.swig | 6 +- base/recordio.cc | 8 +- base/recordio.h | 6 +- constraint_solver/constraint_solver.swig | 144 +++++++++++------------ constraint_solver/routing.swig | 2 +- graph/flow.swig | 2 +- linear_solver/linear_solver.swig | 4 +- util/data.swig | 59 +++++----- 9 files changed, 115 insertions(+), 119 deletions(-) diff --git a/Makefile b/Makefile index 0562b1639a..53a2dcfb6e 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,8 @@ help: @echo " - mathematical programming: lplibs lpexe pylp javalp" @echo " - algorithms: algorithmslibs pyalgorithms javaalgorithms" @echo " - graph: graphlibs pygraph javagraph" - @echo " - .NET on windows: csharp csharpcp csharplp csharpalgorithms csharpgraph csharpexe" + @echo " - .NET on windows: csharp csharpcp csharplp csharpalgorithms" + @echo " csharpgraph csharpexe" @echo " - misc: clean cleancsharp" .PHONY : python cc java diff --git a/algorithms/knapsack_solver.swig b/algorithms/knapsack_solver.swig index 4ec6ca27e5..2cec9cd61d 100644 --- a/algorithms/knapsack_solver.swig +++ b/algorithms/knapsack_solver.swig @@ -1,4 +1,4 @@ -// Copyright 2010-2011 Google +// Copyright 2010-2012 Google // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at @@ -28,10 +28,6 @@ #endif // SWIGJAVA #if defined(SWIGCSHARP) -%rename (bestSolutionContains) operations_research::KnapsackSolver::BestSolutionContains; -%rename (GetName) operations_research::KnapsackSolver::GetName; -%rename (Init) operations_research::KnapsackSolver::Init; -%rename (Solve) operations_research::KnapsackSolver::Solve; %rename (UseReduction) operations_research::KnapsackSolver::use_reduction; %rename (SetUseReduction) operations_research::KnapsackSolver::set_use_reduction; #endif // SWIGCSHARP diff --git a/base/recordio.cc b/base/recordio.cc index 02a1f3852b..96ba9a3ead 100644 --- a/base/recordio.cc +++ b/base/recordio.cc @@ -32,10 +32,10 @@ void RecordWriter::set_use_compression(bool use_compression) { } std::string RecordWriter::Compress(std::string const& s) const { - const unsigned long source_size = s.size(); + const unsigned long source_size = s.size(); // NOLINT const char * source = s.c_str(); - unsigned long dsize = source_size + (source_size * 0.1f) + 16; + unsigned long dsize = source_size + (source_size * 0.1f) + 16; // NOLINT scoped_ptr destination(new char[dsize]); // Use compress() from zlib.h. const int result = @@ -58,7 +58,7 @@ void RecordReader::Uncompress(const char* const source, uint64 source_size, char* const output_buffer, uint64 output_size) const { - unsigned long result_size = output_size; + unsigned long result_size = output_size; // NOLINT // Use uncompress() from zlib.h const int result = uncompress(reinterpret_cast(output_buffer), &result_size, @@ -66,6 +66,6 @@ void RecordReader::Uncompress(const char* const source, if (result != Z_OK) { LOG(FATAL) << "Uncompress error occured! Error code: " << result; } - CHECK_LE(result_size, static_cast(output_size)); + CHECK_LE(result_size, static_cast(output_size)); // NOLINT } } // namespace operations_research diff --git a/base/recordio.h b/base/recordio.h index e7bb5e9333..0bc4d135f8 100644 --- a/base/recordio.h +++ b/base/recordio.h @@ -11,8 +11,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -#ifndef UTIL_OPERATIONS_RESEARCH_OPEN_SOURCE_BASE_RECORDIO_H_ -#define UTIL_OPERATIONS_RESEARCH_OPEN_SOURCE_BASE_RECORDIO_H_ +#ifndef OR_TOOLS_BASE_RECORDIO_H_ +#define OR_TOOLS_BASE_RECORDIO_H_ #include #include "base/file.h" @@ -132,4 +132,4 @@ class RecordReader { }; } // namespace operations_research -#endif // UTIL_OPERATIONS_RESEARCH_OPEN_SOURCE_BASE_RECORDIO_H_ +#endif // OR_TOOLS_BASE_RECORDIO_H_ diff --git a/constraint_solver/constraint_solver.swig b/constraint_solver/constraint_solver.swig index 384535f146..e9d8e23255 100644 --- a/constraint_solver/constraint_solver.swig +++ b/constraint_solver/constraint_solver.swig @@ -1,4 +1,4 @@ -// Copyright 2010-2011 Google +// Copyright 2010-2012 Google // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at @@ -1842,75 +1842,75 @@ namespace operations_research { // Add arithmetic operators to integer expressions. %typemap(cscode) IntExpr %{ - public static IntExpr operator+(IntExpr a, IntExpr b) { - return a.solver().MakeSum(a, b); - } - public static IntExpr operator+(IntExpr a, long v) { - return a.solver().MakeSum(a, v); - } - public static IntExpr operator+(long v, IntExpr a) { - return a.solver().MakeSum(a, v); - } - public static IntExpr operator-(IntExpr a, IntExpr b) { - return a.solver().MakeDifference(a, b); - } - public static IntExpr operator-(IntExpr a, long v) { - return a.solver().MakeSum(a, -v); - } - public static IntExpr operator-(long v, IntExpr a) { - return a.solver().MakeDifference(v, a); - } - public static IntExpr operator*(IntExpr a, IntExpr b) { - return a.solver().MakeProd(a, b); - } - public static IntExpr operator*(IntExpr a, long v) { - return a.solver().MakeProd(a, v); - } - public static IntExpr operator*(long v, IntExpr a) { - return a.solver().MakeProd(a, v); - } - public static IntExpr operator/(IntExpr a, long v) { - return a.solver().MakeDiv(a, v); - } - public static IntExpr operator-(IntExpr a) { - return a.solver().MakeOpposite(a); - } - public IntExpr Abs() { - return this.solver().MakeAbs(this); - } - public IntExpr Square() { - return this.solver().MakeSquare(this); - } - public static ValCstPair operator ==(IntExpr a, long v) { - return new ValCstPair(a.solver().MakeEquality(a, v)); - } - public static ValCstPair operator !=(IntExpr a, long v) { - return new ValCstPair(a.solver().MakeNonEquality(a.Var(), v)); - } - public static ValCstPair operator >=(IntExpr a, long v) { - return new ValCstPair(a.solver().MakeGreaterOrEqual(a, v)); - } - public static ValCstPair operator >(IntExpr a, long v) { - return new ValCstPair(a.solver().MakeGreater(a, v)); - } - public static ValCstPair operator <=(IntExpr a, long v) { - return new ValCstPair(a.solver().MakeLessOrEqual(a, v)); - } - public static ValCstPair operator <(IntExpr a, long v) { - return new ValCstPair(a.solver().MakeLess(a, v)); - } - public static ValCstPair operator >=(IntExpr a, IntExpr b) { - return new ValCstPair(a.solver().MakeGreaterOrEqual(a.Var(), b.Var())); - } - public static ValCstPair operator >(IntExpr a, IntExpr b) { - return new ValCstPair(a.solver().MakeGreater(a.Var(), b.Var())); - } - public static ValCstPair operator <=(IntExpr a, IntExpr b) { - return new ValCstPair(a.solver().MakeLessOrEqual(a.Var(), b.Var())); - } - public static ValCstPair operator <(IntExpr a, IntExpr b) { - return new ValCstPair(a.solver().MakeLess(a.Var(), b.Var())); - } + public static IntExpr operator+(IntExpr a, IntExpr b) { + return a.solver().MakeSum(a, b); + } + public static IntExpr operator+(IntExpr a, long v) { + return a.solver().MakeSum(a, v); + } + public static IntExpr operator+(long v, IntExpr a) { + return a.solver().MakeSum(a, v); + } + public static IntExpr operator-(IntExpr a, IntExpr b) { + return a.solver().MakeDifference(a, b); + } + public static IntExpr operator-(IntExpr a, long v) { + return a.solver().MakeSum(a, -v); + } + public static IntExpr operator-(long v, IntExpr a) { + return a.solver().MakeDifference(v, a); + } + public static IntExpr operator*(IntExpr a, IntExpr b) { + return a.solver().MakeProd(a, b); + } + public static IntExpr operator*(IntExpr a, long v) { + return a.solver().MakeProd(a, v); + } + public static IntExpr operator*(long v, IntExpr a) { + return a.solver().MakeProd(a, v); + } + public static IntExpr operator/(IntExpr a, long v) { + return a.solver().MakeDiv(a, v); + } + public static IntExpr operator-(IntExpr a) { + return a.solver().MakeOpposite(a); + } + public IntExpr Abs() { + return this.solver().MakeAbs(this); + } + public IntExpr Square() { + return this.solver().MakeSquare(this); + } + public static ValCstPair operator ==(IntExpr a, long v) { + return new ValCstPair(a.solver().MakeEquality(a, v)); + } + public static ValCstPair operator !=(IntExpr a, long v) { + return new ValCstPair(a.solver().MakeNonEquality(a.Var(), v)); + } + public static ValCstPair operator >=(IntExpr a, long v) { + return new ValCstPair(a.solver().MakeGreaterOrEqual(a, v)); + } + public static ValCstPair operator >(IntExpr a, long v) { + return new ValCstPair(a.solver().MakeGreater(a, v)); + } + public static ValCstPair operator <=(IntExpr a, long v) { + return new ValCstPair(a.solver().MakeLessOrEqual(a, v)); + } + public static ValCstPair operator <(IntExpr a, long v) { + return new ValCstPair(a.solver().MakeLess(a, v)); + } + public static ValCstPair operator >=(IntExpr a, IntExpr b) { + return new ValCstPair(a.solver().MakeGreaterOrEqual(a.Var(), b.Var())); + } + public static ValCstPair operator >(IntExpr a, IntExpr b) { + return new ValCstPair(a.solver().MakeGreater(a.Var(), b.Var())); + } + public static ValCstPair operator <=(IntExpr a, IntExpr b) { + return new ValCstPair(a.solver().MakeLessOrEqual(a.Var(), b.Var())); + } + public static ValCstPair operator <(IntExpr a, IntExpr b) { + return new ValCstPair(a.solver().MakeLess(a.Var(), b.Var())); + } %} %extend IntervalVar { @@ -2039,7 +2039,7 @@ namespace operations_research { delete intercept;\ } else {\ solver->clear_fail_intercept();\ - SWIG_CSharpSetPendingException(SWIG_CSharpApplicationException, "fail");\ + SWIG_CSharpSetPendingException(SWIG_CSharpApplicationException, "fail");\ return $null;\ } @@ -2087,7 +2087,7 @@ namespace operations_research { } } // namespace operations_research -#endif // SWIGCSHARP +#endif // SWIGCSHARP // Wrap cp includes %include constraint_solver/constraint_solver.h diff --git a/constraint_solver/routing.swig b/constraint_solver/routing.swig index 5d52e9d364..f66a33d54c 100644 --- a/constraint_solver/routing.swig +++ b/constraint_solver/routing.swig @@ -1,4 +1,4 @@ -// Copyright 2010-2011 Google +// Copyright 2010-2012 Google // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at diff --git a/graph/flow.swig b/graph/flow.swig index cdfc9bb1de..07d2f2c972 100644 --- a/graph/flow.swig +++ b/graph/flow.swig @@ -1,4 +1,4 @@ -// Copyright 2010-2011 Google +// Copyright 2010-2012 Google // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at diff --git a/linear_solver/linear_solver.swig b/linear_solver/linear_solver.swig index a6350a03fb..3d148fa96e 100644 --- a/linear_solver/linear_solver.swig +++ b/linear_solver/linear_solver.swig @@ -1,4 +1,4 @@ -// Copyright 2010-2011 Google +// Copyright 2010-2012 Google // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at @@ -700,7 +700,7 @@ namespace operations_research { } // namespace operations_research -#endif // SWIGCSHARP +#endif // SWIGCSHARP // Wrap linear_solver includes %include "linear_solver/linear_solver.h" diff --git a/util/data.swig b/util/data.swig index 23299daeca..7aefeeec25 100644 --- a/util/data.swig +++ b/util/data.swig @@ -1,4 +1,4 @@ -// Copyright 2010-2011 Google +// Copyright 2010-2012 Google // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at @@ -553,18 +553,18 @@ class LongResultCallback3 : private ResultCallback3 //////////////////////////////////////////////// // -// CS_TYPEMAP_STDVECTOR +// CS_TYPEMAP_STDVECTOR // //////////////////////////////////////////////// %define CS_TYPEMAP_STDVECTOR(TYPE, CTYPE, CSHARPTYPE) -%typemap(ctype) const std::vector& %{ int length$argnum, CTYPE* %} -%typemap(imtype) const std::vector& %{ int length$argnum, CSHARPTYPE[] %} -%typemap(cstype) const std::vector& %{ CSHARPTYPE[] %} -%typemap(csin) const std::vector& "$csinput.Length, $csinput" -%typemap(freearg) const std::vector& { delete $1; } -%typemap(in) const std::vector& %{ +%typemap(ctype) const std::vector& %{ int length$argnum, CTYPE* %} +%typemap(imtype) const std::vector& %{ int length$argnum, CSHARPTYPE[] %} +%typemap(cstype) const std::vector& %{ CSHARPTYPE[] %} +%typemap(csin) const std::vector& "$csinput.Length, $csinput" +%typemap(freearg) const std::vector& { delete $1; } +%typemap(in) const std::vector& %{ $1 = new std::vector; for(int i = 0; i < length$argnum; ++i) $1->push_back($input[i]); @@ -573,7 +573,7 @@ class LongResultCallback3 : private ResultCallback3 //////////////////////////////////////////////// // -// CS_TYPEMAP_STDVECTOR_IN1 +// CS_TYPEMAP_STDVECTOR_IN1 // //////////////////////////////////////////////// @@ -597,11 +597,11 @@ class LongResultCallback3 : private ResultCallback3 class NestedArrayHelper {}; %} -%typemap(ctype) const std::vector >& %{ int len$argnum_1, int len$argnum_2, CTYPE* %} -%typemap(imtype) const std::vector >& %{ int len$argnum_1, int len$argnum_2, CSHARPTYPE[] %} -%typemap(cstype) const std::vector >& %{ CSHARPTYPE[,] %} -%typemap(csin) const std::vector >& "$csinput.GetLength(0), $csinput.GetLength(1), NestedArrayHelper.GetFlatArray($csinput)" -%typemap(in) const std::vector >& (std::vector > result) %{ +%typemap(ctype) const std::vector >& %{ int len$argnum_1, int len$argnum_2, CTYPE* %} +%typemap(imtype) const std::vector >& %{ int len$argnum_1, int len$argnum_2, CSHARPTYPE[] %} +%typemap(cstype) const std::vector >& %{ CSHARPTYPE[,] %} +%typemap(csin) const std::vector >& "$csinput.GetLength(0), $csinput.GetLength(1), NestedArrayHelper.GetFlatArray($csinput)" +%typemap(in) const std::vector >& (std::vector > result) %{ const int size_x = len$argnum_1; const int size_y = len$argnum_2; @@ -625,7 +625,7 @@ class LongResultCallback3 : private ResultCallback3 //////////////////////////////////////////////// // -// CS_TYPEMAP_PTRARRAY +// CS_TYPEMAP_PTRARRAY // //////////////////////////////////////////////// @@ -640,24 +640,24 @@ class LongResultCallback3 : private ResultCallback3 } %} -%typemap(ctype) CTYPE** "CTYPE**" +%typemap(ctype) CTYPE** "CTYPE**" %typemap(imtype, inattributes="[In, Out, MarshalAs(UnmanagedType.LPArray)]", outattributes="[return: MarshalAs(UnmanagedType.LPArray)]") CTYPE** "IntPtr[]" -%typemap(cstype) CTYPE** "TYPE[]" -%typemap(csin) CTYPE** "TYPE.getCPtr($csinput)" -%typemap(in) CTYPE** "$1 = $input;" -%typemap(freearg) CTYPE** "" -%typemap(argout) CTYPE** "" +%typemap(cstype) CTYPE** "TYPE[]" +%typemap(csin) CTYPE** "TYPE.getCPtr($csinput)" +%typemap(in) CTYPE** "$1 = $input;" +%typemap(freearg) CTYPE** "" +%typemap(argout) CTYPE** "" -%enddef // CS_TYPEMAP_PTRARRAY +%enddef // CS_TYPEMAP_PTRARRAY //////////////////////////////////////////////// // -// CS_TYPEMAP_STDVECTOR_OBJECT +// CS_TYPEMAP_STDVECTOR_OBJECT // //////////////////////////////////////////////// @@ -681,7 +681,7 @@ CTYPE** "IntPtr[]" result.push_back($input[i]); $1 = &result; } -%enddef // CS_TYPEMAP_STDVECTOR_OBJECT +%enddef // CS_TYPEMAP_STDVECTOR_OBJECT %{ #include @@ -788,12 +788,11 @@ CS_TYPEMAP_STDVECTOR_IN1(int64, int64, long) // type // @param param_name the parameter name %define PROTO_INPUT(CppProtoType, CSharpProtoType, param_name) -%typemap(ctype) PROTO_TYPE* INPUT, PROTO_TYPE& INPUT "int proto_size, char*" -%typemap(imtype) PROTO_TYPE* INPUT, PROTO_TYPE& INPUT "int proto_size, byte[]" -%typemap(cstype) PROTO_TYPE* INPUT, PROTO_TYPE& INPUT "CSharpProtoType" -%typemap(csin) PROTO_TYPE* INPUT, PROTO_TYPE& INPUT "$csinput.GetByteArrayLength(), $csinput.ToByteArray()" -%typemap(in) PROTO_TYPE* INPUT (CppProtoType temp), - PROTO_TYPE& INPUT (CppProtoType temp) { +%typemap(ctype) PROTO_TYPE* INPUT, PROTO_TYPE& INPUT "int proto_size, char*" +%typemap(imtype) PROTO_TYPE* INPUT, PROTO_TYPE& INPUT "int proto_size, byte[]" +%typemap(cstype) PROTO_TYPE* INPUT, PROTO_TYPE& INPUT "CSharpProtoType" +%typemap(csin) PROTO_TYPE* INPUT, PROTO_TYPE& INPUT "$csinput.GetByteArrayLength(), $csinput.ToByteArray()" +%typemap(in) PROTO_TYPE* INPUT (CppProtoType temp), PROTO_TYPE& INPUT (CppProtoType temp) { int proto_size = 0; scoped_array proto_buffer($input); bool parsed_ok = temp.ParseFromArray(proto_buffer.get(), proto_size);