scoped_ptr -> unique_ptr
This commit is contained in:
@@ -14,6 +14,7 @@
|
||||
|
||||
#include "base/hash.h"
|
||||
#include <limits>
|
||||
#include "base/unique_ptr.h"
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
@@ -294,8 +295,8 @@ MPSolver::ResultStatus CBCInterface::Solve(const MPSolverParameters& param) {
|
||||
max_row_length = ct->coefficients_.size();
|
||||
}
|
||||
}
|
||||
scoped_ptr<int[]> indices(new int[max_row_length]);
|
||||
scoped_ptr<double[]> coefs(new double[max_row_length]);
|
||||
std::unique_ptr<int[]> indices(new int[max_row_length]);
|
||||
std::unique_ptr<double[]> coefs(new double[max_row_length]);
|
||||
|
||||
for (int i = 0; i < solver_->constraints_.size(); ++i) {
|
||||
MPConstraint* const ct = solver_->constraints_[i];
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
|
||||
#include <algorithm>
|
||||
#include "base/hash.h"
|
||||
#include "base/unique_ptr.h"
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
@@ -137,8 +138,8 @@ class CLPInterface : public MPSolverInterface {
|
||||
MPSolver::BasisStatus
|
||||
TransformCLPBasisStatus(ClpSimplex::Status clp_basis_status) const;
|
||||
|
||||
scoped_ptr<ClpSimplex> clp_; // TODO(user) : remove pointer.
|
||||
scoped_ptr<ClpSolve> options_; // For parameter setting.
|
||||
std::unique_ptr<ClpSimplex> clp_; // TODO(user) : remove pointer.
|
||||
std::unique_ptr<ClpSolve> options_; // For parameter setting.
|
||||
};
|
||||
|
||||
// ----- Solver -----
|
||||
@@ -349,8 +350,8 @@ void CLPInterface::ExtractNewConstraints() {
|
||||
}
|
||||
// Make space for dummy variable.
|
||||
max_row_length = std::max(1, max_row_length);
|
||||
scoped_ptr<int[]> indices(new int[max_row_length]);
|
||||
scoped_ptr<double[]> coefs(new double[max_row_length]);
|
||||
std::unique_ptr<int[]> indices(new int[max_row_length]);
|
||||
std::unique_ptr<double[]> coefs(new double[max_row_length]);
|
||||
CoinBuild build_object;
|
||||
// Add each new constraint.
|
||||
for (int i = last_constraint_index_; i < total_num_rows; ++i) {
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
#include <stddef.h>
|
||||
#include "base/hash.h"
|
||||
#include <limits>
|
||||
#include "base/unique_ptr.h"
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
@@ -213,7 +214,7 @@ class GLPKInterface : public MPSolverInterface {
|
||||
glp_smcp lp_param_;
|
||||
glp_iocp mip_param_;
|
||||
// For the callback
|
||||
scoped_ptr<GLPKInformation> mip_callback_info_;
|
||||
std::unique_ptr<GLPKInformation> mip_callback_info_;
|
||||
};
|
||||
|
||||
// Creates a LP/MIP instance with the specified name and minimization objective.
|
||||
@@ -326,8 +327,8 @@ void GLPKInterface::SetCoefficient(MPConstraint* const constraint,
|
||||
(sync_status_ == MODEL_SYNCHRONIZED ||
|
||||
!constraint->ContainsNewVariables())) {
|
||||
const int size = constraint->coefficients_.size();
|
||||
scoped_ptr<int[]> indices(new int[size + 1]);
|
||||
scoped_ptr<double[]> coefs(new double[size + 1]);
|
||||
std::unique_ptr<int[]> indices(new int[size + 1]);
|
||||
std::unique_ptr<double[]> coefs(new double[size + 1]);
|
||||
ExtractOneConstraint(constraint, indices.get(), coefs.get());
|
||||
}
|
||||
}
|
||||
@@ -408,8 +409,8 @@ void GLPKInterface::ExtractOldConstraints() {
|
||||
0, last_constraint_index_);
|
||||
// The first entry in the following arrays is dummy, to be
|
||||
// consistent with glpk API.
|
||||
scoped_ptr<int[]> indices(new int[max_constraint_size + 1]);
|
||||
scoped_ptr<double[]> coefs(new double[max_constraint_size + 1]);
|
||||
std::unique_ptr<int[]> indices(new int[max_constraint_size + 1]);
|
||||
std::unique_ptr<double[]> coefs(new double[max_constraint_size + 1]);
|
||||
|
||||
for (int i = 0; i < last_constraint_index_; ++i) {
|
||||
MPConstraint* const ct = solver_->constraints_[i];
|
||||
@@ -474,9 +475,9 @@ void GLPKInterface::ExtractNewConstraints() {
|
||||
|
||||
// The first entry in the following arrays is dummy, to be
|
||||
// consistent with glpk API.
|
||||
scoped_ptr<int[]> variable_indices(new int[num_coefs + 1]);
|
||||
scoped_ptr<int[]> constraint_indices(new int[num_coefs + 1]);
|
||||
scoped_ptr<double[]> coefs(new double[num_coefs + 1]);
|
||||
std::unique_ptr<int[]> variable_indices(new int[num_coefs + 1]);
|
||||
std::unique_ptr<int[]> constraint_indices(new int[num_coefs + 1]);
|
||||
std::unique_ptr<double[]> coefs(new double[num_coefs + 1]);
|
||||
int k = 1;
|
||||
for (int i = 0; i < solver_->constraints_.size(); ++i) {
|
||||
MPConstraint* ct = solver_->constraints_[i];
|
||||
@@ -497,8 +498,8 @@ void GLPKInterface::ExtractNewConstraints() {
|
||||
last_constraint_index_, total_num_rows);
|
||||
// The first entry in the following arrays is dummy, to be
|
||||
// consistent with glpk API.
|
||||
scoped_ptr<int[]> indices(new int[max_constraint_size + 1]);
|
||||
scoped_ptr<double[]> coefs(new double[max_constraint_size + 1]);
|
||||
std::unique_ptr<int[]> indices(new int[max_constraint_size + 1]);
|
||||
std::unique_ptr<double[]> coefs(new double[max_constraint_size + 1]);
|
||||
for (int i = last_constraint_index_; i < total_num_rows; i++) {
|
||||
ExtractOneConstraint(solver_->constraints_[i], indices.get(),
|
||||
coefs.get());
|
||||
@@ -770,8 +771,8 @@ double GLPKInterface::ComputeExactConditionNumber() const {
|
||||
const int num_rows = glp_get_num_rows(lp_);
|
||||
const int num_cols = glp_get_num_cols(lp_);
|
||||
// GLPK indexes everything starting from 1 instead of 0.
|
||||
scoped_ptr<double[]> row_scaling_factor(new double[num_rows + 1]);
|
||||
scoped_ptr<double[]> column_scaling_factor(new double[num_cols + 1]);
|
||||
std::unique_ptr<double[]> row_scaling_factor(new double[num_rows + 1]);
|
||||
std::unique_ptr<double[]> column_scaling_factor(new double[num_cols + 1]);
|
||||
for (int row = 1; row <= num_rows; ++row) {
|
||||
row_scaling_factor[row] = glp_get_rii(lp_, row);
|
||||
}
|
||||
@@ -791,8 +792,8 @@ double GLPKInterface::ComputeScaledBasisL1Norm(
|
||||
int num_rows, int num_cols,
|
||||
double* row_scaling_factor, double* column_scaling_factor) const {
|
||||
double norm = 0.0;
|
||||
scoped_ptr<double[]> values(new double[num_rows + 1]);
|
||||
scoped_ptr<int[]> indices(new int[num_rows + 1]);
|
||||
std::unique_ptr<double[]> values(new double[num_rows + 1]);
|
||||
std::unique_ptr<int[]> indices(new int[num_rows + 1]);
|
||||
for (int col = 1; col <= num_cols; ++col) {
|
||||
const int glpk_basis_status = glp_get_col_stat(lp_, col);
|
||||
// Take into account only basic columns.
|
||||
@@ -850,7 +851,7 @@ double GLPKInterface::ComputeInverseScaledBasisL1Norm(
|
||||
break;
|
||||
}
|
||||
}
|
||||
scoped_ptr<double[]> right_hand_side(new double[num_rows + 1]);
|
||||
std::unique_ptr<double[]> right_hand_side(new double[num_rows + 1]);
|
||||
double norm = 0.0;
|
||||
// Iteratively solve B x = e_k, where e_k is the kth unit vector.
|
||||
// The result of this computation is the kth column of B^-1.
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
#include <stddef.h>
|
||||
#include "base/hash.h"
|
||||
#include <limits>
|
||||
#include "base/unique_ptr.h"
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
@@ -450,11 +451,12 @@ void GurobiInterface::ExtractNewVariables() {
|
||||
int total_num_vars = solver_->variables_.size();
|
||||
if (total_num_vars > last_variable_index_) {
|
||||
int num_new_variables = total_num_vars - last_variable_index_;
|
||||
scoped_ptr<double[]> obj_coefs(new double[num_new_variables]);
|
||||
scoped_ptr<double[]> lb(new double[num_new_variables]);
|
||||
scoped_ptr<double[]> ub(new double[num_new_variables]);
|
||||
scoped_ptr<char[]> ctype(new char[num_new_variables]);
|
||||
scoped_ptr<const char * []> colname(new const char* [num_new_variables]);
|
||||
std::unique_ptr<double[]> obj_coefs(new double[num_new_variables]);
|
||||
std::unique_ptr<double[]> lb(new double[num_new_variables]);
|
||||
std::unique_ptr<double[]> ub(new double[num_new_variables]);
|
||||
std::unique_ptr<char[]> ctype(new char[num_new_variables]);
|
||||
std::unique_ptr<const char * []> colname(
|
||||
new const char* [num_new_variables]);
|
||||
|
||||
for (int j = 0; j < num_new_variables; ++j) {
|
||||
MPVariable* const var = solver_->variables_[last_variable_index_+j];
|
||||
@@ -502,8 +504,8 @@ void GurobiInterface::ExtractNewConstraints() {
|
||||
}
|
||||
|
||||
max_row_length = std::max(1, max_row_length);
|
||||
scoped_ptr<int[]> col_indices(new int[max_row_length]);
|
||||
scoped_ptr<double[]> coefs(new double[max_row_length]);
|
||||
std::unique_ptr<int[]> col_indices(new int[max_row_length]);
|
||||
std::unique_ptr<double[]> coefs(new double[max_row_length]);
|
||||
|
||||
// Add each new constraint.
|
||||
for (int row = last_constraint_index_; row < total_num_rows; ++row) {
|
||||
@@ -732,11 +734,11 @@ MPSolver::ResultStatus GurobiInterface::Solve(const MPSolverParameters& param) {
|
||||
const int total_num_rows = solver_->constraints_.size();
|
||||
const int total_num_cols = solver_->variables_.size();
|
||||
|
||||
scoped_ptr<double[]> values(new double[total_num_cols]);
|
||||
scoped_ptr<double[]> dual_values(new double[total_num_rows]);
|
||||
scoped_ptr<double[]> slacks(new double[total_num_rows]);
|
||||
scoped_ptr<double[]> rhs(new double[total_num_rows]);
|
||||
scoped_ptr<double[]> reduced_costs(new double[total_num_cols]);
|
||||
std::unique_ptr<double[]> values(new double[total_num_cols]);
|
||||
std::unique_ptr<double[]> dual_values(new double[total_num_rows]);
|
||||
std::unique_ptr<double[]> slacks(new double[total_num_rows]);
|
||||
std::unique_ptr<double[]> rhs(new double[total_num_rows]);
|
||||
std::unique_ptr<double[]> reduced_costs(new double[total_num_cols]);
|
||||
|
||||
CHECKED_GUROBI_CALL(GRBgetdblattr(model_,
|
||||
GRB_DBL_ATTR_OBJVAL,
|
||||
|
||||
@@ -499,7 +499,7 @@ MPSolver::LoadStatus MPSolver::LoadModel(const MPModelProto& input_model) {
|
||||
}
|
||||
}
|
||||
// To detect duplicate variables in each constraint, and in the objective.
|
||||
hash_set<MPVariable*> tmp_variable_set;
|
||||
hash_set<const MPVariable*> tmp_variable_set;
|
||||
for (int i = 0; i < input_model.constraints_size(); ++i) {
|
||||
tmp_variable_set.clear();
|
||||
const MPConstraintProto& ct_proto = input_model.constraints(i);
|
||||
@@ -1580,3 +1580,4 @@ int MPSolverParameters::GetIntegerParam(
|
||||
|
||||
|
||||
} // namespace operations_research
|
||||
|
||||
|
||||
@@ -134,6 +134,7 @@
|
||||
#include "base/hash.h"
|
||||
#include <limits>
|
||||
#include <map>
|
||||
#include "base/unique_ptr.h"
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
@@ -564,7 +565,7 @@ class MPSolver {
|
||||
const OptimizationProblemType problem_type_;
|
||||
|
||||
// The solver interface.
|
||||
scoped_ptr<MPSolverInterface> interface_;
|
||||
std::unique_ptr<MPSolverInterface> interface_;
|
||||
|
||||
// The vector of variables in the problem.
|
||||
std::vector<MPVariable*> variables_;
|
||||
@@ -577,7 +578,7 @@ class MPSolver {
|
||||
hash_map<string, int> constraint_name_to_index_;
|
||||
|
||||
// The linear objective function.
|
||||
scoped_ptr<MPObjective> objective_;
|
||||
std::unique_ptr<MPObjective> objective_;
|
||||
|
||||
// Time limit in milliseconds (0 = no limit).
|
||||
int64 time_limit_;
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
|
||||
#include <stddef.h>
|
||||
#include "base/hash.h"
|
||||
#include "base/unique_ptr.h"
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
@@ -394,8 +395,8 @@ void SCIPInterface::ExtractNewConstraints() {
|
||||
max_row_length = ct->coefficients_.size();
|
||||
}
|
||||
}
|
||||
scoped_ptr<SCIP_VAR * []> vars(new SCIP_VAR* [max_row_length]);
|
||||
scoped_ptr<double[]> coefs(new double[max_row_length]);
|
||||
std::unique_ptr<SCIP_VAR * []> vars(new SCIP_VAR* [max_row_length]);
|
||||
std::unique_ptr<double[]> coefs(new double[max_row_length]);
|
||||
// Add each new constraint.
|
||||
for (int i = last_constraint_index_; i < total_num_rows; ++i) {
|
||||
MPConstraint* const ct = solver_->constraints_[i];
|
||||
|
||||
Reference in New Issue
Block a user