if (pool.size() != unassigned) System.out.println("CANNOT HAPPEN: pool size wrong.");   while (pool.size() > 0)
for (int n=0;  n < optionalRoles;  ++n)
  public void assignRolesAlternative()  {    int dimRoles       = getRoles().getNumber();    int unassignedRole = dimRoles + 1; // Marker for an unassigned role    Random rand = new Random();    debug = false;        if (debug)      System.out.println("Using role shuffling on initial matrix:\n" + solution.debugString());    // Determine the number of required roles per session (with minimum occurence)    int requiredRoles = 0;        for (int r=0;  r < roles.getNumber();  ++r)      requiredRoles += roles.getMinimumPerSession(r);          if (debug)    	System.out.println(requiredRoles + " roles are required per session.");    // Build a pool of possible roles to choose from for non-required roles.    Vector rolePool = new Vector();        for (int r=0;  r < roles.getNumber();  ++r)    {      int optional = roles.getMaximumPerSession(r) - roles.getMinimumPerSession(r);            for (int i=0;  i < optional;  ++i)      	rolePool.add(new Integer(r));    }    if (debug)    	System.out.println("For each session, there are " + rolePool.size() + " roles in the pool of optional roles.");        // First, we go through each session and assign the roles with a minimum occurence    for (int t=0;  t < topics.getNumber();  ++t)      for (int r=0;  r < roles.getNumber();  ++r)        for (int n=0;  n < roles.getMinimumPerSession(r);  ++n)          solution.setRole(chooseMostInterestedPerson(t), t, r+1);    if (debug)    	System.out.println("\nAfter assigning the required roles:\n" + solution.debugString());        // Now, we distribute the optional roles for each session    for (int t=0;  t < topics.getNumber();  ++t)    {      // Make a copy of the complete rolePool      Vector pool = (Vector) rolePool.clone();            // Count the unassigned persons in this session      // (this is done to enable this algorithm to cope with a varying       // number of participants per session).      int unassigned = 0;            for (int p=0;  p < persons.getNumber();  ++p)        if (solution.getRole(p, t) == unassignedRole)          ++unassigned;              // Randomly remove roles from the pool until we have the right number      while (pool.size() > unassigned)      {        int index = rand.nextInt(pool.size());        pool.remove(index);      }      if (pool.size() != unassigned)        System.out.println("CANNOT HAPPEN: pool size wrong.");            // Assign the remaining roles in the pool      while (pool.size() > 0)        {        int index = rand.nextInt(pool.size());        int r     = ((Integer)pool.elementAt(index)).intValue();        pool.remove(index);        solution.setRole(chooseMostInterestedPerson(t), t, r+1);      }    }        if (debug)    	System.out.println("\nAfter assigning the other roles:\n" + solution.debugString());        solved = true;    debug = false;  }