String node = getBiggestDifference(oldnodes, newnodes);
String node = getBiggestDifference(oldnodes, newnodes, needChange, lastChangeNode);
  public void moveAgents(Map layout) {    String communityName = model.getCommunityName();    Map oldnodes = new HashMap(); //save all nodes and the number of agents in each current node    Map newnodes = new HashMap(); //save all nodes and the number of agents in each node after balancing    Map temp = new HashMap();    synchronized (layout) {      temp.putAll(layout);    }    //remove all agents who don't need move.    for (Iterator it = temp.entrySet().iterator(); it.hasNext(); ) {      Map.Entry me = (Map.Entry) it.next();      String agent = (String) me.getKey();      String newNode = (String) me.getValue();      increaseCounts(newnodes, newNode);      String currentNode = model.getLocation(agent);      if (currentNode != null) {        increaseCounts(oldnodes, currentNode);        if (newNode.equals(currentNode)) {          it.remove();        }      }      else {        it.remove();      }    }//logger.info("oldnodes: " + oldnodes);//logger.info("newnodes: " + newnodes);//logger.info("temp: " + temp);    /**     * This loop does the following jobs to keep node balancing during agents moving:     * 1. Find the node who has the most number of agents need to be moved out.     * 2. Move five agents from the node to destinations.     * 3. Repeat step1 to step2 until all agents get destinations.     */    while (!temp.isEmpty()) {      String node = getBiggestDifference(oldnodes, newnodes);      int count = 0;      for (Iterator it = temp.keySet().iterator(); it.hasNext(); ) {        if (count == 5) {          break;        }        String agent = (String) it.next();        String newNode = (String) temp.get(agent);        String currentNode = model.getLocation(agent);        if ( (currentNode.equals(node) && ! (newNode.equals(currentNode))) ||            node.equals("")) {          logger.debug("move agent " + agent + " from " + currentNode + " to " +                       newNode + " in comm " + communityName);          moveHelper.moveAgent(agent, currentNode, newNode, communityName);          count++;          int num = ( (Integer) oldnodes.get(currentNode)).intValue();          oldnodes.put(currentNode, new Integer(num - 1));          if (oldnodes.containsKey(newNode)) {            num = ( (Integer) oldnodes.get(newNode)).intValue();            oldnodes.put(newNode, new Integer(num + 1));          }          else {            oldnodes.put(newNode, new Integer(1));          }          it.remove();        }      }//logger.info("after move: oldnodes=" + oldnodes + ", newnodes=" + newnodes);    }    logger.debug("LoadBalance finished.");  }