getPersonDao().detachAll();
getFeatureDao().detachAll();
getLocationDao().detachAll();
getEventDao().detachAll();
BufferedReader bReader = new BufferedReader(reader);
updateStatus(10);
try {
//1. The first line defines the number of some data:
String numberOf[] = bReader.readLine().split(" ");
int noOfEvents = Integer.parseInt(numberOf[0]);
int noOfLocations = Integer.parseInt(numberOf[1]);
int noOfFeatures = Integer.parseInt(numberOf[2]);
int noOfPersons = Integer.parseInt(numberOf[3]);
// 2. Every line contains the capacity of one room
for (int i = 0; i < noOfLocations; i++) {
Location location = createLocation(Integer.parseInt(bReader.readLine()));
location.putConstraint(newRasterConstraint());
// EventSetConstraint esc = (EventSetConstraint) appCtx.getBean(ES_CONSTRAINT);
// location.putConstraint(esc);
}
// initialize events
for (int i = 0; i < noOfEvents; i++) {
createEvent();
}
// initialize features
for (int i = 0; i < noOfFeatures; i++) {
createFeature();
}
updateStatus(30);
double tmp = 10.0 / (noOfPersons + 1);
// 3. 'noOfSubjects'-lines describes the choice of one person (student/event)
Person currentPerson;
for (int p = 0; p < noOfPersons; p++) {
updateStatus(30 + (int) (p * tmp));
currentPerson = createPerson();
currentPerson.putConstraint(newRasterConstraint());
for (Event event : getEventDao().getAll()) {
if ((Integer.parseInt(bReader.readLine()) > 0)) {
currentPerson.addEvent(event, true);
}
}
}
updateStatus(40);
// 4. Now 'noOfFeatures'-lines describes the features of one room (room/feature)
for (Location currentLocation : getLocationDao().getAll()) {
for (Feature feature : getFeatureDao().getAll()) {
if ((Integer.parseInt(bReader.readLine()) > 0)) {
currentLocation.addFeature(feature);
}
}
}
updateStatus(50);
// 5. 'noOfFeatures'-lines describes the features-requirements of one subject (event/feature)
for (Event currentSubject : getEventDao().getAll()) {
for (Feature feature : getFeatureDao().getAll()) {
if ((Integer.parseInt(bReader.readLine()) != 0)) {
currentSubject.addFeature(feature);
}
}
}
updateStatus(60);
// 6. 'noOfTimeSlots'-lines describes the valid assignments of one subject (event/timeslot)
int noOfTimeSlots = poolSettings.getTimeslotsPerWeek();
for (Event currentEvent : getEventDao().getAll()) {
RasterConstraint rc = newRasterConstraint();
currentEvent.putConstraint(rc);
WeekRaster raster = rc.getRaster();
for (int ts = 0; ts < noOfTimeSlots; ts++) {
//String s = reader.readLine(); sb.append(s);
if (Integer.parseInt(bReader.readLine()) != 0) {
raster.set(ts, RasterEnum.ALLOWED);
}
}
}
updateStatus(70);
// 7. 'noOfSubjects'-lines describes the 'follow/before'-matrix of one subject (event/event)
for (Event firstEvent : getEventDao().getAll()) {
for (Event secEvent : getEventDao().getAll()) {
int i = Integer.parseInt(bReader.readLine());
if (i == 1) {
// add the constraint to the both event
EventOrderConstraint firstConstraint = firstEvent.getConstraint(EventOrderConstraint.class);
if (firstConstraint == null) {
firstConstraint = new EventOrderConstraint(firstEvent);
firstEvent.putConstraint(firstConstraint);
}
firstConstraint.addFollow(secEvent);
EventOrderConstraint secConstraint = secEvent.getConstraint(EventOrderConstraint.class);
if (secConstraint == null) {
secConstraint = new EventOrderConstraint(secEvent);
secEvent.putConstraint(secConstraint);
}
secConstraint.addBefore(firstEvent);
} else if (i == -1) {
// We could check now the priviously added followers and beforers,
// but this is not possible because '-1' could occur the
// first time (instead of expected '1')
}
}
}
updateStatus(80);
// getMagicNumbersOfDataPool();
String line = bReader.readLine();
if (line != null) {
logger.fatal("End of file should be reached. But content of line was:" + line);
int counter = 0;
while ((line = bReader.readLine()) != null) {
counter++;
}
logger.fatal("Further " + counter + " unprocessed lines detected");
}
} finally {