@@ -596,7 +596,6 @@ def setReducedCosts(fba, reduced_costs):
596
596
r .reduced_cost = None
597
597
598
598
599
- '''
600
599
def glpk_FluxVariabilityAnalysis (
601
600
fba ,
602
601
selected_reactions = None ,
@@ -983,7 +982,7 @@ def glpk_func_SetObjectiveFunctionAsConstraint(
983
982
984
983
def glpk_setSingleConstraint (c , cid , expr = [], sense = 'E' , rhs = 0.0 ):
985
984
"""
986
- Sets a new sigle constraint to a GLPK model
985
+ Sets a new single constraint to a GLPK model
987
986
988
987
- *c* a GLPK instance
989
988
- *cid* the constraint id
@@ -1069,64 +1068,75 @@ def glpk_setObjective(c, oid, expr=None, sense='maximize', reset=True):
1069
1068
# c.write(cpxlp='test_obja.lp')
1070
1069
1071
1070
1071
+ '''
1072
+ def cplx_getDualValues(c):
1073
+ """
1074
+ Get the get the dual values of the solution
1072
1075
1076
+ - *c* a CPLEX LP
1073
1077
1074
- # def cplx_getDualValues(c):
1075
- # """
1076
- # Get the get the dual values of the solution
1077
-
1078
- # - *c* a CPLEX LP
1079
-
1080
- # Output is a dictionary of {name : value} pairs
1081
-
1082
- # """
1083
- # d_names = c.linear_constraints.get_names()
1084
- # d_values = c.solution.get_dual_values()
1085
- # output = {}
1086
- # for j in range(len(d_names)):
1087
- # output.update({d_names[j] : d_values[j]})
1088
- # return output
1078
+ Output is a dictionary of {name : value} pairs
1089
1079
1090
- # def cplx_getSensitivities(c):
1091
- # """
1092
- # Get the sensitivities of each constraint on the objective function with input
1080
+ """
1081
+ d_names = c.linear_constraints.get_names()
1082
+ d_values = c.solution.get_dual_values()
1083
+ output = {}
1084
+ for j in range(len(d_names)):
1085
+ output.update({d_names[j]: d_values[j]})
1086
+ return output
1093
1087
1094
- # - *c* a CPLEX LP
1095
1088
1096
- # Output is a tuple of bound and objective sensitivities where the objective
1097
- # sensitivity is described in the CPLEX reference manual as::
1089
+ def cplx_getSensitivities(c):
1090
+ """
1091
+ Get the sensitivities of each constraint on the objective function with input
1098
1092
1099
- # ... the objective sensitivity shows each variable, its reduced cost and the range over
1100
- # which its objective function coefficient can vary without forcing a change
1101
- # in the optimal basis. The current value of each objective coefficient is
1102
- # also displayed for reference.
1093
+ - *c* a CPLEX LP
1103
1094
1104
- # - *objective coefficient sensitivity* {flux : (reduced_cost, lower_obj_sensitivity, coeff_value, upper_obj_sensitivity)}
1105
- # - *rhs sensitivity* {constraint : (low, value, high)}
1106
- # - *bound sensitivity ranges* {flux : (lb_low, lb_high, ub_low, ub_high)}
1095
+ Output is a tuple of bound and objective sensitivities where the objective
1096
+ sensitivity is described in the CPLEX reference manual as::
1107
1097
1108
- # """
1109
- # SENSE_RHS = {}
1110
- # SENSE_BND = {}
1111
- # SENSE_OBJ = {}
1112
- # c_names = c.linear_constraints.get_names()
1113
- # rhs_val = c.linear_constraints.get_rhs()
1114
- # j_names = c.variables.get_names()
1098
+ ... the objective sensitivity shows each variable, its reduced cost and the range over
1099
+ which its objective function coefficient can vary without forcing a change
1100
+ in the optimal basis. The current value of each objective coefficient is
1101
+ also displayed for reference.
1115
1102
1116
- # rhs_sense = c.solution.sensitivity.rhs()
1117
- # bnd_sense = c.solution.sensitivity.bounds()
1118
- # obj_sense = c.solution.sensitivity.objective()
1119
- # obj_coeff = c.objective.get_linear()
1120
- # red_cost = c.solution.get_reduced_costs()
1103
+ - *objective coefficient sensitivity* {flux : (reduced_cost, lower_obj_sensitivity, coeff_value, upper_obj_sensitivity)}
1104
+ - *rhs sensitivity* {constraint : (low, value, high)}
1105
+ - *bound sensitivity ranges* {flux : (lb_low, lb_high, ub_low, ub_high)}
1121
1106
1122
- # for r in range(c.variables.get_num()):
1123
- # SENSE_BND.update({j_names[r] : (bnd_sense[r][0], bnd_sense[r][1], bnd_sense[r][2], bnd_sense[r][3])})
1124
- # SENSE_OBJ.update({j_names[r] : (red_cost[r], obj_sense[r][0], obj_coeff[r], obj_sense[r][1])})
1107
+ """
1108
+ SENSE_RHS = {}
1109
+ SENSE_BND = {}
1110
+ SENSE_OBJ = {}
1111
+ c_names = c.linear_constraints.get_names()
1112
+ rhs_val = c.linear_constraints.get_rhs()
1113
+ j_names = c.variables.get_names()
1114
+
1115
+ rhs_sense = c.solution.sensitivity.rhs()
1116
+ bnd_sense = c.solution.sensitivity.bounds()
1117
+ obj_sense = c.solution.sensitivity.objective()
1118
+ obj_coeff = c.objective.get_linear()
1119
+ red_cost = c.solution.get_reduced_costs()
1120
+
1121
+ for r in range(c.variables.get_num()):
1122
+ SENSE_BND.update(
1123
+ {
1124
+ j_names[r]: (
1125
+ bnd_sense[r][0],
1126
+ bnd_sense[r][1],
1127
+ bnd_sense[r][2],
1128
+ bnd_sense[r][3],
1129
+ )
1130
+ }
1131
+ )
1132
+ SENSE_OBJ.update(
1133
+ {j_names[r]: (red_cost[r], obj_sense[r][0], obj_coeff[r], obj_sense[r][1])}
1134
+ )
1125
1135
1126
- # for s in range(c.linear_constraints.get_num()):
1127
- # SENSE_RHS.update({c_names[s] : (rhs_sense[s][0], rhs_val[s], rhs_sense[s][1])})
1136
+ for s in range(c.linear_constraints.get_num()):
1137
+ SENSE_RHS.update({c_names[s]: (rhs_sense[s][0], rhs_val[s], rhs_sense[s][1])})
1128
1138
1129
- # return (SENSE_OBJ, SENSE_RHS, SENSE_BND)
1139
+ return (SENSE_OBJ, SENSE_RHS, SENSE_BND)
1130
1140
1131
1141
1132
1142
def glpk_MinimizeSumOfAbsFluxes(
0 commit comments