def findSolutionValues(self, lp): prob = lp.solverModel if self.mip and self.hasMIPConstraints(lp.solverModel): solutionStatus = glpk.glp_mip_status(prob) else: solutionStatus = glpk.glp_get_status(prob) glpkLpStatus = { glpk.GLP_OPT: LpStatusOptimal, glpk.GLP_UNDEF: LpStatusUndefined, glpk.GLP_FEAS: LpStatusNotSolved, glpk.GLP_INFEAS: LpStatusInfeasible, glpk.GLP_NOFEAS: LpStatusInfeasible, glpk.GLP_UNBND: LpStatusUnbounded } #populate pulp solution values for var in lp.variables(): if self.mip and self.hasMIPConstraints(lp.solverModel): var.varValue = glpk.glp_mip_col_val(prob, var.glpk_index) else: var.varValue = glpk.glp_get_col_prim(prob, var.glpk_index) var.dj = glpk.glp_get_col_dual(prob, var.glpk_index) #put pi and slack variables against the constraints for constr in lp.constraints.values(): if self.mip and self.hasMIPConstraints(lp.solverModel): row_val = glpk.glp_mip_row_val(prob, constr.glpk_index) else: row_val = glpk.glp_get_row_prim(prob, constr.glpk_index) constr.slack = -constr.constant - row_val constr.pi = glpk.glp_get_row_dual(prob, constr.glpk_index) lp.resolveOK = True for var in lp.variables(): var.isModified = False lp.status = glpkLpStatus.get(solutionStatus, LpStatusUndefined) return lp.status
def evaluate_problem(self, data, problem): responses = data["response"] metrics = data["metric"] counter = 0 obj_val = glpki.glp_mip_obj_val(problem) for r in responses: if (1.0 == (glpki.glp_mip_col_val(problem, r.column))): counter = counter + 1 return (counter, obj_val)