long machineId = 0L;
List<MrMachineCapacity> machineCapacityList = new ArrayList<MrMachineCapacity>(machineListSize * resourceListSize);
long machineCapacityId = 0L;
// 2 phases because service dependencies are not in low to high order
for (int i = 0; i < machineListSize; i++) {
MrMachine machine = new MrMachine();
machine.setId(machineId);
machineList.add(machine);
machineId++;
}
for (int i = 0; i < machineListSize; i++) {
MrMachine machine = machineList.get(i);
String line = readStringValue();
int moveCostOffset = 2 + (resourceListSize * 2);
String[] lineTokens = splitBySpace(line, moveCostOffset + machineListSize);
long neighborhoodId = Long.parseLong(lineTokens[0]);
MrNeighborhood neighborhood = idToNeighborhoodMap.get(neighborhoodId);
if (neighborhood == null) {
neighborhood = new MrNeighborhood();
neighborhood.setId(neighborhoodId);
neighborhoodList.add(neighborhood);
idToNeighborhoodMap.put(neighborhoodId, neighborhood);
}
machine.setNeighborhood(neighborhood);
long locationId = Long.parseLong(lineTokens[1]);
MrLocation location = idToLocationMap.get(locationId);
if (location == null) {
location = new MrLocation();
location.setId(locationId);
locationList.add(location);
idToLocationMap.put(locationId, location);
}
machine.setLocation(location);
List<MrMachineCapacity> machineCapacityListOfMachine
= new ArrayList<MrMachineCapacity>(resourceListSize);
for (int j = 0; j < resourceListSize; j++) {
MrMachineCapacity machineCapacity = new MrMachineCapacity();
machineCapacity.setId(machineCapacityId);
machineCapacity.setMachine(machine);
machineCapacity.setResource(resourceList.get(j));
machineCapacity.setMaximumCapacity(Long.parseLong(lineTokens[2 + j]));
machineCapacity.setSafetyCapacity(Long.parseLong(lineTokens[2 + resourceListSize + j]));
machineCapacityList.add(machineCapacity);
machineCapacityListOfMachine.add(machineCapacity);
machineCapacityId++;
}
machine.setMachineCapacityList(machineCapacityListOfMachine);
Map<MrMachine, Integer> machineMoveCostMap = new HashMap<MrMachine, Integer>(machineListSize);
for (int j = 0; j < machineListSize; j++) {
MrMachine toMachine = machineList.get(j);
int moveCost = Integer.parseInt(lineTokens[moveCostOffset + j]);
machineMoveCostMap.put(toMachine, moveCost);
}
machine.setMachineMoveCostMap(machineMoveCostMap);
}