67
67
sw .glp_set_prob_name (lp , "sample" )
68
68
sw .glp_delete_prob (lp )
69
69
HAVE_SWIGLPK = True
70
- print ('\n \n CBGLPK based on swiglpk: not all methods implimented yet!' )
71
70
__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
+
72
76
except :
73
77
raise ImportError
74
78
@@ -696,6 +700,7 @@ def glpk_FluxVariabilityAnalysis(
696
700
except AttributeError :
697
701
OUTPUT_ARRAY = numpy .zeros ((NUM_FLX , 7 ))
698
702
OUTPUT_NAMES = []
703
+ fva_ridx_fails = []
699
704
cntr = 0
700
705
tcnt = 0
701
706
# this is a memory hack --> prevents solver going berserk
@@ -714,8 +719,9 @@ def glpk_FluxVariabilityAnalysis(
714
719
# MIN
715
720
# TODO: bgoli: see whether this also works with 'minimize'
716
721
glpk_setObjective (cpx , 'min%s' % R , [(1 , R )], 'min' , reset = True )
717
- ## cplx_setBounds(c, id, min=None, max=None) # think about this
722
+
718
723
MIN_STAT = glpk_Solve (cpx , method = method )
724
+
719
725
if MIN_STAT == 'LPS_OPT' :
720
726
MIN_STAT = 1
721
727
elif MIN_STAT == 'LPS_UNBND' :
@@ -724,6 +730,7 @@ def glpk_FluxVariabilityAnalysis(
724
730
MIN_STAT = 3
725
731
else :
726
732
MIN_STAT = 4
733
+
727
734
if MIN_STAT == 1 : # solved
728
735
min_oval = cpx .obj .value
729
736
elif MIN_STAT == 2 : # unbound
@@ -735,17 +742,21 @@ def glpk_FluxVariabilityAnalysis(
735
742
min_oval = numpy .NaN
736
743
if debug :
737
744
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
747
757
else :
748
758
GOMIN = False
759
+
749
760
if gomin_cntr >= max_error_iter :
750
761
GOMIN = False
751
762
@@ -765,6 +776,7 @@ def glpk_FluxVariabilityAnalysis(
765
776
MAX_STAT = 3
766
777
else :
767
778
MAX_STAT = 4
779
+
768
780
if MAX_STAT == 1 : # solved
769
781
max_oval = cpx .obj .value
770
782
elif MAX_STAT == 2 : # unbound
@@ -775,24 +787,30 @@ def glpk_FluxVariabilityAnalysis(
775
787
else : # other fail
776
788
max_oval = numpy .NaN
777
789
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
787
801
else :
788
802
GOMAX = False
803
+
789
804
if gomax_cntr >= max_error_iter :
790
805
GOMAX = False
791
806
792
807
# 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 ))
796
814
797
815
# enables using the default value as a solution if the solver fails
798
816
if pre_opt and default_on_fail :
@@ -801,9 +819,6 @@ def glpk_FluxVariabilityAnalysis(
801
819
if MIN_STAT > 1 and not MAX_STAT > 1 :
802
820
min_oval = pre_sol [R ]
803
821
804
- if debug :
805
- cpx .write (cpxlp = os .path .join (debug_dir , '%smax.lp' % R ))
806
-
807
822
OUTPUT_ARRAY [Ridx , 0 ] = pre_sol [R ]
808
823
if R in REDUCED_COSTS :
809
824
OUTPUT_ARRAY [Ridx , 1 ] = REDUCED_COSTS [R ]
@@ -820,18 +835,28 @@ def glpk_FluxVariabilityAnalysis(
820
835
REAC .fva_status = (MIN_STAT , MAX_STAT )
821
836
if R in REDUCED_COSTS :
822
837
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
+
829
849
cntr += 1
830
850
if cntr == 200 :
831
851
tcnt += cntr
832
852
print ('FVA has processed {} of {} reactions' .format (tcnt , NUM_FLX ))
833
853
cntr = 0
834
854
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
+
835
860
os .remove (mps_filename )
836
861
837
862
# cpx.write(cpxlp='thefinaldebug.lp')
0 commit comments