-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Multi-threaded solving and nearby selection become services (…
…#53) Signed-off-by: Lukáš Petrovický <[email protected]>
- Loading branch information
Showing
99 changed files
with
985 additions
and
671 deletions.
There are no files selected for viewing
41 changes: 41 additions & 0 deletions
41
...ore-impl/src/main/java/ai/timefold/solver/core/MultithreadedSolvingEnterpriseService.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,41 @@ | ||
package ai.timefold.solver.core; | ||
|
||
import java.util.Iterator; | ||
import java.util.ServiceLoader; | ||
|
||
import ai.timefold.solver.core.config.solver.EnvironmentMode; | ||
import ai.timefold.solver.core.impl.constructionheuristic.decider.ConstructionHeuristicDecider; | ||
import ai.timefold.solver.core.impl.constructionheuristic.decider.forager.ConstructionHeuristicForager; | ||
import ai.timefold.solver.core.impl.heuristic.HeuristicConfigPolicy; | ||
import ai.timefold.solver.core.impl.heuristic.selector.move.MoveSelector; | ||
import ai.timefold.solver.core.impl.localsearch.decider.LocalSearchDecider; | ||
import ai.timefold.solver.core.impl.localsearch.decider.acceptor.Acceptor; | ||
import ai.timefold.solver.core.impl.localsearch.decider.forager.LocalSearchForager; | ||
import ai.timefold.solver.core.impl.solver.termination.Termination; | ||
|
||
public interface MultithreadedSolvingEnterpriseService { | ||
|
||
static MultithreadedSolvingEnterpriseService load(Integer moveThreadCount) { | ||
ServiceLoader<MultithreadedSolvingEnterpriseService> serviceLoader = | ||
ServiceLoader.load(MultithreadedSolvingEnterpriseService.class); | ||
Iterator<MultithreadedSolvingEnterpriseService> iterator = serviceLoader.iterator(); | ||
if (!iterator.hasNext()) { | ||
throw new IllegalStateException( | ||
"Multi-threaded solving requested with moveThreadCount (" + moveThreadCount | ||
+ ") but Timefold Enterprise not found on classpath.\n" + | ||
"Either add the ai.timefold.solver:timefold-solver-enterprise dependency, " + | ||
"or remove moveThreadCount from solver configuration.\n" + | ||
"Note: Timefold Enterprise is a commercial product."); | ||
} | ||
return iterator.next(); | ||
} | ||
|
||
<Solution_> ConstructionHeuristicDecider<Solution_> buildConstructionHeuristic(int moveThreadCount, | ||
Termination<Solution_> termination, ConstructionHeuristicForager<Solution_> forager, | ||
EnvironmentMode environmentMode, HeuristicConfigPolicy<Solution_> configPolicy); | ||
|
||
<Solution_> LocalSearchDecider<Solution_> buildLocalSearch(int moveThreadCount, Termination<Solution_> termination, | ||
MoveSelector<Solution_> moveSelector, Acceptor<Solution_> acceptor, LocalSearchForager<Solution_> forager, | ||
EnvironmentMode environmentMode, HeuristicConfigPolicy<Solution_> configPolicy); | ||
|
||
} |
54 changes: 54 additions & 0 deletions
54
core/core-impl/src/main/java/ai/timefold/solver/core/NearbySelectionEnterpriseService.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,54 @@ | ||
package ai.timefold.solver.core; | ||
|
||
import java.util.Iterator; | ||
import java.util.ServiceLoader; | ||
|
||
import ai.timefold.solver.core.config.heuristic.selector.common.SelectionCacheType; | ||
import ai.timefold.solver.core.config.heuristic.selector.common.SelectionOrder; | ||
import ai.timefold.solver.core.config.heuristic.selector.common.nearby.NearbySelectionConfig; | ||
import ai.timefold.solver.core.config.heuristic.selector.entity.EntitySelectorConfig; | ||
import ai.timefold.solver.core.config.heuristic.selector.list.DestinationSelectorConfig; | ||
import ai.timefold.solver.core.config.heuristic.selector.list.SubListSelectorConfig; | ||
import ai.timefold.solver.core.config.heuristic.selector.value.ValueSelectorConfig; | ||
import ai.timefold.solver.core.impl.domain.entity.descriptor.EntityDescriptor; | ||
import ai.timefold.solver.core.impl.heuristic.HeuristicConfigPolicy; | ||
import ai.timefold.solver.core.impl.heuristic.selector.entity.EntitySelector; | ||
import ai.timefold.solver.core.impl.heuristic.selector.list.DestinationSelector; | ||
import ai.timefold.solver.core.impl.heuristic.selector.list.ElementDestinationSelector; | ||
import ai.timefold.solver.core.impl.heuristic.selector.list.RandomSubListSelector; | ||
import ai.timefold.solver.core.impl.heuristic.selector.list.SubListSelector; | ||
import ai.timefold.solver.core.impl.heuristic.selector.value.ValueSelector; | ||
|
||
public interface NearbySelectionEnterpriseService { | ||
|
||
static NearbySelectionEnterpriseService load() { | ||
ServiceLoader<NearbySelectionEnterpriseService> serviceLoader = | ||
ServiceLoader.load(NearbySelectionEnterpriseService.class); | ||
Iterator<NearbySelectionEnterpriseService> iterator = serviceLoader.iterator(); | ||
if (!iterator.hasNext()) { | ||
throw new IllegalStateException( | ||
"Nearby selection requested but Timefold Enterprise not found on classpath.\n" + | ||
"Either add the ai.timefold.solver:timefold-solver-enterprise dependency, " + | ||
"or remove nearby selection from solver configuration.\n" + | ||
"Note: Timefold Enterprise is a commercial product."); | ||
} | ||
return iterator.next(); | ||
} | ||
|
||
<Solution_> EntitySelector<Solution_> applyNearbySelection(EntitySelectorConfig entitySelectorConfig, | ||
HeuristicConfigPolicy<Solution_> configPolicy, NearbySelectionConfig nearbySelectionConfig, | ||
SelectionCacheType minimumCacheType, SelectionOrder resolvedSelectionOrder, | ||
EntitySelector<Solution_> entitySelector); | ||
|
||
<Solution_> ValueSelector<Solution_> applyNearbySelection(ValueSelectorConfig valueSelectorConfig, | ||
HeuristicConfigPolicy<Solution_> configPolicy, EntityDescriptor<Solution_> entityDescriptor, | ||
SelectionCacheType minimumCacheType, SelectionOrder resolvedSelectionOrder, ValueSelector<Solution_> valueSelector); | ||
|
||
<Solution_> SubListSelector<Solution_> applyNearbySelection(SubListSelectorConfig subListSelectorConfig, | ||
HeuristicConfigPolicy<Solution_> configPolicy, SelectionCacheType minimumCacheType, | ||
SelectionOrder resolvedSelectionOrder, RandomSubListSelector<Solution_> subListSelector); | ||
|
||
<Solution_> DestinationSelector<Solution_> applyNearbySelection(DestinationSelectorConfig destinationSelectorConfig, | ||
HeuristicConfigPolicy<Solution_> configPolicy, SelectionCacheType minimumCacheType, | ||
SelectionOrder resolvedSelectionOrder, ElementDestinationSelector<Solution_> destinationSelector); | ||
} |
33 changes: 33 additions & 0 deletions
33
core/core-impl/src/main/java/ai/timefold/solver/core/PartitionedSearchEnterpriseService.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,33 @@ | ||
package ai.timefold.solver.core; | ||
|
||
import java.util.Iterator; | ||
import java.util.ServiceLoader; | ||
import java.util.function.BiFunction; | ||
|
||
import ai.timefold.solver.core.config.partitionedsearch.PartitionedSearchPhaseConfig; | ||
import ai.timefold.solver.core.impl.heuristic.HeuristicConfigPolicy; | ||
import ai.timefold.solver.core.impl.partitionedsearch.PartitionedSearchPhase; | ||
import ai.timefold.solver.core.impl.solver.termination.Termination; | ||
|
||
public interface PartitionedSearchEnterpriseService { | ||
|
||
static PartitionedSearchEnterpriseService load() { | ||
ServiceLoader<PartitionedSearchEnterpriseService> serviceLoader = | ||
ServiceLoader.load(PartitionedSearchEnterpriseService.class); | ||
Iterator<PartitionedSearchEnterpriseService> iterator = serviceLoader.iterator(); | ||
if (!iterator.hasNext()) { | ||
throw new IllegalStateException( | ||
"Partitioned search requested but Timefold Enterprise not found on classpath.\n" + | ||
"Either add the ai.timefold.solver:timefold-solver-enterprise dependency, " + | ||
"or remove partitioned search from solver configuration.\n" + | ||
"Note: Timefold Enterprise is a commercial product."); | ||
} | ||
return iterator.next(); | ||
} | ||
|
||
<Solution_> PartitionedSearchPhase<Solution_> buildPartitionedSearch(int phaseIndex, | ||
PartitionedSearchPhaseConfig phaseConfig, HeuristicConfigPolicy<Solution_> solverConfigPolicy, | ||
Termination<Solution_> solverTermination, | ||
BiFunction<HeuristicConfigPolicy<Solution_>, Termination<Solution_>, Termination<Solution_>> phaseTerminationFunction); | ||
|
||
} |
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.