static int pickAgent(int k, double[] capacity, double[][][] graph) throws Exception {

		double[] probs = moveProbs(k, capacity, graph);

		double[] cumul = new double[probs.length + 1];
		for (int i = 0; i < probs.length; ++i) {
			cumul[i + 1] = cumul[i] + probs[i]; // consider setting cumul[cuml.length-1] to 1.00
		}

		double p = generator.nextDouble();
		for (int i = 0; i < cumul.length-1; ++i) { 
			if (p >= cumul[i] && p < cumul[i + 1]) { // we subtract capacities here
				capacity[i] -= graph[i][k][1];
				return i;
			}
		}
		return -1; //means we didn't find a valid agent, so we return sentinel value
	}