Program: 144026
Project: 144026
Buggy source:
Builder addRule(int[] headVariableIndexes,int[] bodyVariableIndexes,boolean[] headNegations,boolean[] bodyNegations,double power,double weight){
  RulePart headPart=convertRulePartToInternalRepresentation(headVariableIndexes,headNegations,true);
  RulePart bodyPart=convertRulePartToInternalRepresentation(bodyVariableIndexes,bodyNegations,false);
  double ruleMaximumValue=1 + headPart.observedConstant + bodyPart.observedConstant;
  if (ruleMaximumValue == 0)   return this;
  int[] variableIndexes=Utilities.union(headPart.variableIndexes,bodyPart.variableIndexes);
  if (variableIndexes.length == 0)   return this;
  LinearFunction linearFunction=new LinearFunction(Vectors.dense(variableIndexes.length),ruleMaximumValue);
  for (int headVariable=0; headVariable < headPart.variableIndexes.length; headVariable++) {
    Vector coefficients=Vectors.dense(variableIndexes.length);
    if (headPart.negations[headVariable]) {
      coefficients.set(ArrayUtils.indexOf(variableIndexes,headPart.variableIndexes[headVariable]),1);
      linearFunction=linearFunction.add(new LinearFunction(coefficients,-1));
    }
 else {
      coefficients.set(ArrayUtils.indexOf(variableIndexes,headPart.variableIndexes[headVariable]),-1);
      linearFunction=linearFunction.add(new LinearFunction(coefficients,0));
    }
  }
  for (int bodyVariable=0; bodyVariable < bodyPart.variableIndexes.length; bodyVariable++) {
    Vector coefficients=Vectors.dense(variableIndexes.length);
    if (bodyPart.negations[bodyVariable]) {
      coefficients.set(ArrayUtils.indexOf(variableIndexes,bodyPart.variableIndexes[bodyVariable]),-1);
      linearFunction=linearFunction.add(new LinearFunction(coefficients,0));
    }
 else {
      coefficients.set(ArrayUtils.indexOf(variableIndexes,bodyPart.variableIndexes[bodyVariable]),1);
      linearFunction=linearFunction.add(new LinearFunction(coefficients,-1));
    }
  }
  FunctionTerm term=new FunctionTerm(variableIndexes,linearFunction,weight,power);
  functionTerms.add(term);
  return this;
}

Fixed version (ground truth):
Builder addRule(int[] headVariableIndexes,int[] bodyVariableIndexes,boolean[] headNegations,boolean[] bodyNegations,double power,double weight){
  RulePart headPart=convertRulePartToInternalRepresentation(headVariableIndexes,headNegations,true);
  RulePart bodyPart=convertRulePartToInternalRepresentation(bodyVariableIndexes,bodyNegations,false);
  double ruleMaximumValue=1 + headPart.observedConstant + bodyPart.observedConstant;
  if (ruleMaximumValue <= 0)   return this;
  int[] variableIndexes=Utilities.union(headPart.variableIndexes,bodyPart.variableIndexes);
  if (variableIndexes.length == 0)   return this;
  LinearFunction linearFunction=new LinearFunction(Vectors.dense(variableIndexes.length),ruleMaximumValue);
  for (int headVariable=0; headVariable < headPart.variableIndexes.length; headVariable++) {
    Vector coefficients=Vectors.dense(variableIndexes.length);
    if (headPart.negations[headVariable]) {
      coefficients.set(ArrayUtils.indexOf(variableIndexes,headPart.variableIndexes[headVariable]),1);
      linearFunction=linearFunction.add(new LinearFunction(coefficients,-1));
    }
 else {
      coefficients.set(ArrayUtils.indexOf(variableIndexes,headPart.variableIndexes[headVariable]),-1);
      linearFunction=linearFunction.add(new LinearFunction(coefficients,0));
    }
  }
  for (int bodyVariable=0; bodyVariable < bodyPart.variableIndexes.length; bodyVariable++) {
    Vector coefficients=Vectors.dense(variableIndexes.length);
    if (bodyPart.negations[bodyVariable]) {
      coefficients.set(ArrayUtils.indexOf(variableIndexes,bodyPart.variableIndexes[bodyVariable]),-1);
      linearFunction=linearFunction.add(new LinearFunction(coefficients,0));
    }
 else {
      coefficients.set(ArrayUtils.indexOf(variableIndexes,bodyPart.variableIndexes[bodyVariable]),1);
      linearFunction=linearFunction.add(new LinearFunction(coefficients,-1));
    }
  }
  FunctionTerm term=new FunctionTerm(variableIndexes,linearFunction,weight,power);
  functionTerms.add(term);
  return this;
}