This is an automated email from the ASF dual-hosted git repository.

erans pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-math.git

commit 7be143d11ca393afdb33a6522c8149f4d6f1ff42
Author: Gilles Sadowski <gillese...@gmail.com>
AuthorDate: Mon May 12 17:10:11 2025 +0200

    Add unit test (see MATH-1674).
---
 .../legacy/optim/linear/SimplexSolverTest.java     | 172 +++++++++++++++++++++
 1 file changed, 172 insertions(+)

diff --git 
a/commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/optim/linear/SimplexSolverTest.java
 
b/commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/optim/linear/SimplexSolverTest.java
index cd9277924..cfa3753ad 100644
--- 
a/commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/optim/linear/SimplexSolverTest.java
+++ 
b/commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/optim/linear/SimplexSolverTest.java
@@ -23,6 +23,7 @@ import org.junit.Test;
 import org.junit.Assert;
 
 import org.apache.commons.numbers.core.Precision;
+import org.apache.commons.numbers.core.Sum;
 import org.apache.commons.math4.legacy.exception.DimensionMismatchException;
 import org.apache.commons.math4.legacy.exception.TooManyIterationsException;
 import org.apache.commons.math4.legacy.optim.MaxIter;
@@ -902,4 +903,175 @@ public class SimplexSolverTest {
 
         return true;
     }
+
+    /* See JIRA report: MATH-1674 */
+    @Test
+    public void testMath1674() throws Exception {
+        final double[] c = new double[]{109.8416722130, 3995.2249004467, 
4153.0918625648, 4205.9691060980, 6864.1761563995, 9985.9467230921, 
6354.9344334526, 1460.7566224849, 9404.5575989194, 3074.9619692427, 
6738.9813645788, 4251.4858953042, 3110.4876355988, 4790.6080441726, 
8105.0878555759, 6994.9651570951, 6436.5681652562, 1938.6650475701, 
1991.3366023235, 8807.6044972149, 1319.3678145792, 279.4114357595, 
2406.8106667864, 721.4302264969, 8229.6476579561, 8081.4398910261, 
1120.88748071 [...]
+
+        final double[] d = new double[]{2443.4617219283173, 
1173.9746798742185, 4392.083363038196, 1390.8295640100537, 304.54498814002363, 
3945.528655298191, 3423.0368504289595, 4256.823613052879, 821.3597860392124, 
2451.720430980302, 4458.615770028524, 4566.059436861297, 2823.6879242564887, 
543.3702798436418, 1077.6404845531451, 4032.1898198315507, 2692.8144489810506, 
3224.220920651318, 1027.2527158190137, 4185.736937549958, 3991.8068663807326, 
3532.2224429213907, 4536.16351791805, 3366 [...]
+
+        final int nCoef = 43;
+        final List<LinearConstraint> constraints = new 
ArrayList<LinearConstraint>() {
+            {
+                add(new LinearConstraint(new double[]{-18.4721096232, 
-346.7827878415, 190.4497509093, -330.1702770265, 448.8851105324, 
-324.7721331591, -41.4894142939, 398.1964809931, 463.1362097737, 
-381.3526533422, -474.7408449269, 462.4340720610, -466.1439468990, 
415.9941329301, -229.7720934493, -480.0419990356, -359.8361731590, 
-229.0774350493, 382.3688199190, 235.7328265513, -169.4850416538, 
41.1742463794, -136.9424841461, -274.6086332855, 72.8639834681, 360.1892515767, 
-442.379394 [...]
+                add(new LinearConstraint(new double[]{-142.0218156776, 
-325.6755905771, 325.9103281986, 425.5525979901, -100.8818306524, 
359.9526168657, 19.8640958157, 101.0496674864, 72.5794388944, 343.8017139721, 
-417.7203389850, -276.8717066617, 482.6350083618, 282.4425554939, 
111.3131183011, -408.8982090277, -208.5374729647, -103.7724850339, 
-272.2678819564, -19.1039841475, -402.7216612885, 134.3300718162, 
343.1853280760, 20.6322270365, -199.8831750852, 414.1073518711, 498.4687409141 
[...]
+                add(new LinearConstraint(new double[]{280.5264359768, 
-440.9029839729, 254.2293245718, 211.6627419456, 254.8057819197, 
-60.6178062887, -269.6717804385, -362.1205618329, 108.4787074840, 
-145.5803917982, 294.5542177837, -123.4965247386, -272.5995474795, 
-331.6065661963, -108.8823485644, -91.2369235269, -460.2851164778, 
5.2095309814, -19.9563858245, -108.6507009265, 158.3232789187, 365.4537468646, 
-331.4843842776, -374.9844223849, 135.9679065769, -138.6563987535, 294.5099191 
[...]
+                add(new LinearConstraint(new double[]{-177.4894743518, 
-67.9908085983, -222.8973447862, -237.2123374249, -329.8409313977, 
465.4735911581, 174.3300783257, -471.3072404862, -41.3462072806, 
482.3935826175, -371.7462653377, -91.0188575698, -339.6122496783, 
-301.1754391495, 314.0294251084, 239.2963702057, -379.1406195440, 
-470.4083935254, 298.1063991917, 494.0195860421, -190.1331973394, 
-41.1672631643, 473.2276495541, 499.6494985034, -83.2682883237, 248.9637912508, 
-112.415222 [...]
+                add(new LinearConstraint(new double[]{106.6565294021, 
-371.1818345738, -95.9586185145, 201.7415424771, -325.7385298650, 
54.3236171225, 444.9441819132, 336.9488035905, -394.1983141613, 374.4370581817, 
60.7546944337, -394.6167862437, 143.3976341525, -205.2879276325, 
371.1235081032, -256.5487760721, -496.4337469161, -27.1136131757, 
48.7711410535, 73.2036734543, -153.8197644177, -267.2379241177, 247.7506005761, 
259.7210844013, -355.9332501729, 482.4437633829, 146.0490189775,  [...]
+                add(new LinearConstraint(new double[]{-2.8370631388, 
413.6772809576, 271.6209399819, 150.6847226997, -276.2750537300, 
-472.7076574957, -449.4708229028, -331.1752705878, -16.4346414648, 
227.3535295815, 385.7658282909, 23.9202552069, -336.1712375444, 312.2294103332, 
-382.0329537481, -361.2778235142, -135.7536208646, -378.2927678121, 
-236.5567268759, -425.3073778324, 363.7978938321, 128.2982924008, 
280.5832475304, -63.6683731926, 88.5682601884, 213.0955504480, -332.148376272 
[...]
+                add(new LinearConstraint(new double[]{164.1118381892, 
-52.6929605099, -368.6998544699, -418.3014942408, 296.7708341063, 
-50.9112446279, -274.4635428920, 290.7114646211, 415.1951631117, 
133.5554583795, 333.4237188449, -136.2679881845, 142.7917138379, 
-20.8839686666, 409.6354488447, 330.3312796033, -31.7995014119, 121.0518940942, 
-418.2605909000, -237.3828464293, -433.2546692557, 454.9218185770, 
-338.8542143359, 389.3988225528, -13.6699375994, -12.2794719274, -81.2763486384 
[...]
+                add(new LinearConstraint(new double[]{-374.5989502169, 
-151.5219749339, 14.4226309306, 357.9162462609, 320.4530835626, -9.9657806960, 
175.0012462657, 10.4166342802, 331.7943741048, -482.2409478442, 174.5166172026, 
-466.4563945960, 216.3188631720, 131.6031294907, -379.5023819223, 
451.2426649663, -379.3032893924, -91.8425766315, -213.0011901317, 
169.9988024655, 298.0983224083, 307.6672326004, 244.2684429396, 481.9466025513, 
-165.9399747057, 43.7599328801, -379.2696061729, - [...]
+                add(new LinearConstraint(new double[]{-45.6010907457, 
-93.1186154639, 344.1452758225, -164.7021085866, 211.9989950393, 
-88.2105531379, 349.6093606232, -457.2528562809, 362.6473587699, 
-325.8981255598, 451.6277474446, 461.4458321371, 112.4424937334, 
-60.1455726789, -243.7897271852, 139.3033364843, 59.7717060692, 340.3445860842, 
-175.5114719859, 427.9375810690, -362.5584153005, -392.6491442968, 
169.3034533287, 326.2992816507, 308.8415883739, -213.4668189361, 
-94.9276060888, [...]
+                add(new LinearConstraint(new double[]{393.2818734855, 
-59.9684286941, 393.9213867728, 32.8295448441, -226.7491721961, 66.6514348656, 
-115.6339927551, -125.9102951498, 254.3870965919, 160.0007056159, 
-77.6267544076, -363.9964465444, 17.4209317152, 213.1998112124, 213.9941112423, 
486.0501401269, 339.3093011083, 411.8412558021, -51.9764095515, 321.0616644466, 
-13.1955403123, 431.3457104075, 187.9806816005, -168.3585282637, 
-172.1079346745, 357.2251367606, 310.4036063770, -3. [...]
+                add(new LinearConstraint(new double[]{132.5220276415, 
440.1671576721, 90.7991473280, -264.6244963333, -396.0509121443, 
110.0967219182, 338.7752165862, -346.6980624342, -91.2336832963, 
268.8865198452, -288.9586214274, -462.1588724540, 63.6505937154, -1.4895284824, 
264.6480042052, 416.9179370121, 396.4575432613, 232.8937855657, 364.3567255559, 
398.3101731718, 119.4078490950, -263.0757611444, -314.9907213011, 
420.1008257886, 221.6753537232, 291.1031647740, 244.0677935138, 40 [...]
+                add(new LinearConstraint(new double[]{-493.7498617776, 
29.1857671258, 229.1786073483, 468.6054596725, -404.8935838125, 
-345.4323724601, -149.9280647907, -132.3267396818, 130.5546682526, 
-11.4750580288, -455.1759579289, -491.4502441971, -220.1900416600, 
25.8838812341, 115.8896600822, 306.5296351717, 111.7035182752, -58.4538224941, 
437.0742082521, 168.3155804046, 186.0652931382, 232.5090487205, 
-125.9388483588, 134.9560728616, 420.4855085864, 75.0159006362, 28.5373053316, 
- [...]
+                add(new LinearConstraint(new double[]{-188.7727375378, 
-169.5310846918, -303.1966255195, -420.6353176520, 427.9785158873, 
-160.4309006280, -246.5688251870, -487.0911467043, 447.5917412607, 
254.9497948505, -200.5372457354, 210.2059120451, 20.5382986122, 115.3781090026, 
171.4941603184, 395.4433421053, 252.9327094737, 434.2868305895, 172.8683199242, 
-172.4028689434, -336.6616706437, 24.2428933749, 219.1541938549, 
439.7675158718, 450.1245649666, 441.5451577749, 128.9705980594 [...]
+                add(new LinearConstraint(new double[]{-116.0840969613, 
176.0236541893, 319.6460134129, -332.4496729070, -162.8534030284, 
258.9631354848, 134.2117958037, 135.0363468297, -395.7159912184, 
-65.8914562081, -103.4843857136, 153.9867048455, 38.4610292899, -63.1456218390, 
324.3346573466, -443.8217892205, 246.5575463718, 236.3333822714, 
-157.0614570239, 107.4725395850, -314.4456320591, 256.1089122557, 
-332.4131320816, -198.8265393365, -103.4433478021, 484.2534406266, -399.8115573 
[...]
+                add(new LinearConstraint(new double[]{465.6494664987, 
-404.3123086097, 405.9785929502, 347.0026855289, -302.0163191133, 
-129.0812589156, 157.1747559572, 9.8292205414, 37.8410472448, -195.8621494638, 
380.5833324032, 320.3120288624, 475.6303813355, 12.0577469801, -186.1876464245, 
156.5349153410, 239.3078932632, -14.3540460805, 190.9073870661, 182.0399993664, 
129.5530061776, -228.5973253467, -214.5424452754, -339.2096651463, 
332.4271343461, 144.2893275872, 202.5009517364, 32 [...]
+                add(new LinearConstraint(new double[]{-249.8432963461, 
-217.7849574530, 12.3034711862, -236.8850653427, -230.7155653959, 
-80.7044507171, -133.7508175074, 331.7872335009, -176.6951583506, 
-129.2412996213, -240.2837832926, -344.3605421425, -365.5413408480, 
-436.1143117092, -160.7044330882, -312.8271801157, -96.4663415211, 
376.8298702529, 246.0187570979, -345.2216189795, 216.5346454118, 
-148.3221086008, 360.4359107405, -366.8996766400, 0.0947974934, 303.1834360606, 
15.700736 [...]
+                add(new LinearConstraint(new double[]{340.7055228332, 
191.8798668704, -135.0489137154, 463.8107893025, 161.0968896351, 
-482.6906410608, -34.1980892000, 109.9085785902, 218.9331519377, 
-373.3997050356, -84.1441046371, -287.5170643603, 439.9782716428, 
-247.6349478722, -248.9294670748, 458.1003519812, -103.1223569766, 
1.9089360083, 296.5206574938, 435.2583333115, 259.6428436210, 336.3578139309, 
478.8353594909, -283.5946369464, 316.3314266572, -380.0116485730, 
-270.8298407000 [...]
+                add(new LinearConstraint(new double[]{145.8881914948, 
124.8061001421, -248.9645583668, 108.2343762982, 305.8011956353, 
385.1484851277, -119.5009175183, -488.5656924659, 57.7562949402, 
362.3320918154, -415.4507553431, -100.5784807509, 25.7717362478, -9.8221916581, 
238.9395515691, 25.1813044978, -186.0652536901, 334.5209746453, 83.0152234813, 
-169.8475027125, -481.0800111064, -107.9749706700, 495.1694950281, 
-27.1285807549, -496.8979386883, 372.9855408050, 103.4333981728, - [...]
+                add(new LinearConstraint(new double[]{-486.4217021206, 
-467.4490173170, 41.0900266896, 103.9422087749, 387.2392464598, 292.7796831550, 
145.7313685349, 157.4409248006, -185.8660567480, 353.3043774206, 64.3042477644, 
-273.1899508685, -134.8286387832, 402.6464433744, -494.0153046113, 
82.9544117496, -136.9788148143, 132.4070889074, -254.8062230479, 
404.1786805838, -72.9666378284, -115.0278473496, -307.7428332974, 
-478.6171283368, -143.1537562050, -92.9968689006, 384.617015821 [...]
+                add(new LinearConstraint(new double[]{141.8470098609, 
422.5408670808, -176.9100253797, -411.4176239018, -171.7938138004, 
37.5031194482, -95.7931411206, 355.6019584141, 225.8970424648, -320.0327557650, 
-54.1596611246, 71.5984121408, -172.6627075340, 87.9104795122, -48.8516985530, 
354.0093508783, 365.4353693460, -219.8627584674, 497.7557289404, 
116.8044222239, -280.3232022783, 213.9164831062, -221.4252863134, 
-206.6283997286, -154.5608039830, -153.0413536323, -291.834275565 [...]
+                add(new LinearConstraint(new double[]{13.6344526147, 
-430.2218606986, -86.3007778471, 215.9913073246, -449.1268043093, 
282.8860958719, -23.3009920749, 455.6349608322, -126.8330404790, 
-406.3412165528, 250.1188941470, -158.8879782875, 464.5794182879, 
-357.4048514455, 389.1640065078, -482.1430031973, -492.4002036851, 
-440.1657336644, 422.4442494437, -90.5125580096, -256.1894835548, 
-418.1476420800, -313.0643816691, -173.0191705691, 367.5185154660, 
16.5608190357, -248.207998 [...]
+                add(new LinearConstraint(new double[]{-221.2703728708, 
305.8079968772, -232.5360219037, -30.6660630025, 307.7180579448, 
301.5253755327, -363.9309876951, 431.8956707468, 104.2025672231, 
-288.5766197206, -68.5778302327, 490.8409110829, 232.7972812415, 
446.5946012489, 310.0052570196, 453.6780063108, -421.7687109338, 
-477.7708337208, 143.0133933409, 305.9213452138, 424.9100139475, 26.8344849484, 
424.7117281805, -81.1305887899, 123.1212461885, -1.8247376875, 90.0221648059, 
-14 [...]
+                add(new LinearConstraint(new double[]{-347.8798681921, 
433.2547339785, 28.3068486031, -294.6418390485, 432.2986500266, 
-401.3417089841, -156.4340855726, 435.2761706826, 156.6331926853, 
-85.6589288282, 237.8817393927, -354.7696577597, 211.1695225080, 
447.6613692970, 122.4007804501, 21.5281667458, 193.1944285200, -466.2991180177, 
498.5751746066, -305.7987023452, 51.1524484454, 91.0564660002, -19.3079106949, 
215.6568427847, 127.5825854718, 485.6789848089, -136.1663991063, 11 [...]
+                add(new LinearConstraint(new double[]{12.0308357297, 
-188.6931051284, 160.0585557805, 334.0301149052, -120.2884648549, 
-453.0365554161, 305.0394912124, 413.0095655502, 249.1934459322, 
-366.5801283780, -73.2596367387, -416.8385206607, 220.2318954615, 
-347.6853204405, -262.9005740040, 275.5248594729, -250.0487508415, 
197.0237107974, -351.8429991368, -214.9799529653, 177.9766275429, 
-214.0910789289, -482.6910404890, -191.5443244343, -47.5935584928, 
16.6988004821, -491.239304 [...]
+                add(new LinearConstraint(new double[]{463.9782865378, 
-126.6486051866, 253.8972455705, 456.7618479127, 415.8361825765, 
-465.0383387450, 272.0841775369, -29.8215509600, -185.4161739495, 
235.4225596403, -194.7358004314, -418.7448656171, 39.2417242699, 
214.1505343552, 225.4494150021, 390.2341333030, -438.4724106572, 
-315.6336145987, 325.4333140158, 283.9492469810, -429.2890407892, 
-492.2283591102, 269.3426146368, -405.8680128690, 297.3249121927, 
323.9495763785, 383.480181796 [...]
+                add(new LinearConstraint(new double[]{188.9257485555, 
272.5268019012, -259.5519682499, -75.8615756160, 272.4730575255, 
-277.7514160796, -450.7342886472, 440.6704977995, -91.6615770407, 
468.0700465229, -489.3954296181, 58.3279198187, -305.7668603846, 
-86.0437229621, -362.5097958901, -312.0769221290, -203.3252187779, 
80.6563658348, 217.4777865005, 78.5573371277, 185.9710314276, 275.1148656604, 
-268.6496121358, -414.1188165050, -12.9774811366, 417.4577469666, 
208.2690645451, [...]
+                add(new LinearConstraint(new double[]{-85.8687748877, 
4.2866019774, 332.9282018899, 130.4965975233, -487.7587740016, 304.3601910921, 
-326.5363481386, -351.9809978115, 161.5894532992, 389.8842749749, 
-146.9578838012, 133.2748206289, -472.5734364921, -51.8966578050, 
381.1376502468, -20.4623150699, 498.4128551706, -386.2557553740, 
-334.9846623673, 222.5596586537, 244.2865603186, 92.0550239172, 
-154.0527643120, 493.4006464464, 444.0077821058, -399.7233232370, 
258.8613065029,  [...]
+                add(new LinearConstraint(new double[]{-165.4610208114, 
-272.8673269503, 95.1065522642, -62.0970032526, -257.3904625958, 
218.3933904669, -295.0026988705, 68.0122555113, 447.3756582877, 
-105.4973528261, 426.9281350106, -403.6524478942, -33.3374469519, 
282.5119139621, -149.8238318635, -23.7882902065, -432.6005384292, 
144.8723920407, 74.0360540432, -300.6076989795, 466.9255532098, 
-103.1698585205, 3.6982980633, 249.3869152583, 115.8737912550, -70.1297524579, 
266.1121820306, 3 [...]
+                add(new LinearConstraint(new double[]{270.5724382583, 
-406.4988392858, 63.9777726576, -83.9757497260, -317.3069976318, 
467.5735196577, -487.4160328535, 55.1503666330, -299.3504473227, 
-157.3822423827, -457.7287120636, 400.2436070455, -409.7111466599, 
389.0511036653, 243.6541940028, -209.1931022834, -320.4238689057, 
-491.2270033800, -410.2341330665, 366.5463565205, 39.1404787022, 
425.7313453473, -267.2328225376, -265.7203077591, 230.6958326120, 
165.6613751134, -54.48787736 [...]
+                add(new LinearConstraint(new double[]{-225.0552145496, 
-287.6486377011, 361.9359651763, 97.0778700799, 419.4533904019, 
-291.2187105377, -154.6878420434, 463.9737670023, 71.3965213493, 
-63.2346321950, -152.6995263051, -397.3838145546, 228.4367762832, 
-40.4404708024, -257.0875923825, -469.5687419976, -340.6980127574, 
-272.7089885922, -286.1283239265, -380.3054802799, -179.9298500970, 
413.8462372493, -7.4045028631, 245.1208036947, -381.4268211483, -9.6870957478, 
22.974459575 [...]
+                add(new LinearConstraint(new double[]{-203.3890862894, 
393.3298897887, 206.8640763352, -323.5031125266, -8.2981037655, 431.6221385110, 
-135.3047880709, 383.9831112191, -201.7137526731, -184.9955070618, 
298.4674373312, 235.5602111346, 455.8810051491, 189.7404655446, 404.8564628007, 
-318.9240371565, -150.3078817866, -226.2529652858, -355.5886328972, 
172.0873685962, -253.7121139709, -136.4591911698, -9.2268152600, 
267.0911562624, 170.3292586792, 258.1279391526, -465.54535001 [...]
+                add(new LinearConstraint(new double[]{-125.7580404843, 
-430.5476869122, -329.0613636976, 40.1374649634, 210.8081351842, 
-39.0593159812, 158.5027355167, -186.6851309429, -132.9648560098, 
399.1037012553, 389.2355847304, -159.6746583063, -85.3152842872, 
441.0068832093, 291.2195051827, 404.4582529847, -488.8638682516, 
437.3265032213, 185.4221129909, -80.1081843261, 271.4949277850, 
-360.0731753511, 415.8907807194, -162.2654487960, -193.8576068637, 
208.5276888386, 56.8409894288 [...]
+                add(new LinearConstraint(new double[]{-335.3874998383, 
261.0643845250, 450.0822398726, 167.8034923491, 366.2790764480, 
-363.2458727582, -424.5487890416, -78.4667458203, -336.8342393925, 
311.1677312205, -227.3657297988, 386.9519592152, 456.5898757790, 
-477.0788326502, 483.4418332745, 4.8518006798, 236.9799597504, -72.3988066645, 
109.1731546473, 158.0899552529, 49.1156888434, 399.6315231994, -78.4512341685, 
244.0717950758, -402.6127611954, -14.1152206841, 376.1898497261, -4 [...]
+                add(new LinearConstraint(new double[]{-86.9529570658, 
-371.5839802671, 285.8791340642, -149.4422777221, -327.6220773493, 
-133.6021443615, -494.0328902263, 95.8435798960, 443.1076797193, 
169.7091748018, -395.0593709913, -1.2785607051, 115.6199464662, 492.1958703537, 
-268.5717076358, -319.8677407108, -197.8881332917, 168.8595663312, 
-141.0083485838, 424.2511432258, -102.4408467105, -174.9926235520, 
-392.1690034058, -38.2454431156, -75.7754136456, 429.0603907112, -83.2386679 
[...]
+                add(new LinearConstraint(new double[]{-256.4188442794, 
63.5007620009, 30.4016501694, 265.7341655379, -11.2880623399, 303.2475486454, 
489.1189626257, 227.7278044205, -469.4085739882, -208.0096822630, 
98.9836017650, 320.2575788229, 410.6207487201, -263.7096465920, 
-448.1732437602, 246.4601949270, -244.2983761690, 262.2426725155, 
454.2038335871, -21.0638973699, 389.6687856423, 320.4896124659, 126.4323944809, 
-366.8965002794, 259.4855069591, -65.1859884224, 40.4438917805, -22 [...]
+                add(new LinearConstraint(new double[]{385.7499254679, 
-106.1156520446, -338.2215805749, 278.7619196076, 493.2249994649, 
184.7021581775, 249.4478702989, -321.5514436648, -302.9548096880, 
-235.9697597976, -94.5516946672, -494.1891830186, 435.4722205151, 
200.4605623382, -372.3961441281, -180.0303686322, 433.5991047879, 
340.7530583419, 401.1156554556, 381.6868263631, 178.3907523687, 
-268.8705791913, -115.7358399012, 487.3202383376, 346.1528285485, 
258.8247361338, 81.039360022 [...]
+                add(new LinearConstraint(new double[]{-337.0754411150, 
-387.9340132320, -155.5320445811, 384.8558239556, -399.7105721507, 
-140.8179819806, 459.8081490899, 62.0625106321, 205.2121448091, 492.9925746017, 
39.1908121635, -339.2970905850, -378.5376221934, -73.3124231363, 
365.5767483564, 451.5252733552, -101.0929833532, 8.0238483958, 325.0904042270, 
-209.4983869589, 409.9485815752, 265.4013455721, -362.2579016841, 
-68.6416118345, 181.2517624779, 396.3834743795, -298.4873050824, [...]
+                add(new LinearConstraint(new double[]{243.8753390356, 
103.4862849448, -116.9158032348, 466.3247096751, 499.5986526032, 
-252.2824865913, -312.5367716984, 403.5304480620, 484.4633991129, 
-271.2596467681, 134.9567317240, 144.1043902127, -48.1780194039, 
-398.7675789703, 442.1928392672, 442.0571022678, -379.0001193017, 
-263.6942507953, -81.3363570672, -499.6106779009, 283.8197034492, 
-354.7963291225, -443.9033506746, 83.8841241656, 333.2182699209, 
181.8856633708, -145.30666112 [...]
+                add(new LinearConstraint(new double[]{-195.2525091291, 
124.6164685994, 142.2529075985, -477.3068630553, 243.3206763086, 
420.2732330804, 110.5645014077, 367.2052647911, 364.2898604480, 
-367.8364205570, -146.9700144933, 435.2628643210, -227.3233170539, 
-445.3661537393, 110.2318148145, -483.8240432172, 473.7692273932, 2.4503243312, 
-350.7318584021, -156.9568651290, -4.4326087363, -434.4594714911, 
-413.0736422843, -212.5480399317, -297.1774311119, -37.9253435334, 289.04835624 
[...]
+                add(new LinearConstraint(new double[]{-137.1060743081, 
279.6329315315, 197.3614426922, 231.0282557735, 329.4796472661, 120.2733855944, 
-309.2265599218, 107.4259103756, 219.2138952115, -222.5437382016, 
260.2204436622, 277.9954539704, 177.6811137083, -376.2132665340, 
-49.7624030384, 200.7196035517, -126.8671496466, -437.2623440818, 
487.5248981135, -105.1313845705, -55.9105668208, -175.3045917568, 
-319.1513855364, 115.4667856060, -110.5180904036, -367.4444001026, 171.0296400 
[...]
+                add(new LinearConstraint(new double[]{127.0166849936, 
-39.9971042887, 142.1963182879, -387.1917959935, 218.7910108044, 
-57.1357601804, -444.8295072288, -131.8607936123, 273.8698310927, 3.8399496330, 
-14.7678782657, -450.2963339389, 245.3568401422, 470.3088588205, 
-369.6297342137, -357.4266406943, -418.1459895424, 108.2172398166, 
-296.8111920535, 484.5465096126, 199.1026172884, -17.2247008036, 
124.4850638710, -409.3014982622, -154.6942161832, 480.4208008286, 
-5.8688799011, [...]
+                add(new LinearConstraint(new double[]{-240.1730204728, 
145.8755080635, -390.6533731249, 221.3641193784, 180.1835036666, 
-36.7301979877, 376.7267957101, -247.5819297289, -318.7404862535, 
-220.6995059742, -110.1632353235, -248.6352397960, 178.6644482658, 
352.7239680226, 87.0009102021, -293.4444288458, -113.5264103255, 
-398.1989347949, -469.2797383338, -245.9939275934, -192.3102234512, 
122.3259048952, -107.8486033723, 251.0609758784, 488.4733740424, 
-352.1025724146, -487.826 [...]
+                add(new LinearConstraint(new double[]{-30.0588147584, 
-378.5051316986, 157.8835245521, 120.3731377987, 286.9986665802, 
-78.8326674476, -452.5024927606, 95.4389515886, -179.8024252018, 
-295.2742472052, -91.5899174779, 183.8988891394, -364.4023093951, 
-27.9401916913, 355.7553534234, -480.6474695409, 496.6670478137, 
-123.3317858105, 230.0870951978, 8.1301750386, -429.5056130047, 219.2877390926, 
-443.4958157674, 336.0622027617, 405.5518207904, -377.2516937227, 
-29.5291171888, [...]
+                add(equationFromString(nCoef, "x0 <= 10"));
+                add(equationFromString(nCoef, "x0 >= -10"));
+                add(equationFromString(nCoef, "x1 <= 10"));
+                add(equationFromString(nCoef, "x1 >= -10"));
+                add(equationFromString(nCoef, "x2 <= 10"));
+                add(equationFromString(nCoef, "x2 >= -10"));
+                add(equationFromString(nCoef, "x3 <= 10"));
+                add(equationFromString(nCoef, "x3 >= -10"));
+                add(equationFromString(nCoef, "x4 <= 10"));
+                add(equationFromString(nCoef, "x4 >= -10"));
+                add(equationFromString(nCoef, "x5 <= 10"));
+                add(equationFromString(nCoef, "x5 >= -10"));
+                add(equationFromString(nCoef, "x6 <= 10"));
+                add(equationFromString(nCoef, "x6 >= -10"));
+                add(equationFromString(nCoef, "x7 <= 10"));
+                add(equationFromString(nCoef, "x7 >= -10"));
+                add(equationFromString(nCoef, "x8 <= 10"));
+                add(equationFromString(nCoef, "x8 >= -10"));
+                add(equationFromString(nCoef, "x9 <= 10"));
+                add(equationFromString(nCoef, "x9 >= -10"));
+                add(equationFromString(nCoef, "x10 <= 10"));
+                add(equationFromString(nCoef, "x10 >= -10"));
+                add(equationFromString(nCoef, "x11 <= 10"));
+                add(equationFromString(nCoef, "x11 >= -10"));
+                add(equationFromString(nCoef, "x12 <= 10"));
+                add(equationFromString(nCoef, "x12 >= -10"));
+                add(equationFromString(nCoef, "x13 <= 10"));
+                add(equationFromString(nCoef, "x13 >= -10"));
+                add(equationFromString(nCoef, "x14 <= 10"));
+                add(equationFromString(nCoef, "x14 >= -10"));
+                add(equationFromString(nCoef, "x15 <= 10"));
+                add(equationFromString(nCoef, "x15 >= -10"));
+                add(equationFromString(nCoef, "x16 <= 10"));
+                add(equationFromString(nCoef, "x16 >= -10"));
+                add(equationFromString(nCoef, "x17 <= 10"));
+                add(equationFromString(nCoef, "x17 >= -10"));
+                add(equationFromString(nCoef, "x18 <= 10"));
+                add(equationFromString(nCoef, "x18 >= -10"));
+                add(equationFromString(nCoef, "x19 <= 10"));
+                add(equationFromString(nCoef, "x19 >= -10"));
+                add(equationFromString(nCoef, "x20 <= 10"));
+                add(equationFromString(nCoef, "x20 >= -10"));
+                add(equationFromString(nCoef, "x21 <= 10"));
+                add(equationFromString(nCoef, "x21 >= -10"));
+                add(equationFromString(nCoef, "x22 <= 10"));
+                add(equationFromString(nCoef, "x22 >= -10"));
+                add(equationFromString(nCoef, "x23 <= 10"));
+                add(equationFromString(nCoef, "x23 >= -10"));
+                add(equationFromString(nCoef, "x24 <= 10"));
+                add(equationFromString(nCoef, "x24 >= -10"));
+                add(equationFromString(nCoef, "x25 <= 10"));
+                add(equationFromString(nCoef, "x25 >= -10"));
+                add(equationFromString(nCoef, "x26 <= 10"));
+                add(equationFromString(nCoef, "x26 >= -10"));
+                add(equationFromString(nCoef, "x27 <= 10"));
+                add(equationFromString(nCoef, "x27 >= -10"));
+                add(equationFromString(nCoef, "x28 <= 10"));
+                add(equationFromString(nCoef, "x28 >= -10"));
+                add(equationFromString(nCoef, "x29 <= 10"));
+                add(equationFromString(nCoef, "x29 >= -10"));
+                add(equationFromString(nCoef, "x30 <= 10"));
+                add(equationFromString(nCoef, "x30 >= -10"));
+                add(equationFromString(nCoef, "x31 <= 10"));
+                add(equationFromString(nCoef, "x31 >= -10"));
+                add(equationFromString(nCoef, "x32 <= 10"));
+                add(equationFromString(nCoef, "x32 >= -10"));
+                add(equationFromString(nCoef, "x33 <= 10"));
+                add(equationFromString(nCoef, "x33 >= -10"));
+                add(equationFromString(nCoef, "x34 <= 10"));
+                add(equationFromString(nCoef, "x34 >= -10"));
+                add(equationFromString(nCoef, "x35 <= 10"));
+                add(equationFromString(nCoef, "x35 >= -10"));
+                add(equationFromString(nCoef, "x36 <= 10"));
+                add(equationFromString(nCoef, "x36 >= -10"));
+                add(equationFromString(nCoef, "x37 <= 10"));
+                add(equationFromString(nCoef, "x37 >= -10"));
+                add(equationFromString(nCoef, "x38 <= 10"));
+                add(equationFromString(nCoef, "x38 >= -10"));
+                add(equationFromString(nCoef, "x39 <= 10"));
+                add(equationFromString(nCoef, "x39 >= -10"));
+                add(equationFromString(nCoef, "x40 <= 10"));
+                add(equationFromString(nCoef, "x40 >= -10"));
+                add(equationFromString(nCoef, "x41 <= 10"));
+                add(equationFromString(nCoef, "x41 >= -10"));
+                add(equationFromString(nCoef, "x42 <= 10"));
+                add(equationFromString(nCoef, "x42 >= -10"));
+            }};
+
+        final PointValuePair resultOriginal = solve(c, constraints);
+        final double z1 = resultOriginal.getValue();
+        System.out.println("z1=" + z1); // XXX REMOVE
+
+        final List<LinearConstraint> shiftedConstraints = new ArrayList<>();
+        for (LinearConstraint cons : constraints) {
+            final double[] coeffs = cons.getCoefficients().toArray();
+            final double rhs = cons.getValue() + Sum.ofProducts(coeffs, 
d).getAsDouble();
+            shiftedConstraints.add(new LinearConstraint(coeffs, 
cons.getRelationship(), rhs));
+        }
+
+        final PointValuePair resultShifted = solve(c, shiftedConstraints);
+        final double z2 = resultShifted.getValue();
+
+        final double z1New = z2 - Sum.ofProducts(c, d).getAsDouble();
+        Assert.assertEquals("MR violated", z1, z1New, 1e-4);
+    }
+
+    private static PointValuePair solve(double[] c,
+                                        Collection<LinearConstraint> 
constraints)
+        throws Exception {
+        final LinearObjectiveFunction f = new LinearObjectiveFunction(c, 0);
+        final double epsilon = 1e-5; // Fails at 1e-6.
+        final SimplexSolver solver = new SimplexSolver(epsilon);
+        return solver.optimize(new MaxIter(1000),
+                               f,
+                               new LinearConstraintSet(constraints),
+                               GoalType.MAXIMIZE);
+    }
 }

Reply via email to