public void migrateAgentToGroup(Agent a, Group toGroup) {
		//int numExternal = a.getNumExternalNeighbors();
		numMigrations++;
		if(a.getNumExternalNeighbors() > 20) System.out.println("whaaaa");
		//long[] profile = new long[10];
		
		Group fromGroup = a.getGroup();
		
		//remove neighbors from a's original set of agents
		fromGroup.removeAgent(a);
		a.group = null;
		
		//profile[0] = System.nanoTime();
		for(Agent a1: a.getExternalNeighbors()){
			a1.removeNeighbor(a);
		}
		//profile[1] = System.nanoTime();
		
		
		//Add new neighbors to a1 (directed)
		//profile[2] = System.nanoTime();
		a.setGroup(toGroup);
		toGroup.addAgent(a);
		//numEdges -= a.getNumExternalNeighbors();
		a.resetExternal();
		//profile[3] = System.nanoTime();
		
		//int numExternal = 0;
		/*for(int i = 0; i < Constants._numnodes; i++) {
			if(rand.nextDouble() < Constants._p_ext) numExternal++;
		}//*/
		
		//profile[4] = System.nanoTime();
		double rndDub = rand.nextDouble();
		int numExternal = (int)Math.round((agents.size()-toGroup.getAgents().size()) * ((rndDub*(rndDub-0.5)+1)*Constants._p_ext)); //*/
		//int numExternal = (int)Math.round((agents.size()-toGroup.getAgents().size()) * Constants._p_ext);
		if(numExternal > agents.size() - toGroup.getAgents().size()) numExternal = agents.size() - toGroup.getAgents().size(); //*/
		//profile[5] = System.nanoTime();
		//numEdges += numExternal;
		//profile[6] = System.nanoTime();
		ArrayList<Group> exGroupSet = new ArrayList<Group>(groups);
		exGroupSet.remove(toGroup);
		Group tGroup = exGroupSet.get(0);
		int rndAgentID;
		Agent rndAgent;
		for(int i = 0; i < numExternal; i++) {
			//tMeasure[1] += System.nanoTime();
			do {
				rndAgentID = rand.nextInt(agents.size()-toGroup.getAgents().size());
				for(Group g: exGroupSet) {
					if(rndAgentID >= (tGroup = g).getAgents().size()) rndAgentID -= g.getAgents().size();
					else break;
				}
				rndAgent = tGroup.getAgents().get(rndAgentID);
			}
			while(a.hasNeighbor(rndAgent));
			//tMeasure[2] += System.nanoTime();
			a.addNeighbor(rndAgent);
		}
		//profile[7] = System.nanoTime();
		
		//profile[8] = System.nanoTime();
		//Set neighbors in opposite direction
		for(Agent a3: a.getExternalNeighbors()) {
			a3.addNeighbor(a);
		}
		//profile[9] = System.nanoTime();
	}