Program: 19746
Project: 19746
Buggy source:
/** 
 * This method enables agents to check their compatibility to already existing groups
 * @param none
 * @return The group ID that this agent has chosen to join. If null no group is chosen.
 */
private String agentGroupGrouping(){
  String chosenGroup="String_Node_Str";
  double currentHeuristic=0, previousHeuristic=0;
  double vectorDistance;
  double maxDistance=Math.sqrt(2);
  double economic, social, esFaction=0;
  double trustFaction=0, trustSum;
  int numKnownTrustValues;
  PublicGroupDataModel aGroup;
  for (  String groupID : getConn().availableGroups()) {
    aGroup=getConn().getGroupById(groupID);
    numKnownTrustValues=0;
    trustSum=0;
    for (    String trustee : aGroup.getMemberList()) {
      Double trustValue=this.getDataModel().getTrust(trustee);
      if (trustValue != null) {
        trustSum+=trustValue;
        numKnownTrustValues++;
      }
    }
    if (numKnownTrustValues != 0) {
      trustFaction=trustSum / numKnownTrustValues;
    }
 else {
      trustFaction=0;
    }
    economic=aGroup.getCurrentEconomicPoisition() - this.getDataModel().getEconomicBelief();
    social=aGroup.getEstimatedSocialLocation() - getDataModel().getSocialBelief();
    vectorDistance=Math.sqrt(Math.pow(economic,2) + Math.pow(social,2));
    esFaction=1 - (vectorDistance / maxDistance);
    currentHeuristic=0.5 * trustFaction + 0.5 * esFaction;
    if ((currentHeuristic > 0.5) && (previousHeuristic < currentHeuristic)) {
      chosenGroup=aGroup.getId();
      previousHeuristic=currentHeuristic;
    }
  }
  return chosenGroup;
}

Fixed version (ground truth):
/** 
 * This method enables agents to check their compatibility to already existing groups
 * @param none
 * @return The group ID that this agent has chosen to join. If null no group is chosen.
 */
private String agentGroupGrouping(){
  String chosenGroup="String_Node_Str";
  double currentHeuristic=0, previousHeuristic=0;
  double vectorDistance;
  double maxDistance=Math.sqrt(2);
  double economic, social, esFaction=0;
  double trustFaction=0, trustSum;
  int numKnownTrustValues;
  PublicGroupDataModel aGroup;
  for (  String groupID : getConn().availableGroups()) {
    aGroup=getConn().getGroupById(groupID);
    numKnownTrustValues=0;
    trustSum=0;
    for (    String trustee : aGroup.getMemberList()) {
      Double trustValue=this.getDataModel().getTrust(trustee);
      if (trustValue != null) {
        trustSum+=trustValue;
        numKnownTrustValues++;
      }
    }
    if (numKnownTrustValues != 0) {
      trustFaction=trustSum / numKnownTrustValues;
    }
 else {
      trustFaction=0;
    }
    economic=aGroup.getCurrentEconomicPoisition() - this.getDataModel().getEconomicBelief();
    social=aGroup.getEstimatedSocialLocation() - getDataModel().getSocialBelief();
    vectorDistance=Math.sqrt(Math.pow(economic,2) + Math.pow(social,2));
    esFaction=1 - (vectorDistance / maxDistance);
    currentHeuristic=0.3 * trustFaction + 0.7 * esFaction;
    if ((currentHeuristic > 0.7) && (previousHeuristic < currentHeuristic)) {
      chosenGroup=aGroup.getId();
      previousHeuristic=currentHeuristic;
    }
  }
  return chosenGroup;
}