82 const ModelProto& model_proto) {
87 const VariablesProto& variables = model_proto.variables();
88 const LinearConstraintsProto& linear_constraints =
89 model_proto.linear_constraints();
91 linear_constraints.ids_size());
92 if (!model_proto.name().empty()) {
95 if (variables.names_size() > 0) {
97 variables.names().end()};
99 if (linear_constraints.names_size() > 0) {
101 linear_constraints.names().end()};
103 for (
int i = 0; i < variables.ids_size(); ++i) {
104 result.var_id_to_pdlp_index_[variables.ids(i)] = i;
105 result.pdlp_index_to_var_id_.push_back(variables.ids(i));
109 for (
int i = 0; i < linear_constraints.ids_size(); ++i) {
110 result.lin_con_id_to_pdlp_index_[linear_constraints.ids(i)] = i;
111 result.pdlp_index_to_lin_con_id_.push_back(linear_constraints.ids(i));
115 const bool is_maximize = model_proto.objective().maximize();
116 const double obj_scale = is_maximize ? -1.0 : 1.0;
118 for (
const auto [var_id,
coef] :
119 MakeView(model_proto.objective().linear_coefficients())) {
123 const SparseDoubleMatrixProto& quadratic_objective =
124 model_proto.objective().quadratic_coefficients();
125 const int obj_nnz = quadratic_objective.row_ids().size();
130 for (
int i = 0; i < obj_nnz; ++i) {
131 const int64_t row_index =
132 result.var_id_to_pdlp_index_.at(quadratic_objective.row_ids(i));
133 const int64_t column_index =
134 result.var_id_to_pdlp_index_.at(quadratic_objective.column_ids(i));
135 const double value = obj_scale * quadratic_objective.coefficients(i);
136 if (row_index != column_index) {
137 return absl::InvalidArgumentError(
138 "PDLP cannot solve problems with non-diagonal objective matrices");
152 std::vector<Eigen::Triplet<double, int64_t>> mat_triplets;
153 const int nnz = model_proto.linear_constraint_matrix().row_ids_size();
154 mat_triplets.reserve(nnz);
155 const SparseDoubleMatrixProto& proto_mat =
156 model_proto.linear_constraint_matrix();
157 for (
int i = 0; i < nnz; ++i) {
158 const int64_t row_index =
159 result.lin_con_id_to_pdlp_index_.at(proto_mat.row_ids(i));
160 const int64_t column_index =
161 result.var_id_to_pdlp_index_.at(proto_mat.column_ids(i));
162 const double value = proto_mat.coefficients(i);
163 mat_triplets.emplace_back(row_index, column_index,
value);