Skip to content

Commit

Permalink
PLANNER-403 Rename before/afterProblemFactChanged to before/afterProb…
Browse files Browse the repository at this point in the history
…lemPropertyChanged
  • Loading branch information
ge0ffrey committed Jul 5, 2016
1 parent 8c3769d commit fa5ccce
Show file tree
Hide file tree
Showing 11 changed files with 35 additions and 38 deletions.
Expand Up @@ -76,8 +76,8 @@ public interface Move {
/** /**
* Does the move (which indirectly affects the {@link ScoreDirector#getWorkingSolution()}). * Does the move (which indirectly affects the {@link ScoreDirector#getWorkingSolution()}).
* When the {@link PlanningSolution working solution} is modified, the {@link ScoreDirector} must be correctly notified * When the {@link PlanningSolution working solution} is modified, the {@link ScoreDirector} must be correctly notified
* (through {@link ScoreDirector#beforeVariableChanged(Object, String)}, * (through {@link ScoreDirector#beforeVariableChanged(Object, String)} and
* {@link ScoreDirector#afterProblemFactChanged(Object)}, etc), * {@link ScoreDirector#afterVariableChanged(Object, String)}),
* otherwise later calculated {@link Score}s will be corrupted. * otherwise later calculated {@link Score}s will be corrupted.
* <p> * <p>
* This method must end with calling {@link ScoreDirector#triggerVariableListeners()} to ensure all shadow variables are updated. * This method must end with calling {@link ScoreDirector#triggerVariableListeners()} to ensure all shadow variables are updated.
Expand Down
Expand Up @@ -47,8 +47,8 @@ public interface CustomPhaseCommand<Solution_> {
/** /**
* Changes {@link PlanningSolution working solution} of {@link ScoreDirector#getWorkingSolution()}. * Changes {@link PlanningSolution working solution} of {@link ScoreDirector#getWorkingSolution()}.
* When the {@link PlanningSolution working solution} is modified, the {@link ScoreDirector} must be correctly notified * When the {@link PlanningSolution working solution} is modified, the {@link ScoreDirector} must be correctly notified
* (through {@link ScoreDirector#beforeVariableChanged(Object, String)}, * (through {@link ScoreDirector#beforeVariableChanged(Object, String)} and
* {@link ScoreDirector#afterProblemFactChanged(Object)}, etc), * {@link ScoreDirector#afterVariableChanged(Object, String)}),
* otherwise calculated {@link Score}s will be corrupted. * otherwise calculated {@link Score}s will be corrupted.
* <p> * <p>
* Don't forget to call {@link ScoreDirector#triggerVariableListeners()} after each set of changes * Don't forget to call {@link ScoreDirector#triggerVariableListeners()} after each set of changes
Expand Down
Expand Up @@ -325,12 +325,12 @@ public void afterProblemFactAdded(Object problemFact) {
} }


@Override @Override
public void beforeProblemFactChanged(Object problemFact) { public void beforeProblemPropertyChanged(Object problemFactOrEntity) {
// Do nothing // Do nothing
} }


@Override @Override
public void afterProblemFactChanged(Object problemFact) { public void afterProblemPropertyChanged(Object problemFactOrEntity) {
variableListenerSupport.resetWorkingSolution(); // TODO do not nuke it variableListenerSupport.resetWorkingSolution(); // TODO do not nuke it
} }


Expand Down
Expand Up @@ -99,9 +99,9 @@ public interface ScoreDirector<Solution_> {


void afterProblemFactAdded(Object problemFact); void afterProblemFactAdded(Object problemFact);


void beforeProblemFactChanged(Object problemFact); void beforeProblemPropertyChanged(Object problemFactOrEntity);


void afterProblemFactChanged(Object problemFact); void afterProblemPropertyChanged(Object problemFactOrEntity);


void beforeProblemFactRemoved(Object problemFact); void beforeProblemFactRemoved(Object problemFact);


Expand Down
Expand Up @@ -200,26 +200,26 @@ public void afterProblemFactAdded(Object problemFact) {
+ "Maybe that specific instance is already in the " + "Maybe that specific instance is already in the "
+ PlanningSolution.class.getSimpleName() + "'s problem fact members (" + PlanningSolution.class.getSimpleName() + "'s problem fact members ("
+ getSolutionDescriptor().getProblemFactMemberAndProblemFactCollectionMemberNames() + ").\n" + getSolutionDescriptor().getProblemFactMemberAndProblemFactCollectionMemberNames() + ").\n"
+ "Maybe use before/afterProblemFactChanged() instead of before/afterProblemFactAdded()."); + "Maybe use before/afterProblemPropertyChanged() instead of before/afterProblemFactAdded().");
} }
kieSession.insert(problemFact); kieSession.insert(problemFact);
super.afterProblemFactAdded(problemFact); super.afterProblemFactAdded(problemFact);
} }


// public void beforeProblemFactChanged(Object problemFact) // Do nothing // public void beforeProblemPropertyChanged(Object problemFactOrEntity) // Do nothing


@Override @Override
public void afterProblemFactChanged(Object problemFact) { public void afterProblemPropertyChanged(Object problemFactOrEntity) {
FactHandle factHandle = kieSession.getFactHandle(problemFact); FactHandle factHandle = kieSession.getFactHandle(problemFactOrEntity);
if (factHandle == null) { if (factHandle == null) {
throw new IllegalArgumentException("The problemFact (" + problemFact throw new IllegalArgumentException("The problemFact (" + problemFactOrEntity
+ ") was never added to this ScoreDirector.\n" + ") was never added to this ScoreDirector.\n"
+ "Maybe that specific instance is not in the " + "Maybe that specific instance is not in the "
+ PlanningSolution.class.getSimpleName() + "'s problem fact members (" + PlanningSolution.class.getSimpleName() + "'s problem fact members ("
+ getSolutionDescriptor().getProblemFactMemberAndProblemFactCollectionMemberNames() + ")."); + getSolutionDescriptor().getProblemFactMemberAndProblemFactCollectionMemberNames() + ").");
} }
kieSession.update(factHandle, problemFact); kieSession.update(factHandle, problemFactOrEntity);
super.afterProblemFactChanged(problemFact); super.afterProblemPropertyChanged(problemFactOrEntity);
} }


// public void beforeProblemFactRemoved(Object problemFact) // Do nothing // public void beforeProblemFactRemoved(Object problemFact) // Do nothing
Expand Down
Expand Up @@ -144,14 +144,14 @@ public void afterProblemFactAdded(Object problemFact) {
} }


@Override @Override
public void beforeProblemFactChanged(Object problemFact) { public void beforeProblemPropertyChanged(Object problemFactOrEntity) {
super.beforeProblemFactChanged(problemFact); super.beforeProblemPropertyChanged(problemFactOrEntity);
} }


@Override @Override
public void afterProblemFactChanged(Object problemFact) { public void afterProblemPropertyChanged(Object problemFactOrEntity) {
incrementalScoreCalculator.resetWorkingSolution(workingSolution); // TODO do not nuke it incrementalScoreCalculator.resetWorkingSolution(workingSolution); // TODO do not nuke it
super.afterProblemFactChanged(problemFact); super.afterProblemPropertyChanged(problemFactOrEntity);
} }


@Override @Override
Expand Down
Expand Up @@ -130,7 +130,7 @@ private void save() {
examinationPanel.doProblemFactChange(scoreDirector -> { examinationPanel.doProblemFactChange(scoreDirector -> {
Examination examination = scoreDirector.getWorkingSolution(); Examination examination = scoreDirector.getWorkingSolution();
InstitutionParametrization institutionParametrization = examination.getInstitutionParametrization(); InstitutionParametrization institutionParametrization = examination.getInstitutionParametrization();
scoreDirector.beforeProblemFactChanged(institutionParametrization); scoreDirector.beforeProblemPropertyChanged(institutionParametrization);
institutionParametrization.setTwoInARowPenalty(twoInARowPenalty); institutionParametrization.setTwoInARowPenalty(twoInARowPenalty);
institutionParametrization.setTwoInADayPenalty(twoInADayPenalty); institutionParametrization.setTwoInADayPenalty(twoInADayPenalty);
institutionParametrization.setPeriodSpreadLength(periodSpreadLength); institutionParametrization.setPeriodSpreadLength(periodSpreadLength);
Expand All @@ -139,7 +139,7 @@ private void save() {
institutionParametrization.setFrontLoadLargeTopicSize(frontLoadLargeTopicSize); institutionParametrization.setFrontLoadLargeTopicSize(frontLoadLargeTopicSize);
institutionParametrization.setFrontLoadLastPeriodSize(frontLoadLastPeriodSize); institutionParametrization.setFrontLoadLastPeriodSize(frontLoadLastPeriodSize);
institutionParametrization.setFrontLoadPenalty(frontLoadPenalty); institutionParametrization.setFrontLoadPenalty(frontLoadPenalty);
scoreDirector.afterProblemFactChanged(institutionParametrization); scoreDirector.afterProblemPropertyChanged(institutionParametrization);
}, true); }, true);
} }


Expand Down
Expand Up @@ -300,9 +300,9 @@ private void changeStandardDeviationMillisMaximum(final long standardDeviationMi
doProblemFactChange(scoreDirector -> { doProblemFactChange(scoreDirector -> {
InvestmentSolution solution = scoreDirector.getWorkingSolution(); InvestmentSolution solution = scoreDirector.getWorkingSolution();
InvestmentParametrization parametrization = solution.getParametrization(); InvestmentParametrization parametrization = solution.getParametrization();
scoreDirector.beforeProblemFactChanged(parametrization); scoreDirector.beforeProblemPropertyChanged(parametrization);
parametrization.setStandardDeviationMillisMaximum(standardDeviationMillisMaximum); parametrization.setStandardDeviationMillisMaximum(standardDeviationMillisMaximum);
scoreDirector.afterProblemFactChanged(parametrization); scoreDirector.afterProblemPropertyChanged(parametrization);
}, true); }, true);
} }


Expand All @@ -311,9 +311,9 @@ private void changeRegionQuantityMillisMaximum(final Region region, final long q
InvestmentSolution solution = scoreDirector.getWorkingSolution(); InvestmentSolution solution = scoreDirector.getWorkingSolution();
for (Region workingRegion : solution.getRegionList()) { for (Region workingRegion : solution.getRegionList()) {
if (region.getId().equals(workingRegion.getId())) { if (region.getId().equals(workingRegion.getId())) {
scoreDirector.beforeProblemFactChanged(workingRegion); scoreDirector.beforeProblemPropertyChanged(workingRegion);
workingRegion.setQuantityMillisMaximum(quantityMillisMaximum); workingRegion.setQuantityMillisMaximum(quantityMillisMaximum);
scoreDirector.afterProblemFactChanged(workingRegion); scoreDirector.afterProblemPropertyChanged(workingRegion);
break; break;
} }
} }
Expand All @@ -325,9 +325,9 @@ private void changeSectorQuantityMillisMaximum(final Sector sector, final long q
InvestmentSolution solution = scoreDirector.getWorkingSolution(); InvestmentSolution solution = scoreDirector.getWorkingSolution();
for (Sector workingSector : solution.getSectorList()) { for (Sector workingSector : solution.getSectorList()) {
if (sector.getId().equals(workingSector.getId())) { if (sector.getId().equals(workingSector.getId())) {
scoreDirector.beforeProblemFactChanged(workingSector); scoreDirector.beforeProblemPropertyChanged(workingSector);
workingSector.setQuantityMillisMaximum(quantityMillisMaximum); workingSector.setQuantityMillisMaximum(quantityMillisMaximum);
scoreDirector.afterProblemFactChanged(workingSector); scoreDirector.afterProblemPropertyChanged(workingSector);
break; break;
} }
} }
Expand Down
Expand Up @@ -136,9 +136,9 @@ public void deleteMachine(final MrMachine machine) {
// First remove the problem fact from all planning entities that use it // First remove the problem fact from all planning entities that use it
for (MrProcessAssignment processAssignment : machineReassignment.getProcessAssignmentList()) { for (MrProcessAssignment processAssignment : machineReassignment.getProcessAssignmentList()) {
if (Objects.equals(processAssignment.getOriginalMachine(), machine)) { if (Objects.equals(processAssignment.getOriginalMachine(), machine)) {
scoreDirector.beforeProblemFactChanged(processAssignment); scoreDirector.beforeProblemPropertyChanged(processAssignment);
processAssignment.setOriginalMachine(null); processAssignment.setOriginalMachine(null);
scoreDirector.afterProblemFactChanged(processAssignment); scoreDirector.afterProblemPropertyChanged(processAssignment);
} }
if (Objects.equals(processAssignment.getMachine(), machine)) { if (Objects.equals(processAssignment.getMachine(), machine)) {
scoreDirector.beforeVariableChanged(processAssignment, "machine"); scoreDirector.beforeVariableChanged(processAssignment, "machine");
Expand Down
Expand Up @@ -229,9 +229,10 @@ private void advancePlanningWindowStart() {
} }
windowStartIndex++; windowStartIndex++;
ShiftDate newPlanningWindowStart = shiftDateList.get(windowStartIndex); ShiftDate newPlanningWindowStart = shiftDateList.get(windowStartIndex);
scoreDirector.beforeProblemPropertyChanged(nurseRosterParametrization);
nurseRosterParametrization.setPlanningWindowStart(newPlanningWindowStart); nurseRosterParametrization.setPlanningWindowStart(newPlanningWindowStart);
nurseRosterParametrization.setLastShiftDate(newShiftDate); nurseRosterParametrization.setLastShiftDate(newShiftDate);
scoreDirector.afterProblemFactChanged(nurseRosterParametrization); scoreDirector.afterProblemPropertyChanged(nurseRosterParametrization);
}, true); }, true);
} }


Expand Down
Expand Up @@ -24,7 +24,6 @@
import java.util.Random; import java.util.Random;


import javax.swing.AbstractAction; import javax.swing.AbstractAction;
import javax.swing.ImageIcon;
import javax.swing.JLabel; import javax.swing.JLabel;
import javax.swing.JPanel; import javax.swing.JPanel;
import javax.swing.JScrollPane; import javax.swing.JScrollPane;
Expand All @@ -33,15 +32,12 @@
import javax.swing.SpinnerNumberModel; import javax.swing.SpinnerNumberModel;
import javax.swing.Timer; import javax.swing.Timer;


import org.optaplanner.core.impl.score.director.InnerScoreDirector;
import org.optaplanner.examples.common.swingui.SolutionPanel; import org.optaplanner.examples.common.swingui.SolutionPanel;
import org.optaplanner.examples.taskassigning.domain.Affinity;
import org.optaplanner.examples.taskassigning.domain.Customer; import org.optaplanner.examples.taskassigning.domain.Customer;
import org.optaplanner.examples.taskassigning.domain.Priority; import org.optaplanner.examples.taskassigning.domain.Priority;
import org.optaplanner.examples.taskassigning.domain.Task; import org.optaplanner.examples.taskassigning.domain.Task;
import org.optaplanner.examples.taskassigning.domain.TaskAssigningSolution; import org.optaplanner.examples.taskassigning.domain.TaskAssigningSolution;
import org.optaplanner.examples.taskassigning.domain.TaskType; import org.optaplanner.examples.taskassigning.domain.TaskType;
import org.optaplanner.examples.taskassigning.persistence.TaskAssigningGenerator;


import static org.optaplanner.examples.taskassigning.persistence.TaskAssigningGenerator.*; import static org.optaplanner.examples.taskassigning.persistence.TaskAssigningGenerator.*;


Expand Down Expand Up @@ -139,15 +135,15 @@ public void consumeUpTo(final int consumedDuration) {
for (Task task : solution.getTaskList()) { for (Task task : solution.getTaskList()) {
if (!task.isLocked()) { if (!task.isLocked()) {
if (task.getStartTime() != null && task.getStartTime() < consumedDuration) { if (task.getStartTime() != null && task.getStartTime() < consumedDuration) {
scoreDirector.beforeProblemFactChanged(task); scoreDirector.beforeProblemPropertyChanged(task);
task.setLocked(true); task.setLocked(true);
scoreDirector.afterProblemFactChanged(task); scoreDirector.afterProblemPropertyChanged(task);
logger.trace("Consumed task ({}).", task); logger.trace("Consumed task ({}).", task);
} else if (task.getReadyTime() < consumedDuration) { } else if (task.getReadyTime() < consumedDuration) {
// Prevent a non-locked task from being assigned retroactively // Prevent a non-locked task from being assigned retroactively
scoreDirector.beforeProblemFactChanged(task); scoreDirector.beforeProblemPropertyChanged(task);
task.setReadyTime(consumedDuration); task.setReadyTime(consumedDuration);
scoreDirector.afterProblemFactChanged(task); scoreDirector.afterProblemPropertyChanged(task);
} }
} }
} }
Expand Down

0 comments on commit fa5ccce

Please sign in to comment.