Example #1
0
 private void updateTotals() {
   boolean used = processAssignmentList.size() > 0;
   machineLabel.setEnabled(used);
   for (MrResource resource : resourceList) {
     JTextField resourceField = resourceFieldMap.get(resource);
     long maximumCapacity;
     long safetyCapacity;
     if (machine != null) {
       MrMachineCapacity machineCapacity = machine.getMachineCapacity(resource);
       maximumCapacity = machineCapacity.getMaximumCapacity();
       safetyCapacity = machineCapacity.getSafetyCapacity();
     } else {
       maximumCapacity = 0L;
       safetyCapacity = 0L;
     }
     long usedTotal = 0L;
     for (MrProcessAssignment processAssignment : processAssignmentList) {
       usedTotal += processAssignment.getProcess().getProcessRequirement(resource).getUsage();
     }
     resourceField.setText(usedTotal + " / " + maximumCapacity);
     resourceField.setForeground(
         usedTotal > maximumCapacity
             ? TangoColorFactory.SCARLET_3
             : (usedTotal > safetyCapacity ? TangoColorFactory.ORANGE_3 : Color.BLACK));
     resourceField.setEnabled(used);
   }
   numberOfProcessesLabel.setText(processAssignmentList.size() + " processes ");
   numberOfProcessesLabel.setEnabled(used);
 }
 private void readMachineList() throws IOException {
   int machineListSize = readIntegerValue();
   List<MrNeighborhood> neighborhoodList = new ArrayList<>(machineListSize);
   Map<Long, MrNeighborhood> idToNeighborhoodMap = new HashMap<>(machineListSize);
   List<MrLocation> locationList = new ArrayList<>(machineListSize);
   Map<Long, MrLocation> idToLocationMap = new HashMap<>(machineListSize);
   machineList = new ArrayList<>(machineListSize);
   long machineId = 0L;
   List<MrMachineCapacity> machineCapacityList =
       new ArrayList<>(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<>(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<>(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);
   }
   machineReassignment.setNeighborhoodList(neighborhoodList);
   machineReassignment.setLocationList(locationList);
   machineReassignment.setMachineList(machineList);
   machineReassignment.setMachineCapacityList(machineCapacityList);
 }