Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PLANNER-491 locator prototype (unfinished)
- Loading branch information
Showing
27 changed files
with
248 additions
and
91 deletions.
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
optaplanner-core/src/main/java/org/optaplanner/core/api/domain/id/PlanningId.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* Copyright 2016 Red Hat, Inc. and/or its affiliates. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.optaplanner.core.api.domain.id; | ||
|
||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.Target; | ||
import java.util.Comparator; | ||
|
||
import org.optaplanner.core.api.domain.entity.PlanningEntity; | ||
import org.optaplanner.core.api.domain.solution.PlanningSolution; | ||
import org.optaplanner.core.api.domain.solution.drools.ProblemFactCollectionProperty; | ||
import org.optaplanner.core.api.domain.valuerange.ValueRangeProvider; | ||
import org.optaplanner.core.api.domain.variable.PlanningVariableGraphType; | ||
import org.optaplanner.core.impl.heuristic.move.Move; | ||
import org.optaplanner.core.impl.heuristic.selector.common.decorator.SelectionFilter; | ||
import org.optaplanner.core.impl.heuristic.selector.common.decorator.SelectionSorterWeightFactory; | ||
import org.optaplanner.core.impl.score.director.ScoreDirector; | ||
import org.optaplanner.core.impl.solver.ProblemFactChange; | ||
|
||
import static java.lang.annotation.ElementType.*; | ||
import static java.lang.annotation.RetentionPolicy.*; | ||
|
||
/** | ||
* Specifies that a bean property (or a field) is the id to match | ||
* when {@link ScoreDirector#locateWorkingObject(Object) locating} | ||
* an externalObject (often from another {@link Thread} or JVM). | ||
* Used during {@link Move} relocation and in a {@link ProblemFactChange}. | ||
* <p> | ||
* It is specified on a getter of a java bean property (or directly on a field) of a {@link PlanningEntity} class, | ||
* {@link ValueRangeProvider planning value} class or any {@link ProblemFactCollectionProperty problem fact} class. | ||
*/ | ||
@Target({METHOD, FIELD}) | ||
@Retention(RUNTIME) | ||
public @interface PlanningId { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
optaplanner-core/src/main/java/org/optaplanner/core/impl/domain/id/Locator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/* | ||
* Copyright 2016 Red Hat, Inc. and/or its affiliates. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.optaplanner.core.impl.domain.id; | ||
|
||
import java.math.BigDecimal; | ||
import java.math.BigInteger; | ||
import java.time.LocalDate; | ||
import java.time.LocalDateTime; | ||
import java.time.LocalTime; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import org.optaplanner.core.api.domain.id.PlanningId; | ||
import org.optaplanner.core.impl.domain.solution.descriptor.SolutionDescriptor; | ||
import org.optaplanner.core.impl.score.director.ScoreDirector; | ||
|
||
/** | ||
* @see PlanningId | ||
* @see ScoreDirector#locateWorkingObject(Object) | ||
*/ | ||
public class Locator { | ||
|
||
protected final Map<Class, LocationStrategy> decisionClassCache = new HashMap<>(); | ||
|
||
public Locator() { | ||
decisionClassCache.put(Boolean.class, new ImmutableLocationStrategy()); | ||
decisionClassCache.put(Byte.class, new ImmutableLocationStrategy()); | ||
decisionClassCache.put(Short.class, new ImmutableLocationStrategy()); | ||
decisionClassCache.put(Integer.class, new ImmutableLocationStrategy()); | ||
decisionClassCache.put(Long.class, new ImmutableLocationStrategy()); | ||
decisionClassCache.put(Float.class, new ImmutableLocationStrategy()); | ||
decisionClassCache.put(Double.class, new ImmutableLocationStrategy()); | ||
decisionClassCache.put(BigInteger.class, new ImmutableLocationStrategy()); | ||
decisionClassCache.put(BigDecimal.class, new ImmutableLocationStrategy()); | ||
decisionClassCache.put(Character.class, new ImmutableLocationStrategy()); | ||
decisionClassCache.put(String.class, new ImmutableLocationStrategy()); | ||
decisionClassCache.put(LocalDate.class, new ImmutableLocationStrategy()); | ||
decisionClassCache.put(LocalTime.class, new ImmutableLocationStrategy()); | ||
decisionClassCache.put(LocalDateTime.class, new ImmutableLocationStrategy()); | ||
|
||
} | ||
|
||
public <E> E locateWorkingObject(E externalObject) { | ||
if (externalObject == null) { | ||
return null; | ||
} | ||
// TODO HACK UNEFFICIENT BUGGY IMPLEMENTATION!!!! | ||
|
||
// SolutionDescriptor<Solution_> solutionDescriptor = getSolutionDescriptor(); | ||
// for (Object object : solutionDescriptor.getAllFacts(workingSolution)) { | ||
// if (externalObject.toString().equals(object.toString())) { | ||
// return (E) object; | ||
// } | ||
// } | ||
|
||
throw new IllegalArgumentException("The externalObject (" + externalObject + ") cannot be located."); | ||
} | ||
|
||
public void clearWorkingSolution() { | ||
|
||
} | ||
|
||
private interface LocationStrategy { | ||
|
||
} | ||
|
||
private static class ImmutableLocationStrategy implements LocationStrategy { | ||
|
||
} | ||
|
||
private static class PlanningIdLocationStrategy implements LocationStrategy { | ||
|
||
} | ||
|
||
private static class EqualsLocationStrategy implements LocationStrategy { | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.