Mercurial > repos > bimib > cobraxy
comparison COBRAxy/utils/CBS_backend.py @ 342:057909a104d9 draft default tip
Uploaded
author | luca_milaz |
---|---|
date | Thu, 04 Sep 2025 13:20:46 +0000 |
parents | 2aea7e27ae0f |
children |
comparison
equal
deleted
inserted
replaced
341:fe87d6fd7884 | 342:057909a104d9 |
---|---|
70 i+=1 | 70 i+=1 |
71 | 71 |
72 # Initialize the parameters | 72 # Initialize the parameters |
73 params=glp_smcp() | 73 params=glp_smcp() |
74 params.presolve=GLP_ON | 74 params.presolve=GLP_ON |
75 params.msg_lev = GLP_MSG_ALL | 75 params.msg_lev = GLP_MSG_ERR |
76 params.tm_lim=4000 | 76 params.tm_lim=4000 |
77 glp_init_smcp(params) | 77 glp_init_smcp(params) |
78 | 78 |
79 # Solve the problem | 79 glp_term_out(GLP_OFF) |
80 glp_scale_prob(lp,GLP_SF_AUTO) | 80 |
81 | 81 try: |
82 value=glp_simplex(lp, params) | 82 |
83 | 83 # Solve the problem |
84 Z = glp_get_obj_val(lp); | 84 glp_scale_prob(lp,GLP_SF_AUTO) |
85 | 85 |
86 if value == 0: | 86 value=glp_simplex(lp, params) |
87 fluxes = [] | 87 |
88 for i in range(len(reactions)): fluxes.append(glp_get_col_prim(lp, i+1)) | 88 Z = glp_get_obj_val(lp); |
89 return fluxes,Z | 89 |
90 else: | 90 if value == 0: |
91 raise Exception("error in LP problem. Problem:",str(value)) | 91 fluxes = [] |
92 | 92 for i in range(len(reactions)): fluxes.append(glp_get_col_prim(lp, i+1)) |
93 | 93 return fluxes,Z |
94 else: | |
95 raise Exception("error in LP problem. Problem:",str(value)) | |
96 except Exception as e: | |
97 # Re-enable terminal output for error reporting | |
98 glp_term_out(GLP_ON) | |
99 raise Exception(e) | |
100 finally: | |
101 # Re-enable terminal output after solving | |
102 glp_term_out(GLP_ON) | |
103 | |
94 # Create LP structure | 104 # Create LP structure |
95 def create_lp_structure(model): | 105 def create_lp_structure(model): |
96 | 106 |
97 reactions=[el.id for el in model.reactions] | 107 reactions=[el.id for el in model.reactions] |
98 coefs_obj=[reaction.objective_coefficient for reaction in model.reactions] | 108 coefs_obj=[reaction.objective_coefficient for reaction in model.reactions] |