public void deleteMachine(final MrMachine machine) {
logger.info("Scheduling delete of machine ({}).", machine);
doProblemFactChange(new ProblemFactChange() {
public void doChange(ScoreDirector scoreDirector) {
MachineReassignment machineReassignment = (MachineReassignment) scoreDirector.getWorkingSolution();
// First remove the planning fact from all planning entities that use it
for (MrProcessAssignment processAssignment : machineReassignment.getProcessAssignmentList()) {
if (ObjectUtils.equals(processAssignment.getMachine(), machine)) {
// TODO HACK we are removing it because it becomes uninitialized,
// which means it has to be retracted
// This is nonsense from a ProblemFactChange point of view, FIXME!
scoreDirector.beforeEntityRemoved(processAssignment);
processAssignment.setMachine(null);
scoreDirector.afterEntityRemoved(processAssignment);
}
}
// A SolutionCloner does not clone problem fact lists (such as machineList)
// Shallow clone the machineList so only workingSolution is affected, not bestSolution or guiSolution
machineReassignment.setMachineList(new ArrayList<MrMachine>(machineReassignment.getMachineList()));
// Next remove it the planning fact itself
for (Iterator<MrMachine> it = machineReassignment.getMachineList().iterator(); it.hasNext(); ) {
MrMachine workingMachine = it.next();
if (ObjectUtils.equals(workingMachine, machine)) {
scoreDirector.beforeProblemFactRemoved(workingMachine);
it.remove(); // remove from list
scoreDirector.beforeProblemFactRemoved(workingMachine);