@@ -255,46 +255,73 @@ def main():
255
255
# Step 4: Run ILP weight calculation
256
256
print ("STEP 4: Running ILP weight calculation" )
257
257
258
+ # Define output file for ILP weights
259
+ ilp_weights_path = os .path .join (args .output_dir , f"ilp_weights_{ args .base_size } _{ args .query_size } .txt" )
260
+
258
261
if not ensure_executable_exists (ilp_script , "ilp.py" ):
259
262
print ("⚠ ILP script not found, skipping weight calculation" )
260
263
print ("You can run ILP manually later using the generated ground truth files" )
264
+ ilp_result = None
261
265
else :
262
266
ilp_cmd = [
263
267
sys .executable ,
264
268
ilp_script ,
265
269
unfiltered_gt_path ,
266
270
filtered_gt_path ,
267
- # Note: match scores file not available, ILP script will work without it
271
+ unfiltered_match_scores_path ,
268
272
"--method" , "pulp" , # Start with simple pulp method
269
273
"--eps" , "0.001"
270
274
]
271
275
272
276
if args .norm_factors :
273
277
ilp_cmd .extend (["--norm_factors" , args .norm_factors ])
274
278
275
- result = run_command (ilp_cmd , "ILP weight calculation" )
276
- if result is None :
279
+ ilp_result = run_command (ilp_cmd , "ILP weight calculation" )
280
+ if ilp_result is None :
277
281
print ("ILP weight calculation failed. Trying with different parameters..." )
278
282
279
283
# Try with PuLP method if ratio fails
280
284
ilp_cmd_pulp = ilp_cmd .copy ()
281
285
try :
282
286
ilp_cmd_pulp [ilp_cmd_pulp .index ("ratio" )] = "pulp"
283
- result = run_command (ilp_cmd_pulp , "ILP weight calculation (PuLP method)" )
287
+ ilp_result = run_command (ilp_cmd_pulp , "ILP weight calculation (PuLP method)" )
284
288
except ValueError :
285
289
# "ratio" not in list, already using pulp
286
290
print ("Already using PuLP method, trying with different epsilon..." )
287
291
ilp_cmd_eps = ilp_cmd .copy ()
288
292
ilp_cmd_eps [ilp_cmd_eps .index ("0.001" )] = "0.01"
289
- result = run_command (ilp_cmd_eps , "ILP weight calculation (larger epsilon)" )
293
+ ilp_result = run_command (ilp_cmd_eps , "ILP weight calculation (larger epsilon)" )
290
294
291
- if result is None :
295
+ if ilp_result is None :
292
296
print ("⚠ All ILP methods failed. Check your data and try manually." )
293
297
print ("Ground truth files are ready for manual ILP execution:" )
294
298
print (f" Unfiltered GT: { unfiltered_gt_path } " )
295
299
print (f" Filtered GT: { filtered_gt_path } " )
296
300
else :
297
301
print ("✓ ILP weight calculation completed successfully!" )
302
+ # Save the ILP output to a file since the script doesn't support --output
303
+ print ("⚠ Saving ILP output manually..." )
304
+ with open (ilp_weights_path , 'w' ) as f :
305
+ f .write ("ILP Weight Calculation Results\n " )
306
+ f .write ("=" * 40 + "\n \n " )
307
+ f .write ("STDOUT:\n " )
308
+ f .write (ilp_result .stdout )
309
+ f .write ("\n \n STDERR:\n " )
310
+ f .write (ilp_result .stderr )
311
+ f .write (f"\n \n Generated at: { __import__ ('datetime' ).datetime .now ()} \n " )
312
+ print (f"✓ ILP output saved to: { ilp_weights_path } " )
313
+
314
+ # Extract w_m weight and save to separate file
315
+ import re
316
+ w_m_match = re .search (r'w_m = ([\d.]+)' , ilp_result .stdout )
317
+ if w_m_match :
318
+ w_m_value = w_m_match .group (1 )
319
+ w_m_file = os .path .join (args .output_dir , "w_m_weight.txt" )
320
+ with open (w_m_file , 'w' ) as f :
321
+ f .write (w_m_value )
322
+ print (f"✓ w_m weight ({ w_m_value } ) saved to: { w_m_file } " )
323
+ else :
324
+ print ("⚠ Could not extract w_m value from ILP output" )
298
325
299
326
# Save results summary
300
327
summary_path = os .path .join (args .output_dir , "pipeline_summary.txt" )
@@ -316,10 +343,15 @@ def main():
316
343
f .write (f" Filtered GT: { filtered_gt_path } ({ 'exists' if os .path .exists (filtered_gt_path ) else 'missing' } )\n " )
317
344
if args .norm_factors :
318
345
f .write (f" Normalization factors: { args .norm_factors } ({ 'exists' if os .path .exists (args .norm_factors ) else 'missing' } )\n " )
346
+ if 'ilp_weights_path' in locals ():
347
+ f .write (f" ILP weights: { ilp_weights_path } ({ 'exists' if os .path .exists (ilp_weights_path ) else 'missing' } )\n " )
348
+ w_m_file = os .path .join (args .output_dir , "w_m_weight.txt" )
349
+ if os .path .exists (w_m_file ):
350
+ f .write (f" w_m weight: { w_m_file } (exists)\n " )
319
351
f .write (f"\n " )
320
- if 'result ' in locals () and result :
352
+ if 'ilp_result ' in locals () and ilp_result :
321
353
f .write ("ILP Results:\n " )
322
- f .write (result .stdout )
354
+ f .write (ilp_result .stdout )
323
355
f .write (f"\n Pipeline completed at: { __import__ ('datetime' ).datetime .now ()} \n " )
324
356
325
357
print (f"\n { '=' * 60 } " )
@@ -335,10 +367,19 @@ def main():
335
367
print (f" Filtered GT: { '✓' if os .path .exists (filtered_gt_path ) else '✗' } " )
336
368
if args .norm_factors :
337
369
print (f" Norm factors: { '✓' if os .path .exists (args .norm_factors ) else '✗' } " )
370
+ if 'ilp_weights_path' in locals ():
371
+ print (f" ILP weights: { '✓' if os .path .exists (ilp_weights_path ) else '✗' } " )
372
+ w_m_file = os .path .join (args .output_dir , "w_m_weight.txt" )
373
+ if os .path .exists (w_m_file ):
374
+ print (f" w_m weight: ✓" )
338
375
339
376
if os .path .exists (unfiltered_gt_path ) and os .path .exists (filtered_gt_path ):
340
- print (f"\n ✓ Ready for ILP weight calculation!" )
341
- print (f"Check the summary file for ILP weights (w_d, w_m)" )
377
+ if 'ilp_weights_path' in locals () and os .path .exists (ilp_weights_path ):
378
+ print (f"\n ✓ ILP pipeline completed successfully!" )
379
+ print (f"✓ ILP weights are available in: { ilp_weights_path } " )
380
+ else :
381
+ print (f"\n ✓ Ground truth files ready for ILP weight calculation!" )
382
+ print (f"Check the summary file for results" )
342
383
else :
343
384
print (f"\n ⚠ Some ground truth files are missing. Check the log above for errors." )
344
385
0 commit comments