Program: 131702
Project: 131702
Buggy source:
/** 
 * Gets the dual objective value from CPLEX.
 */
public static double getDualObjectiveValue(IloCplex cplex,IloLPMatrix mat) throws IloException {
  if (!cplex.isDualFeasible()) {
    throw new IllegalStateException("String_Node_Str");
  }
  double[] duals=cplex.getDuals(mat);
  double[] redCosts=cplex.getReducedCosts(mat);
  IloNumVar[] numVars=mat.getNumVars();
  BasisStatus[] varBasis=cplex.getBasisStatuses(numVars);
  BasisStatus[] conBasis=cplex.getBasisStatuses(mat.getRanges());
  int numRows=mat.getNrows();
  double[] lb=new double[numRows];
  double[] ub=new double[numRows];
  int[][] Aind=new int[numRows][];
  double[][] Aval=new double[numRows][];
  mat.getRows(0,numRows,lb,ub,Aind,Aval);
  double dualObjVal=0.0;
  for (int i=0; i < duals.length; i++) {
    if (Utilities.equals(lb[i],ub[i],1e-13) && !isInfinite(lb[i])) {
      dualObjVal+=duals[i] * lb[i];
    }
 else {
      if (!isInfinite(lb[i]) && conBasis[i] == BasisStatus.AtLower) {
        dualObjVal+=duals[i] * lb[i];
      }
 else       if (!isInfinite(ub[i]) && conBasis[i] == BasisStatus.AtUpper) {
        dualObjVal+=duals[i] * ub[i];
      }
 else       if (conBasis[i] == BasisStatus.AtUpper || conBasis[i] == BasisStatus.AtLower) {
        if (!isInfinite(lb[i]) && isInfinite(ub[i])) {
          dualObjVal+=duals[i] * lb[i];
        }
 else         if (isInfinite(lb[i]) && !isInfinite(ub[i])) {
          dualObjVal+=duals[i] * ub[i];
        }
      }
    }
  }
  for (int i=0; i < redCosts.length; i++) {
    double varLb=numVars[i].getLB();
    double varUb=numVars[i].getUB();
    if (varBasis[i] == BasisStatus.AtLower && !Utilities.equals(varLb,0.0,1e-13) && !isInfinite(varLb)) {
      dualObjVal+=redCosts[i] * varLb;
    }
 else     if (varBasis[i] == BasisStatus.AtUpper && !Utilities.equals(varUb,0.0,1e-13) && !isInfinite(varUb)) {
      dualObjVal+=redCosts[i] * varUb;
    }
 else     if (varBasis[i] == BasisStatus.AtLower || varBasis[i] == BasisStatus.AtUpper) {
      if (!isInfinite(varLb) && isInfinite(varUb)) {
        dualObjVal+=redCosts[i] * varLb;
      }
 else       if (isInfinite(varLb) && !isInfinite(varUb)) {
        dualObjVal+=redCosts[i] * varUb;
      }
    }
  }
  return dualObjVal;
}

Fixed version (ground truth):
/** 
 * Gets the dual objective value from CPLEX. This method is currently broken. We would need to test it on a CPLEX problem where we can do early stopping as we do in RLT. Then we could compare against the objective value given by the dual simplex algorithm, which (it turns out) is exactly what we want anyway.
 */
@Deprecated public static double getDualObjectiveValue(IloCplex cplex,IloLPMatrix mat) throws IloException {
  if (!cplex.isDualFeasible()) {
    throw new IllegalStateException("String_Node_Str");
  }
  double[] duals=cplex.getDuals(mat);
  double[] redCosts=cplex.getReducedCosts(mat);
  IloNumVar[] numVars=mat.getNumVars();
  BasisStatus[] varBasis=cplex.getBasisStatuses(numVars);
  BasisStatus[] conBasis=cplex.getBasisStatuses(mat.getRanges());
  int numRows=mat.getNrows();
  double[] lb=new double[numRows];
  double[] ub=new double[numRows];
  int[][] Aind=new int[numRows][];
  double[][] Aval=new double[numRows][];
  mat.getRows(0,numRows,lb,ub,Aind,Aval);
  double dualObjVal=0.0;
  for (int i=0; i < duals.length; i++) {
    if (Utilities.equals(lb[i],ub[i],1e-13) && !isInfinite(lb[i])) {
      dualObjVal+=duals[i] * lb[i];
    }
 else {
      if (!isInfinite(lb[i]) && conBasis[i] == BasisStatus.AtLower) {
        dualObjVal+=duals[i] * lb[i];
      }
 else       if (!isInfinite(ub[i]) && conBasis[i] == BasisStatus.AtUpper) {
        dualObjVal+=duals[i] * ub[i];
      }
 else       if (conBasis[i] == BasisStatus.AtUpper || conBasis[i] == BasisStatus.AtLower) {
        if (!isInfinite(lb[i]) && isInfinite(ub[i])) {
          dualObjVal+=duals[i] * lb[i];
        }
 else         if (isInfinite(lb[i]) && !isInfinite(ub[i])) {
          dualObjVal+=duals[i] * ub[i];
        }
      }
    }
  }
  for (int i=0; i < redCosts.length; i++) {
    double varLb=numVars[i].getLB();
    double varUb=numVars[i].getUB();
    if (varBasis[i] == BasisStatus.AtLower && !Utilities.equals(varLb,0.0,1e-13) && !isInfinite(varLb)) {
      dualObjVal+=redCosts[i] * varLb;
    }
 else     if (varBasis[i] == BasisStatus.AtUpper && !Utilities.equals(varUb,0.0,1e-13) && !isInfinite(varUb)) {
      dualObjVal+=redCosts[i] * varUb;
    }
 else     if (varBasis[i] == BasisStatus.AtLower || varBasis[i] == BasisStatus.AtUpper) {
      if (!isInfinite(varLb) && isInfinite(varUb)) {
        dualObjVal+=redCosts[i] * varLb;
      }
 else       if (isInfinite(varLb) && !isInfinite(varUb)) {
        dualObjVal+=redCosts[i] * varUb;
      }
    }
  }
  return dualObjVal;
}