From 010468391a5ef80fee992e1694e88cbb1b8fe799 Mon Sep 17 00:00:00 2001 From: "laurent.perron@gmail.com" Date: Tue, 11 Jun 2013 21:52:54 +0000 Subject: [PATCH] fix visual studio compilation --- src/constraint_solver/routing.cc | 16 +++++++++------- src/constraint_solver/routing.h | 2 +- src/graph/graph.h | 11 +++++++++++ src/graph/graphs.h | 5 +++++ src/linear_solver/linear_solver.cc | 17 ++++++++++------- src/linear_solver/linear_solver.h | 14 ++++++++++++++ src/linear_solver/model_exporter.cc | 6 +++--- src/util/fp_utils.h | 2 +- 8 files changed, 54 insertions(+), 19 deletions(-) diff --git a/src/constraint_solver/routing.cc b/src/constraint_solver/routing.cc index 57adab0049..a9ecf7780b 100644 --- a/src/constraint_solver/routing.cc +++ b/src/constraint_solver/routing.cc @@ -2100,13 +2100,13 @@ void RoutingModel::CloseModel() { } struct Link { - Link(pair link, double value, int vehicle_class, + Link(std::pair link, double value, int vehicle_class, int64 start_depot, int64 end_depot) : link(link), value(value), vehicle_class(vehicle_class), start_depot(start_depot), end_depot(end_depot) { } ~Link() { } - pair link; + std::pair link; int64 value; int vehicle_class; int64 start_depot; @@ -2212,7 +2212,7 @@ class RouteConstructor { node_to_vehicle_class_index_(nodes_number, -1) { model_->GetAllDimensions(&dimensions_); cumuls_.resize(dimensions_.size()); - for (MutableIter > > it(cumuls_); + for (MutableIter > > it(cumuls_); !it.at_end(); ++it) { it->resize(nodes_number_); } @@ -2649,9 +2649,9 @@ class RouteConstructor { const std::vector vehicle_classes_; std::vector nexts_; std::vector dimensions_; - std::vector > cumuls_; + std::vector > cumuls_; std::vector > new_possible_cumuls_; - std::vector > routes_; + std::vector > routes_; std::vector in_route_; hash_set deleted_routes_; std::vector > final_routes_; @@ -2808,7 +2808,7 @@ struct SweepNodeSortDistance { } SweepNodeDistanceComparator; SweepArranger::SweepArranger( - const ITIVector >& points) + const ITIVector >& points) : coordinates_(2 * points.size(), 0), sectors_(1) { for (RoutingModel::NodeIndex i(0); i < points.size(); ++i) { coordinates_[2 * i] = points[i].first; @@ -3829,7 +3829,9 @@ string RoutingModel::DebugOutputAssignment( "%" GG_LL_FORMAT "d Vehicle(%" GG_LL_FORMAT "d) ", index, solution_assignment.Value(vehicle)); - for (const string& dimension_name : dimension_names) { + for (int dim_index = 0; dim_index < dimension_names.size(); + ++dim_index) { + const string& dimension_name = dimension_names[dim_index]; const IntVar* var = CumulVar(index, dimension_name); StringAppendF( &output, diff --git a/src/constraint_solver/routing.h b/src/constraint_solver/routing.h index 3b7759f137..91d4a94758 100644 --- a/src/constraint_solver/routing.h +++ b/src/constraint_solver/routing.h @@ -1078,7 +1078,7 @@ class RoutingDimension { class SweepArranger { public: explicit SweepArranger( - const ITIVector >& points); + const ITIVector >& points); virtual ~SweepArranger() {} void ArrangeNodes(std::vector* nodes); void SetSectors(int sectors) { sectors_ = sectors; } diff --git a/src/graph/graph.h b/src/graph/graph.h index 705f942eee..0e5a0478dd 100644 --- a/src/graph/graph.h +++ b/src/graph/graph.h @@ -1607,11 +1607,22 @@ void ReverseArcStaticGraph for (int i = 0; i < num_arcs_; ++i) { opposite_[opposite_[i]] = i; } +#if defined(_MSC_VER) + for (IntegerRangeIterator node_iter = Base::AllNodes().begin(); + node_iter != Base::AllNodes().end(); ++node_iter) { + for (IntegerRangeIterator arc_iter = + OutgoingArcs(*node_iter).begin(); + arc_iter != OutgoingArcs(*node_iter).end(); ++arc_iter) { + head_[opposite_[*arc_iter]] = *node_iter; + } + } +#else for (const NodeIndexType node : Base::AllNodes()) { for (const ArcIndexType arc : OutgoingArcs(node)) { head_[opposite_[arc]] = node; } } +#endif } template diff --git a/src/graph/graphs.h b/src/graph/graphs.h index 6a1ce9542c..342a100259 100644 --- a/src/graph/graphs.h +++ b/src/graph/graphs.h @@ -50,8 +50,13 @@ struct Graphs { template<> struct Graphs { typedef operations_research::StarGraph Graph; +#if defined(_MSC_VER) + typedef Graph::ArcIndex ArcIndex; + typedef Graph::NodeIndex NodeIndex; +#else typedef typename Graph::ArcIndex ArcIndex; typedef typename Graph::NodeIndex NodeIndex; +#endif static ArcIndex OppositeArc(const Graph& graph, ArcIndex arc) { return graph.Opposite(arc); } diff --git a/src/linear_solver/linear_solver.cc b/src/linear_solver/linear_solver.cc index aeb04ccf52..9255a179f8 100644 --- a/src/linear_solver/linear_solver.cc +++ b/src/linear_solver/linear_solver.cc @@ -379,7 +379,7 @@ int NumDigits(int n) { // Number of digits needed to write a non-negative integer in base 10. // Note(user): max(1, log(0) + 1) == max(1, -inf) == 1. #if defined(_MSC_VER) - return static_cast(std::max(1.0, log(1.0L * n) / log(10.0L) + 1.0)); + return static_cast(std::max(1.0L, log(1.0L * n) / log(10.0L) + 1.0)); #else return static_cast(std::max(1.0, log10(n) + 1)); #endif @@ -389,8 +389,10 @@ int NumDigits(int n) { MPSolver::MPSolver(const string& name, OptimizationProblemType problem_type) : name_(name), problem_type_(problem_type), +#if !defined(_MSC_VER) variable_name_to_index_(1), constraint_name_to_index_(1), +#endif time_limit_(0.0), var_and_constraint_names_allow_export_(true) { timer_.Restart(); @@ -594,20 +596,21 @@ void OutputTermsToProto( google::protobuf::RepeatedPtrField* output_terms) { // Vector linear_term will contain pairs (variable index, coeff), that will // be sorted by variable index. - std::vector > linear_term; - for (CoeffEntry entry : var_coeff_map) { - const MPVariable* const var = entry.first; - const double coef = entry.second; + std::vector > linear_term; + for (CoeffMap::const_iterator entry = var_coeff_map.begin(); + entry != var_coeff_map.end(); ++entry) { + const MPVariable* const var = entry->first; + const double coef = entry->second; const int var_index = FindWithDefault(var_name_to_index, var, -1); DCHECK_NE(-1, var_index); - linear_term.push_back(pair(var_index, coef)); + linear_term.push_back(std::pair(var_index, coef)); } // The cost of sort is expected to be low as constraints usually have very // few terms. sort(linear_term.begin(), linear_term.end()); // Now use linear term. for (int k = 0; k < linear_term.size(); ++k) { - const pair& p = linear_term[k]; + const std::pair& p = linear_term[k]; const int var_index = p.first; const double coef = p.second; const MPVariable* const var = variables[var_index]; diff --git a/src/linear_solver/linear_solver.h b/src/linear_solver/linear_solver.h index ce1657d817..4431c27d57 100644 --- a/src/linear_solver/linear_solver.h +++ b/src/linear_solver/linear_solver.h @@ -648,8 +648,13 @@ class MPObjective { // to several models. // At construction, an MPObjective has no terms (which is equivalent // on having a coefficient of 0 for all variables), and an offset of 0. +#if defined(_MSC_VER) + explicit MPObjective(MPSolverInterface* const interface) + : interface_(interface), offset_(0.0) {} +#else explicit MPObjective(MPSolverInterface* const interface) : interface_(interface), coefficients_(1), offset_(0.0) {} +#endif MPSolverInterface* const interface_; @@ -802,12 +807,21 @@ class MPConstraint { // Constructor. A constraint points to a single MPSolverInterface // that is specified in the constructor. A constraint cannot belong // to several models. +#if defined(_MSC_VER) + MPConstraint(double lb, + double ub, + const string& name, + MPSolverInterface* const interface) + : lb_(lb), ub_(ub), name_(name), is_lazy_(false), + index_(-1), dual_value_(0.0), activity_(0.0), interface_(interface) {} +#else MPConstraint(double lb, double ub, const string& name, MPSolverInterface* const interface) : coefficients_(1), lb_(lb), ub_(ub), name_(name), is_lazy_(false), index_(-1), dual_value_(0.0), activity_(0.0), interface_(interface) {} +#endif void set_index(int index) { index_ = index; } void set_activity(double activity) { activity_ = activity; } diff --git a/src/linear_solver/model_exporter.cc b/src/linear_solver/model_exporter.cc index be14f1df8a..a1cddece25 100644 --- a/src/linear_solver/model_exporter.cc +++ b/src/linear_solver/model_exporter.cc @@ -438,7 +438,7 @@ bool MPModelProtoExporter::ExportModelAsMpsFormat(bool fixed_format, // As the information regarding a column needs to be contiguous, we create // a map associating a variable to a the vector containing the indices of the // constraints where this variable appears. - std::vector > > transpose(proto_.variables_size()); + std::vector > > transpose(proto_.variables_size()); for (int cst_index = 0; cst_index < proto_.constraints_size(); ++cst_index) { const MPConstraintProto& ct_proto = proto_.constraints(cst_index); for (int k = 0; k < ct_proto.terms_size(); ++k) { @@ -452,7 +452,7 @@ bool MPModelProtoExporter::ExportModelAsMpsFormat(bool fixed_format, } const double coeff = term_proto.coefficient(); if (coeff != 0.0) { - transpose[var_index].push_back(pair(cst_index, coeff)); + transpose[var_index].push_back(std::pair(cst_index, coeff)); } } } @@ -491,7 +491,7 @@ bool MPModelProtoExporter::ExportModelAsMpsFormat(bool fixed_format, var_name, "COST", objective_coef, &columns_section); } for (int k = 0; k < transpose[var_index].size(); ++k) { - const pair p = transpose[var_index][k]; + const std::pair p = transpose[var_index][k]; const int cst_index = p.first; const double coeff = p.second; const string cst_name = GetConstraintName(cst_index); diff --git a/src/util/fp_utils.h b/src/util/fp_utils.h index 9b7568553b..63b5736c6b 100644 --- a/src/util/fp_utils.h +++ b/src/util/fp_utils.h @@ -22,8 +22,8 @@ #ifndef OR_TOOLS_UTIL_FP_UTILS_H_ #define OR_TOOLS_UTIL_FP_UTILS_H_ -#include // NOLINT #if defined(__GNUC__) && defined(__linux__) +#include // NOLINT #include #ifdef __SSE__ #include