Invalid solve not detected

97 views
Skip to first unread message

brett king

unread,
Feb 22, 2022, 1:14:14 AM2/22/22
to lp_solve
Hi,

I have been using lpsolve for over 10 years and think it is a wonderful product.  I have recently come across a problem that puzzled me and am hoping someone can shed some light on it.

int initialRetVal = solve(m_lp);

auto saveLp = m_lp;
lprec *swapLp = copy_lp(m_lp);
delete_lp(m_lp);
m_lp = swapLp;

int iRetValAgain = solve(m_lp);

I have a lprec (m_lp) that is updated and resolved thousands of times, most parameters staying the same.  I have found a case where when I solve  initialRetVal comes out 0 (LP_SOLVE_OPTIMAL) but iRetValAgain comes out correctly as 2 (LP_SOLVE_INFEASIBBLE).

I have written out the initial lprec to file (attached at the end of this message) and solved it in the Windows IDE (version 5.5.2.11) and it came out "unsuccessful" which I believe is correct.  

Obviously this memory copy and re-solve doubles my times, a particular problem because I don't know when this will happen so have to do it every time.  I have also tried different presolve options without success.

Seems like something is carrying over, not sure what to reset before I solve again so that it gets the correct result.

Appreciate any ideas.

//* Conc_TPH */

/* Objective function */
max: -12470.403745 C1 +55.1469121153 C7 +2757.04876145 C9 +2726.83339119 C11 +3041.18020573 C13 +391.091200313 C14
+1091.37991643 C15 +2459.89982787 C16 +918.141373107 C17 +2646.97649354 C18 +861.913532795 C19 +2819.99769641 C20
+606.369184718 C21 +3270.46720589 C22 +20517.2918257 C23 +26477.1878865 C24 +109.113471868 C25 +7976.86266849 C26
+703.52192465 C27 +2294.8856559 C28;

/* Constraints */
MaxCapacity_1_Mass: +103.77954703 C1 +0.151025205282 C7 +6.44755453886 C9 +4.80564378001 C11 +4.49737485838 C13 +0.575998994581 C14
+1.37307803509 C15 +3.15864247072 C16 +1.0224638953 C17 +3.00193388106 C18 +0.817584082039 C19 +2.8731057047 C20
+0.550037497535 C21 +2.99551575831 C22 +10.7156908598 C23 +17.2591294437 C24 +0.0404498569293 C25 +3.25158263877 C26
+0.2334028239 C27 +0.762290938835 C28 <= 1000000000;
MaxCapacity_2_M_TPH: +55456.950889 C1 +80.7837417928 C7 +3448.81227005 C9 +2570.55029688 C11 +2405.65651692 C13 +308.103233261 C14
+734.462709331 C15 +1689.56537616 C16 +546.918371383 C17 +1605.74157853 C18 +394.261537865 C19 +1536.83108034 C20
+294.216366694 C21 +1602.30850939 C22 +722.119162844 C23 +7695.17796001 C24 +21.6367247549 C25 +1739.27929327 C26
+124.847726077 C27 +407.751237676 C28 <= 8361.71168762;
MaxCapacity_3_A_TPH: +128.632468726 C1 +100.766128911 C19 +8063.84927347 C23 <= 6633.04130163;
MaxCapacity_4_U_TPH: +8760.00073969 C24 <= 8760;
MaxCapacity_5_T_TPH: 0 C1 <= 0;
MaxCapacity_6_O_TPH: +8883.50612585 C23 <= 8760;
MaxCapacity_7_CON_M_5: +62.8530053073 C24 <= 62.853;
MaxCapacity_8_TOT_R_NI: +8.81984071663 C1 +0.0630990591962 C7 +3.16807416252 C9 +2.97711296137 C11 +3.12314345845 C13 +0.493151323959 C14
+0.806569540214 C15 +2.89276307801 C16 +0.638346966479 C17 +3.00591896319 C18 +0.490277367188 C19 +3.12403449188 C20
+0.361475020603 C21 +3.68977825635 C22 +2.35832303916 C23 +28.9622416577 C24 +0.0276299773792 C25 +6.30566354224 C26
+0.147596995519 C27 +0.864240579848 C28 <= 32.7829043225;
MaxCapacity_9_TOT_CON: +4357.19931515 C1 +6.34305862212 C7 +270.797290644 C9 +201.837038747 C11 +188.889744042 C13 +24.1919577719 C14
+57.6692774784 C15 +132.662983767 C16 +42.9434836032 C17 +126.081223 C18 +33.1308493911 C19 +120.670439586 C20
+23.1015748966 C21 +125.811661851 C22 +303.72833281 C23 +963.09171342 C24 +1.69889399107 C25 +136.566470828 C26
+9.802918604 C27 +32.0162194339 C28 <= 1582.99180328;
MaxCapacity_10_TOT_R_CU: +4.18465490069 C1 +0.0548335514628 C7 +1.86855115537 C9 +1.96093343295 C11 +2.10299850563 C13 +0.375760845481 C14
+0.439041440434 C15 +2.18993137952 C16 +0.355114621555 C17 +2.24773465312 C18 +0.272006871923 C19 +2.31153676623 C20
+0.20155128762 C21 +2.70252049733 C22 +1.10087364253 C23 +20.6988517581 C24 +0.0124637368198 C25 +4.40780016097 C26
+0.0593368881693 C27 +0.537535154776 C28 <= 20.7422697102;
MaxCapacity_11_TOT_POC: +358.874035177 C24 <= 358.874035177;
MaxBinCOGRange_12_CON_M_0: +2 C24 >= 2;
Bin_1: +C1 <= 1;
Bin_2: +C2 <= 1;
Bin_3: +C3 <= 1;
Bin_4: +C4 <= 1;
Bin_5: +C5 <= 1;
Bin_6: +C6 <= 1;
Bin_7: +C7 <= 1;
Bin_8: +C8 <= 1;
Bin_9: +C9 <= 1;
Bin_10: +C10 <= 1;
Bin_11: +C11 <= 1;
Bin_12: +C12 <= 1;
Bin_13: +C13 <= 1;
Bin_14: +C14 <= 1;
Bin_15: +C15 <= 1;
Bin_16: +C16 <= 1;
Bin_17: +C17 <= 1;
Bin_18: +C18 <= 1;
Bin_19: +C19 <= 1;
Bin_20: +C20 <= 1;
Bin_21: +C21 <= 1;
Bin_22: +C22 <= 1;
Bin_23: +C23 <= 1;
Bin_24: +C24 <= 1;
Bin_25: +C25 <= 1;
Bin_26: +C26 <= 1;
Bin_27: +C27 <= 1;
Bin_28: +C28 <= 1;

/* Variable bounds */
C1 <= 1;
C2 <= 1;
C3 <= 1;
C4 <= 1;
C5 <= 1;
C6 <= 1;
C7 <= 1;
C8 <= 1;
C9 <= 1;
C10 <= 1;
C11 <= 1;
C12 <= 1;
C13 <= 1;
C14 <= 1;
C15 <= 1;
C16 <= 1;
C17 <= 1;
C18 <= 1;
C19 <= 1;
C20 <= 1;
C21 <= 1;
C22 <= 1;
C23 <= 1;
C24 <= 1;
C25 <= 1;
C26 <= 1;
C27 <= 1;
C28 <= 1;

brett king

unread,
Feb 23, 2022, 11:51:41 PM2/23/22
to lp_solve
Ok, I know a little more now.  When the initial solution is solved, all the solution variables are 0 except c24 = 1.
This means there are three problem constraints 4, 7 and 12.  If C24=1, then 4 and 7 fail, if c24 is less than 1, then 12 fails.

I have checked the numbers that feed into the matrix and then rh constraints, they are all correct.  Therefore this model should fail, but it initially does not.

How do I reset the solve so it does not get an invalid solution that fails on some of the constraints?

I have also attached the dump of the first and last model models, not sure how to read this though.

Thanks for your help.

S_LP_Dump_last.txt
S_LP_Dump_init.txt

brett king

unread,
Feb 24, 2022, 9:45:37 AM2/24/22
to lp_solve
Resolved:

Have had some joy with the scaling.  If I set scaling to extreme just before I solve it solves properly.  Here is my code:

set_scaling(m_lp, SCALE_EXTREME);
int iRetVal = solve(m_lp);

Thanks for the documentation on scaling algorithms.  Would be good to have some more detail as to which to use when.

Thanks for the great product.

Reply all
Reply to author
Forward
0 new messages