From 4c0a40f7bfabc1b75cc680a083095f637e92313e Mon Sep 17 00:00:00 2001 From: Laurent Perron Date: Mon, 25 Nov 2019 15:34:42 +0100 Subject: [PATCH] sync with internal code --- ortools/base/file.cc | 2 +- ortools/base/file.h | 2 +- ortools/constraint_solver/constraint_solver.h | 4 +- ortools/constraint_solver/doc/routing_svg.py | 8 ++-- ortools/constraint_solver/routing.h | 7 ++-- .../samples/SimpleMipProgram.java | 38 ++++++++----------- ortools/util/sorted_interval_list.h | 22 ++++++----- 7 files changed, 39 insertions(+), 44 deletions(-) diff --git a/ortools/base/file.cc b/ortools/base/file.cc index c9cd2e08f2..31ba32a231 100644 --- a/ortools/base/file.cc +++ b/ortools/base/file.cc @@ -264,7 +264,7 @@ void WriteProtoToFileOrDie(const google::protobuf::Message& proto, } util::Status GetTextProto(const absl::string_view& filename, - google::protobuf::Message* proto, int flags) { + google::protobuf::Message* proto, int flags) { if (flags == Defaults()) { if (ReadFileToProto(filename, proto)) return util::Status::OK; } diff --git a/ortools/base/file.h b/ortools/base/file.h index 048d1d2941..71c5891e60 100644 --- a/ortools/base/file.h +++ b/ortools/base/file.h @@ -124,7 +124,7 @@ util::Status Open(const absl::string_view& filename, File* OpenOrDie(const absl::string_view& filename, const absl::string_view& mode, int flags); util::Status GetTextProto(const absl::string_view& filename, - google::protobuf::Message* proto, int flags); + google::protobuf::Message* proto, int flags); util::Status SetTextProto(const absl::string_view& filename, const google::protobuf::Message& proto, int flags); util::Status SetBinaryProto(const absl::string_view& filename, diff --git a/ortools/constraint_solver/constraint_solver.h b/ortools/constraint_solver/constraint_solver.h index 47c623c7fe..f9d132dc9b 100644 --- a/ortools/constraint_solver/constraint_solver.h +++ b/ortools/constraint_solver/constraint_solver.h @@ -3462,8 +3462,8 @@ class ModelVisitor : public BaseObject { /// ----- Virtual methods for visitors ----- /// Begin/End visit element. - virtual void BeginVisitModel(const std::string& solver_name); - virtual void EndVisitModel(const std::string& solver_name); + virtual void BeginVisitModel(const std::string& type_name); + virtual void EndVisitModel(const std::string& type_name); virtual void BeginVisitConstraint(const std::string& type_name, const Constraint* const constraint); virtual void EndVisitConstraint(const std::string& type_name, diff --git a/ortools/constraint_solver/doc/routing_svg.py b/ortools/constraint_solver/doc/routing_svg.py index 1eb6d6446f..7e0654f7ab 100755 --- a/ortools/constraint_solver/doc/routing_svg.py +++ b/ortools/constraint_solver/doc/routing_svg.py @@ -22,7 +22,7 @@ from ortools.constraint_solver import routing_enums_pb2 # [START data_model] -class DataModel: # pylint: disable=too-many-instance-attributes +class DataModel(object): # pylint: disable=too-many-instance-attributes """Stores the data for the problem.""" def __init__(self, args): @@ -253,7 +253,7 @@ class DataModel: # pylint: disable=too-many-instance-attributes ########### # Printer # ########### -class GoogleColorPalette(): +class GoogleColorPalette(object): """Google color codes palette.""" def __init__(self): @@ -288,7 +288,7 @@ class GoogleColorPalette(): return dict(self._colors)[name] -class SVG(): +class SVG(object): """SVG draw primitives.""" @staticmethod @@ -375,7 +375,7 @@ class SVG(): txt=text)) -class SVGPrinter(): # pylint: disable=too-many-instance-attributes +class SVGPrinter(object): # pylint: disable=too-many-instance-attributes """Generate Problem as svg file to stdout.""" # pylint: disable=too-many-arguments diff --git a/ortools/constraint_solver/routing.h b/ortools/constraint_solver/routing.h index 10cadbeaba..aa135b351d 100644 --- a/ortools/constraint_solver/routing.h +++ b/ortools/constraint_solver/routing.h @@ -457,9 +457,9 @@ class RoutingModel { /// model. /// Returns false if a dimension with the same name has already been created /// (and doesn't create the new dimension). - bool AddMatrixDimension(std::vector> values, - int64 capacity, bool fix_start_cumul_to_zero, - const std::string& name); + bool AddMatrixDimension( + std::vector /*needed_for_swig*/> values, + int64 capacity, bool fix_start_cumul_to_zero, const std::string& name); /// Creates a dimension with transits depending on the cumuls of another /// dimension. 'pure_transits' are the per-vehicle fixed transits as above. /// 'dependent_transits' is a vector containing for each vehicle an index to a @@ -476,6 +476,7 @@ class RoutingModel { pure_transits, dependent_transits, base_dimension, slack_max, std::move(vehicle_capacities), fix_start_cumul_to_zero, name); } + /// As above, but pure_transits are taken to be zero evaluators. bool AddDimensionDependentDimensionWithVehicleCapacity( const std::vector& transits, const RoutingDimension* base_dimension, diff --git a/ortools/linear_solver/samples/SimpleMipProgram.java b/ortools/linear_solver/samples/SimpleMipProgram.java index 1b1f5b0bed..955295d068 100644 --- a/ortools/linear_solver/samples/SimpleMipProgram.java +++ b/ortools/linear_solver/samples/SimpleMipProgram.java @@ -66,33 +66,25 @@ public class SimpleMipProgram { // [START solve] final MPSolver.ResultStatus resultStatus = solver.solve(); - // Check that the problem has an optimal solution. - if (resultStatus != MPSolver.ResultStatus.OPTIMAL) { - System.err.println("The problem does not have an optimal solution!"); - return; - } - // Verify that the solution satisfies all constraints (when using solvers - // others than GLOP_LINEAR_PROGRAMMING, this is highly recommended!). - if (!solver.verifySolution(/*tolerance=*/1e-7, /*log_errors=*/true)) { - System.err.println("The solution returned by the solver violated the" - + " problem constraints by at least 1e-7"); - return; - } // [END solve] // [START print_solution] - System.out.println("Solution:"); - System.out.println("Objective value = " + objective.value()); - System.out.println("x = " + x.solutionValue()); - System.out.println("y = " + y.solutionValue()); - // [END print_solution] + if (resultStatus == MPSolver.ResultStatus.OPTIMAL) { + System.out.println("Solution:"); + System.out.println("Objective value = " + objective.value()); + System.out.println("x = " + x.solutionValue()); + System.out.println("y = " + y.solutionValue()); + // [END print_solution] - // [START advanced] - System.out.println("\nAdvanced usage:"); - System.out.println("Problem solved in " + solver.wallTime() + " milliseconds"); - System.out.println("Problem solved in " + solver.iterations() + " iterations"); - System.out.println("Problem solved in " + solver.nodes() + " branch-and-bound nodes"); - // [END advanced] + // [START advanced] + System.out.println("\nAdvanced usage:"); + System.out.println("Problem solved in " + solver.wallTime() + " milliseconds"); + System.out.println("Problem solved in " + solver.iterations() + " iterations"); + System.out.println("Problem solved in " + solver.nodes() + " branch-and-bound nodes"); + // [END advanced] + } else { + System.err.println("The problem does not have an optimal solution!"); + } } } // [END program] diff --git a/ortools/util/sorted_interval_list.h b/ortools/util/sorted_interval_list.h index 0f3f8b2ac3..197fa86514 100644 --- a/ortools/util/sorted_interval_list.h +++ b/ortools/util/sorted_interval_list.h @@ -226,16 +226,18 @@ class Domain { */ Domain ContinuousMultiplicationBy(int64 coeff) const; - /// Returns a super-set of MultiplicationBy() to avoid the explosion in the - /// representation size. This behaves as if we replace the set D of - /// non-adjacent integer intervals by the set of floating-point element in the - /// same intervals. - /// - /// For instance, [1, 100] * 2 will be transformed in [2, 200] and not in - /// [2][4][6]...[200] like in MultiplicationBy(). Note that this would be - /// similar to a InverseDivisionBy(), but not quite the same because if we - /// look for {x ∈ Int64, ∃ e ∈ D, x / coeff = e}, then we will get [2, 201] in - /// the case above. + /** + * Returns a superset of MultiplicationBy() to avoid the explosion in the + * representation size. This behaves as if we replace the set D of + * non-adjacent integer intervals by the set of floating-point elements in the + * same intervals. + * + * For instance, [1, 100] * 2 will be transformed in [2, 200] and not in + * [2][4][6]...[200] like in MultiplicationBy(). Note that this would be + * similar to a InverseDivisionBy(), but not quite the same because if we + * look for {x ∈ Int64, ∃ e ∈ D, x / coeff = e}, then we will get [2, 201] in + * the case above. + */ Domain ContinuousMultiplicationBy(const Domain& domain) const; /**