|
| 1 | +package ai.timefold.solver.core.enterprise; |
| 2 | + |
| 3 | +import java.util.ServiceLoader; |
| 4 | +import java.util.function.BiFunction; |
| 5 | + |
| 6 | +import ai.timefold.solver.core.api.solver.SolverFactory; |
| 7 | +import ai.timefold.solver.core.config.heuristic.selector.common.SelectionCacheType; |
| 8 | +import ai.timefold.solver.core.config.heuristic.selector.common.SelectionOrder; |
| 9 | +import ai.timefold.solver.core.config.heuristic.selector.common.nearby.NearbySelectionConfig; |
| 10 | +import ai.timefold.solver.core.config.heuristic.selector.entity.EntitySelectorConfig; |
| 11 | +import ai.timefold.solver.core.config.heuristic.selector.list.DestinationSelectorConfig; |
| 12 | +import ai.timefold.solver.core.config.heuristic.selector.list.SubListSelectorConfig; |
| 13 | +import ai.timefold.solver.core.config.heuristic.selector.value.ValueSelectorConfig; |
| 14 | +import ai.timefold.solver.core.config.partitionedsearch.PartitionedSearchPhaseConfig; |
| 15 | +import ai.timefold.solver.core.config.solver.EnvironmentMode; |
| 16 | +import ai.timefold.solver.core.impl.constructionheuristic.decider.ConstructionHeuristicDecider; |
| 17 | +import ai.timefold.solver.core.impl.constructionheuristic.decider.forager.ConstructionHeuristicForager; |
| 18 | +import ai.timefold.solver.core.impl.domain.entity.descriptor.EntityDescriptor; |
| 19 | +import ai.timefold.solver.core.impl.heuristic.HeuristicConfigPolicy; |
| 20 | +import ai.timefold.solver.core.impl.heuristic.selector.entity.EntitySelector; |
| 21 | +import ai.timefold.solver.core.impl.heuristic.selector.list.DestinationSelector; |
| 22 | +import ai.timefold.solver.core.impl.heuristic.selector.list.ElementDestinationSelector; |
| 23 | +import ai.timefold.solver.core.impl.heuristic.selector.list.RandomSubListSelector; |
| 24 | +import ai.timefold.solver.core.impl.heuristic.selector.list.SubListSelector; |
| 25 | +import ai.timefold.solver.core.impl.heuristic.selector.move.MoveSelector; |
| 26 | +import ai.timefold.solver.core.impl.heuristic.selector.value.ValueSelector; |
| 27 | +import ai.timefold.solver.core.impl.localsearch.decider.LocalSearchDecider; |
| 28 | +import ai.timefold.solver.core.impl.localsearch.decider.acceptor.Acceptor; |
| 29 | +import ai.timefold.solver.core.impl.localsearch.decider.forager.LocalSearchForager; |
| 30 | +import ai.timefold.solver.core.impl.partitionedsearch.PartitionedSearchPhase; |
| 31 | +import ai.timefold.solver.core.impl.solver.termination.Termination; |
| 32 | + |
| 33 | +public interface TimefoldSolverEnterpriseService { |
| 34 | + |
| 35 | + static String identifySolverVersion() { |
| 36 | + var packaging = TimefoldSolverEnterpriseService.load() == null ? "Community Edition" : "Enterprise Edition"; |
| 37 | + var version = SolverFactory.class.getPackage().getImplementationVersion(); |
| 38 | + return packaging + " " + (version == null ? "(Development snapshot)" : "v" + version); |
| 39 | + } |
| 40 | + |
| 41 | + static TimefoldSolverEnterpriseService load() { |
| 42 | + var serviceLoader = ServiceLoader.load(TimefoldSolverEnterpriseService.class); |
| 43 | + var iterator = serviceLoader.iterator(); |
| 44 | + return iterator.hasNext() ? iterator.next() : null; |
| 45 | + } |
| 46 | + |
| 47 | + static TimefoldSolverEnterpriseService loadOrFail(Feature feature) { |
| 48 | + var service = load(); |
| 49 | + if (service == null) { |
| 50 | + throw new IllegalStateException(""" |
| 51 | + %s requested but Timefold Solver Enterprise Edition not found on classpath |
| 52 | + Either add the ai.timefold.solver.enterprise:timefold-solver-enterprise-core dependency, |
| 53 | + or %s. |
| 54 | + "Note: Timefold Solver Enterprise Edition is a commercial product.""" |
| 55 | + .formatted(feature.getName(), feature.getWorkaround())); |
| 56 | + } |
| 57 | + return service; |
| 58 | + } |
| 59 | + |
| 60 | + <Solution_> ConstructionHeuristicDecider<Solution_> buildConstructionHeuristic(int moveThreadCount, |
| 61 | + Termination<Solution_> termination, ConstructionHeuristicForager<Solution_> forager, |
| 62 | + EnvironmentMode environmentMode, HeuristicConfigPolicy<Solution_> configPolicy); |
| 63 | + |
| 64 | + <Solution_> LocalSearchDecider<Solution_> buildLocalSearch(int moveThreadCount, Termination<Solution_> termination, |
| 65 | + MoveSelector<Solution_> moveSelector, Acceptor<Solution_> acceptor, LocalSearchForager<Solution_> forager, |
| 66 | + EnvironmentMode environmentMode, HeuristicConfigPolicy<Solution_> configPolicy); |
| 67 | + |
| 68 | + <Solution_> PartitionedSearchPhase<Solution_> buildPartitionedSearch(int phaseIndex, |
| 69 | + PartitionedSearchPhaseConfig phaseConfig, HeuristicConfigPolicy<Solution_> solverConfigPolicy, |
| 70 | + Termination<Solution_> solverTermination, |
| 71 | + BiFunction<HeuristicConfigPolicy<Solution_>, Termination<Solution_>, Termination<Solution_>> phaseTerminationFunction); |
| 72 | + |
| 73 | + <Solution_> EntitySelector<Solution_> applyNearbySelection(EntitySelectorConfig entitySelectorConfig, |
| 74 | + HeuristicConfigPolicy<Solution_> configPolicy, NearbySelectionConfig nearbySelectionConfig, |
| 75 | + SelectionCacheType minimumCacheType, SelectionOrder resolvedSelectionOrder, |
| 76 | + EntitySelector<Solution_> entitySelector); |
| 77 | + |
| 78 | + <Solution_> ValueSelector<Solution_> applyNearbySelection(ValueSelectorConfig valueSelectorConfig, |
| 79 | + HeuristicConfigPolicy<Solution_> configPolicy, EntityDescriptor<Solution_> entityDescriptor, |
| 80 | + SelectionCacheType minimumCacheType, SelectionOrder resolvedSelectionOrder, ValueSelector<Solution_> valueSelector); |
| 81 | + |
| 82 | + <Solution_> SubListSelector<Solution_> applyNearbySelection(SubListSelectorConfig subListSelectorConfig, |
| 83 | + HeuristicConfigPolicy<Solution_> configPolicy, SelectionCacheType minimumCacheType, |
| 84 | + SelectionOrder resolvedSelectionOrder, RandomSubListSelector<Solution_> subListSelector); |
| 85 | + |
| 86 | + <Solution_> DestinationSelector<Solution_> applyNearbySelection(DestinationSelectorConfig destinationSelectorConfig, |
| 87 | + HeuristicConfigPolicy<Solution_> configPolicy, SelectionCacheType minimumCacheType, |
| 88 | + SelectionOrder resolvedSelectionOrder, ElementDestinationSelector<Solution_> destinationSelector); |
| 89 | + |
| 90 | + public enum Feature { |
| 91 | + MULTITHREADED_SOLVING("Multi-threaded solving", "remove moveThreadCount from solver configuration"), |
| 92 | + PARTITIONED_SEARCH("Partitioned search", "remove partitioned search phase from solver configuration"), |
| 93 | + NEARBY_SELECTION("Nearby selection", "remove nearby selection from solver configuration"); |
| 94 | + |
| 95 | + private final String name; |
| 96 | + private final String workaround; |
| 97 | + |
| 98 | + Feature(String name, String workaround) { |
| 99 | + this.name = name; |
| 100 | + this.workaround = workaround; |
| 101 | + } |
| 102 | + |
| 103 | + public String getName() { |
| 104 | + return name; |
| 105 | + } |
| 106 | + |
| 107 | + public String getWorkaround() { |
| 108 | + return workaround; |
| 109 | + } |
| 110 | + |
| 111 | + } |
| 112 | + |
| 113 | +} |
0 commit comments