Skip to content

Commit b9dac21

Browse files
committed
synch
1 parent cf86979 commit b9dac21

File tree

2 files changed

+357
-340
lines changed

2 files changed

+357
-340
lines changed

cbmpy/CBGLPK.py

Lines changed: 58 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -596,7 +596,6 @@ def setReducedCosts(fba, reduced_costs):
596596
r.reduced_cost = None
597597

598598

599-
'''
600599
def glpk_FluxVariabilityAnalysis(
601600
fba,
602601
selected_reactions=None,
@@ -983,7 +982,7 @@ def glpk_func_SetObjectiveFunctionAsConstraint(
983982

984983
def glpk_setSingleConstraint(c, cid, expr=[], sense='E', rhs=0.0):
985984
"""
986-
Sets a new sigle constraint to a GLPK model
985+
Sets a new single constraint to a GLPK model
987986
988987
- *c* a GLPK instance
989988
- *cid* the constraint id
@@ -1069,64 +1068,75 @@ def glpk_setObjective(c, oid, expr=None, sense='maximize', reset=True):
10691068
# c.write(cpxlp='test_obja.lp')
10701069

10711070

1071+
'''
1072+
def cplx_getDualValues(c):
1073+
"""
1074+
Get the get the dual values of the solution
10721075
1076+
- *c* a CPLEX LP
10731077
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
10891079
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
10931087
1094-
# - *c* a CPLEX LP
10951088
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
10981092
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
11031094
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::
11071097
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.
11151102
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)}
11211106
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+
)
11251135
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])})
11281138
1129-
# return (SENSE_OBJ, SENSE_RHS, SENSE_BND)
1139+
return (SENSE_OBJ, SENSE_RHS, SENSE_BND)
11301140
11311141
11321142
def glpk_MinimizeSumOfAbsFluxes(

0 commit comments

Comments
 (0)