Program: 131728
Project: 131728
Buggy source:
public Pair<RelaxStatus,Double> runDWAlgo(IloCplex cplex,MasterProblem mp,double upperBound) throws UnknownObjectException, IloException {
  if (hasInfeasibleBounds || !areFeasibleBounds(bounds)) {
    return new Pair<RelaxStatus,Double>(RelaxStatus.Infeasible,INTERNAL_WORST_SCORE);
  }
  RelaxStatus status=RelaxStatus.Unknown;
  DmvCkyParser parser=new DmvCkyParser();
  double lowerBound=INTERNAL_BEST_SCORE;
  TDoubleArrayList iterationLowerBounds=new TDoubleArrayList();
  TDoubleArrayList iterationObjVals=new TDoubleArrayList();
  WarmStart warmStart=null;
  int dwIter;
  for (dwIter=0; ; dwIter++) {
    if (tempDir != null) {
      cplex.exportModel(new File(tempDir,String.format("String_Node_Str",dwIter)).getAbsolutePath());
    }
    if (warmStart != null) {
      setWarmStart(warmStart);
    }
    simplexTimer.start();
    cplex.solve();
    simplexTimer.stop();
    warmStart=getWarmStart();
    status=RelaxStatus.get(cplex.getStatus());
    log.trace("String_Node_Str" + cplex.getStatus());
    if (status == RelaxStatus.Infeasible) {
      lowerBound=INTERNAL_WORST_SCORE;
      return new Pair<RelaxStatus,Double>(status,lowerBound);
    }
    if (dwIter >= maxDwIterations) {
      break;
    }
    if (tempDir != null) {
      cplex.writeSolution(new File(tempDir,String.format("String_Node_Str",dwIter)).getAbsolutePath());
    }
    double objVal=cplex.getObjValue();
    log.trace("String_Node_Str" + objVal);
    double prevObjVal=iterationObjVals.size() > 0 ? iterationObjVals.get(iterationObjVals.size() - 1) : INTERNAL_WORST_SCORE;
    if (objVal > prevObjVal + OBJ_VAL_DECREASE_TOLERANCE) {
      log.warn("String_Node_Str" + prevObjVal + "String_Node_Str"+ objVal);
    }
    iterationObjVals.add(objVal);
    double[] pricesLower=cplex.getDuals(mp.lpMatrix,0,idm.getNumTotalParams());
    double[] pricesUpper=cplex.getDuals(mp.lpMatrix,idm.getNumTotalParams(),idm.getNumTotalParams());
    int numConds=idm.getNumConds();
    double[][] parseWeights=new double[numConds][];
    int j=0;
    for (int c=0; c < numConds; c++) {
      int numParams=idm.getNumParams(c);
      parseWeights[c]=new double[numParams];
      for (int m=0; m < numParams; m++) {
        parseWeights[c][m]=(pricesLower[j] * bounds.getLb(c,m) + pricesUpper[j] * bounds.getUb(c,m));
        j++;
      }
    }
    DepProbMatrix dpm=idm.getDepProbMatrix(parseWeights);
    double[] convexLambdaPrices=cplex.getDuals(mp.lambdaSumCons);
    double[][] modelWeights=new double[numConds][];
    j=0;
    for (int c=0; c < numConds; c++) {
      int numParams=idm.getNumParams(c);
      modelWeights[c]=new double[numParams];
      for (int m=0; m < numParams; m++) {
        modelWeights[c][m]=-pricesLower[j] * idm.getTotalMaxFreqCm(c,m);
        j++;
      }
    }
    double convexGammaPrice=cplex.getDual(mp.gammaSumCons);
    double sumReducedCost=0.0;
    int numPositiveGammaRedCosts=0;
    ModelParamSubproblem mps=new ModelParamSubproblem();
    stoTimer.start();
    Pair<double[][],Double> mPair=mps.solveModelParamSubproblemJOptimizeLogProb(modelWeights,bounds);
    stoTimer.stop();
    if (mPair == null) {
      hasInfeasibleBounds=true;
      return new Pair<RelaxStatus,Double>(RelaxStatus.Infeasible,INTERNAL_WORST_SCORE);
    }
    double[][] logProbs=mPair.get1();
    double mReducedCost=mPair.get2() - convexGammaPrice;
    if (log.isDebugEnabled()) {
      int index=mp.gammaVars.indexOf(new GammaVar(null,logProbs));
      if (index != -1) {
        GammaVar gv=mp.gammaVars.get(index);
        log.debug(String.format("String_Node_Str",cplex.getReducedCost(gv.gammaVar),mReducedCost));
        assert(Utilities.equals(cplex.getReducedCost(gv.gammaVar),mReducedCost,1e-13));
      }
    }
    if (mReducedCost < NEGATIVE_REDUCED_COST_TOLERANCE) {
      if (addGammaVar(logProbs)) {
        numPositiveGammaRedCosts++;
        if (mp.gammaVars.size() > mp.lpMatrix.getNrows()) {
          for (int i=0; i < mp.gammaVars.size(); i++) {
            GammaVar gv=mp.gammaVars.get(i);
            BasisStatus bstatus=cplex.getBasisStatus(gv.gammaVar);
            if (bstatus != BasisStatus.Basic) {
              removeGammaVar(gv);
            }
          }
          assert(mp.gammaVars.size() > 0);
        }
      }
    }
    sumReducedCost+=mReducedCost;
    int numPositiveLambdaRedCosts=0;
    for (int s=0; s < sentences.size(); s++) {
      parsingTimer.start();
      Pair<DepTree,Double> pPair=parser.parse(sentences.get(s),dpm);
      parsingTimer.stop();
      DepTree tree=pPair.get1();
      double pReducedCost=-pPair.get2() - convexLambdaPrices[s];
      if (pReducedCost < NEGATIVE_REDUCED_COST_TOLERANCE) {
        if (addLambdaVar(s,tree)) {
          numPositiveLambdaRedCosts++;
        }
 else {
          log.warn(String.format("String_Node_Str",pReducedCost,s,tree.getParents().toString()));
        }
      }
      sumReducedCost+=pReducedCost;
    }
    lowerBound=objVal + sumReducedCost;
    iterationLowerBounds.add(lowerBound);
    if (numPositiveLambdaRedCosts > 0 && sumReducedCost > 1e-6) {
      log.warn("String_Node_Str" + sumReducedCost);
    }
    if (lowerBound >= upperBound) {
      break;
    }
 else     if (numPositiveLambdaRedCosts + numPositiveGammaRedCosts == 0) {
      lowerBound=cplex.getObjValue();
      status=RelaxStatus.Optimal;
      break;
    }
 else {
      log.debug(String.format("String_Node_Str",numPositiveLambdaRedCosts,numPositiveGammaRedCosts));
    }
  }
  lowerBound=Vectors.max(iterationLowerBounds.toNativeArray());
  log.debug("String_Node_Str" + dwIter);
  log.debug("String_Node_Str" + maxDwIterations);
  log.debug("String_Node_Str" + lowerBound);
  log.debug("String_Node_Str" + iterationObjVals);
  log.debug("String_Node_Str" + iterationLowerBounds);
  log.debug("String_Node_Str" + Time.totMs(simplexTimer));
  log.debug("String_Node_Str" + Time.totMs(parsingTimer));
  log.debug("String_Node_Str" + Time.totMs(stoTimer));
  return new Pair<RelaxStatus,Double>(status,lowerBound);
}

Fixed version (ground truth):
public Pair<RelaxStatus,Double> runDWAlgo(IloCplex cplex,MasterProblem mp,double upperBound) throws UnknownObjectException, IloException {
  if (hasInfeasibleBounds || !areFeasibleBounds(bounds)) {
    return new Pair<RelaxStatus,Double>(RelaxStatus.Infeasible,INTERNAL_WORST_SCORE);
  }
  RelaxStatus status=RelaxStatus.Unknown;
  DmvCkyParser parser=new DmvCkyParser();
  double lowerBound=INTERNAL_BEST_SCORE;
  TDoubleArrayList iterationLowerBounds=new TDoubleArrayList();
  TDoubleArrayList iterationObjVals=new TDoubleArrayList();
  WarmStart warmStart=null;
  int dwIter;
  for (dwIter=0; ; dwIter++) {
    if (tempDir != null) {
      cplex.exportModel(new File(tempDir,String.format("String_Node_Str",dwIter)).getAbsolutePath());
    }
    if (warmStart != null) {
      setWarmStart(warmStart);
    }
    simplexTimer.start();
    cplex.solve();
    simplexTimer.stop();
    warmStart=getWarmStart();
    status=RelaxStatus.get(cplex.getStatus());
    log.trace("String_Node_Str" + cplex.getStatus());
    if (status == RelaxStatus.Infeasible) {
      lowerBound=INTERNAL_WORST_SCORE;
      return new Pair<RelaxStatus,Double>(status,lowerBound);
    }
    if (dwIter >= maxDwIterations) {
      break;
    }
    if (tempDir != null) {
      cplex.writeSolution(new File(tempDir,String.format("String_Node_Str",dwIter)).getAbsolutePath());
    }
    double objVal=cplex.getObjValue();
    log.trace("String_Node_Str" + objVal);
    double prevObjVal=iterationObjVals.size() > 0 ? iterationObjVals.get(iterationObjVals.size() - 1) : INTERNAL_WORST_SCORE;
    if (objVal > prevObjVal + OBJ_VAL_DECREASE_TOLERANCE) {
      log.warn("String_Node_Str" + prevObjVal + "String_Node_Str"+ objVal);
    }
    iterationObjVals.add(objVal);
    double[] pricesLower=cplex.getDuals(mp.lpMatrix,0,idm.getNumTotalParams());
    double[] pricesUpper=cplex.getDuals(mp.lpMatrix,idm.getNumTotalParams(),idm.getNumTotalParams());
    int numConds=idm.getNumConds();
    double[][] parseWeights=new double[numConds][];
    int j=0;
    for (int c=0; c < numConds; c++) {
      int numParams=idm.getNumParams(c);
      parseWeights[c]=new double[numParams];
      for (int m=0; m < numParams; m++) {
        parseWeights[c][m]=(pricesLower[j] * bounds.getLb(c,m) + pricesUpper[j] * bounds.getUb(c,m));
        j++;
      }
    }
    DepProbMatrix dpm=idm.getDepProbMatrix(parseWeights);
    double[] convexLambdaPrices=cplex.getDuals(mp.lambdaSumCons);
    double[][] modelWeights=new double[numConds][];
    j=0;
    for (int c=0; c < numConds; c++) {
      int numParams=idm.getNumParams(c);
      modelWeights[c]=new double[numParams];
      for (int m=0; m < numParams; m++) {
        modelWeights[c][m]=-pricesLower[j] * idm.getTotalMaxFreqCm(c,m);
        j++;
      }
    }
    double convexGammaPrice=cplex.getDual(mp.gammaSumCons);
    double sumReducedCost=0.0;
    int numPositiveGammaRedCosts=0;
    ModelParamSubproblem mps=new ModelParamSubproblem();
    stoTimer.start();
    Pair<double[][],Double> mPair=mps.solveModelParamSubproblemJOptimizeLogProb(modelWeights,bounds);
    stoTimer.stop();
    if (mPair == null) {
      hasInfeasibleBounds=true;
      return new Pair<RelaxStatus,Double>(RelaxStatus.Infeasible,INTERNAL_WORST_SCORE);
    }
    double[][] logProbs=mPair.get1();
    double mReducedCost=mPair.get2() - convexGammaPrice;
    if (log.isDebugEnabled()) {
      int index=mp.gammaVars.indexOf(new GammaVar(null,logProbs));
      if (index != -1) {
        GammaVar gv=mp.gammaVars.get(index);
        log.debug(String.format("String_Node_Str",cplex.getReducedCost(gv.gammaVar),mReducedCost));
        assert(Utilities.equals(cplex.getReducedCost(gv.gammaVar),mReducedCost,1e-13));
      }
    }
    if (mReducedCost < NEGATIVE_REDUCED_COST_TOLERANCE) {
      if (addGammaVar(logProbs)) {
        numPositiveGammaRedCosts++;
        if (mp.gammaVars.size() > mp.lpMatrix.getNrows()) {
          for (int i=0; i < mp.gammaVars.size(); i++) {
            GammaVar gv=mp.gammaVars.get(i);
            BasisStatus bstatus=cplex.getBasisStatus(gv.gammaVar);
            if (bstatus != BasisStatus.Basic) {
              removeGammaVar(gv);
            }
          }
          assert(mp.gammaVars.size() > 0);
        }
      }
    }
    sumReducedCost+=mReducedCost;
    int numPositiveLambdaRedCosts=0;
    for (int s=0; s < sentences.size(); s++) {
      parsingTimer.start();
      Pair<DepTree,Double> pPair=parser.parse(sentences.get(s),dpm);
      parsingTimer.stop();
      DepTree tree=pPair.get1();
      double pReducedCost=-pPair.get2() - convexLambdaPrices[s];
      if (pReducedCost < NEGATIVE_REDUCED_COST_TOLERANCE) {
        if (addLambdaVar(s,tree)) {
          numPositiveLambdaRedCosts++;
        }
 else {
          log.warn(String.format("String_Node_Str",pReducedCost,s,tree.getParents().toString()));
        }
      }
      sumReducedCost+=pReducedCost;
    }
    lowerBound=objVal + sumReducedCost;
    iterationLowerBounds.add(lowerBound);
    if (numPositiveLambdaRedCosts > 0 && sumReducedCost > 1e-6) {
      log.warn("String_Node_Str" + sumReducedCost);
    }
    if (lowerBound >= upperBound) {
      status=RelaxStatus.Fathomed;
      break;
    }
 else     if (numPositiveLambdaRedCosts + numPositiveGammaRedCosts == 0) {
      lowerBound=cplex.getObjValue();
      status=RelaxStatus.Optimal;
      break;
    }
 else {
      log.debug(String.format("String_Node_Str",numPositiveLambdaRedCosts,numPositiveGammaRedCosts));
    }
  }
  lowerBound=Vectors.max(iterationLowerBounds.toNativeArray());
  log.debug("String_Node_Str" + dwIter);
  log.debug("String_Node_Str" + maxDwIterations);
  log.debug("String_Node_Str" + lowerBound);
  log.debug("String_Node_Str" + iterationObjVals);
  log.debug("String_Node_Str" + iterationLowerBounds);
  log.debug("String_Node_Str" + Time.totMs(simplexTimer));
  log.debug("String_Node_Str" + Time.totMs(parsingTimer));
  log.debug("String_Node_Str" + Time.totMs(stoTimer));
  return new Pair<RelaxStatus,Double>(status,lowerBound);
}