| 57 | using std::endl; |
| 58 | |
| 59 | int main() { |
| 60 | // Create and populate a HighsModel instance for the LP |
| 61 | // |
| 62 | // Min f = x_0 + x_1 + 3 |
| 63 | // s.t. x_1 <= 7 |
| 64 | // 5 <= x_0 + 2x_1 <= 15 |
| 65 | // 6 <= 3x_0 + 2x_1 |
| 66 | // 0 <= x_0 <= 4; 1 <= x_1 |
| 67 | // |
| 68 | // Although the first constraint could be expressed as an upper |
| 69 | // bound on x_1, it serves to illustrate a non-trivial packed |
| 70 | // column-wise matrix. |
| 71 | // |
| 72 | HighsModel model; |
| 73 | model.lp_.num_col_ = 2; |
| 74 | model.lp_.num_row_ = 3; |
| 75 | model.lp_.sense_ = ObjSense::kMinimize; |
| 76 | model.lp_.offset_ = 3; |
| 77 | model.lp_.col_cost_ = {1.0, 1.0}; |
| 78 | model.lp_.col_lower_ = {0.0, 1.0}; |
| 79 | model.lp_.col_upper_ = {4.0, 1.0e30}; |
| 80 | model.lp_.row_lower_ = {-1.0e30, 5.0, 6.0}; |
| 81 | model.lp_.row_upper_ = {7.0, 15.0, 1.0e30}; |
| 82 | // |
| 83 | // Here the orientation of the matrix is column-wise |
| 84 | model.lp_.a_matrix_.format_ = MatrixFormat::kColwise; |
| 85 | // a_start_ has num_col_1 entries, and the last entry is the number |
| 86 | // of nonzeros in A, allowing the number of nonzeros in the last |
| 87 | // column to be defined |
| 88 | model.lp_.a_matrix_.start_ = {0, 2, 5}; |
| 89 | model.lp_.a_matrix_.index_ = {1, 2, 0, 1, 2}; |
| 90 | model.lp_.a_matrix_.value_ = {1.0, 3.0, 1.0, 2.0, 2.0}; |
| 91 | // |
| 92 | // Create a Highs instance |
| 93 | Highs highs; |
| 94 | HighsStatus return_status; |
| 95 | // |
| 96 | // Pass the model to HiGHS |
| 97 | return_status = highs.passModel(model); |
| 98 | assert(return_status == HighsStatus::kOk); |
| 99 | // If a user passes a model with entries in |
| 100 | // model.lp_.a_matrix_.value_ less than (the option) |
| 101 | // small_matrix_value in magnitude, they will be ignored. A logging |
| 102 | // message will indicate this, and passModel will return |
| 103 | // HighsStatus::kWarning |
| 104 | // |
| 105 | // Get a const reference to the LP data in HiGHS |
| 106 | const HighsLp& lp = highs.getLp(); |
| 107 | // |
| 108 | // Solve the model |
| 109 | return_status = highs.run(); |
| 110 | assert(return_status == HighsStatus::kOk); |
| 111 | // |
| 112 | // Get the model status |
| 113 | const HighsModelStatus& model_status = highs.getModelStatus(); |
| 114 | assert(model_status == HighsModelStatus::kOptimal); |
| 115 | cout << "Model status: " << highs.modelStatusToString(model_status) << endl; |
| 116 | // |
nothing calls this directly
no test coverage detected