Interface IOptimization
- All Superinterfaces:
IOptimizationEventListener
- All Known Implementing Classes:
Optimization
- Since:
- 29/07/2018
- Version:
- 14/10/2019
- Author:
- DNA
-
Method Summary
Modifier and TypeMethodDescriptionvoidaddDistanceMatrix(double[][] distanceMatrix) Deprecated.voidaddElement(INode node) Adds anINodeto the optimization.voidaddElement(IPillarNode pillarnode) Adds aIPillarNodeto the optimization.voidaddElement(IResource res) Adds anIResourceto the optimization.voidaddElement(Properties properties) Sets the given properties asOptimization.getUserProperties()and invokes the user properties.voidAdds allnodesin the list to the optimization.voidaddReassignNodes(List<INode> nodes) Adds reassign nodes.voidaddReassignResources(List<IResource> ress) Adds reassign resources.voidaddResources(List<IResource> resources) Adds allresourcesin the list to the optimization.voidaddTimeMatrix(double[][] timeMatrix) Deprecated.Adding time as aINodeConnectorItemis preferred.voidClean up none optimizable elements detail holder.booleanClean up optimization boolean.CallsIEntity.getAllEntityElements()andINodeUnassigner.getUnassignedNodes(), then returns all of these elements.getAllRoutesElements(String resourceId) com.dna.jopt.revision.algorithm.IOptimizationAlgorithmgetFirstMatchingRoute(INode node) getFirstMatchingRoute(String nodeId) longgetId()Gets the id of the current thread.Gets theOptimization.getNodeConnector().getNoneOptimizableNodDetail(String elementId) Gets the value in theOptimization.getNoneOptimizableElementsDetailHolder()for the givenelementId.Gets the optimization element.getOptimizationElement(String id, boolean includeUnassignedElements) Gets the optimization element.Gets the optimization run ident.Gets the definedIOptimizationScheme.com.dna.jopt.framework.body.setup.IOptimizationSetupGets theIOptimizationSetup.intcom.dna.jopt.framework.inputplausibility.properties.IPropertyProviderGets the property provider throughIOptimizationSetup.getPropertyProvider().Gets theOptimization.threadPrefix, the standard value is"JOPT-".Gets an unassigned element if present.Gets theINodeUnassignerof the optimization.Gets theOptimization.userEntityCoreBuildOptionsOpt.Gets information about the build of the library.Gets theOptimization.workEntity.voidHandle on error interruption state after throwable in preparation statebooleanChecksOptimization.hasEntitySetByUser(), the default value isfalse.booleanUsed internally to keep track if the optimization is stopped.voidChecks thatOptimization.getCurrentOptimizationAlgo()is notnull, then callsIOptimizationAlgorithm.jumpToEnd().voidpause()Checks thatOptimization.getCurrentOptimizationAlgo()is notnull, then callsIOptimizationAlgorithm.pause().voidproceed()Checks thatOptimization.getCurrentOptimizationAlgo()is notnull, then callsIOptimizationAlgorithm.proceed()which wakes up all threads that are waiting on this object's monitor.voidputNoneOptimizableNodDetail(String elementId, ILogicRouteElementDetailItem details) Puts a value atelementIdinOptimization.getNoneOptimizableElementsDetailHolder().voidRequested asynchronous optimization result.voidrequestExportState(OutputStream output, String executionId) Request export state with 100 Days of internal timeOut.voidrequestExportState(OutputStream output, String executionId, Duration timeOut) Request export state with time out.voidRequesting aIOptimizationProgress progresswhich will be provided in an async.voidRequesting an intermediateIOptimizationResult resultwhich will be provided in an async.voidReset initial entity.voidsetAutoFilterExecutionSchedule(List<Double> executionList) voidsetInitialEntity(IEntity initialEntity) voidsetInitialEntity(IEntity initialEntity, boolean reassignUnassignedNode) Sets the givenIEntityas the initial Entity.voidsetInitialEntityRenewAutoFilterControllers(IEntity initialEntity) SetsOptimization.hasEntitySetByUser()andtryRenewAutoFilterControllertotrue, then sets the input initialEntity as theOptimization.getWorkEntity().voidsetLicenceKey(String key) Deprecated.voidsetLicense(com.dna.jopt.framework.licensing.IRapotLicense key) Deprecated.voidsetLicense(File file) Deprecated.voidsetLicense(ObjectInputStream licensestream) Deprecated.voidsetLicenseJSON(File file) voidsetLicenseJSON(String jsonLic) voidsetNodeConnector(INodeEdgeConnector nodeConnector) Sets theOptimization.getNodeConnector().voidsetOptimizationAlgorithmStart(com.dna.jopt.revision.algorithm.IOptimizationAlgorithm.OptimizationAlgorithmStart modeSA, com.dna.jopt.revision.algorithm.IOptimizationAlgorithm.OptimizationAlgorithmStart modeGE) Sets theOptimization.initialOptimizationModeGEandOptimization.initialOptimizationModeSA, both have the default valueSTATE_MODE_BATCH.booleansetOptimizationCreator(String creator) booleansetOptimizationRunIdent(String ident) Sets the optimization run identification string.voidsetOptimizationScheme(IOptimizationScheme optimizationScheme) Sets theIOptimizationScheme.voidsetThreadPrefix(String threadPrefix) Sets theOptimization.getThreadPrefix(), the default value is"JOPT-".voidInternally called to settle the optimization, e.g.voidsetTypeDictionaryManager(ITypeDictionaryManager typeDictionaryManager) voidsetUnassignNodeManager(INodeUnassigner unassignNodeManager) Sets theINodeUnassigner.voidsetUserEntityCoreBuildOptions(Properties userEntityCoreBuildOptions) SetsOptimization.userEntityCoreBuildOptionsOptas anOptionalwith the parameter values if notnull.voidsetWorkEntity(IEntity currentBestEntity) Sets theOptimization.workEntity.voidDeprecated.Start asynchronous optimization run.Start run async.startRunAsync(ObjectInputStream license) Deprecated.startRunSync(long timeout, TimeUnit unit) Start run sync.voidChecks thatOptimization.getCurrentOptimizationAlgo()is notnull, then setsOptimization.isStopOptimization()totrueand callsIOptimizationAlgorithm.jumpToEnd().Methods inherited from interface com.dna.jopt.framework.body.event.IOptimizationEventListener
onAfterNodeFilteringOptimizationResult, onAsynchronousOptimizationResult, onBeforeNodeFilteringOptimizationResult, onError, onError, onNodeFiltering, onNodeFiltering, onProgress, onProgress, onRequestCodeExecutionDone, onStatus, onStatus, onWarning, onWarning
-
Method Details
-
proceed
void proceed()Checks thatOptimization.getCurrentOptimizationAlgo()is notnull, then callsIOptimizationAlgorithm.proceed()which wakes up all threads that are waiting on this object's monitor.- See Also:
-
pause
void pause()Checks thatOptimization.getCurrentOptimizationAlgo()is notnull, then callsIOptimizationAlgorithm.pause().- See Also:
-
stopOptimization
void stopOptimization()Checks thatOptimization.getCurrentOptimizationAlgo()is notnull, then setsOptimization.isStopOptimization()totrueand callsIOptimizationAlgorithm.jumpToEnd(). This call will trigger a graceful optimization stop triggering the optimization result. -
jumpToNextStage
void jumpToNextStage()Checks thatOptimization.getCurrentOptimizationAlgo()is notnull, then callsIOptimizationAlgorithm.jumpToEnd(). -
requestResult
void requestResult()Requesting an intermediateIOptimizationResult resultwhich will be provided in an async. manner.Checks that
Optimization.getCurrentOptimizationAlgo()is notnull, then callsIOptimizationAlgorithm.requestResult(). -
requestedAsynchronousOptimizationResult
Requested asynchronous optimization result.- Specified by:
requestedAsynchronousOptimizationResultin interfaceIOptimizationEventListener- Parameters:
result- the result to print
-
setInitialEntity
Sets the initialIEntityas the workEntity andOptimization.hasEntitySetByUser()totrue. This method is used to load custom solutions and is used during the loading of a snapshot.Will throw an
IllegalStateExceptionif the initial entity isnull.- Parameters:
initialEntity- the new initial entity
-
setInitialEntity
Sets the givenIEntityas the initial Entity.- Parameters:
initialEntity- the entity to be setreassignUnassignedNode- the reassign unassigned node
-
setThreadPrefix
Sets theOptimization.getThreadPrefix(), the default value is"JOPT-". This helps to identify the running optimization thread on the user system.- Parameters:
threadPrefix- the prefix to be set
-
getPropertyProvider
com.dna.jopt.framework.inputplausibility.properties.IPropertyProvider getPropertyProvider()Gets the property provider throughIOptimizationSetup.getPropertyProvider().- Returns:
- the propertyProvider
-
setNodeConnector
Sets theOptimization.getNodeConnector().Cannot be
null.- Parameters:
nodeConnector- the new node connector
-
getNodeConnector
INodeEdgeConnector getNodeConnector()Gets theOptimization.getNodeConnector().- Returns:
- the node connector
-
addElement
Adds anINodeto the optimization.- Parameters:
node- the element to be added.
-
addElement
Adds anIResourceto the optimization.- Parameters:
res- the resource
-
addElement
Sets the given properties asOptimization.getUserProperties()and invokes the user properties.A list of all properties can be generated by the following code example:
public static void printJOptProperties() { List<String> categories = new ArrayList<>(); categories.add("CATEGORY_MISC"); categories.add("CATEGORY_SYSTEM"); categories.add("CATEGORY_OPTIMIZATION_GENERAL_SETUP"); categories.add("CATEGORY_OPTIMIZATION_CONSTRUCTION"); categories.add("CATEGORY_OPTIMIZATION_PRE_OPTIMIZATION_SETUP"); categories.add("CATEGORY_OPTIMIZATION_GENETIC_SETUP"); categories.add("CATEGORY_OPTIMIZATION_2OPT"); categories.add("CATEGORY_OPTIMIZATION_WEIGHTS"); categories.add("CATEGORY_OPTIMIZATION_AUTOFILTER"); categories.add("CATEGORY_OPTIMIZATION_CO_SETUP"); categories.add("CATEGORY_OPTIMIZATION_DEPRECATED"); IOptimization myDummyOptimization = new Optimization(); // Read out current properties List<PropertyItem> categorySortedPropItems = myDummyOptimization.getPropertyProvider() .getPropertyItems() .stream() .sorted((o1,o2)->Integer.compare(o1.getCategoryIdent(), o2.getCategoryIdent())) .collect(Collectors.toList()); categorySortedPropItems .stream() .forEach( i -> { if (i.getCategoryIdent() == PropertyItem.CATEGORY_OPTIMIZATION_DEPRECATED) { System.out.print("\n-== DEPRECATED PROPERTY ==-"); } else { System.out.print("\n"); } System.out.print( "\nCategory: " + categories.get(i.getCategoryIdent()) + "\nDescription: " + i.getDescription() + "\nDefault Key: " + i.getValidatedPropertyName() + "\nDefault Value: " + i.getDefaultValue() + "\nAllowed Values: " + i.getAllowedValues() + "\n"); }); }- Parameters:
properties- the properties
-
setLicenceKey
Deprecated.Sets the licence key.- Parameters:
key- the string new licence key
-
setLicense
Deprecated.Sets the license key loaded from a file and already read in license object.- Parameters:
key- the iRapotLicense new license
-
setLicense
Deprecated.Sets the license key via an input stream.The following code example can be used to read in a file from a resource folder:
public class ExampleLicenseHelper { private static final String LICNCES_PATH = "src/test/resources/myKeyFile.dli"; private ExampleLicenseHelper() { // Nothing to do } public static boolean setLicense(IOptimization opti) { try { ObjectInputStream ois = new ObjectInputStream(new FileInputStream(new File(ExampleLicenseHelper.LICNCES_PATH))); opti.setLicense(ois); return true; } catch (IOException e) { e.printStackTrace(); return false; } } }- Parameters:
licensestream- the objectinputstream
-
setLicense
Deprecated.Sets the license key via a file object.- Parameters:
file- the key- Throws:
IOException- the io exception
-
addElement
Adds aIPillarNodeto the optimization.- Parameters:
pillarnode- the pillarnode to be added
-
setOptimizationScheme
Sets theIOptimizationScheme.- Parameters:
optimizationScheme- the iOptimizationscheme to add
-
getCurrentOptimizationAlgo
com.dna.jopt.revision.algorithm.IOptimizationAlgorithm getCurrentOptimizationAlgo()CallsOptimizationSubController.getCurrentOptimizationAlgo(). Returns the currently running optimization algorithm.- Returns:
- the current optimizationalgorithm
-
getOptimizationScheme
IOptimizationScheme getOptimizationScheme()Gets the definedIOptimizationScheme.- Returns:
- the optimizationscheme
-
settleOptimization
void settleOptimization()Internally called to settle the optimization, e.g. finishing all running postStepManagers. -
getUnassignNodeManager
INodeUnassigner getUnassignNodeManager()Gets theINodeUnassignerof the optimization.- Returns:
- the unassignNodeManager
-
setUnassignNodeManager
Sets theINodeUnassigner.Cannot be
null.- Parameters:
unassignNodeManager- the unassign node manager
-
startAsynchronousOptimizationRun
Deprecated.Start asynchronous optimization run.- Throws:
InvalidLicenceException- the invalid licence exception
-
getVersion
String getVersion()Gets information about the build of the library.- Returns:
- the string myVersion
-
addDistanceMatrix
Deprecated.Adding distance as aINodeConnectorItemis preferred.Sets a distancematrix. Later on this information will be used to create aNodeEdgeConnector. This method acts as a wrapper.- Parameters:
distanceMatrix- the double array distance matrix- Category:
- Legacy
-
addTimeMatrix
Deprecated.Adding time as aINodeConnectorItemis preferred.Sets a timematrix. Later on this information will be used to create aNodeEdgeConnector. This method acts as a wrapper.s.- Parameters:
timeMatrix- the double array time matrix- Category:
- Legacy
-
getOptimizationStage
int getOptimizationStage()CallsOptimizationSubController.getCurrentOptimizationAlgo(). For example, in case three optimization algorithms and currently the second algorithm is running the stage identifier is one. The first algorithm would have the stage identifier zero.- Returns:
- returns the optimizationAlgo
-
getThreadPrefix
String getThreadPrefix()Gets theOptimization.threadPrefix, the standard value is"JOPT-".- Returns:
- the string threadPrefix
-
getOptimizationSetup
com.dna.jopt.framework.body.setup.IOptimizationSetup getOptimizationSetup()Gets theIOptimizationSetup.- Returns:
- the optimizationSetup
-
isStopOptimization
boolean isStopOptimization()Used internally to keep track if the optimization is stopped.- Returns:
- the boolean optimizationWasStopped
-
getWorkEntity
IEntity getWorkEntity()Gets theOptimization.workEntity.- Returns:
- the iEntity workEntity
-
setWorkEntity
Sets theOptimization.workEntity.- Parameters:
currentBestEntity- the workEntity to be set
-
getAllElements
List<IOptimizationElement> getAllElements()CallsIEntity.getAllEntityElements()andINodeUnassigner.getUnassignedNodes(), then returns all of these elements. Returns a newArraylistif these arenull.- Returns:
- the
List<IOptimizationElement>with all the elements
-
getNoneOptimizableElements
List<IOptimizationElement> getNoneOptimizableElements()CallsIEntity.getNoneOptimizableElements()ifOptimization.getWorkEntity()is notnull. Otherwise returns a newArraylist.- Returns:
- a
List<IOptimizationElement>
-
getOptimizableElements
List<IOptimizationElement> getOptimizableElements()CallsIEntity.getNoneOptimizableElements()if thegetWorkEntity()is notnull. Otherwise returns a newArraylist.- Returns:
- the
List<IOptimizationElement>
-
getAllRoutesElements
CallsIEntity.getAllRoutesElements(String), ifgetWorkEntity()is notnull.If the route of the given resource does not have any elements returns a new
ArrayList<>.- Parameters:
resourceId- the string resourceId- Returns:
- the
ArrayList<>of the route elements
-
getNoneOptimizableElementsDetails
Map<String,ILogicRouteElementDetailItem> getNoneOptimizableElementsDetails()- Returns:
- none optimizable elements details
-
getNoneOptimizableNodDetail
Gets the value in theOptimization.getNoneOptimizableElementsDetailHolder()for the givenelementId. This method is primarily used for internal purpose. Please try to extract details from the route itself.- Parameters:
elementId- the string key for the value- Returns:
- the value of the elementId in noneOptimizableElementsDetailHolder
-
putNoneOptimizableNodDetail
Puts a value atelementIdinOptimization.getNoneOptimizableElementsDetailHolder().- Parameters:
elementId- the string id for the value to be putdetails- the iLogicRouteElementDetailItem that is supposed to be put
-
addNodes
Adds allnodesin the list to the optimization.- Parameters:
nodes- thelist<INode>of nodes to be added
-
addResources
Adds allresourcesin the list to the optimization.- Parameters:
resources- thelist<IResource>to be added
-
hasEntitySetByUser
boolean hasEntitySetByUser()ChecksOptimization.hasEntitySetByUser(), the default value isfalse.- Returns:
- the boolean hasUserEntity
-
getId
long getId()Gets the id of the current thread.- Returns:
- the long thread id
- See Also:
-
getOptimizationEvents
OptimizationEvents getOptimizationEvents()Gets theOptimizationEventswhich are backed by multipleReplaySubjectandCompletableFuture.OptimizationEventscan be used to subscribe to different events of the optimization.- Returns:
- the optimizationevents
-
setOptimizationAlgorithmStart
void setOptimizationAlgorithmStart(com.dna.jopt.revision.algorithm.IOptimizationAlgorithm.OptimizationAlgorithmStart modeSA, com.dna.jopt.revision.algorithm.IOptimizationAlgorithm.OptimizationAlgorithmStart modeGE) Sets theOptimization.initialOptimizationModeGEandOptimization.initialOptimizationModeSA, both have the default valueSTATE_MODE_BATCH.- Parameters:
modeSA- the modeSAmodeGE- the modeGE
-
startRunSync
IOptimizationResult startRunSync(long timeout, TimeUnit unit) throws InvalidLicenceException, InterruptedException, ExecutionException, TimeoutException Start run sync. internally creates acompletable future. The optimization is started within aForkJoinPool. Internallyget()is called on it so that the code will block until thecompletable futurereturns. However, as the run is outsourced into multiple threads the Optimization object itself stays responsive to allow for example to request an intermediate optimization result.The
timeoutsets the time within which thecompletable futureneeds to return, otherwise aTimeoutExceptionis thrownFor use without a timeout please use
startRunAsync()- Parameters:
timeout- the long number of the to be defined time unit until timeoutunit- the timeUnit of the timeout- Returns:
- the ioptimization result
- Throws:
InvalidLicenceException- the invalid licence exceptionInterruptedException- the interrupted exceptionExecutionException- the execution exceptionTimeoutException- the timeout exception if the completable future has not been done within the timeout
-
startRunAsync
Start run async. creates acompletable futurewhich is returned.- Returns:
- completable future
- Throws:
InvalidLicenceException- the invalid licence exception
-
setInitialEntityRenewAutoFilterControllers
SetsOptimization.hasEntitySetByUser()andtryRenewAutoFilterControllertotrue, then sets the input initialEntity as theOptimization.getWorkEntity().- Parameters:
initialEntity- the iEntity to be set as workEntity
-
setAutoFilterExecutionSchedule
- Parameters:
executionList- theList<Double>to be set as userExecutionList
-
getUserProperties
Optional<Properties> getUserProperties()- Returns:
- the userProperties
-
cleanUpOptimization
boolean cleanUpOptimization()Clean up optimization boolean. Returnstrue.- Returns:
- true
-
cleanUpNoneOptimizableElementsDetailHolder
Clean up none optimizable elements detail holder.- Parameters:
deadIds- the dead ids
-
getCoreVersionProperties
Properties getCoreVersionProperties()- Returns:
- the
versionCoreProperties
-
getCoreVersion
String getCoreVersion()- Returns:
- the
versionCoreProperties
-
setUserEntityCoreBuildOptions
SetsOptimization.userEntityCoreBuildOptionsOptas anOptionalwith the parameter values if notnull. Will set it as an emptyOptionalifnull.- Parameters:
userEntityCoreBuildOptions- the optional with the given parameters
-
getUserEntityCoreBuildOptions
Optional<Properties> getUserEntityCoreBuildOptions()Gets theOptimization.userEntityCoreBuildOptionsOpt. The default value is an emptyOptional.- Returns:
- the optional userEntityCoreBuildOptionsOpt
-
getFirstMatchingRoute
- Parameters:
nodeId- the string of the nodeId that is supposed to match- Returns:
- an optional with the matching route or an empty optional
-
getFirstMatchingRoute
- Parameters:
node- the iNode that is supposed to match- Returns:
- an optional with the matching route or an empty optional
-
getAnchoredRoutes
List<ILogicEntityRoute> getAnchoredRoutes()InvokesIEntity.getAnchoredRoutes()ifOptimization.workEntityis notnull. Otherwise returns a newArrayList.- Returns:
- the anchored routes
-
addReassignNodes
Adds reassign nodes. In case a custom solution is usedsetInitialEntity(com.dna.jopt.member.bucket.entity.IEntity), or the optimization is resumed from a snapshot additional nodes can be added. In contrast toaddElement(com.dna.jopt.member.unit.node.INode), nodes are put in an optimized fashion into the existing solution.If no solution by the user is provided, calling this method has the same effect as
addElement(com.dna.jopt.member.unit.node.INode).- Parameters:
nodes- the nodes
-
addReassignResources
Adds reassign resources. In case a custom solution is usedsetInitialEntity(com.dna.jopt.member.bucket.entity.IEntity), or the optimization is resumed from a snapshot additional resources can be added.If no solution by the user is provided, calling this method has the same effect as
addElement(com.dna.jopt.member.unit.node.INode).- Parameters:
ress- the resources
-
startRunAsync
@Deprecated CompletableFuture<IOptimizationResult> startRunAsync(ObjectInputStream license) throws InvalidLicenceException Deprecated.Start run async by providing an additional license stream.- Parameters:
license- the license- Returns:
- the completable future
- Throws:
InvalidLicenceException- the invalid licence exception- See Also:
-
setLicenseJSON
-
setLicenseJSON
- Throws:
IOException
-
getReassignNodes
-
getReassignResources
-
requestProgress
void requestProgress()Requesting aIOptimizationProgress progresswhich will be provided in an async. manner.Checks that
Optimization.getCurrentOptimizationAlgo()is notnull, then callsIOptimizationAlgorithm.requestProgress(). -
requestExportState
Request export state with 100 Days of internal timeOut. The optimization will be saved as JSON to the provided outputStream. Further, when the saving is done, to returned CompletableFuture is completed with the provided executionId.- Parameters:
output- the outputexecutionId- the execution id
-
requestExportState
void requestExportState(OutputStream output, String executionId, Duration timeOut) throws TimeoutException Request export state with time out. The optimization will be saved as JSON to the provided outputStream. Further, when the saving is done, to returned CompletableFuture is completed with the provided executionId.- Parameters:
output- the outputexecutionId- the execution idtimeOut- the time out- Throws:
TimeoutException- the timeout exception
-
resetInitialEntity
void resetInitialEntity()Reset initial entity. This method will reset an entity that was assigned to the optimization. It is only allowed to reset an entity before the optimization is started.This methods helps to use an existing solution to be used only as data provider, ignoring an existing solution.
-
getOptimizationElement
Gets the optimization element. Extracts an element (Resource or Node) that is member of any route of the current optimization run. Unassigned elements are not found.- Parameters:
id- the id- Returns:
- the optimization element
-
getOptimizationElement
Gets the optimization element. Extracts an element (Resource or Node) that is member of any route of the current optimization run. Unassigned elements can be found if includeUnassignedElements is true.- Parameters:
id- the idincludeUnassignedElements- the include unassigned elements- Returns:
- the optimization element
-
getUnassignedElement
Gets an unassigned element if present.- Parameters:
id- the id- Returns:
- the unassigned element
-
setOptimizationRunIdent
Sets the optimization run identification string. This can be an arbitrary user provided String to identify a run. If no ident is provided, the Optimizer will generate an ident whenever the optimization is saved.- Parameters:
ident- the ident- Returns:
- true, if accepted
-
getOptimizationRunIdent
String getOptimizationRunIdent()Gets the optimization run ident. If no ident was provided the Optimizer creates an ident on the first call of this method.- Returns:
- the optimization run ident
-
setOptimizationCreator
-
getOptimizationCreator
-
handleOnErrorInterruptionState
Handle on error interruption state after throwable in preparation state- Parameters:
e- the e
-
getTypeDictionaryManager
ITypeDictionaryManager getTypeDictionaryManager() -
setTypeDictionaryManager
-
INodeConnectorItemis preferred.