6767 sw .glp_set_prob_name (lp , "sample" )
6868 sw .glp_delete_prob (lp )
6969 HAVE_SWIGLPK = True
70- print ('\n \n CBGLPK based on swiglpk: not all methods implimented yet!' )
7170 __solver_version__ = '{}.{}' .format (sw .GLP_MAJOR_VERSION , sw .GLP_MINOR_VERSION )
71+ print (
72+ 'CBGLPK based on swiglpk: not all methods implimented yet!' ,
73+ __solver_version__ ,
74+ )
75+
7276except :
7377 raise ImportError
7478
@@ -696,6 +700,7 @@ def glpk_FluxVariabilityAnalysis(
696700 except AttributeError :
697701 OUTPUT_ARRAY = numpy .zeros ((NUM_FLX , 7 ))
698702 OUTPUT_NAMES = []
703+ fva_ridx_fails = []
699704 cntr = 0
700705 tcnt = 0
701706 # this is a memory hack --> prevents solver going berserk
@@ -714,8 +719,9 @@ def glpk_FluxVariabilityAnalysis(
714719 # MIN
715720 # TODO: bgoli: see whether this also works with 'minimize'
716721 glpk_setObjective (cpx , 'min%s' % R , [(1 , R )], 'min' , reset = True )
717- ## cplx_setBounds(c, id, min=None, max=None) # think about this
722+
718723 MIN_STAT = glpk_Solve (cpx , method = method )
724+
719725 if MIN_STAT == 'LPS_OPT' :
720726 MIN_STAT = 1
721727 elif MIN_STAT == 'LPS_UNBND' :
@@ -724,6 +730,7 @@ def glpk_FluxVariabilityAnalysis(
724730 MIN_STAT = 3
725731 else :
726732 MIN_STAT = 4
733+
727734 if MIN_STAT == 1 : # solved
728735 min_oval = cpx .obj .value
729736 elif MIN_STAT == 2 : # unbound
@@ -735,17 +742,21 @@ def glpk_FluxVariabilityAnalysis(
735742 min_oval = numpy .NaN
736743 if debug :
737744 cpx .write (cpxlp = os .path .join (debug_dir , '%smin.lp' % R ))
738- if MIN_STAT >= 3 :
739- if gomin_cntr == 0 :
740- cpx .erase ()
741- del cpx
742- time .sleep (0.1 )
743- cpx = glpk .LPX (mps = mps_filename )
744- gomin_cntr += 1
745- else :
746- GOMIN = False
745+
746+ if MIN_STAT > 3 :
747+ print ('Mysterious GLPK MIN_STAT > 3: if you see this please contact a developer (not an error).' )
748+ #if gomin_cntr == 0:
749+ #cpx.erase()
750+ #del cpx
751+ #time.sleep(0.1)
752+ #cpx = glpk.LPX(mps=mps_filename)
753+ #gomin_cntr += 1
754+ #else:
755+ #GOMIN = False
756+ GOMIN = False
747757 else :
748758 GOMIN = False
759+
749760 if gomin_cntr >= max_error_iter :
750761 GOMIN = False
751762
@@ -765,6 +776,7 @@ def glpk_FluxVariabilityAnalysis(
765776 MAX_STAT = 3
766777 else :
767778 MAX_STAT = 4
779+
768780 if MAX_STAT == 1 : # solved
769781 max_oval = cpx .obj .value
770782 elif MAX_STAT == 2 : # unbound
@@ -775,24 +787,30 @@ def glpk_FluxVariabilityAnalysis(
775787 else : # other fail
776788 max_oval = numpy .NaN
777789
778- if MAX_STAT >= 3 :
779- if gomax_cntr == 0 :
780- cpx .erase ()
781- del cpx
782- time .sleep (0.1 )
783- cpx = glpk .LPX (mps = mps_filename )
784- gomax_cntr += 1
785- else :
786- GOMAX = False
790+ if MAX_STAT > 3 :
791+ print ('Mysterious GLPK MAX_STAT > 3: if you see this please contact a developer (not an error).' )
792+ #if gomax_cntr == 0:
793+ #cpx.erase()
794+ #del cpx
795+ #time.sleep(0.1)
796+ #cpx = glpk.LPX(mps=mps_filename)
797+ #gomax_cntr += 1
798+ #else:
799+ #GOMAX = False
800+ GOMAX = False
787801 else :
788802 GOMAX = False
803+
789804 if gomax_cntr >= max_error_iter :
790805 GOMAX = False
791806
792807 # check for solver going berserk
793- if MIN_STAT > 1 and MAX_STAT > 1 :
794- print (Ridx )
795- time .sleep (1 )
808+ #if MIN_STAT > 1 and MAX_STAT > 1:
809+ #print(Ridx)
810+ #time.sleep(1)
811+
812+ if debug :
813+ cpx .write (cpxlp = os .path .join (debug_dir , '%smax.lp' % R ))
796814
797815 # enables using the default value as a solution if the solver fails
798816 if pre_opt and default_on_fail :
@@ -801,9 +819,6 @@ def glpk_FluxVariabilityAnalysis(
801819 if MIN_STAT > 1 and not MAX_STAT > 1 :
802820 min_oval = pre_sol [R ]
803821
804- if debug :
805- cpx .write (cpxlp = os .path .join (debug_dir , '%smax.lp' % R ))
806-
807822 OUTPUT_ARRAY [Ridx , 0 ] = pre_sol [R ]
808823 if R in REDUCED_COSTS :
809824 OUTPUT_ARRAY [Ridx , 1 ] = REDUCED_COSTS [R ]
@@ -820,18 +835,28 @@ def glpk_FluxVariabilityAnalysis(
820835 REAC .fva_status = (MIN_STAT , MAX_STAT )
821836 if R in REDUCED_COSTS :
822837 REAC .reduced_costs = REDUCED_COSTS [R ]
823- if not quiet and MAX_STAT > 1 or MIN_STAT > 1 :
824- print (
825- 'Solver fail for reaction \" {}\" (MIN_STAT: {} MAX_STAT: {})' .format (
826- R , MIN_STAT , MAX_STAT
827- )
828- )
838+
839+ if not quiet :
840+ if MAX_STAT > 1 :
841+ fva_ridx_fails .append ((R , MAX_STAT ))
842+ #print(
843+ #'Solver fail for reaction \"{}\" (MIN_STAT: {} MAX_STAT: {})'.format(
844+ #R, MIN_STAT, MAX_STAT
845+ #)
846+ if MIN_STAT > 1 :
847+ fva_ridx_fails .append ((R , MIN_STAT ))
848+
829849 cntr += 1
830850 if cntr == 200 :
831851 tcnt += cntr
832852 print ('FVA has processed {} of {} reactions' .format (tcnt , NUM_FLX ))
833853 cntr = 0
834854
855+ if len (fva_ridx_fails ) > 0 :
856+ print ('Optimization failed for the following FVA operations. If this is a large list consider adjusting the FVA tolerances.' )
857+ print (fva_ridx_fails )
858+
859+
835860 os .remove (mps_filename )
836861
837862 # cpx.write(cpxlp='thefinaldebug.lp')
0 commit comments