more absl support: span...

This commit is contained in:
Laurent Perron
2024-10-16 14:11:26 +02:00
parent c930dd656e
commit 19317b21fd
5 changed files with 31 additions and 11 deletions

View File

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

View File

@@ -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:

View File

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

View File

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

View File

@@ -1599,11 +1599,31 @@ class Model:
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: