Skip to content

Commit

Permalink
more absl support: span...
Browse files Browse the repository at this point in the history
  • Loading branch information
lperron committed Oct 16, 2024
1 parent 1e2387d commit 2ce45ed
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 11 deletions.
4 changes: 2 additions & 2 deletions ortools/algorithms/set_cover_heuristics.cc
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ bool GreedySolutionGenerator::NextSolution(
return NextSolution(focus, inv_->model()->subset_costs());
}

bool GreedySolutionGenerator::NextSolution(
const std::vector<SubsetIndex>& focus, const SubsetCostVector& costs) {
bool GreedySolutionGenerator::NextSolution(absl::Span<const SubsetIndex> focus,
const SubsetCostVector& costs) {
DCHECK(inv_->CheckConsistency());
inv_->ClearTrace();
SubsetCostVector elements_per_cost(costs.size(), 0.0);
Expand Down
2 changes: 1 addition & 1 deletion ortools/algorithms/set_cover_heuristics.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ class GreedySolutionGenerator {
bool NextSolution(const std::vector<SubsetIndex>& focus);

// Same with a different set of costs.
bool NextSolution(const std::vector<SubsetIndex>& focus,
bool NextSolution(absl::Span<const SubsetIndex> focus,
const SubsetCostVector& costs);

private:
Expand Down
2 changes: 1 addition & 1 deletion ortools/glop/lu_factorization.cc
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ namespace {
// norm of the given column, otherwise do the same with a sparse version. In
// both cases column is cleared.
Fractional ComputeSquaredNormAndResetToZero(
const std::vector<RowIndex>& non_zeros, absl::Span<Fractional> column) {
absl::Span<const RowIndex> non_zeros, absl::Span<Fractional> column) {
Fractional sum = 0.0;
if (non_zeros.empty()) {
sum = SquaredNormAndResetToZero(column);
Expand Down
10 changes: 5 additions & 5 deletions ortools/linear_solver/model_exporter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,11 @@ class MPModelProtoExporter {

// Appends a pair name, value to "output", formatted to comply with the MPS
// standard.
void AppendMpsPair(const std::string& name, double value,
void AppendMpsPair(absl::string_view name, double value,
std::string* output) const;

// Appends the head of a line, consisting of an id and a name to output.
void AppendMpsLineHeader(const std::string& id, const std::string& name,
void AppendMpsLineHeader(absl::string_view id, absl::string_view name,
std::string* output) const;

// Same as AppendMpsLineHeader. Appends an extra new-line at the end the
Expand Down Expand Up @@ -674,13 +674,13 @@ bool MPModelProtoExporter::ExportModelAsLpFormat(
return true;
}

void MPModelProtoExporter::AppendMpsPair(const std::string& name, double value,
void MPModelProtoExporter::AppendMpsPair(absl::string_view name, double value,
std::string* output) const {
absl::StrAppendFormat(output, *mps_format_, name, DoubleToString(value));
}

void MPModelProtoExporter::AppendMpsLineHeader(const std::string& id,
const std::string& name,
void MPModelProtoExporter::AppendMpsLineHeader(absl::string_view id,
absl::string_view name,
std::string* output) const {
absl::StrAppendFormat(output, *mps_header_format_, id, name);
}
Expand Down
24 changes: 22 additions & 2 deletions ortools/linear_solver/python/model_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -1599,11 +1599,31 @@ def import_from_mps_file(self, mps_file: str) -> bool:
return self.__helper.import_from_mps_file(mps_file)

def import_from_lp_string(self, lp_string: str) -> bool:
"""Reads a model from a LP string."""
"""Reads a model from a LP string.
Note that this code is very limited, and will not support any real lp.
It is only intented to be use to parse test lp problems.
Args:
lp_string: The LP string to import.
Returns:
True if the import was successful.
"""
return self.__helper.import_from_lp_string(lp_string)

def import_from_lp_file(self, lp_file: str) -> bool:
"""Reads a model from a .lp file."""
"""Reads a model from a .lp file.
Note that this code is very limited, and will not support any real lp.
It is only intented to be use to parse test lp problems.
Args:
lp_file: The LP file to import.
Returns:
True if the import was successful.
"""
return self.__helper.import_from_lp_file(lp_file)

def import_from_proto_file(self, proto_file: str) -> bool:
Expand Down

0 comments on commit 2ce45ed

Please sign in to comment.