1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* */
/* This file is part of the class library */
/* SoPlex --- the Sequential object-oriented simPlex. */
/* */
/* Copyright 1996-2022 Zuse Institute Berlin */
/* */
/* Licensed under the Apache License, Version 2.0 (the "License"); */
/* you may not use this file except in compliance with the License. */
/* You may obtain a copy of the License at */
/* */
/* http://www.apache.org/licenses/LICENSE-2.0 */
/* */
/* Unless required by applicable law or agreed to in writing, software */
/* distributed under the License is distributed on an "AS IS" BASIS, */
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
/* See the License for the specific language governing permissions and */
/* limitations under the License. */
/* */
/* You should have received a copy of the Apache-2.0 license */
/* along with SoPlex; see the file LICENSE. If not email to soplex@zib.de. */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/**@file spxsolver.h
* @brief main LP solver class
*/
#ifndef _SPXSOLVER_H_
#define _SPXSOLVER_H_
#include <assert.h>
#include <iostream>
#include <iomanip>
#include <sstream>
#include "soplex/spxdefines.h"
#include "soplex/timer.h"
#include "soplex/timerfactory.h"
#include "soplex/spxlp.h"
#include "soplex/spxbasis.h"
#include "soplex/array.h"
#include "soplex/random.h"
#include "soplex/unitvector.h"
#include "soplex/updatevector.h"
#include "soplex/stablesum.h"
#include "soplex/spxlpbase.h"
#define HYPERPRICINGTHRESHOLD 5000 /**< do (auto) hyper pricing only if problem size (cols+rows) is larger than HYPERPRICINGTHRESHOLD */
#define HYPERPRICINGSIZE 100 /**< size of initial candidate list for hyper pricing */
#define SPARSITYFACTOR 0.6 /**< percentage of infeasibilities that is considered sparse */
#define DENSEROUNDS 5 /**< number of refactorizations until sparsity is tested again */
#define SPARSITY_TRADEOFF 0.8 /**< threshold to decide whether Ids or coIds are preferred to enter the basis;
* coIds are more likely to enter if SPARSITY_TRADEOFF is close to 0
*/
#define MAXNCLCKSKIPS 32 /**< maximum number of clock skips (iterations without time measuring) */
#define SAFETYFACTOR 1e-2 /**< the probability to skip the clock when the time limit has been reached */
#define NINITCALLS 200 /**< the number of clock updates in isTimelimitReached() before clock skipping starts */
namespace soplex
{
template <class R>
class SPxPricer;
template <class R>
class SPxRatioTester;
template <class R>
class SPxStarter;
template <class R>
class SPxFastRT;
template <class R>
class SPxBoundFlippingRT;
/**@brief Sequential object-oriented SimPlex.
@ingroup Algo
SPxSolverBase is an LP solver class using the revised Simplex algorithm. It
provides two basis representations, namely a column basis and a row basis
(see #Representation). For both representations, a primal and
dual algorithm is available (see \ref Type).
In addition, SPxSolverBase can be customized with various respects:
- pricing algorithms using SPxPricer
- ratio test using class SPxRatioTester
- computation of a start basis using class SPxStarter
- preprocessing of the LP using class SPxSimplifier
- termination criteria by overriding
SPxSolverBase is derived from SPxLPBase<R> that is used to store the LP to be solved.
Hence, the LPs solved with SPxSolverBase have the general format
\f[
\begin{array}{rl}
\hbox{max} & \mbox{maxObj}^T x \\
\hbox{s.t.} & \mbox{lhs} \le Ax \le \mbox{rhs} \\
& \mbox{low} \le x \le \mbox{up}
\end{array}
\f]
Also, SPxLPBase<R> provide all manipulation methods for the LP. They allow
SPxSolverBase to be used within cutting plane algorithms.
*/
template <class R>
class SPxSolverBase : public SPxLPBase<R>, protected SPxBasisBase<R>
{
friend SPxFastRT<R>;
friend SPxBoundFlippingRT<R>;
public:
//-----------------------------
/**@name Data Types */
///@{
/// LP basis representation.
/** Solving LPs with the Simplex algorithm requires the definition of a
* \em basis. A basis can be defined as a set of column vectors or a
* set of row vectors building a nonsingular matrix. We will refer to
* the first case as the \em columnwise representation and the latter
* case will be called the \em rowwise representation.
*
* Type Representation determines the representation of SPxSolverBase, i.e.
* a columnwise (#COLUMN == 1) or rowwise (#ROW == -1) one.
*/
enum Representation
{
ROW = -1, ///< rowwise representation.
COLUMN = 1 ///< columnwise representation.
};
/// Algorithmic type.
/** SPxSolverBase uses the reviesed Simplex algorithm to solve LPs.
* Mathematically, one distinguishes the \em primal from the
* \em dual algorihm. Algorithmically, these relate to the two
* types #ENTER or #LEAVE. How they relate, depends on the chosen
* basis representation. This is desribed by the following table:
*
* <TABLE>
* <TR><TD> </TD><TD>ENTER </TD><TD>LEAVE </TD></TR>
* <TR><TD>ROW </TD><TD>DUAL </TD><TD>PRIMAL</TD></TR>
* <TR><TD>COLUMN</TD><TD>PRIMAL</TD><TD>DUAL </TD></TR>
* </TABLE>
*/
enum Type
{
/// Entering Simplex.
/** The Simplex loop for the entering Simplex can be sketched
* as follows:
* - \em Pricing : Select a variable to #ENTER the basis.
* - \em Ratio-Test : Select variable to #LEAVE the
* basis such that the basis remains feasible.
* - Perform the basis update.
*/
ENTER = -1,
/// Leaving Simplex.
/** The Simplex loop for the leaving Simplex can be sketched
* as follows:
* - \em Pricing: Select a variable to #LEAVE the basis.
* - \em Ratio-Test: Select variable to #ENTER the
* basis such that the basis remains priced.
* - Perform the basis update.
*/
LEAVE = 1
};
/// Pricing type.
/** In case of the #ENTER%ing Simplex algorithm, for performance
* reasons it may be advisable not to compute and maintain up to
* date vectors #pVec() and #test() and instead compute only some
* of its elements explicitely. This is controled by the #Pricing type.
*/
enum Pricing
{
/// Full pricing.
/** If #FULL pricing in selected for the #ENTER%ing Simplex,
* vectors #pVec() and #test() are kept up to date by
* SPxSolverBase. An SPxPricer only needs to select an Id such
* that the #test() or #coTest() value is < 0.
*/
FULL,
/// Partial pricing.
/** When #PARTIAL pricing in selected for the #ENTER%ing
* Simplex, vectors #pVec() and #test() are not set up and
* updated by SPxSolverBase. However, vectors #coPvec() and
* #coTest() are still kept up to date by SPxSolverBase.
* An SPxPricer object needs to compute the values for
* #pVec() and #test() itself in order to select an
* appropriate pivot with #test() < 0. Methods \ref computePvec(int)
* "computePvec(i)" and \ref computeTest(int) "computeTest(i)"
* will assist the used to do so. Note
* that it may be feasible for a pricer to return an Id with
* #test() > 0; such will be rejected by SPxSolverBase.
*/
PARTIAL
};
/// Improved dual simplex status
/** The improved dual simplex requires a starting basis to perform the problem partitioning. This flag sets the
* status of the improved dual simplex to indicate whether the starting basis must be found or not.
*/
enum DecompStatus
{
/// Starting basis has not been found yet
FINDSTARTBASIS = 0,
/// Starting basis has been found and the simplex can be executed as normal
DONTFINDSTARTBASIS = 1
};
enum VarStatus
{
ON_UPPER, ///< variable set to its upper bound.
ON_LOWER, ///< variable set to its lower bound.
FIXED, ///< variable fixed to identical bounds.
ZERO, ///< free variable fixed to zero.
BASIC, ///< variable is basic.
UNDEFINED ///< nothing known about basis status (possibly due to a singular basis in transformed problem)
};
/**@todo In spxchange, change the status to
if (m_status > 0) m_status = REGULAR;
*/
enum Status
{
ERROR = -15, ///< an error occured.
NO_RATIOTESTER = -14, ///< No ratiotester loaded
NO_PRICER = -13, ///< No pricer loaded
NO_SOLVER = -12, ///< No linear solver loaded
NOT_INIT = -11, ///< not initialised error
ABORT_EXDECOMP = -10, ///< solve() aborted to exit decomposition simplex
ABORT_DECOMP = -9, ///< solve() aborted due to commence decomposition simplex
ABORT_CYCLING = -8, ///< solve() aborted due to detection of cycling.
ABORT_TIME = -7, ///< solve() aborted due to time limit.
ABORT_ITER = -6, ///< solve() aborted due to iteration limit.
ABORT_VALUE = -5, ///< solve() aborted due to objective limit.
SINGULAR = -4, ///< Basis is singular, numerical troubles?
NO_PROBLEM = -3, ///< No Problem has been loaded.
REGULAR = -2, ///< LP has a usable Basis (maybe LP is changed).
RUNNING = -1, ///< algorithm is running
UNKNOWN = 0, ///< nothing known on loaded problem.
OPTIMAL = 1, ///< LP has been solved to optimality.
UNBOUNDED = 2, ///< LP has been proven to be primal unbounded.
INFEASIBLE = 3, ///< LP has been proven to be primal infeasible.
INForUNBD = 4, ///< LP is primal infeasible or unbounded.
OPTIMAL_UNSCALED_VIOLATIONS = 5 ///< LP has beed solved to optimality but unscaled solution contains violations.
};
/// objective for solution polishing
enum SolutionPolish
{
POLISH_OFF, ///< don't perform modifications on optimal basis
POLISH_INTEGRALITY, ///< maximize number of basic slack variables, i.e. more variables on bounds
POLISH_FRACTIONALITY ///< minimize number of basic slack variables, i.e. more variables in between bounds
};
///@}
private:
//-----------------------------
/**@name Private data */
///@{
Type theType; ///< entering or leaving algortihm.
Pricing thePricing; ///< full or partial pricing.
Representation theRep; ///< row or column representation.
SolutionPolish polishObj; ///< objective of solution polishing
Timer* theTime; ///< time spent in last call to method solve()
Timer::TYPE timerType; ///< type of timer (user or wallclock)
Real theCumulativeTime; ///< cumulative time spent in all calls to method solve()
int maxIters; ///< maximum allowed iterations.
Real maxTime; ///< maximum allowed time.
int nClckSkipsLeft; ///< remaining number of times the clock can be safely skipped
long nCallsToTimelim; /// < the number of calls to the method isTimeLimitReached()
R objLimit; ///< objective value limit.
Status m_status; ///< status of algorithm.
R m_nonbasicValue; ///< nonbasic part of current objective value
bool m_nonbasicValueUpToDate; ///< true, if the stored objValue is up to date
R m_pricingViol; ///< maximal feasibility violation of current solution
bool m_pricingViolUpToDate; ///< true, if the stored violation is up to date
R
m_pricingViolCo; ///< maximal feasibility violation of current solution in coDim
bool m_pricingViolCoUpToDate; ///< true, if the stored violation in coDim is up to date
int m_numViol; ///< number of violations of current solution
R m_entertol; ///< feasibility tolerance maintained during entering algorithm
R m_leavetol; ///< feasibility tolerance maintained during leaving algorithm
R theShift; ///< sum of all shifts applied to any bound.
R lastShift; ///< for forcing feasibility.
int m_maxCycle; ///< maximum steps before cycling is detected.
int m_numCycle; ///< actual number of degenerate steps so far.
bool initialized; ///< true, if all vectors are setup.
SSVectorBase<R>*
solveVector2; ///< when 2 systems are to be solved at a time; typically for speepest edge weights
SSVectorBase<R>*
solveVector2rhs; ///< when 2 systems are to be solved at a time; typically for speepest edge weights
SSVectorBase<R>*
solveVector3; ///< when 3 systems are to be solved at a time; typically reserved for bound flipping ratio test (basic solution will be modified!)
SSVectorBase<R>*
solveVector3rhs; ///< when 3 systems are to be solved at a time; typically reserved for bound flipping ratio test (basic solution will be modified!)
SSVectorBase<R>*
coSolveVector2; ///< when 2 systems are to be solved at a time; typically for speepest edge weights
SSVectorBase<R>*
coSolveVector2rhs; ///< when 2 systems are to be solved at a time; typically for speepest edge weights
SSVectorBase<R>*
coSolveVector3; ///< when 3 systems are to be solved at a time; typically reserved for bound flipping ratio test (basic solution will be modified!)
SSVectorBase<R>*
coSolveVector3rhs; ///< when 3 systems are to be solved at a time; typically reserved for bound flipping ratio test (basic solution will be modified!)
bool freePricer; ///< true iff thepricer should be freed inside of object
bool freeRatioTester; ///< true iff theratiotester should be freed inside of object
bool freeStarter; ///< true iff thestarter should be freed inside of object
/* Store the index of a leaving variable if only an instable entering variable has been found.
instableLeave == true iff this instable basis change should be performed.
(see spxsolve.hpp and leave.hpp) */
int instableLeaveNum;
bool instableLeave;
R instableLeaveVal;
/* Store the id of an entering row or column if only an instable pivot has been found.
instableEnter == true iff this instable basis change should be performed.
(see spxsolve.hpp and enter.hpp) */
SPxId instableEnterId;
bool instableEnter;
R instableEnterVal;
bool
recomputedVectors; ///< flag to perform clean up step to reduce numerical errors only once
int displayLine;
int displayFreq;
R sparsePricingFactor; ///< enable sparse pricing when viols < factor * dim()
bool
getStartingDecompBasis; ///< flag to indicate whether the simplex is solved to get the starting improved dual simplex basis
bool computeDegeneracy;
int
degenCompIterOffset; ///< the number of iterations performed before the degeneracy level is computed
int
decompIterationLimit; ///< the maximum number of iterations before the decomposition simplex is aborted.
bool
fullPerturbation; ///< whether to perturb the entire problem or just the bounds relevant for the current pivot
int
printBasisMetric; ///< printing the current basis metric in the log (-1: off, 0: condition estimate, 1: trace, 2: determinant, 3: condition)
///@}
protected:
//-----------------------------
/**@name Protected data */
///@{
Array < UnitVectorBase<R> > unitVecs; ///< array of unit vectors
const SVSetBase<R>* thevectors; ///< the LP vectors according to representation
const SVSetBase<R>* thecovectors; ///< the LP coVectors according to representation
VectorBase<R> primRhs; ///< rhs VectorBase<R> for computing the primal vector
UpdateVector<R> primVec; ///< primal vector
VectorBase<R> dualRhs; ///< rhs VectorBase<R> for computing the dual vector
UpdateVector<R> dualVec; ///< dual vector
UpdateVector<R> addVec; ///< storage for thePvec = &addVec
VectorBase<R> theURbound; ///< Upper Row Feasibility bound
VectorBase<R> theLRbound; ///< Lower Row Feasibility bound
VectorBase<R> theUCbound; ///< Upper Column Feasibility bound
VectorBase<R> theLCbound; ///< Lower Column Feasibility bound
/** In entering Simplex algorithm, the ratio test must ensure that all
* \em basic variables remain within their feasibility bounds. To give fast
* acces to them, the bounds of basic variables are copied into the
* following two vectors.
*/
VectorBase<R> theUBbound; ///< Upper Basic Feasibility bound
VectorBase<R> theLBbound; ///< Lower Basic Feasibility bound
/** The values of the rhs corresponding to the current basis.*/
VectorBase<R>* theFrhs;
/** The values of all basis variables. */
UpdateVector<R>* theFvec;
/* The Copricing rhs and VectorBase<R> */
VectorBase<R>* theCoPrhs;
UpdateVector<R>* theCoPvec;
/** The pricing VectorBase<R> */
UpdateVector<R>* thePvec;
UpdateVector<R>* theRPvec; ///< row pricing vector
UpdateVector<R>* theCPvec; ///< column pricing vector
// The following vectors serve for the virtualization of shift bounds
//@todo In prinziple this schould be references.
VectorBase<R>* theUbound; ///< Upper bound for vars
VectorBase<R>* theLbound; ///< Lower bound for vars
VectorBase<R>* theCoUbound; ///< Upper bound for covars
VectorBase<R>* theCoLbound; ///< Lower bound for covars
// The following vectors serve for the virtualization of testing vectors
VectorBase<R> theCoTest;
VectorBase<R> theTest;
DSVectorBase<R> primalRay; ///< stores primal ray in case of unboundedness
DSVectorBase<R> dualFarkas; ///< stores dual farkas proof in case of infeasibility
int leaveCount; ///< number of LEAVE iterations
int enterCount; ///< number of ENTER iterations
int primalCount; ///< number of primal iterations
int polishCount; ///< number of solution polishing iterations
int boundflips; ///< number of performed bound flips
int totalboundflips; ///< total number of bound flips
int enterCycles; ///< the number of degenerate steps during the entering algorithm
int leaveCycles; ///< the number of degenerate steps during the leaving algorithm
int enterDegenCand; ///< the number of degenerate candidates in the entering algorithm
int leaveDegenCand; ///< the number of degenerate candidates in the leaving algorithm
R primalDegenSum; ///< the sum of the primal degeneracy percentage
R dualDegenSum; ///< the sum of the dual degeneracy percentage
SPxPricer<R>* thepricer;
SPxRatioTester<R>* theratiotester;
SPxStarter<R>* thestarter;
R boundrange; ///< absolute range of all bounds in the problem
R siderange; ///< absolute range of all side in the problem
R objrange; ///< absolute range of all objective coefficients in the problem
///@}
//-----------------------------
/**@name Precision */
///@{
/// is the solution precise enough, or should we increase delta() ?
virtual bool precisionReached(R& newpricertol) const;
/// determine ranges of problem values for bounds, sides and objective to assess numerical difficulties
void calculateProblemRanges();
///@}
public:
/// The random number generator used throughout the whole computation. Its seed can be modified.
Random random;
/** For the leaving Simplex algorithm this vector contains the indices of infeasible basic variables;
* for the entering Simplex algorithm this vector contains the indices of infeasible slack variables.
*/
DIdxSet infeasibilities;
/**For the entering Simplex algorithm these vectors contains the indices of infeasible basic variables.
*/
DIdxSet infeasibilitiesCo;
/// store indices that were changed in the previous iteration and must be checked in hyper pricing
DIdxSet updateViols;
DIdxSet updateViolsCo;
/** Binary vectors to store whether basic indices are infeasible
* the i-th entry equals false, if the i-th basic variable is not infeasible
* the i-th entry equals true, if the i-th basic variable is infeasible
*/
DataArray<int>
isInfeasible; ///< 0: index not violated, 1: index violated, 2: index violated and among candidate list
DataArray<int>
isInfeasibleCo; ///< 0: index not violated, 1: index violated, 2: index violated and among candidate list
/// These values enable or disable sparse pricing
bool sparsePricingLeave; ///< true if sparsePricing is turned on in the leaving Simplex
bool sparsePricingEnter; ///< true if sparsePricing is turned on in the entering Simplex for slack variables
bool sparsePricingEnterCo; ///< true if sparsePricing is turned on in the entering Simplex
bool hyperPricingLeave; ///< true if hyper sparse pricing is turned on in the leaving Simplex
bool hyperPricingEnter; ///< true if hyper sparse pricing is turned on in the entering Simplex
int remainingRoundsLeave; ///< number of dense rounds/refactorizations until sparsePricing is enabled again
int remainingRoundsEnter;
int remainingRoundsEnterCo;
/// dual pricing norms
VectorBase<R> weights; ///< store dual norms
VectorBase<R> coWeights; ///< store dual norms
bool weightsAreSetup; ///< are the dual norms already set up?
Timer* multTimeSparse; ///< time spent in setupPupdate() exploiting sparsity
Timer* multTimeFull; ///< time spent in setupPupdate() ignoring sparsity
Timer* multTimeColwise; ///< time spent in setupPupdate(), columnwise multiplication
Timer* multTimeUnsetup; ///< time spent in setupPupdate() w/o sparsity information
int multSparseCalls; ///< number of products exploiting sparsity
int multFullCalls; ///< number of products ignoring sparsity
int multColwiseCalls; ///< number of products, columnwise multiplication
int multUnsetupCalls; ///< number of products w/o sparsity information
SPxOut* spxout; ///< message handler
DataArray<int>
integerVariables; ///< supplementary variable information, 0: continous variable, 1: integer variable
//-----------------------------
void setOutstream(SPxOut& newOutstream)
{
spxout = &newOutstream;
SPxLPBase<R>::spxout = &newOutstream;
}
/// set refactor threshold for nonzeros in last factorized basis matrix compared to updated basis matrix
void setNonzeroFactor(R f)
{
SPxBasisBase<R>::nonzeroFactor = f;
}
/// set refactor threshold for fill-in in current factor update compared to fill-in in last factorization
void setFillFactor(R f)
{
SPxBasisBase<R>::fillFactor = f;
}
/// set refactor threshold for memory growth in current factor update compared to the last factorization
void setMemFactor(R f)
{
SPxBasisBase<R>::memFactor = f;
}
/**@name Access */
///@{
/// return the version of SPxSolverBase as number like 123 for 1.2.3
int version() const
{
return SOPLEX_VERSION;
}
/// return the internal subversion of SPxSolverBase as number
int subversion() const
{
return SOPLEX_SUBVERSION;
}
/// return the current basis representation.
Representation rep() const
{
return theRep;
}
/// return current Type.
Type type() const
{
return theType;
}
/// return current Pricing.
Pricing pricing() const
{
return thePricing;
}
/// return current starter.
SPxStarter<R>* starter() const
{
return thestarter;
}
///@}
//-----------------------------
/**@name Setup
* Before solving an LP with an instance of SPxSolverBase,
* the following steps must be performed:
*
* -# Load the LP by copying an external LP or reading it from an
* input stream.
* -# Setup the pricer to use by loading an \ref soplex::SPxPricer
* "SPxPricer" object (if not already done in a previous call).
* -# Setup the ratio test method to use by loading an
* \ref soplex::SPxRatioTester "SPxRatioTester" object
* (if not already done in a previous call).
* -# Setup the linear system solver to use by loading an
* \ref soplex::SLinSolver "SLinSolver" object
* (if not already done in a previous call).
* -# Optionally setup an start basis generation method by loading an
* \ref soplex::SPxStarter "SPxStarter" object.
* -# Optionally setup a start basis by loading a
* \ref soplex::SPxBasisBase<R>::Desc "SPxBasisBase<R>::Desc" object.
* -# Optionally switch to another basis
* \ref soplex::SPxSolverBase<R>::Representation "Representation"
* by calling method \ref soplex::SPxSolverBase<R>::setRep() "setRep()".
* -# Optionally switch to another algorithm
* \ref soplex::SPxSolverBase<R>::Type "Type"
* by calling method \ref soplex::SPxSolverBase<R>::setType() "setType()".
*
* Now the solver is ready for execution. If the loaded LP is to be solved
* again from scratch, this can be done with method
* \ref soplex::SPxSolverBase<R>::reLoad() "reLoad()". Finally,
* \ref soplex::SPxSolverBase<R>::clear() "clear()" removes the LP from the solver.
*/
///@{
/// read LP from input stream.
virtual bool read(std::istream& in, NameSet* rowNames = 0,
NameSet* colNames = 0, DIdxSet* intVars = 0);
/// copy LP.
virtual void loadLP(const SPxLPBase<R>& LP, bool initSlackBasis = true);
/// setup linear solver to use. If \p destroy is true, \p slusolver will be freed in destructor.
virtual void setBasisSolver(SLinSolver<R>* slu, const bool destroy = false);
/// setup pricer to use. If \p destroy is true, \p pricer will be freed in destructor.
virtual void setPricer(SPxPricer<R>* pricer, const bool destroy = false);
/// setup ratio-tester to use. If \p destroy is true, \p tester will be freed in destructor.
virtual void setTester(SPxRatioTester<R>* tester, const bool destroy = false);
/// setup starting basis generator to use. If \p destroy is true, \p starter will be freed in destructor.
virtual void setStarter(SPxStarter<R>* starter, const bool destroy = false);
/// set a start basis.
virtual void loadBasis(const typename SPxBasisBase<R>::Desc&);
/// initialize #ROW or #COLUMN representation.
void initRep(Representation p_rep);
/// switch to #ROW or #COLUMN representation if not already used.
void setRep(Representation p_rep);
/// set \ref soplex::SPxSolverBase<R>::LEAVE "LEAVE" or \ref soplex::SPxSolverBase<R>::ENTER "ENTER" algorithm.
void setType(Type tp);
/// set \ref soplex::SPxSolverBase<R>::FULL "FULL" or \ref soplex::SPxSolverBase<R>::PARTIAL "PARTIAL" pricing.
void setPricing(Pricing pr);
/// turn on or off the improved dual simplex.
void setDecompStatus(DecompStatus decomp_stat);
/// reload LP.
virtual void reLoad();
/// clear all data in solver.
virtual void clear();
/// unscales the LP and reloads the basis
void unscaleLPandReloadBasis();
/// invalidates the basis, triggers refactorization
void invalidateBasis();
/** Load basis from \p filename in MPS format. If \p rowNames and \p
* colNames are \c NULL, default names are used for the constraints and
* variables.
*/
virtual bool readBasisFile(const char* filename,
const NameSet* rowNames, const NameSet* colNames);
/** Write basis to \p filename in MPS format. If \p rowNames and \p
* colNames are \c NULL, default names are used for the constraints and
* variables.
*/
virtual bool writeBasisFile(const char* filename,
const NameSet* rowNames, const NameSet* colNames, const bool cpxFormat = false) const;
/** Write current LP, basis, and parameter settings.
* LP is written in MPS format to "\p filename".mps, basis is written in "\p filename".bas, and parameters
* are written to "\p filename".set. If \p rowNames and \p colNames are \c NULL, default names are used for
* the constraints and variables.
*/
virtual bool writeState(const char* filename,
const NameSet* rowNames = NULL, const NameSet* colNames = NULL, const bool cpxFormat = false) const;
///@}
/**@name Solving LPs */
///@{
/// solve loaded LP.
/** Solves the loaded LP by processing the Simplex iteration until
* the termination criteria is fullfilled (see #terminate()).
* The SPxStatus of the solver will indicate the reason for termination.
*
* @throw SPxStatusException if either no problem, solver, pricer
* or ratiotester loaded or if solve is still running when it shouldn't be
*/
virtual Status solve(volatile bool* interrupt = NULL);
/** Identify primal basic variables that have zero reduced costs and
* try to pivot them out of the basis to make them tight.
* This is supposed to decrease the number of fractional variables
* when solving LP relaxations of (mixed) integer programs.
* The objective must not be modified during this procedure.
*/
void performSolutionPolishing();
/// set objective of solution polishing (0: off, 1: max_basic_slack, 2: min_basic_slack)
void setSolutionPolishing(SolutionPolish _polishObj)
{
polishObj = _polishObj;
}
/// return objective of solution polishing
SolutionPolish getSolutionPolishing()
{
return polishObj;
}
/// Status of solution process.
Status status() const;
/// current objective value.
/**@return Objective value of the current solution vector
* (see #getPrimalSol()).
*/
virtual R value();
// update nonbasic part of the objective value by the given amount
/**@return whether nonbasic part of objective is reliable
*/
bool updateNonbasicValue(R objChange);
// trigger a recomputation of the nonbasic part of the objective value
void forceRecompNonbasicValue()
{
m_nonbasicValue = 0.0;
m_nonbasicValueUpToDate = false;
}
/// get solution vector for primal variables.
/** This method returns the Status of the basis.
* If it is #REGULAR or better,
* the primal solution vector of the current basis will be copied
* to the argument \p vector. Hence, \p vector must be of dimension
* #nCols().
*
* @throw SPxStatusException if not initialized
*/
virtual Status getPrimalSol(VectorBase<R>& vector) const;
/// get VectorBase<R> of slack variables.
/** This method returns the Status of the basis.
* If it is #REGULAR or better,
* the slack variables of the current basis will be copied
* to the argument \p vector. Hence, \p VectorBase<R> must be of dimension
* #nRows().
*
* @warning Because SPxSolverBase supports range constraints as its
* default, slack variables are defined in a nonstandard way:
* Let \em x be the current solution vector and \em A the constraint
* matrix. Then the vector of slack variables is defined as
* \f$s = Ax\f$.
*
* @throw SPxStatusException if no problem loaded
*/
virtual Status getSlacks(VectorBase<R>& vector) const;
/// get current solution VectorBase<R> for dual variables.
/** This method returns the Status of the basis.
* If it is #REGULAR or better,
* the VectorBase<R> of dual variables of the current basis will be copied
* to the argument \p vector. Hence, \p VectorBase<R> must be of dimension
* #nRows().
*
* @warning Even though mathematically, each range constraint would
* account for two dual variables (one for each inequaility), only
* #nRows() dual variables are setup via the following
* construction: Given a range constraint, there are three possible
* situations:
* - None of its inequalities is tight: The dual variables
* for both are 0. However, when shifting (see below)
* occurs, it may be set to a value other than 0, which
* models a perturbed objective vector.
* - Both of its inequalities are tight: In this case the
* range constraint models an equality and we adopt the
* standard definition.
* - One of its inequalities is tight while the other is not:
* In this case only the dual variable for the tight
* constraint is given with the standard definition, while
* the other constraint is implicitely set to 0.
*
* @throw SPxStatusException if no problem loaded
*/
virtual Status getDualSol(VectorBase<R>& vector) const;
/// get vector of reduced costs.
/** This method returns the Status of the basis.
* If it is #REGULAR or better,
* the vector of reduced costs of the current basis will be copied
* to the argument \p vector. Hence, \p vector must be of dimension
* #nCols().
*
* Let \em d denote the vector of dual variables, as defined above,
* and \em A the LPs constraint matrix. Then the reduced cost vector
* \em r is defined as \f$r^T = c^T - d^TA\f$.
*
* @throw SPxStatusException if no problem loaded
*/
virtual Status getRedCostSol(VectorBase<R>& vector) const;
/// get primal ray in case of unboundedness.
/// @throw SPxStatusException if no problem loaded
virtual Status getPrimalray(VectorBase<R>& vector) const;
/// get dual farkas proof of infeasibility.
/// @throw SPxStatusException if no problem loaded
virtual Status getDualfarkas(VectorBase<R>& vector) const;
/// print display line of flying table
virtual void printDisplayLine(const bool force = false, const bool forceHead = false);
/// Termination criterion.
/** This method is called in each Simplex iteration to determine, if
* the algorithm is to terminate. In this case a nonzero value is
* returned.
*
* This method is declared virtual to allow for implementation of
* other stopping criteria or using it as callback method within the
* Simplex loop, by overriding the method in a derived class.
* However, all implementations must terminate with the
* statement \c return SPxSolverBase<R>::#terminate(), if no own termination
* criteria is encountered.
*
* Note, that the Simplex loop stopped even when #terminate()
* returns 0, if the LP has been solved to optimality (i.e. no
* further pricing succeeds and no shift is present).
*/
virtual bool terminate();
///@}
//-----------------------------
/**@name Control Parameters */
///@{
/// values \f$|x| < \epsilon\f$ are considered to be 0.
/** if you want another value for epsilon, use
* \ref soplex::Param::setEpsilon() "Param::setEpsilon()".
*/
R epsilon() const
{
return primVec.delta().getEpsilon();
}
/// feasibility tolerance maintained by ratio test during ENTER algorithm.
R entertol() const
{
assert(m_entertol > 0.0);
return m_entertol;
}
/// feasibility tolerance maintained by ratio test during LEAVE algorithm.
R leavetol() const
{
assert(m_leavetol > 0.0);
return m_leavetol;
}
/// allowed primal feasibility tolerance.
R feastol() const
{
assert(m_entertol > 0.0);
assert(m_leavetol > 0.0);
return theRep == COLUMN ? m_entertol : m_leavetol;
}
/// allowed optimality, i.e., dual feasibility tolerance.
R opttol() const
{
assert(m_entertol > 0.0);
assert(m_leavetol > 0.0);
return theRep == COLUMN ? m_leavetol : m_entertol;
}
/// guaranteed primal and dual bound violation for optimal solution, returning the maximum of feastol() and opttol(), i.e., the less tight tolerance.
R delta() const
{
assert(m_entertol > 0.0);
assert(m_leavetol > 0.0);
return m_entertol > m_leavetol ? m_entertol : m_leavetol;
}
/// set parameter \p feastol.
void setFeastol(R d);
/// set parameter \p opttol.
void setOpttol(R d);
/// set parameter \p delta, i.e., set \p feastol and \p opttol to same value.
void setDelta(R d);
/// set timing type
void setTiming(Timer::TYPE ttype)
{
theTime = TimerFactory::switchTimer(theTime, ttype);
multTimeSparse = TimerFactory::switchTimer(multTimeSparse, ttype);
multTimeFull = TimerFactory::switchTimer(multTimeFull, ttype);
multTimeColwise = TimerFactory::switchTimer(multTimeColwise, ttype);
multTimeUnsetup = TimerFactory::switchTimer(multTimeUnsetup, ttype);
timerType = ttype;
}
/// set timing type
Timer::TYPE getTiming()
{
assert(timerType == theTime->type());
assert(timerType == multTimeSparse->type());
assert(timerType == multTimeFull->type());
assert(timerType == multTimeColwise->type());
assert(timerType == multTimeUnsetup->type());
return timerType;
}
/// set display frequency
void setDisplayFreq(int freq)
{
displayFreq = freq;
}
/// get display frequency
int getDisplayFreq()
{
return displayFreq;
}
/// print basis metric within the usual output
void setMetricInformation(int type)
{
printBasisMetric = type;
}
// enable sparse pricing when viols < fac * dim()
void setSparsePricingFactor(R fac)
{
sparsePricingFactor = fac;
}
/// enable or disable hyper sparse pricing
void hyperPricing(bool h);
/** SPxSolverBase considers a Simplex step as degenerate if the
* steplength does not exceed #epsilon(). Cycling occurs if only
* degenerate steps are taken. To prevent this situation, SPxSolverBase
* perturbs the problem such that nondegenerate steps are ensured.
*
* maxCycle() controls how agressive such perturbation is
* performed, since no more than maxCycle() degenerate steps are
* accepted before perturbing the LP. The current number of consecutive
* degenerate steps is counted by numCycle().
*/
/// maximum number of degenerate simplex steps before we detect cycling.
int maxCycle() const
{
return m_maxCycle;
}
/// actual number of degenerate simplex steps encountered so far.
int numCycle() const
{
return m_numCycle;
}
/// perturb entire problem or only the bounds relevant to the current pivot
void useFullPerturbation(bool full)
{
fullPerturbation = full;
}
virtual R getBasisMetric(int type)
{
return basis().getMatrixMetric(type);
}
///@}
private:
//-----------------------------
/**@name Private helpers */
///@{
///
void localAddRows(int start);
///
void localAddCols(int start);
///
void setPrimal(VectorBase<R>& p_vector);
///
void setSlacks(VectorBase<R>& p_vector);
///
void setDual(VectorBase<R>& p_vector);
///
void setRedCost(VectorBase<R>& p_vector);
///@}
protected:
//-----------------------------
/**@name Protected helpers */
///@{
///
virtual void addedRows(int n);
///
virtual void addedCols(int n);
///
virtual void doRemoveRow(int i);
///
virtual void doRemoveRows(int perm[]);
///
virtual void doRemoveCol(int i);
///
virtual void doRemoveCols(int perm[]);
///@}
public:
//-----------------------------
/**@name Modification */
/// \p scale determines whether the new data needs to be scaled according to the existing LP (persistent scaling)
///@{
///
virtual void changeObj(const VectorBase<R>& newObj, bool scale = false);
///
virtual void changeObj(int i, const R& newVal, bool scale = false);
///
using SPxLPBase<R>::changeObj; /// overloading a virtual function
virtual void changeObj(SPxColId p_id, const R& p_newVal, bool scale = false)
{
changeObj(this->number(p_id), p_newVal, scale);
}
///
virtual void changeMaxObj(const VectorBase<R>& newObj, bool scale = false);
///
virtual void changeMaxObj(int i, const R& newVal, bool scale = false);
///
using SPxLPBase<R>::changeMaxObj; /// overloading a virtual function
virtual void changeMaxObj(SPxColId p_id, const R& p_newVal, bool scale = false)
{
changeMaxObj(this->number(p_id), p_newVal, scale);
}
///
virtual void changeRowObj(const VectorBase<R>& newObj, bool scale = false);
///
virtual void changeRowObj(int i, const R& newVal, bool scale = false);
///
using SPxLPBase<R>::changeRowObj;
virtual void changeRowObj(SPxRowId p_id, const R& p_newVal, bool scale = false)
{
changeRowObj(this->number(p_id), p_newVal);
}
///
virtual void clearRowObjs()
{
SPxLPBase<R>::clearRowObjs();
unInit();
}
///
virtual void changeLowerStatus(int i, R newLower, R oldLower = 0.0);
///
virtual void changeLower(const VectorBase<R>& newLower, bool scale = false);
///
virtual void changeLower(int i, const R& newLower, bool scale = false);
///
using SPxLPBase<R>::changeLower;
virtual void changeLower(SPxColId p_id, const R& p_newLower, bool scale = false)
{
changeLower(this->number(p_id), p_newLower, scale);
}
///
virtual void changeUpperStatus(int i, R newUpper, R oldLower = 0.0);
///
virtual void changeUpper(const VectorBase<R>& newUpper, bool scale = false);
///
virtual void changeUpper(int i, const R& newUpper, bool scale = false);
///
using SPxLPBase<R>::changeUpper; /// overloading virtual function
virtual void changeUpper(SPxColId p_id, const R& p_newUpper, bool scale = false)
{
changeUpper(this->number(p_id), p_newUpper, scale);
}
///
virtual void changeBounds(const VectorBase<R>& newLower, const VectorBase<R>& newUpper,
bool scale = false);
///
virtual void changeBounds(int i, const R& newLower, const R& newUpper, bool scale = false);
///
using SPxLPBase<R>::changeBounds;
virtual void changeBounds(SPxColId p_id, const R& p_newLower, const R& p_newUpper,
bool scale = false)
{
changeBounds(this->number(p_id), p_newLower, p_newUpper, scale);
}
///
virtual void changeLhsStatus(int i, R newLhs, R oldLhs = 0.0);
///
virtual void changeLhs(const VectorBase<R>& newLhs, bool scale = false);
///
virtual void changeLhs(int i, const R& newLhs, bool scale = false);
///
using SPxLPBase<R>::changeLhs;
virtual void changeLhs(SPxRowId p_id, const R& p_newLhs, bool scale = false)
{
changeLhs(this->number(p_id), p_newLhs, scale);
}
///
virtual void changeRhsStatus(int i, R newRhs, R oldRhs = 0.0);
///
virtual void changeRhs(const VectorBase<R>& newRhs, bool scale = false);
///
virtual void changeRhs(int i, const R& newRhs, bool scale = false);
///
using SPxLPBase<R>::changeRhs;
virtual void changeRhs(SPxRowId p_id, const R& p_newRhs, bool scale = false)
{
changeRhs(this->number(p_id), p_newRhs, scale);
}
///
virtual void changeRange(const VectorBase<R>& newLhs, const VectorBase<R>& newRhs,
bool scale = false);
///
virtual void changeRange(int i, const R& newLhs, const R& newRhs, bool scale = false);
///
using SPxLPBase<R>::changeRange;
virtual void changeRange(SPxRowId p_id, const R& p_newLhs, const R& p_newRhs, bool scale = false)
{
changeRange(this->number(p_id), p_newLhs, p_newRhs, scale);
}
///
virtual void changeRow(int i, const LPRowBase<R>& newRow, bool scale = false);
///
using SPxLPBase<R>::changeRow;
virtual void changeRow(SPxRowId p_id, const LPRowBase<R>& p_newRow, bool scale = false)
{
changeRow(this->number(p_id), p_newRow, scale);
}
///
virtual void changeCol(int i, const LPColBase<R>& newCol, bool scale = false);
///
using SPxLPBase<R>::changeCol;
virtual void changeCol(SPxColId p_id, const LPColBase<R>& p_newCol, bool scale = false)
{
changeCol(this->number(p_id), p_newCol, scale);
}
///
virtual void changeElement(int i, int j, const R& val, bool scale = false);
///
using SPxLPBase<R>::changeElement;
virtual void changeElement(SPxRowId rid, SPxColId cid, const R& val, bool scale = false)
{
changeElement(this->number(rid), this->number(cid), val, scale);
}
///
virtual void changeSense(typename SPxLPBase<R>::SPxSense sns);
///@}
//------------------------------------
/**@name Dimension and codimension */
///@{
/// dimension of basis matrix.
int dim() const
{
return thecovectors->num();
}
/// codimension.
int coDim() const
{
return thevectors->num();
}
///@}
//------------------------------------
/**@name Variables and Covariables
* Class SPxLPBase<R> introduces \ref soplex::SPxId "SPxIds" to identify
* row or column data of an LP. SPxSolverBase uses this concept to
* access data with respect to the chosen representation.
*/
///@{
/// id of \p i 'th vector.
/** The \p i 'th Id is the \p i 'th SPxRowId for a rowwise and the
* \p i 'th SPxColId for a columnwise basis represenation. Hence,
* 0 <= i < #coDim().
*/
SPxId id(int i) const
{
if(rep() == ROW)
{
SPxRowId rid = SPxLPBase<R>::rId(i);
return SPxId(rid);
}
else
{
SPxColId cid = SPxLPBase<R>::cId(i);
return SPxId(cid);
}
}
/// id of \p i 'th covector.
/** The \p i 'th #coId() is the \p i 'th SPxColId for a rowwise and the
* \p i 'th SPxRowId for a columnwise basis represenation. Hence,
* 0 <= i < #dim().
*/
SPxId coId(int i) const
{
if(rep() == ROW)
{
SPxColId cid = SPxLPBase<R>::cId(i);
return SPxId(cid);
}
else
{
SPxRowId rid = SPxLPBase<R>::rId(i);
return SPxId(rid);
}
}
/// Is \p p_id an SPxId ?
/** This method returns wheather or not \p p_id identifies a vector
* with respect to the chosen representation.
*/
bool isId(const SPxId& p_id) const
{
return p_id.info * theRep > 0;
}
/// Is \p p_id a CoId.
/** This method returns wheather or not \p p_id identifies a coVector
* with respect to the chosen representation.
*/
bool isCoId(const SPxId& p_id) const
{
return p_id.info * theRep < 0;
}
///@}
//------------------------------------
/**@name Vectors and Covectors */
///@{
/// \p i 'th vector.
/**@return a reference to the \p i 'th, 0 <= i < #coDim(), vector of
* the loaded LP (with respect to the chosen representation).
*/
const SVectorBase<R>& vector(int i) const
{
return (*thevectors)[i];
}
///
const SVectorBase<R>& vector(const SPxRowId& rid) const
{
assert(rid.isValid());
return (rep() == ROW)
? (*thevectors)[this->number(rid)]
: static_cast<const SVectorBase<R>&>(unitVecs[this->number(rid)]);
}
///
const SVectorBase<R>& vector(const SPxColId& cid) const
{
assert(cid.isValid());
return (rep() == COLUMN)
? (*thevectors)[this->number(cid)]
: static_cast<const SVectorBase<R>&>(unitVecs[this->number(cid)]);
}
/// VectorBase<R> associated to \p p_id.
/**@return Returns a reference to the VectorBase<R> of the loaded LP corresponding
* to \p id (with respect to the chosen representation). If \p p_id is
* an id, a vector of the constraint matrix is returned, otherwise
* the corresponding unit vector (of the slack variable or bound
* inequality) is returned.
* @todo The implementation does not exactly look like it will do
* what is promised in the describtion.
*/
const SVectorBase<R>& vector(const SPxId& p_id) const
{
assert(p_id.isValid());
return p_id.isSPxRowId()
? vector(SPxRowId(p_id))
: vector(SPxColId(p_id));
}
/// \p i 'th covector of LP.
/**@return a reference to the \p i 'th, 0 <= i < #dim(), covector of
* the loaded LP (with respect to the chosen representation).
*/
const SVectorBase<R>& coVector(int i) const
{
return (*thecovectors)[i];
}
///
const SVectorBase<R>& coVector(const SPxRowId& rid) const
{
assert(rid.isValid());
return (rep() == COLUMN)
? (*thecovectors)[this->number(rid)]
: static_cast<const SVector&>(unitVecs[this->number(rid)]);
}
///
const SVectorBase<R>& coVector(const SPxColId& cid) const
{
assert(cid.isValid());
return (rep() == ROW)
? (*thecovectors)[this->number(cid)]
: static_cast<const SVectorBase<R>&>(unitVecs[this->number(cid)]);
}
/// coVector associated to \p p_id.
/**@return a reference to the covector of the loaded LP
* corresponding to \p p_id (with respect to the chosen
* representation). If \p p_id is a coid, a covector of the constraint
* matrix is returned, otherwise the corresponding unit vector is
* returned.
*/
const SVectorBase<R>& coVector(const SPxId& p_id) const
{
assert(p_id.isValid());
return p_id.isSPxRowId()
? coVector(SPxRowId(p_id))
: coVector(SPxColId(p_id));
}
/// return \p i 'th unit vector.
const SVectorBase<R>& unitVector(int i) const
{
return unitVecs[i];
}
///@}
//------------------------------------
/**@name Variable status
* The Simplex basis assigns a \ref soplex::SPxBasisBase<R>::Desc::Status
* "Status" to each variable and covariable. Depending on the
* representation, the status indicates that the corresponding
* vector is in the basis matrix or not.
*/
///@{
/// Status of \p i 'th variable.
typename SPxBasisBase<R>::Desc::Status varStatus(int i) const
{
return this->desc().status(i);
}
/// Status of \p i 'th covariable.
typename SPxBasisBase<R>::Desc::Status covarStatus(int i) const
{
return this->desc().coStatus(i);
}
/// does \p stat describe a basic index ?
bool isBasic(typename SPxBasisBase<R>::Desc::Status stat) const
{
return (stat * rep() > 0);
}
/// is the \p p_id 'th vector basic ?
bool isBasic(const SPxId& p_id) const
{
assert(p_id.isValid());
return p_id.isSPxRowId()
? isBasic(SPxRowId(p_id))
: isBasic(SPxColId(p_id));
}
/// is the \p rid 'th vector basic ?
bool isBasic(const SPxRowId& rid) const
{
return isBasic(this->desc().rowStatus(this->number(rid)));
}
/// is the \p cid 'th vector basic ?
bool isBasic(const SPxColId& cid) const
{
return isBasic(this->desc().colStatus(this->number(cid)));
}
/// is the \p i 'th row vector basic ?
bool isRowBasic(int i) const
{
return isBasic(this->desc().rowStatus(i));
}
/// is the \p i 'th column vector basic ?
bool isColBasic(int i) const
{
return isBasic(this->desc().colStatus(i));
}
/// is the \p i 'th vector basic ?
bool isBasic(int i) const
{
return isBasic(this->desc().status(i));
}
/// is the \p i 'th covector basic ?
bool isCoBasic(int i) const
{
return isBasic(this->desc().coStatus(i));
}
///@}
/// feasibility vector.
/** This method return the \em feasibility vector. If it satisfies its
* bound, the basis is called feasible (independently of the chosen
* representation). The feasibility vector has dimension #dim().
*
* For the entering Simplex, #fVec is kept within its bounds. In
* contrast to this, the pricing of the leaving Simplex selects an
* element of #fVec, that violates its bounds.
*/
UpdateVector<R>& fVec() const
{
return *theFvec;
}
/// right-hand side vector for \ref soplex::SPxSolverBase<R>::fVec "fVec"
/** The feasibility vector is computed by solving a linear system with the
* basis matrix. The right-hand side vector of this system is referred
* to as \em feasibility, \em right-hand \em side \em vector #fRhs().
*
* For a row basis, #fRhs() is the objective vector (ignoring shifts).
* For a column basis, it is the sum of all nonbasic vectors scaled by
* the factor of their bound.
*/
const VectorBase<R>& fRhs() const
{
return *theFrhs;
}
/// upper bound for \ref soplex::SPxSolverBase<R>::fVec "fVec".
const VectorBase<R>& ubBound() const
{
return theUBbound;
}
/// upper bound for #fVec, writable.
/** This method returns the upper bound for the feasibility vector.
* It may only be called for the #ENTER%ing Simplex.
*
* For the #ENTER%ing Simplex algorithms, the feasibility vector is
* maintained to fullfill its bounds. As #fVec itself, also its
* bounds depend on the chosen representation. Further, they may
* need to be shifted (see below).
*/
VectorBase<R>& ubBound()
{
return theUBbound;
}
/// lower bound for \ref soplex::SPxSolverBase<R>::fVec "fVec".
const VectorBase<R>& lbBound() const
{
return theLBbound;
}
/// lower bound for #fVec, writable.
/** This method returns the lower bound for the feasibility vector.
* It may only be called for the #ENTER%ing Simplex.
*
* For the #ENTER%ing Simplex algorithms, the feasibility vector is
* maintained to fullfill its bounds. As #fVec itself, also its
* bound depend on the chosen representation. Further, they may
* need to be shifted (see below).
*/
VectorBase<R>& lbBound()
{
return theLBbound;
}
/// Violations of \ref soplex::SPxSolverBase<R>::fVec "fVec"
/** For the leaving Simplex algorithm, pricing involves selecting a
* variable from #fVec that violates its bounds that is to leave
* the basis. When a SPxPricer is called to select such a
* leaving variable, #fTest() contains the vector of violations:
* For #fTest()[i] < 0, the \c i 'th basic variable violates one of
* its bounds by the given value. Otherwise no bound is violated.
*/
const VectorBase<R>& fTest() const
{
assert(type() == LEAVE);
return theCoTest;
}
/// copricing vector.
/** The copricing vector #coPvec along with the pricing vector
* #pVec are used for pricing in the #ENTER%ing Simplex algorithm,
* i.e. one variable is selected, that violates its bounds. In
* contrast to this, the #LEAVE%ing Simplex algorithm keeps both
* vectors within their bounds.
*/
UpdateVector<R>& coPvec() const
{
return *theCoPvec;
}
/// Right-hand side vector for \ref soplex::SPxSolverBase<R>::coPvec "coPvec".
/** The vector #coPvec is computed by solving a linear system with the
* basis matrix and #coPrhs as the right-hand side vector. For
* column basis representation, #coPrhs is build up of the
* objective vector elements of all basic variables. For a row
* basis, it consists of the tight bounds of all basic
* constraints.
*/
const VectorBase<R>& coPrhs() const
{
return *theCoPrhs;
}
///
const VectorBase<R>& ucBound() const
{
assert(theType == LEAVE);
return *theCoUbound;
}
/// upper bound for #coPvec.
/** This method returns the upper bound for #coPvec. It may only be
* called for the leaving Simplex algorithm.
*
* For the leaving Simplex algorithms #coPvec is maintained to
* fullfill its bounds. As #coPvec itself, also its bound depend
* on the chosen representation. Further, they may need to be
* shifted (see below).
*/
VectorBase<R>& ucBound()
{
assert(theType == LEAVE);
return *theCoUbound;
}
///
const VectorBase<R>& lcBound() const
{
assert(theType == LEAVE);
return *theCoLbound;
}
/// lower bound for #coPvec.
/** This method returns the lower bound for #coPvec. It may only be
* called for the leaving Simplex algorithm.
*
* For the leaving Simplex algorithms #coPvec is maintained to
* fullfill its bounds. As #coPvec itself, also its bound depend
* on the chosen representation. Further, they may need to be
* shifted (see below).
*/
VectorBase<R>& lcBound()
{
assert(theType == LEAVE);
return *theCoLbound;
}
/// violations of \ref soplex::SPxSolverBase<R>::coPvec "coPvec".
/** In entering Simplex pricing selects checks vectors #coPvec()
* and #pVec() for violation of its bounds. #coTest() contains
* the violations for #coPvec() which are indicated by a negative
* value. That is, if #coTest()[i] < 0, the \p i 'th element of #coPvec()
* is violated by -#coTest()[i].
*/
const VectorBase<R>& coTest() const
{
assert(type() == ENTER);
return theCoTest;
}
/// pricing vector.
/** The pricing vector #pVec is the product of #coPvec with the
* constraint matrix. As #coPvec, also #pVec is maintained within
* its bound for the leaving Simplex algorithm, while the bounds
* are tested for the entering Simplex. #pVec is of dimension
* #coDim(). Vector #pVec() is only up to date for #LEAVE%ing
* Simplex or #FULL pricing in #ENTER%ing Simplex.
*/
UpdateVector<R>& pVec() const
{
return *thePvec;
}
///
const VectorBase<R>& upBound() const
{
assert(theType == LEAVE);
return *theUbound;
}
/// upper bound for #pVec.
/** This method returns the upper bound for #pVec. It may only be
* called for the leaving Simplex algorithm.
*
* For the leaving Simplex algorithms #pVec is maintained to
* fullfill its bounds. As #pVec itself, also its bound depend
* on the chosen representation. Further, they may need to be
* shifted (see below).
*/
VectorBase<R>& upBound()
{
assert(theType == LEAVE);
return *theUbound;
}
///
const VectorBase<R>& lpBound() const
{
assert(theType == LEAVE);
return *theLbound;
}
/// lower bound for #pVec.
/** This method returns the lower bound for #pVec. It may only be
* called for the leaving Simplex algorithm.
*
* For the leaving Simplex algorithms #pVec is maintained to
* fullfill its bounds. As #pVec itself, also its bound depend
* on the chosen representation. Further, they may need to be
* shifted (see below).
*/
VectorBase<R>& lpBound()
{
assert(theType == LEAVE);
return *theLbound;
}
/// Violations of \ref soplex::SPxSolverBase<R>::pVec "pVec".
/** In entering Simplex pricing selects checks vectors #coPvec()
* and #pVec() for violation of its bounds. Vector #test()
* contains the violations for #pVec(), i.e., if #test()[i] < 0,
* the i'th element of #pVec() is violated by #test()[i].
* Vector #test() is only up to date for #FULL pricing.
*/
const VectorBase<R>& test() const
{
assert(type() == ENTER);
return theTest;
}
/// compute and return \ref soplex::SPxSolverBase<R>::pVec() "pVec()"[i].
R computePvec(int i);
/// compute entire \ref soplex::SPxSolverBase<R>::pVec() "pVec()".
void computePvec();
/// compute and return \ref soplex::SPxSolverBase<R>::test() "test()"[i] in \ref soplex::SPxSolverBase<R>::ENTER "ENTER"ing Simplex.
R computeTest(int i);
/// compute test VectorBase<R> in \ref soplex::SPxSolverBase<R>::ENTER "ENTER"ing Simplex.
void computeTest();
//------------------------------------
/**@name Shifting
* The task of the ratio test (implemented in SPxRatioTester classes)
* is to select a variable for the basis update, such that the basis
* remains priced (i.e. both, the pricing and copricing vectors satisfy
* their bounds) or feasible (i.e. the feasibility vector satisfies its
* bounds). However, this can lead to numerically instable basis matrices
* or -- after accumulation of various errors -- even to a singular basis
* matrix.
*
* The key to overcome this problem is to allow the basis to become "a
* bit" infeasible or unpriced, in order provide a better choice for the
* ratio test to select a stable variable. This is equivalent to enlarging
* the bounds by a small amount. This is referred to as \em shifting.
*
* These methods serve for shifting feasibility bounds, either in order
* to maintain numerical stability or initially for computation of
* phase 1. The sum of all shifts applied to any bound is stored in
* \ref soplex::SPxSolverBase<R>::theShift "theShift".
*
* The following methods are used to shift individual bounds. They are
* mainly intended for stable implenentations of SPxRatioTester.
*/
///@{
/// Perform initial shifting to optain an feasible or pricable basis.
void shiftFvec();
/// Perform initial shifting to optain an feasible or pricable basis.
void shiftPvec();
/// shift \p i 'th \ref soplex::SPxSolver::ubBound "ubBound" to \p to.
void shiftUBbound(int i, R to)
{
assert(theType == ENTER);
// use maximum to not count tightened bounds in case of equality shifts
theShift += MAXIMUM(to - theUBbound[i], 0.0);
theUBbound[i] = to;
}
/// shift \p i 'th \ref soplex::SPxSolver::lbBound "lbBound" to \p to.
void shiftLBbound(int i, R to)
{
assert(theType == ENTER);
// use maximum to not count tightened bounds in case of equality shifts
theShift += MAXIMUM(theLBbound[i] - to, 0.0);
theLBbound[i] = to;
}
/// shift \p i 'th \ref soplex::SPxSolver::upBound "upBound" to \p to.
void shiftUPbound(int i, R to)
{
assert(theType == LEAVE);
// use maximum to not count tightened bounds in case of equality shifts
theShift += MAXIMUM(to - (*theUbound)[i], 0.0);
(*theUbound)[i] = to;
}
/// shift \p i 'th \ref soplex::SPxSolver::lpBound "lpBound" to \p to.
void shiftLPbound(int i, R to)
{
assert(theType == LEAVE);
// use maximum to not count tightened bounds in case of equality shifts
theShift += MAXIMUM((*theLbound)[i] - to, 0.0);
(*theLbound)[i] = to;
}
/// shift \p i 'th \ref soplex::SPxSolver::ucBound "ucBound" to \p to.
void shiftUCbound(int i, R to)
{
assert(theType == LEAVE);
// use maximum to not count tightened bounds in case of equality shifts
theShift += MAXIMUM(to - (*theCoUbound)[i], 0.0);
(*theCoUbound)[i] = to;
}
/// shift \p i 'th \ref soplex::SPxSolver::lcBound "lcBound" to \p to.
void shiftLCbound(int i, R to)
{
assert(theType == LEAVE);
// use maximum to not count tightened bounds in case of equality shifts
theShift += MAXIMUM((*theCoLbound)[i] - to, 0.0);
(*theCoLbound)[i] = to;
}
///
void testBounds() const;
/// total current shift amount.
virtual R shift() const
{
return theShift;
}
/// remove shift as much as possible.
virtual void unShift(void);
/// get violation of constraints.
virtual void qualConstraintViolation(R& maxviol, R& sumviol) const;
/// get violations of bounds.
virtual void qualBoundViolation(R& maxviol, R& sumviol) const;
/// get the residuum |Ax-b|.
virtual void qualSlackViolation(R& maxviol, R& sumviol) const;
/// get violation of optimality criterion.
virtual void qualRedCostViolation(R& maxviol, R& sumviol) const;
///@}
private:
//------------------------------------
/**@name Perturbation */
///@{
///
void perturbMin(
const UpdateVector<R>& vec, VectorBase<R>& low, VectorBase<R>& up, R eps, R delta,
int start = 0, int incr = 1);
///
void perturbMax(
const UpdateVector<R>& vec, VectorBase<R>& low, VectorBase<R>& up, R eps, R delta,
int start = 0, int incr = 1);
///
R perturbMin(const UpdateVector<R>& uvec,
VectorBase<R>& low, VectorBase<R>& up, R eps, R delta,
const typename SPxBasisBase<R>::Desc::Status* stat, int start, int incr);
///
R perturbMax(const UpdateVector<R>& uvec,
VectorBase<R>& low, VectorBase<R>& up, R eps, R delta,
const typename SPxBasisBase<R>::Desc::Status* stat, int start, int incr);
///@}
//------------------------------------
/**@name The Simplex Loop
* We now present a set of methods that may be usefull when implementing
* own SPxPricer or SPxRatioTester classes. Here is, how
* SPxSolverBase will call methods from its loaded SPxPricer and
* SPxRatioTester.
*
* For the entering Simplex:
* -# \ref soplex::SPxPricer::selectEnter() "SPxPricer::selectEnter()"
* -# \ref soplex::SPxRatioTester::selectLeave() "SPxRatioTester::selectLeave()"
* -# \ref soplex::SPxPricer::entered4() "SPxPricer::entered4()"
*
* For the leaving Simplex:
* -# \ref soplex::SPxPricer::selectLeave() "SPxPricer::selectLeave()"
* -# \ref soplex::SPxRatioTester::selectEnter() "SPxRatioTester::selectEnter()"
* -# \ref soplex::SPxPricer::left4() "SPxPricer::left4()"
*/
///@{
public:
/// Setup vectors to be solved within Simplex loop.
/** Load vector \p y to be #solve%d with the basis matrix during the
* #LEAVE Simplex. The system will be solved after #SPxSolverBase%'s call
* to SPxRatioTester. The system will be solved along with
* another system. Solving two linear system at a time has
* performance advantages over solving the two linear systems
* seperately.
*/
void setup4solve(SSVectorBase<R>* p_y, SSVectorBase<R>* p_rhs)
{
assert(type() == LEAVE);
solveVector2 = p_y;
solveVector2rhs = p_rhs;
}
/// Setup vectors to be solved within Simplex loop.
/** Load a second additional vector \p y2 to be #solve%d with the
* basis matrix during the #LEAVE Simplex. The system will be
* solved after #SPxSolverBase%'s call to SPxRatioTester.
* The system will be solved along with at least one
* other system. Solving several linear system at a time has
* performance advantages over solving them seperately.
*/
void setup4solve2(SSVectorBase<R>* p_y2, SSVectorBase<R>* p_rhs2)
{
assert(type() == LEAVE);
solveVector3 = p_y2;
solveVector3rhs = p_rhs2;
}
/// Setup vectors to be cosolved within Simplex loop.
/** Load vector \p y to be #coSolve%d with the basis matrix during
* the #ENTER Simplex. The system will be solved after #SPxSolverBase%'s
* call to SPxRatioTester. The system will be solved along
* with another system. Solving two linear system at a time has
* performance advantages over solving the two linear systems
* seperately.
*/
void setup4coSolve(SSVectorBase<R>* p_y, SSVectorBase<R>* p_rhs)
{
assert(type() == ENTER);
coSolveVector2 = p_y;
coSolveVector2rhs = p_rhs;
}
/// Setup vectors to be cosolved within Simplex loop.
/** Load a second vector \p z to be #coSolve%d with the basis matrix during
* the #ENTER Simplex. The system will be solved after #SPxSolverBase%'s
* call to SPxRatioTester. The system will be solved along
* with two other systems.
*/
void setup4coSolve2(SSVectorBase<R>* p_z, SSVectorBase<R>* p_rhs)
{
assert(type() == ENTER);
coSolveVector3 = p_z;
coSolveVector3rhs = p_rhs;
}
/// maximal infeasibility of basis
/** This method is called before concluding optimality. Since it is
* possible that some stable implementation of class
* SPxRatioTester yielded a slightly infeasible (or unpriced)
* basis, this must be checked before terminating with an optimal
* solution.
*/
virtual R maxInfeas() const;
/// check for violations above tol and immediately return false w/o checking the remaining values
/** This method is useful for verifying whether an objective limit can be used as termination criterion
*/
virtual bool noViols(R tol) const;
/// Return current basis.
/**@note The basis can be used to solve linear systems or use
* any other of its (const) methods. It is, however, encuraged
* to use methods #setup4solve() and #setup4coSolve() for solving
* systems, since this is likely to have perfomance advantages.
*/
const SPxBasisBase<R>& basis() const
{
return *this;
}
///
SPxBasisBase<R>& basis()
{
return *this;
}
/// return loaded SPxPricer.
const SPxPricer<R>* pricer() const
{
return thepricer;
}
/// return loaded SLinSolver.
const SLinSolver<R>* slinSolver() const
{
return SPxBasisBase<R>::factor;
}
/// return loaded SPxRatioTester.
const SPxRatioTester<R>* ratiotester() const
{
return theratiotester;
}
/// Factorize basis matrix.
/// @throw SPxStatusException if loaded matrix is singular
virtual void factorize();
private:
/** let index \p i leave the basis and manage entering of another one.
@returns \c false if LP is unbounded/infeasible. */
bool leave(int i, bool polish = false);
/** let id enter the basis and manage leaving of another one.
@returns \c false if LP is unbounded/infeasible. */
bool enter(SPxId& id, bool polish = false);
/// test coVector \p i with status \p stat.
R coTest(int i, typename SPxBasisBase<R>::Desc::Status stat) const;
/// compute coTest vector.
void computeCoTest();
/// recompute coTest vector.
void updateCoTest();
/// test VectorBase<R> \p i with status \p stat.
R test(int i, typename SPxBasisBase<R>::Desc::Status stat) const;
/// recompute test vector.
void updateTest();
/// compute basis feasibility test vector.
void computeFtest();
/// update basis feasibility test vector.
void updateFtest();
///@}
//------------------------------------
/**@name Parallelization
* In this section we present the methods, that are provided in order to
* allow a parallel version to be implemented as a derived class, thereby
* inheriting most of the code of SPxSolverBase.
*
* @par Initialization
* These methods are used to setup all the vectors used in the Simplex
* loop, that where described in the previous sectios.
*/
///@{
public:
/// intialize data structures.
/** If SPxSolverBase is not \ref isInitialized() "initialized", the method
* #solve() calls #init() to setup all vectors and internal data structures.
* Most of the other methods within this section are called by #init().
*
* Derived classes should add the initialization of additional
* data structures by overriding this method. Don't forget,
* however, to call SPxSolverBase<R>::init().
*/
virtual void init();
protected:
/// has the internal data been initialized?
/** As long as an instance of SPxSolverBase is not initialized, no member
* contains setup data. Initialization is performed via method
* #init(). Afterwards all data structures are kept up to date (even
* for all manipulation methods), until #unInit() is called. However,
* some manipulation methods call #unInit() themselfs.
*/
bool isInitialized() const
{
return initialized;
}
/// resets clock average statistics
void resetClockStats();
/// uninitialize data structures.
virtual void unInit()
{
initialized = false;
}
/// setup all vecs fresh
virtual void reinitializeVecs();
/// reset dimensions of vectors according to loaded LP.
virtual void reDim();
/// compute feasibility vector from scratch.
void computeFrhs();
///
virtual void computeFrhsXtra();
///
virtual void computeFrhs1(const VectorBase<R>&, const VectorBase<R>&);
///
void computeFrhs2(VectorBase<R>&, VectorBase<R>&);
/// compute \ref soplex::SPxSolverBase<R>::theCoPrhs "theCoPrhs" for entering Simplex.
virtual void computeEnterCoPrhs();
///
void computeEnterCoPrhs4Row(int i, int n);
///
void computeEnterCoPrhs4Col(int i, int n);
/// compute \ref soplex::SPxSolverBase<R>::theCoPrhs "theCoPrhs" for leaving Simplex.
virtual void computeLeaveCoPrhs();
///
void computeLeaveCoPrhs4Row(int i, int n);
///
void computeLeaveCoPrhs4Col(int i, int n);
/// Compute part of objective value.
/** This method is called from #value() in order to compute the part of
* the objective value resulting form nonbasic variables for #COLUMN
* Representation.
*/
R nonbasicValue();
/// Get pointer to the \p id 'th vector
virtual const SVectorBase<R>* enterVector(const SPxId& p_id)
{
assert(p_id.isValid());
return p_id.isSPxRowId()
? &vector(SPxRowId(p_id)) : &vector(SPxColId(p_id));
}
///
virtual void getLeaveVals(int i,
typename SPxBasisBase<R>::Desc::Status& leaveStat, SPxId& leaveId,
R& leaveMax, R& leavebound, int& leaveNum, StableSum<R>& objChange);
///
virtual void getLeaveVals2(R leaveMax, SPxId enterId,
R& enterBound, R& newUBbound,
R& newLBbound, R& newCoPrhs, StableSum<R>& objChange);
///
virtual void getEnterVals(SPxId id, R& enterTest,
R& enterUB, R& enterLB, R& enterVal, R& enterMax,
R& enterPric, typename SPxBasisBase<R>::Desc::Status& enterStat, R& enterRO,
StableSum<R>& objChange);
///
virtual void getEnterVals2(int leaveIdx,
R enterMax, R& leaveBound, StableSum<R>& objChange);
///
virtual void ungetEnterVal(SPxId enterId, typename SPxBasisBase<R>::Desc::Status enterStat,
R leaveVal, const SVectorBase<R>& vec, StableSum<R>& objChange);
///
virtual void rejectEnter(SPxId enterId,
R enterTest, typename SPxBasisBase<R>::Desc::Status enterStat);
///
virtual void rejectLeave(int leaveNum, SPxId leaveId,
typename SPxBasisBase<R>::Desc::Status leaveStat, const SVectorBase<R>* newVec = 0);
///
virtual void setupPupdate(void);
///
virtual void doPupdate(void);
///
virtual void clearUpdateVecs(void);
///
virtual void perturbMinEnter(void);
/// perturb basis bounds.
virtual void perturbMaxEnter(void);
///
virtual void perturbMinLeave(void);
/// perturb nonbasic bounds.
virtual void perturbMaxLeave(void);
///@}
//------------------------------------
/** The following methods serve for initializing the bounds for dual or
* primal Simplex algorithm of entering or leaving type.
*/
///@{
///
void clearDualBounds(typename SPxBasisBase<R>::Desc::Status, R&, R&) const;
///
void setDualColBounds();
///
void setDualRowBounds();
/// setup feasibility bounds for entering algorithm
void setPrimalBounds();
///
void setEnterBound4Col(int, int);
///
void setEnterBound4Row(int, int);
///
virtual void setEnterBounds();
///
void setLeaveBound4Row(int i, int n);
///
void setLeaveBound4Col(int i, int n);
///
virtual void setLeaveBounds();
///@}
//------------------------------------
/** Compute the primal ray or the farkas proof in case of unboundedness
* or infeasibility.
*/
///@{
///
void computePrimalray4Col(R direction, SPxId enterId);
///
void computePrimalray4Row(R direction);
///
void computeDualfarkas4Col(R direction);
///
void computeDualfarkas4Row(R direction, SPxId enterId);
///@}
public:
//------------------------------------
/** Limits and status inquiry */
///@{
/// set time limit.
virtual void setTerminationTime(Real time = infinity);
/// return time limit.
virtual Real terminationTime() const;
/// set iteration limit.
virtual void setTerminationIter(int iteration = -1);
/// return iteration limit.
virtual int terminationIter() const;
/// set objective limit.
virtual void setTerminationValue(R value = R(infinity));
/// return objective limit.
virtual R terminationValue() const;
/// get objective value of current solution.
virtual R objValue()
{
return value();
}
/// get all results of last solve.
Status
getResult(R* value = 0, VectorBase<R>* primal = 0,
VectorBase<R>* slacks = 0, VectorBase<R>* dual = 0,
VectorBase<R>* reduCost = 0);
protected:
/**@todo put the following basis methods near the variable status methods!*/
/// converts basis status to VarStatus
VarStatus basisStatusToVarStatus(typename SPxBasisBase<R>::Desc::Status stat) const;
/// converts VarStatus to basis status for rows
typename SPxBasisBase<R>::Desc::Status varStatusToBasisStatusRow(int row, VarStatus stat)
const;
/// converts VarStatus to basis status for columns
typename SPxBasisBase<R>::Desc::Status varStatusToBasisStatusCol(int col, VarStatus stat)
const;
public:
/// gets basis status for a single row
VarStatus getBasisRowStatus(int row) const;
/// gets basis status for a single column
VarStatus getBasisColStatus(int col) const;
/// get current basis, and return solver status.
Status getBasis(VarStatus rows[], VarStatus cols[], const int rowsSize = -1,
const int colsSize = -1) const;
/// gets basis status
typename SPxBasisBase<R>::SPxStatus getBasisStatus() const
{
return SPxBasisBase<R>::status();
}
/// check a given basis for validity.
bool isBasisValid(DataArray<VarStatus> rows, DataArray<VarStatus> cols);
/// set the lp solver's basis.
void setBasis(const VarStatus rows[], const VarStatus cols[]);
/// set the lp solver's basis status.
void setBasisStatus(typename SPxBasisBase<R>::SPxStatus stat)
{
if(m_status == OPTIMAL)
m_status = UNKNOWN;
SPxBasisBase<R>::setStatus(stat);
}
/// setting the solver status external from the solve loop.
void setSolverStatus(typename SPxSolverBase<R>::Status stat)
{
m_status = stat;
}
/// get level of dual degeneracy
// this function is used for the improved dual simplex
R getDegeneracyLevel(VectorBase<R> degenvec);
/// get number of dual norms
void getNdualNorms(int& nnormsRow, int& nnormsCol) const;
/// get dual norms
bool getDualNorms(int& nnormsRow, int& nnormsCol, R* norms) const;
/// set dual norms
bool setDualNorms(int nnormsRow, int nnormsCol, R* norms);
/// pass integrality information about the variables to the solver
void setIntegralityInformation(int ncols, int* intInfo);
/// reset cumulative time counter to zero.
void resetCumulativeTime()
{
theCumulativeTime = 0.0;
}
/// get number of bound flips.
int boundFlips() const
{
return totalboundflips;
}
/// get number of dual degenerate pivots
int dualDegeneratePivots()
{
return (rep() == ROW) ? enterCycles : leaveCycles;
}
/// get number of primal degenerate pivots
int primalDegeneratePivots()
{
return (rep() == ROW) ? leaveCycles : enterCycles;
}
/// get the sum of dual degeneracy
R sumDualDegeneracy()
{
return dualDegenSum;
}
/// get the sum of primal degeneracy
R sumPrimalDegeneracy()
{
return primalDegenSum;
}
/// get number of iterations of current solution.
int iterations() const
{
return basis().iteration();
}
/// return number of iterations done with primal algorithm
int primalIterations()
{
assert(iterations() == 0 || primalCount <= iterations());
return (iterations() == 0) ? 0 : primalCount;
}
/// return number of iterations done with primal algorithm
int dualIterations()
{
return iterations() - primalIterations();
}
/// return number of iterations done with primal algorithm
int polishIterations()
{
return polishCount;
}
/// time spent in last call to method solve().
Real time() const
{
return theTime->time();
}
/// returns whether current time limit is reached; call to time() may be skipped unless \p forceCheck is true
///
bool isTimeLimitReached(const bool forceCheck = false);
/// the maximum runtime
Real getMaxTime()
{
return maxTime;
}
/// cumulative time spent in all calls to method solve().
Real cumulativeTime() const
{
return theCumulativeTime;
}
/// the maximum number of iterations
int getMaxIters()
{
return maxIters;
}
/// return const lp's rows if available.
const LPRowSetBase<R>& rows() const
{
return *this->lprowset();
}
/// return const lp's cols if available.
const LPColSet& cols() const
{
return *this->lpcolset();
}
/// copy lower bound VectorBase<R> to \p p_low.
void getLower(VectorBase<R>& p_low) const
{
p_low = SPxLPBase<R>::lower();
}
/// copy upper bound VectorBase<R> to \p p_up.
void getUpper(VectorBase<R>& p_up) const
{
p_up = SPxLPBase<R>::upper();
}
/// copy lhs value VectorBase<R> to \p p_lhs.
void getLhs(VectorBase<R>& p_lhs) const
{
p_lhs = SPxLPBase<R>::lhs();
}
/// copy rhs value VectorBase<R> to \p p_rhs.
void getRhs(VectorBase<R>& p_rhs) const
{
p_rhs = SPxLPBase<R>::rhs();
}
/// optimization sense.
typename SPxLPBase<R>::SPxSense sense() const
{
return this->spxSense();
}
/// returns statistical information in form of a string.
std::string statistics() const
{
std::stringstream s;
s << basis().statistics()
<< "Solution time : " << std::setw(10) << std::fixed << std::setprecision(
2) << time() << std::endl
<< "Iterations : " << std::setw(10) << iterations() << std::endl;
return s.str();
}
/// returns whether a basis needs to be found for the improved dual simplex
DecompStatus getDecompStatus() const
{
if(getStartingDecompBasis)
return FINDSTARTBASIS;
else
return DONTFINDSTARTBASIS;
}
/// sets whether the degeneracy is computed at each iteration
void setComputeDegenFlag(bool computeDegen)
{
computeDegeneracy = computeDegen;
}
/// returns whether the degeneracy is computed in each iteration
bool getComputeDegeneracy() const
{
return computeDegeneracy;
}
/// sets the offset for the number of iterations before the degeneracy is computed
void setDegenCompOffset(int iterOffset)
{
degenCompIterOffset = iterOffset;
}
/// gets the offset for the number of iterations before the degeneracy is computed
int getDegenCompOffset() const
{
return degenCompIterOffset;
}
/// sets the iteration limit for the decomposition simplex initialisation
void setDecompIterationLimit(int iterationLimit)
{
decompIterationLimit = iterationLimit;
}
/// returns the iteration limit for the decomposition simplex initialisation
int getDecompIterationLimit() const
{
return decompIterationLimit;
}
///@}
//------------------------------------
/** Mapping between numbers and Ids */
///@{
/// RowId of \p i 'th inequality.
SPxRowId rowId(int i) const
{
return this->rId(i);
}
/// ColId of \p i 'th column.
SPxColId colId(int i) const
{
return this->cId(i);
}
///@}
//------------------------------------
/** Constructors / destructors */
///@{
/// default constructor.
explicit
SPxSolverBase(Type type = LEAVE,
Representation rep = ROW,
Timer::TYPE ttype = Timer::USER_TIME);
// virtual destructor
virtual ~SPxSolverBase();
///@}
//------------------------------------
/** Miscellaneous */
///@{
/// check consistency.
bool isConsistent() const;
///@}
//------------------------------------
/** assignment operator and copy constructor */
///@{
/// assignment operator
SPxSolverBase<R>& operator=(const SPxSolverBase<R>& base);
/// copy constructor
SPxSolverBase(const SPxSolverBase<R>& base);
///@}
void testVecs();
};
//
// Auxiliary functions.
//
/// Pretty-printing of variable status.
template <class R>
std::ostream& operator<<(std::ostream& os,
const typename SPxSolverBase<R>::VarStatus& status);
/// Pretty-printing of solver status.
template <class R>
std::ostream& operator<<(std::ostream& os,
const typename SPxSolverBase<R>::Status& status);
/// Pretty-printing of algorithm.
template <class R>
std::ostream& operator<<(std::ostream& os,
const typename SPxSolverBase<R>::Type& status);
/// Pretty-printing of representation.
template <class R>
std::ostream& operator<<(std::ostream& os,
const typename SPxSolverBase<R>::Representation& status);
/* For Backwards compatibility */
typedef SPxSolverBase<Real> SPxSolver;
} // namespace soplex
// For general templated functions
#include "spxsolver.hpp"
#include "spxsolve.hpp"
#include "changesoplex.hpp"
#include "leave.hpp"
#include "enter.hpp"
#include "spxshift.hpp"
#include "spxbounds.hpp"
#include "spxchangebasis.hpp"
#include "spxvecs.hpp"
#include "spxwritestate.hpp"
#include "spxfileio.hpp"
#include "spxquality.hpp"
#endif // _SPXSOLVER_H_