I've put together a very basic and raw example. Below are a few scenarios:
Example 1: If user 1/8 is not allowed, the first house in the foor loop to allocated will be house 1, hereafter only disallowed users (1/8) would be allowed to be placed in this house. All other users would be distributed to other houses.
Example 2: if user 5/6 are disallowed users, all houses have already been allocated to allowed users then they will simply be rejected as no secure house can be offered.
The code is very basic and provides a starting point, thank you all who have so far taken time to answer my questions.
public class placement {
/** Linking the user to a house **/
private static Map<Integer, Integer> housesUsed;
/** Hold user data **/
private static Map<Integer, Integer> userData;
/** Hold houses **/
private static Map<Integer, Integer> houses;
public static void main(String[] args) {
setUsers();
setHouses();
housesUsed = new HashMap<Integer, Integer>();
int housePosition = 0;
for (int a = 0; a < userData.size(); a++) {
for (int i = 0; i < houses.size(); i++) {
if (!housesUsed.containsKey(a)) {
housePosition = i;
housesUsed.put(housePosition, a);
}
}
System.out.println("House id: " + housePosition + " User id: " + a);
}
}
public static void setUsers() {
userData = new HashMap<Integer, Integer>();
// User id followed by allowed (o not / 1 allowed)
userData.put(0, 0);
userData.put(1, 1);
userData.put(2, 1);
userData.put(3, 1);
userData.put(4, 0);
userData.put(5, 1);
userData.put(6, 1);
userData.put(7, 0);
userData.put(8, 1);
userData.put(9, 1);
Collection c = userData.keySet();
Iterator itr = c.iterator();
while (itr.hasNext())
System.out.println("user id " + itr.next());
}
public static void setHouses() {
houses = new HashMap<Integer, Integer>();
houses.put(0, 0);
houses.put(1, 1);
houses.put(2, 2);
houses.put(3, 3);
houses.put(4, 4);
Collection c = houses.values();
Iterator itr = c.iterator();
while (itr.hasNext())
System.out.println("houses " + itr.next());
}
}
Thanks,
Dan