1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2 /*                                                                       */
3 /*    This file is part of the HiGHS linear optimization suite           */
4 /*                                                                       */
5 /*    Written and engineered 2008-2019 at the University of Edinburgh    */
6 /*                                                                       */
7 /*    Available as open-source under the MIT License                     */
8 /*                                                                       */
9 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
10 /**@file simplex/SpeciaLps.h
11  * @brief Utilities for tests with special LPs
12  * @author Julian Hall, Ivet Galabova, Qi Huangfu and Michael Feldmeier
13  */
14 #ifndef SIMPLEX_SPECIALPS_H_
15 #define SIMPLEX_SPECIALPS_H_
16 
17 #include <vector>
18 
19 #include "lp_data/HConst.h"
20 #include "lp_data/HighsLp.h"
21 
22 const double inf = HIGHS_CONST_INF;
23 
24 class SpecialLps {
25  public:
issue272Lp(HighsLp & lp,HighsModelStatus & require_model_status,double & optimal_objective)26   void issue272Lp(HighsLp& lp, HighsModelStatus& require_model_status,
27                   double& optimal_objective) {
28     lp.numCol_ = 2;
29     lp.numRow_ = 2;
30     lp.colCost_ = {3, 2};
31     lp.colLower_ = {0, 0};
32     lp.colUpper_ = {inf, inf};
33     lp.rowLower_ = {-inf, -inf};
34     lp.rowUpper_ = {23, 10};
35     lp.Astart_ = {0, 2, 4};
36     lp.Aindex_ = {0, 1, 0, 1};
37     lp.Avalue_ = {3, 5, 6, 2};
38     lp.sense_ = ObjSense::MAXIMIZE;
39     lp.offset_ = 0;
40     require_model_status = HighsModelStatus::OPTIMAL;
41     optimal_objective = 8.83333333333333;
42   }
43 
issue280Lp(HighsLp & lp,HighsModelStatus & require_model_status,double & optimal_objective)44   void issue280Lp(HighsLp& lp, HighsModelStatus& require_model_status,
45                   double& optimal_objective) {
46     lp.numCol_ = 2;
47     lp.numRow_ = 2;
48     lp.colCost_ = {-1, 1};
49     lp.colLower_ = {1, 2};
50     lp.colUpper_ = {1, 2};
51     lp.rowLower_ = {-inf, 2};
52     lp.rowUpper_ = {1, 2};
53     lp.Astart_ = {0, 1, 2};
54     lp.Aindex_ = {0, 1};
55     lp.Avalue_ = {1, 1};
56     lp.sense_ = ObjSense::MINIMIZE;
57     lp.offset_ = 0;
58     require_model_status = HighsModelStatus::OPTIMAL;
59     optimal_objective = 1;
60   }
61 
issue282Lp(HighsLp & lp,HighsModelStatus & require_model_status,double & optimal_objective)62   void issue282Lp(HighsLp& lp, HighsModelStatus& require_model_status,
63                   double& optimal_objective) {
64     lp.numCol_ = 2;
65     lp.numRow_ = 3;
66     lp.colCost_ = {-3, -2};
67     lp.colLower_ = {0, 0};
68     lp.colUpper_ = {inf, inf};
69     lp.rowLower_ = {-inf, -inf, -inf};
70     lp.rowUpper_ = {10, 8, 4};
71     lp.Astart_ = {0, 3, 5};
72     lp.Aindex_ = {0, 1, 2, 0, 1};
73     lp.Avalue_ = {2, 1, 1, 1, 1};
74     lp.sense_ = ObjSense::MINIMIZE;
75     lp.offset_ = 0;
76     require_model_status = HighsModelStatus::OPTIMAL;
77     optimal_objective = -18;
78   }
79 
issue285Lp(HighsLp & lp,HighsModelStatus & require_model_status)80   void issue285Lp(HighsLp& lp, HighsModelStatus& require_model_status) {
81     lp.numCol_ = 2;
82     lp.numRow_ = 3;
83     lp.colCost_ = {-4, 1};
84     lp.colLower_ = {2, 0};
85     lp.colUpper_ = {2, inf};
86     lp.rowLower_ = {-inf, -inf, -inf};
87     lp.rowUpper_ = {14, 0, 3};
88     lp.Astart_ = {0, 2, 5};
89     lp.Aindex_ = {0, 2, 0, 1, 2};
90     lp.Avalue_ = {7, 2, -2, 1, -2};
91     lp.sense_ = ObjSense::MINIMIZE;
92     lp.offset_ = 0;
93     require_model_status = HighsModelStatus::PRIMAL_INFEASIBLE;
94   }
95 
issue295Lp(HighsLp & lp,HighsModelStatus & require_model_status,double & optimal_objective)96   void issue295Lp(HighsLp& lp, HighsModelStatus& require_model_status,
97                   double& optimal_objective) {
98     lp.numCol_ = 5;
99     lp.numRow_ = 2;
100     lp.colCost_ = {0, 0, 0, 1, -1};
101     lp.colLower_ = {-inf, -inf, -inf, -1, -1};
102     lp.colUpper_ = {inf, inf, inf, 1, 1};
103     lp.rowLower_ = {-inf, -inf};
104     lp.rowUpper_ = {2, -2};
105     lp.Astart_ = {0, 1, 2, 2, 2, 2};
106     lp.Aindex_ = {0, 1};
107     lp.Avalue_ = {1, 1};
108     lp.sense_ = ObjSense::MINIMIZE;
109     lp.offset_ = 0;
110     require_model_status = HighsModelStatus::OPTIMAL;
111     optimal_objective = -2;
112   }
113 
issue306Lp(HighsLp & lp,HighsModelStatus & require_model_status,double & optimal_objective)114   void issue306Lp(HighsLp& lp, HighsModelStatus& require_model_status,
115                   double& optimal_objective) {
116     lp.numCol_ = 10;
117     lp.numRow_ = 6;
118     lp.colCost_ = {-1.64, 0.7, 1.8, -1.06, -1.16, 0.26, 2.13, 1.53, 0.66, 0.28};
119     lp.colLower_ = {-0.84, -0.97, 0.34, 0.4,   -0.33,
120                     -0.74, 0.47,  0.09, -1.45, -0.73};
121     lp.colUpper_ = {0.37, 0.02, 2.86, 0.86, 1.18, 0.5, 1.76, 0.17, 0.32, -0.15};
122     lp.rowLower_ = {0.9626, -1e+200, -1e+200, -1e+200, -1e+200, -1e+200};
123     lp.rowUpper_ = {0.9626, 0.615, 0, 0.172, -0.869, -0.022};
124     lp.Astart_ = {0, 0, 1, 2, 5, 5, 6, 7, 9, 10, 12};
125     lp.Aindex_ = {4, 4, 0, 1, 3, 0, 4, 1, 5, 0, 1, 4};
126     lp.Avalue_ = {-1.22, -0.25, 0.93,  1.18, 0.43,  0.65,
127                   -2.06, -0.2,  -0.25, 0.83, -0.22, 1.37};
128     lp.sense_ = ObjSense::MINIMIZE;
129     lp.offset_ = 0;
130     require_model_status = HighsModelStatus::OPTIMAL;
131     optimal_objective = -1.191;
132   }
133 
primalDualInfeasible1Lp(HighsLp & lp,HighsModelStatus & require_model_status)134   void primalDualInfeasible1Lp(HighsLp& lp,
135                                HighsModelStatus& require_model_status) {
136     lp.numCol_ = 2;
137     lp.numRow_ = 2;
138     lp.colCost_ = {-2, 1};
139     lp.colLower_ = {0, 0};
140     lp.colUpper_ = {inf, inf};
141     lp.rowLower_ = {-inf, -inf};
142     lp.rowUpper_ = {1, -2};
143     lp.Astart_ = {0, 2, 4};
144     lp.Aindex_ = {0, 1, 0, 1};
145     lp.Avalue_ = {1, -1, -1, 1};
146     lp.sense_ = ObjSense::MINIMIZE;
147     lp.offset_ = 0;
148     require_model_status = HighsModelStatus::PRIMAL_DUAL_INFEASIBLE;
149   }
150 
primalDualInfeasible2Lp(HighsLp & lp,HighsModelStatus & require_model_status)151   void primalDualInfeasible2Lp(HighsLp& lp,
152                                HighsModelStatus& require_model_status) {
153     lp.numCol_ = 2;
154     lp.numRow_ = 2;
155     lp.colCost_ = {1, 1};
156     lp.colLower_ = {-inf, -inf};
157     lp.colUpper_ = {inf, inf};
158     lp.rowLower_ = {-inf, -inf};
159     lp.rowUpper_ = {0, -1};
160     lp.Astart_ = {0, 2, 4};
161     lp.Aindex_ = {0, 1, 0, 1};
162     lp.Avalue_ = {1, -1, -1, 1};
163     lp.sense_ = ObjSense::MINIMIZE;
164     lp.offset_ = 0;
165     require_model_status = HighsModelStatus::PRIMAL_DUAL_INFEASIBLE;
166   }
167 
scipLpi2Lp(HighsLp & lp,HighsModelStatus & require_model_status)168   void scipLpi2Lp(HighsLp& lp, HighsModelStatus& require_model_status) {
169     lp.numCol_ = 2;
170     lp.numRow_ = 2;
171     lp.colCost_ = {3, 1};
172     lp.colLower_ = {-inf, -inf};
173     lp.colUpper_ = {inf, inf};
174     lp.rowLower_ = {-inf, -inf};
175     lp.rowUpper_ = {10, 15};
176     lp.Astart_ = {0, 2, 4};
177     lp.Aindex_ = {0, 1, 0, 1};
178     lp.Avalue_ = {2, 1, 1, 3};
179     lp.sense_ = ObjSense::MAXIMIZE;
180     lp.offset_ = 0;
181     require_model_status = HighsModelStatus::PRIMAL_UNBOUNDED;
182   }
183 
scipLpi3Lp(HighsLp & lp,HighsModelStatus & require_model_status)184   void scipLpi3Lp(HighsLp& lp, HighsModelStatus& require_model_status) {
185     lp.numCol_ = 2;
186     lp.numRow_ = 2;
187     lp.colCost_ = {10, 15};
188     lp.colLower_ = {0, 0};
189     lp.colUpper_ = {inf, inf};
190     lp.rowLower_ = {3, 1};
191     lp.rowUpper_ = {3, 1};
192     lp.Astart_ = {0, 2, 4};
193     lp.Aindex_ = {0, 1, 0, 1};
194     lp.Avalue_ = {2, 1, 1, 3};
195     lp.sense_ = ObjSense::MINIMIZE;
196     lp.offset_ = 0;
197     require_model_status = HighsModelStatus::PRIMAL_INFEASIBLE;
198   }
199 
blendingLp(HighsLp & lp,HighsModelStatus & require_model_status,double & optimal_objective)200   void blendingLp(HighsLp& lp, HighsModelStatus& require_model_status,
201                   double& optimal_objective) {
202     lp.numCol_ = 2;
203     lp.numRow_ = 2;
204     lp.colCost_ = {-8, -10};
205     lp.colLower_ = {0, 0};
206     lp.colUpper_ = {inf, inf};
207     lp.rowLower_ = {-inf, -inf};
208     lp.rowUpper_ = {120, 210};
209     lp.Astart_ = {0, 2, 4};
210     lp.Aindex_ = {0, 1, 0, 1};
211     lp.Avalue_ = {0.3, 0.7, 0.5, 0.5};
212     lp.sense_ = ObjSense::MINIMIZE;
213     lp.offset_ = 0;
214     require_model_status = HighsModelStatus::OPTIMAL;
215     optimal_objective = -2850;
216   }
217 
blendingMaxLp(HighsLp & lp,HighsModelStatus & require_model_status,double & optimal_objective)218   void blendingMaxLp(HighsLp& lp, HighsModelStatus& require_model_status,
219                      double& optimal_objective) {
220     blendingLp(lp, require_model_status, optimal_objective);
221     for (int iCol = 0; iCol < lp.numCol_; iCol++)
222       lp.colCost_[iCol] = -lp.colCost_[iCol];
223     lp.sense_ = ObjSense::MAXIMIZE;
224     optimal_objective = -optimal_objective;
225   }
226 };
227 
228 #endif /* SIMPLEX_SPECIALPS_H_ */
229