fix visual studio compilation

This commit is contained in:
laurent.perron@gmail.com
2013-06-11 21:52:54 +00:00
parent ca70c43762
commit 010468391a
8 changed files with 54 additions and 19 deletions

View File

@@ -2100,13 +2100,13 @@ void RoutingModel::CloseModel() {
}
struct Link {
Link(pair<int, int> link, double value, int vehicle_class,
Link(std::pair<int, int> 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<int, int> link;
std::pair<int, int> 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<std::vector<vector <int64> > > it(cumuls_);
for (MutableIter<std::vector<std::vector <int64> > > it(cumuls_);
!it.at_end(); ++it) {
it->resize(nodes_number_);
}
@@ -2649,9 +2649,9 @@ class RouteConstructor {
const std::vector<VehicleClass> vehicle_classes_;
std::vector<IntVar*> nexts_;
std::vector<string> dimensions_;
std::vector<vector <int64> > cumuls_;
std::vector<std::vector <int64> > cumuls_;
std::vector<hash_map<int, int64> > new_possible_cumuls_;
std::vector<vector <int> > routes_;
std::vector<std::vector <int> > routes_;
std::vector<int> in_route_;
hash_set<int> deleted_routes_;
std::vector<std::vector<int> > final_routes_;
@@ -2808,7 +2808,7 @@ struct SweepNodeSortDistance {
} SweepNodeDistanceComparator;
SweepArranger::SweepArranger(
const ITIVector<RoutingModel::NodeIndex, pair<int64, int64> >& points)
const ITIVector<RoutingModel::NodeIndex, std::pair<int64, int64> >& 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,

View File

@@ -1078,7 +1078,7 @@ class RoutingDimension {
class SweepArranger {
public:
explicit SweepArranger(
const ITIVector<RoutingModel::NodeIndex, pair<int64, int64> >& points);
const ITIVector<RoutingModel::NodeIndex, std::pair<int64, int64> >& points);
virtual ~SweepArranger() {}
void ArrangeNodes(std::vector<RoutingModel::NodeIndex>* nodes);
void SetSectors(int sectors) { sectors_ = sectors; }

View File

@@ -1607,11 +1607,22 @@ void ReverseArcStaticGraph<NodeIndexType, ArcIndexType>
for (int i = 0; i < num_arcs_; ++i) {
opposite_[opposite_[i]] = i;
}
#if defined(_MSC_VER)
for (IntegerRangeIterator<NodeIndex> node_iter = Base::AllNodes().begin();
node_iter != Base::AllNodes().end(); ++node_iter) {
for (IntegerRangeIterator<ArcIndexType> 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<typename NodeIndexType, typename ArcIndexType>

View File

@@ -50,8 +50,13 @@ struct Graphs {
template<>
struct Graphs<operations_research::StarGraph> {
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);
}

View File

@@ -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<int>(std::max(1.0, log(1.0L * n) / log(10.0L) + 1.0));
return static_cast<int>(std::max(1.0L, log(1.0L * n) / log(10.0L) + 1.0));
#else
return static_cast<int>(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<MPTermProto>* output_terms) {
// Vector linear_term will contain pairs (variable index, coeff), that will
// be sorted by variable index.
std::vector<pair<int, double> > linear_term;
for (CoeffEntry entry : var_coeff_map) {
const MPVariable* const var = entry.first;
const double coef = entry.second;
std::vector<std::pair<int, double> > 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<int, double>(var_index, coef));
linear_term.push_back(std::pair<int, double>(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<int, double>& p = linear_term[k];
const std::pair<int, double>& p = linear_term[k];
const int var_index = p.first;
const double coef = p.second;
const MPVariable* const var = variables[var_index];

View File

@@ -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; }

View File

@@ -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<std::vector<pair<int, double> > > transpose(proto_.variables_size());
std::vector<std::vector<std::pair<int, double> > > 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<int, double>(cst_index, coeff));
transpose[var_index].push_back(std::pair<int, double>(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<int, double> p = transpose[var_index][k];
const std::pair<int, double> p = transpose[var_index][k];
const int cst_index = p.first;
const double coeff = p.second;
const string cst_name = GetConstraintName(cst_index);

View File

@@ -22,8 +22,8 @@
#ifndef OR_TOOLS_UTIL_FP_UTILS_H_
#define OR_TOOLS_UTIL_FP_UTILS_H_
#include <fenv.h> // NOLINT
#if defined(__GNUC__) && defined(__linux__)
#include <fenv.h> // NOLINT
#include <fpu_control.h>
#ifdef __SSE__
#include <xmmintrin.h>