model.addConstraint(rooms[ii]);
ii++;
}
// avoid creating a Vector each time in UniActivity.addResourceGroup
List<UniResource> allRooms = new ArrayList();
for (int j = 0; j < rooms.length; j++) {
allRooms.add(rooms[j]);
}
//TODO GroupsOfRooms
// Vector groupOfRooms[] = new Vector[nrGroupsOfRooms];
// for (int i = 0; i < nrGroupsOfRooms; i++) {
// groupOfRooms[i] = new FastVector();
//
// groupOfRooms[i].add(rooms[r]);
// groupForRoom[r].add(groupOfRooms[i]);
// }
//
// for (int i = 0; i < nrLocations; i++) {
// int cnt = 0;
// for (int j = 0; j < nrGroupsOfRooms; j++) {
// if (groupOfRooms[j].contains(rooms[i]))
// cnt++;
// }
// while (cnt < nrRoomInGroupMin) {
// groupOfRooms[r].add(rooms[i]);
// groupForRoom[i].add(groupOfRooms[r]);
// cnt++;
// }
// }
int nrTeachers = personDao.getAll().size();
UniResource instructors[] = new UniResource[nrTeachers];
Map<Person, UniResource> personToResource = FastMap.newInstance();
ii = 0;
for (Person p : personDao.getAll()) {
instructors[ii] = new UniResource(p.getId() + "",
UniResource.TYPE_INSTRUCTOR, p.getName());
model.addConstraint(instructors[ii]);
personToResource.put(p, instructors[ii]);
ii++;
}
List<Integer> starts = new ArrayList();
Map<UniActivity, UniResource> activityToInitialRoom = FastMap.newInstance();
for (Event event : eventDao.getAll()) {
UniActivity activity = new UniActivity(event.getDuration(), ""
+ event.getId(), event.getName());
eventForActivity.put(activity, event);
starts.add(event.getStart());
UniResource roomRes = null;
if (event.getLocation() != null)
roomRes = locToRoom.get(event.getLocation());
if (roomRes == null) {
int room = ToolBox.random(nrRooms);
activityToInitialRoom.put(activity, rooms[room]);
} else
activityToInitialRoom.put(activity, roomRes);
activity.addResourceGroup(allRooms);
for (Person p : event.getPersons()) {
UniResource res = personToResource.get(p);
if (res == null)
throw new NullPointerException("cannot find activity for:" + p.getName());
activity.addResourceGroup(res);
}
// activity.addResourceGroup(classes[aclass]);
model.addVariable(activity);
}
// specify dicourage slots
for (int i = 0; i < model.variables().size(); i++) {
UniActivity activity = (UniActivity) model.variables().elementAt(i);
for (int day = 0; day < nrDays; day++) {
for (int hour = 0; hour < slotsPerDay; hour++) {
addDiscouragedSlot(activity, day, hour, slotsPerDay);
}
}
// create values/assigments
activity.init();
}
for (int i = 0; i < model.variables().size(); i++) {
UniActivity activity = (UniActivity) model.variables().elementAt(i);
if (initialAssignment) {
int start = starts.get(i);
UniResource room = activityToInitialRoom.get(activity);
// find value/assignment with specific room and slot
UniAssignment assignment = null;
for (Enumeration e = activity.values().elements(); e.hasMoreElements();) {