[jboss-svn-commits] JBL Code SVN: r27233 - labs/jbossrules/trunk/drools-solver/drools-solver-examples/src/main/java/org/drools/solver/examples/patientadmissionschedule/solver/solution/initializer.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Sun Jun 28 08:03:07 EDT 2009
Author: ge0ffrey
Date: 2009-06-28 08:03:07 -0400 (Sun, 28 Jun 2009)
New Revision: 27233
Modified:
labs/jbossrules/trunk/drools-solver/drools-solver-examples/src/main/java/org/drools/solver/examples/patientadmissionschedule/solver/solution/initializer/PatientAdmissionScheduleStartingSolutionInitializer.java
Log:
pas: kick some performance into the solution intializer
Modified: labs/jbossrules/trunk/drools-solver/drools-solver-examples/src/main/java/org/drools/solver/examples/patientadmissionschedule/solver/solution/initializer/PatientAdmissionScheduleStartingSolutionInitializer.java
===================================================================
--- labs/jbossrules/trunk/drools-solver/drools-solver-examples/src/main/java/org/drools/solver/examples/patientadmissionschedule/solver/solution/initializer/PatientAdmissionScheduleStartingSolutionInitializer.java 2009-06-28 11:43:33 UTC (rev 27232)
+++ labs/jbossrules/trunk/drools-solver/drools-solver-examples/src/main/java/org/drools/solver/examples/patientadmissionschedule/solver/solution/initializer/PatientAdmissionScheduleStartingSolutionInitializer.java 2009-06-28 12:03:07 UTC (rev 27233)
@@ -38,8 +38,10 @@
WorkingMemory workingMemory = localSearchSolverScope.getWorkingMemory();
List<BedDesignation> bedDesignationList = createBedDesignationList(patientAdmissionSchedule);
// Assign one admissionPart at a time
- List<Bed> undesignatedBedList = patientAdmissionSchedule.getBedList();
+ List<Bed> bedList = patientAdmissionSchedule.getBedList();
for (BedDesignation bedDesignation : bedDesignationList) {
+ Score unscheduledScore = localSearchSolverScope.calculateScoreFromWorkingMemory();
+ boolean perfectMatch = false;
Score bestScore = DefaultHardAndSoftScore.valueOf(Integer.MIN_VALUE);
Bed bestBed = null;
@@ -47,7 +49,7 @@
// Try every bed for that admissionPart
// TODO by reordening the beds so index 0 has a different table then index 1 and so on,
// this will probably be faster because perfectMatch will be true sooner
- for (Bed bed : undesignatedBedList) {
+ for (Bed bed : bedList) {
if (bed.allowsAdmissionPart(bedDesignation.getAdmissionPart())) {
if (bedDesignationHandle == null) {
bedDesignation.setBed(bed);
@@ -58,19 +60,31 @@
workingMemory.modifyInsert(bedDesignationHandle, bedDesignation);
}
Score score = localSearchSolverScope.calculateScoreFromWorkingMemory();
- if (score.compareTo(bestScore) > 0) {
- bestScore = score;
- bestBed = bed;
+ if (score.compareTo(unscheduledScore) < 0) {
+ if (score.compareTo(bestScore) > 0) {
+ bestScore = score;
+ bestBed = bed;
+ }
+ } else if (score.equals(unscheduledScore)) {
+ perfectMatch = true;
+ break;
+ } else {
+ throw new IllegalStateException("The score (" + score
+ + ") cannot be higher than unscheduledScore (" + unscheduledScore + ").");
}
}
+ if (perfectMatch) {
+ break;
+ }
}
- if (bestBed == null) {
- throw new IllegalStateException("The bestBed (" + bestBed + ") cannot be null.");
+ if (!perfectMatch) {
+ if (bestBed == null) {
+ throw new IllegalStateException("The bestBed (" + bestBed + ") cannot be null.");
+ }
+ workingMemory.modifyRetract(bedDesignationHandle);
+ bedDesignation.setBed(bestBed);
+ workingMemory.modifyInsert(bedDesignationHandle, bedDesignation);
}
- workingMemory.modifyRetract(bedDesignationHandle);
- bedDesignation.setBed(bestBed);
- workingMemory.modifyInsert(bedDesignationHandle, bedDesignation);
- undesignatedBedList.remove(bestBed);
}
// For the GUI's combobox list mainly, not really needed
Collections.sort(bedDesignationList, new PersistableIdComparator());
More information about the jboss-svn-commits
mailing list