public interface IOptimization extends IOptimizationEventListener
Modifier and Type | Method and Description |
---|---|
void |
addDistanceMatrix(double[][] distanceMatrix)
Deprecated.
Adding distance as a
INodeConnectorItem
is preferred. |
void |
addElement(INode node)
Adds an
INode to the optimization. |
void |
addElement(IPillarNode pillarnode)
Adds a
IPillarNode to the optimization. |
void |
addElement(IResource res)
Adds an
IResource to the optimization. |
void |
addElement(Properties properties)
Sets the given properties as
Optimization.getUserProperties() and invokes the user
properties. |
void |
addNodes(List<INode> nodes)
Adds all
nodes in the list to the optimization. |
void |
addReassignNodes(List<INode> nodes)
Adds reassign nodes.
|
void |
addReassignResources(List<IResource> ress)
Adds reassign resources.
|
void |
addResources(List<IResource> resources)
Adds all
resources in the list to the optimization. |
void |
addTimeMatrix(double[][] timeMatrix)
Deprecated.
Adding time as a
INodeConnectorItem is
preferred. |
void |
cleanUpNoneOptimizableElementsDetailHolder(Set<String> deadIds)
Clean up none optimizable elements detail holder.
|
boolean |
cleanUpOptimization()
Clean up optimization boolean.
|
List<IOptimizationElement> |
getAllElements()
Calls
IEntity.getAllEntityElements() and INodeUnassigner.getUnassignedNodes() ,
then returns all of these elements. |
List<IOptimizationElement> |
getAllRoutesElements(String resourceId)
|
List<ILogicEntityRoute> |
getAnchoredRoutes()
|
String |
getCoreVersion()
|
Properties |
getCoreVersionProperties()
|
com.dna.jopt.revision.algorithm.IOptimizationAlgorithm |
getCurrentOptimizationAlgo()
|
Optional<ILogicEntityRoute> |
getFirstMatchingRoute(INode node)
|
Optional<ILogicEntityRoute> |
getFirstMatchingRoute(String nodeId)
|
long |
getId()
Gets the id of the current thread.
|
INodeEdgeConnector |
getNodeConnector()
Gets the
Optimization.getNodeConnector() . |
List<IOptimizationElement> |
getNoneOptimizableElements()
|
Map<String,ILogicRouteElementDetailItem> |
getNoneOptimizableElementsDetails()
|
ILogicRouteElementDetailItem |
getNoneOptimizableNodDetail(String elementId)
Gets the value in the
Optimization.getNoneOptimizableElementsDetailHolder() for the given
elementId . |
List<IOptimizationElement> |
getOptimizableElements()
|
Optional<String> |
getOptimizationCreator() |
Optional<IOptimizationElement> |
getOptimizationElement(String id)
Gets the optimization element.
|
Optional<IOptimizationElement> |
getOptimizationElement(String id,
boolean includeUnassignedElements)
Gets the optimization element.
|
OptimizationEvents |
getOptimizationEvents()
|
String |
getOptimizationRunIdent()
Gets the optimization run ident.
|
IOptimizationScheme |
getOptimizationScheme()
Gets the defined
IOptimizationScheme . |
com.dna.jopt.framework.body.setup.IOptimizationSetup |
getOptimizationSetup()
Gets the
IOptimizationSetup . |
int |
getOptimizationStage()
|
com.dna.jopt.framework.inputplausibility.properties.IPropertyProvider |
getPropertyProvider()
Gets the property provider through
IOptimizationSetup.getPropertyProvider() . |
List<INode> |
getReassignNodes() |
List<IResource> |
getReassignResources() |
String |
getThreadPrefix()
Gets the
Optimization.threadPrefix , the standard value is "JOPT-" . |
Optional<IOptimizationElement> |
getUnassignedElement(String id)
Gets an unassigned element if present.
|
INodeUnassigner |
getUnassignNodeManager()
Gets the
INodeUnassigner of the optimization. |
Optional<Properties> |
getUserEntityCoreBuildOptions()
|
Optional<Properties> |
getUserProperties()
|
String |
getVersion()
Gets information about the build of the library.
|
IEntity |
getWorkEntity()
Gets the
Optimization.workEntity . |
boolean |
hasEntitySetByUser()
Checks
Optimization.hasEntitySetByUser() , the default value is false . |
boolean |
isStopOptimization()
Used internally to keep track if the optimization is stopped.
|
void |
jumpToNextStage()
Checks that
Optimization.getCurrentOptimizationAlgo() is not null , then calls
IOptimizationAlgorithm.jumpToEnd() . |
void |
pause()
Checks that
Optimization.getCurrentOptimizationAlgo() is not null , then calls
IOptimizationAlgorithm.pause() . |
void |
proceed()
Checks that
Optimization.getCurrentOptimizationAlgo() is not null , then calls
IOptimizationAlgorithm.proceed() which wakes up all threads that are waiting on this
object's monitor. |
void |
putNoneOptimizableNodDetail(String elementId,
ILogicRouteElementDetailItem details)
Puts a value at
elementId in Optimization.getNoneOptimizableElementsDetailHolder() . |
void |
requestedAsynchronousOptimizationResult(IOptimizationResult result)
Requested asynchronous optimization result.
|
void |
requestExportState(OutputStream output,
String executionId)
Request export state with 100 Days of internal timeOut.
|
void |
requestExportState(OutputStream output,
String executionId,
Duration timeOut)
Request export state with time out.
|
void |
requestProgress()
Requesting a
IOptimizationProgress progress which will be provided in an async. |
void |
requestResult()
Requesting an intermediate
IOptimizationResult result which will be provided in an
async. |
void |
resetInitialEntity()
Reset initial entity.
|
void |
setAutoFilterExecutionSchedule(List<Double> executionList)
|
void |
setInitialEntity(IEntity initialEntity)
|
void |
setInitialEntity(IEntity initialEntity,
boolean reassignUnassignedNode)
Sets the given
IEntity as the initial Entity. |
void |
setInitialEntityRenewAutoFilterControllers(IEntity initialEntity)
Sets
Optimization.hasEntitySetByUser() and tryRenewAutoFilterController to true , then sets the input initialEntity as the Optimization.getWorkEntity() . |
void |
setLicenceKey(String key)
Deprecated.
please use
setLicense(ObjectInputStream) , setLicense(File) or
setLicense(IRapotLicense) instead. |
void |
setLicense(File file)
Deprecated.
|
void |
setLicense(com.dna.jopt.framework.licensing.IRapotLicense key)
Deprecated.
|
void |
setLicense(ObjectInputStream licensestream)
Deprecated.
|
void |
setLicenseJSON(File file) |
void |
setLicenseJSON(String jsonLic) |
void |
setNodeConnector(INodeEdgeConnector nodeConnector)
Sets the
Optimization.getNodeConnector() . |
void |
setOptimizationAlgorithmStart(com.dna.jopt.revision.algorithm.IOptimizationAlgorithm.OptimizationAlgorithmStart modeSA,
com.dna.jopt.revision.algorithm.IOptimizationAlgorithm.OptimizationAlgorithmStart modeGE)
Sets the
Optimization.initialOptimizationModeGE and Optimization.initialOptimizationModeSA , both have the default value STATE_MODE_BATCH . |
boolean |
setOptimizationCreator(String creator) |
boolean |
setOptimizationRunIdent(String ident)
Sets the optimization run identification string.
|
void |
setOptimizationScheme(IOptimizationScheme optimizationScheme)
Sets the
IOptimizationScheme . |
void |
setThreadPrefix(String threadPrefix)
Sets the
Optimization.getThreadPrefix() , the default value is "JOPT-" . |
void |
settleOptimization()
Internally called to settle the optimization, e.g.
|
void |
setUnassignNodeManager(INodeUnassigner unassignNodeManager)
Sets the
INodeUnassigner . |
void |
setUserEntityCoreBuildOptions(Properties userEntityCoreBuildOptions)
Sets
Optimization.userEntityCoreBuildOptionsOpt as an Optional with the
parameter values if not null . |
void |
setWorkEntity(IEntity currentBestEntity)
Sets the
Optimization.workEntity . |
void |
startAsynchronousOptimizationRun()
Deprecated.
Start asynchronous optimization run.
|
CompletableFuture<IOptimizationResult> |
startRunAsync()
Start run async.
|
CompletableFuture<IOptimizationResult> |
startRunAsync(ObjectInputStream license)
Deprecated.
|
IOptimizationResult |
startRunSync(long timeout,
TimeUnit unit)
Start run sync.
|
void |
stopOptimization()
Checks that
Optimization.getCurrentOptimizationAlgo() is not null , then sets
Optimization.isStopOptimization() to true and calls IOptimizationAlgorithm.jumpToEnd() . |
onAfterNodeFilteringOptimizationResult, onAsynchronousOptimizationResult, onBeforeNodeFilteringOptimizationResult, onError, onError, onNodeFiltering, onNodeFiltering, onProgress, onProgress, onRequestCodeExecutionDone, onStatus, onStatus, onWarning, onWarning
void proceed()
Optimization.getCurrentOptimizationAlgo()
is not null
, then calls
IOptimizationAlgorithm.proceed()
which wakes up all threads that are waiting on this
object's monitor.pause()
void pause()
Optimization.getCurrentOptimizationAlgo()
is not null
, then calls
IOptimizationAlgorithm.pause()
.proceed()
void stopOptimization()
Optimization.getCurrentOptimizationAlgo()
is not null
, then sets
Optimization.isStopOptimization()
to true
and calls IOptimizationAlgorithm.jumpToEnd()
. This call will trigger a graceful optimization stop
triggering the optimization result.void jumpToNextStage()
Optimization.getCurrentOptimizationAlgo()
is not null
, then calls
IOptimizationAlgorithm.jumpToEnd()
.void requestResult()
IOptimizationResult result
which will be provided in an
async. manner.
Checks that Optimization.getCurrentOptimizationAlgo()
is not null
, then
calls IOptimizationAlgorithm.requestResult()
.
void requestedAsynchronousOptimizationResult(IOptimizationResult result)
requestedAsynchronousOptimizationResult
in interface IOptimizationEventListener
result
- the result to printvoid setInitialEntity(IEntity initialEntity)
IEntity
as the workEntity and Optimization.hasEntitySetByUser()
to true
. This method is used to load custom solutions and is used during the loading of
a snapshot.
Will throw an IllegalStateException
if the initial entity is null
.
initialEntity
- the new initial entityvoid setInitialEntity(IEntity initialEntity, boolean reassignUnassignedNode)
IEntity
as the initial Entity.initialEntity
- the entity to be setreassignUnassignedNode
- the reassign unassigned nodevoid setThreadPrefix(String threadPrefix)
Optimization.getThreadPrefix()
, the default value is "JOPT-"
. This
helps to identify the running optimization thread on the user system.threadPrefix
- the prefix to be setcom.dna.jopt.framework.inputplausibility.properties.IPropertyProvider getPropertyProvider()
IOptimizationSetup.getPropertyProvider()
.void setNodeConnector(INodeEdgeConnector nodeConnector)
Optimization.getNodeConnector()
.
Cannot be null
.
nodeConnector
- the new node connectorINodeEdgeConnector getNodeConnector()
Optimization.getNodeConnector()
.void addElement(INode node)
INode
to the optimization.node
- the element to be added.void addElement(IResource res)
IResource
to the optimization.res
- the resourcevoid addElement(Properties properties)
Optimization.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");
});
}
properties
- the properties@Deprecated void setLicenceKey(String key)
setLicense(ObjectInputStream)
, setLicense(File)
or
setLicense(IRapotLicense)
instead.key
- the string new licence key@Deprecated void setLicense(com.dna.jopt.framework.licensing.IRapotLicense key)
key
- the iRapotLicense new license@Deprecated void setLicense(ObjectInputStream licensestream)
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;
}
}
}
licensestream
- the objectinputstream@Deprecated void setLicense(File file) throws IOException
file
- the keyIOException
- the io exceptionvoid addElement(IPillarNode pillarnode)
IPillarNode
to the optimization.pillarnode
- the pillarnode to be addedvoid setOptimizationScheme(IOptimizationScheme optimizationScheme)
IOptimizationScheme
.optimizationScheme
- the iOptimizationscheme to addcom.dna.jopt.revision.algorithm.IOptimizationAlgorithm getCurrentOptimizationAlgo()
OptimizationSubController.getCurrentOptimizationAlgo()
. Returns the currently
running optimization algorithm.IOptimizationScheme getOptimizationScheme()
IOptimizationScheme
.void settleOptimization()
INodeUnassigner getUnassignNodeManager()
INodeUnassigner
of the optimization.void setUnassignNodeManager(INodeUnassigner unassignNodeManager)
INodeUnassigner
.
Cannot be null
.
unassignNodeManager
- the unassign node manager@Deprecated void startAsynchronousOptimizationRun() throws InvalidLicenceException
InvalidLicenceException
- the invalid licence exceptionString getVersion()
@Deprecated void addDistanceMatrix(double[][] distanceMatrix)
INodeConnectorItem
is preferred.matrix
. Later on this information will be used to create a NodeEdgeConnector
. This method acts as a wrapper.distanceMatrix
- the double array distance matrix@Deprecated void addTimeMatrix(double[][] timeMatrix)
INodeConnectorItem
is
preferred.matrix
. Later on this information will be used to create a NodeEdgeConnector
. This method acts as a wrapper.s.timeMatrix
- the double array time matrixint getOptimizationStage()
OptimizationSubController.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.String getThreadPrefix()
Optimization.threadPrefix
, the standard value is "JOPT-"
.com.dna.jopt.framework.body.setup.IOptimizationSetup getOptimizationSetup()
IOptimizationSetup
.boolean isStopOptimization()
IEntity getWorkEntity()
Optimization.workEntity
.void setWorkEntity(IEntity currentBestEntity)
Optimization.workEntity
.currentBestEntity
- the workEntity to be setList<IOptimizationElement> getAllElements()
IEntity.getAllEntityElements()
and INodeUnassigner.getUnassignedNodes()
,
then returns all of these elements. Returns a new Arraylist
if these are null
.List<IOptimizationElement>
with all the elementsList<IOptimizationElement> getNoneOptimizableElements()
IEntity.getNoneOptimizableElements()
if Optimization.getWorkEntity()
is
not null
. Otherwise returns a new Arraylist
.List<IOptimizationElement>
List<IOptimizationElement> getOptimizableElements()
IEntity.getNoneOptimizableElements()
if the getWorkEntity()
is not
null
. Otherwise returns a new Arraylist
.List<IOptimizationElement>
List<IOptimizationElement> getAllRoutesElements(String resourceId)
IEntity.getAllRoutesElements(String)
, if getWorkEntity()
is not null
.
If the route of the given resource does not have any elements returns a new ArrayList<>
.
resourceId
- the string resourceIdArrayList<>
of the route elementsMap<String,ILogicRouteElementDetailItem> getNoneOptimizableElementsDetails()
ILogicRouteElementDetailItem getNoneOptimizableNodDetail(String elementId)
Optimization.getNoneOptimizableElementsDetailHolder()
for the given
elementId
. This method is primarily used for internal purpose. Please try to extract details
from the route itself.elementId
- the string key for the valuevoid putNoneOptimizableNodDetail(String elementId, ILogicRouteElementDetailItem details)
elementId
in Optimization.getNoneOptimizableElementsDetailHolder()
.elementId
- the string id for the value to be putdetails
- the iLogicRouteElementDetailItem that is supposed to be putvoid addNodes(List<INode> nodes)
nodes
in the list to the optimization.nodes
- the list<INode>
of nodes to be addedvoid addResources(List<IResource> resources)
resources
in the list to the optimization.resources
- the list<IResource>
to be addedboolean hasEntitySetByUser()
Optimization.hasEntitySetByUser()
, the default value is false
.long getId()
Thread#getId()
OptimizationEvents getOptimizationEvents()
OptimizationEvents
which are backed by multiple ReplaySubject
and CompletableFuture
. OptimizationEvents
can be used to subscribe to different events of the optimization.void setOptimizationAlgorithmStart(com.dna.jopt.revision.algorithm.IOptimizationAlgorithm.OptimizationAlgorithmStart modeSA, com.dna.jopt.revision.algorithm.IOptimizationAlgorithm.OptimizationAlgorithmStart modeGE)
Optimization.initialOptimizationModeGE
and Optimization.initialOptimizationModeSA
, both have the default value STATE_MODE_BATCH
.modeSA
- the modeSAmodeGE
- the modeGEIOptimizationResult startRunSync(long timeout, TimeUnit unit) throws InvalidLicenceException, InterruptedException, ExecutionException, TimeoutException
completable future
. The optimization is started
within a ForkJoinPool
. Internally get()
is called on it so
that the code will block until the completable future
returns. 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 timeout
sets the time within which the completable future
needs to
return, otherwise a TimeoutException
is thrown
For use without a timeout please use startRunAsync()
timeout
- the long number of the to be defined time unit until timeoutunit
- the timeUnit of the timeoutInvalidLicenceException
- the invalid licence exceptionInterruptedException
- the interrupted exceptionExecutionException
- the execution exceptionTimeoutException
- the timeout exception if the completable future has not been done
within the timeoutCompletableFuture<IOptimizationResult> startRunAsync() throws InvalidLicenceException
completable future
which is returned.InvalidLicenceException
- the invalid licence exceptionvoid setInitialEntityRenewAutoFilterControllers(IEntity initialEntity)
Optimization.hasEntitySetByUser()
and tryRenewAutoFilterController
to true
, then sets the input initialEntity as the Optimization.getWorkEntity()
.initialEntity
- the iEntity to be set as workEntityvoid setAutoFilterExecutionSchedule(List<Double> executionList)
executionList
- the List<Double>
to be set as userExecutionListOptional<Properties> getUserProperties()
boolean cleanUpOptimization()
true
.void cleanUpNoneOptimizableElementsDetailHolder(Set<String> deadIds)
deadIds
- the dead idsProperties getCoreVersionProperties()
versionCoreProperties
String getCoreVersion()
versionCoreProperties
void setUserEntityCoreBuildOptions(Properties userEntityCoreBuildOptions)
Optimization.userEntityCoreBuildOptionsOpt
as an Optional
with the
parameter values if not null
. Will set it as an empty Optional
if null
.userEntityCoreBuildOptions
- the optional with the given parametersOptional<Properties> getUserEntityCoreBuildOptions()
Optimization.userEntityCoreBuildOptionsOpt
. The default value is an empty
Optional
.Optional<ILogicEntityRoute> getFirstMatchingRoute(String nodeId)
nodeId
- the string of the nodeId that is supposed to matchOptional<ILogicEntityRoute> getFirstMatchingRoute(INode node)
node
- the iNode that is supposed to matchList<ILogicEntityRoute> getAnchoredRoutes()
IEntity.getAnchoredRoutes()
if Optimization.workEntity
is not null
. Otherwise returns a new ArrayList
.void addReassignNodes(List<INode> nodes)
setInitialEntity(com.dna.jopt.member.bucket.entity.IEntity)
, or the
optimization is resumed from a snapshot additional nodes can be added. In contrast to addElement(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)
.
nodes
- the nodesvoid addReassignResources(List<IResource> ress)
setInitialEntity(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)
.
ress
- the resources@Deprecated CompletableFuture<IOptimizationResult> startRunAsync(ObjectInputStream license) throws InvalidLicenceException
license
- the licenseInvalidLicenceException
- the invalid licence exceptionstartRunAsync()
void setLicenseJSON(String jsonLic)
void setLicenseJSON(File file) throws IOException
IOException
void requestProgress()
IOptimizationProgress progress
which will be provided in an async. manner.
Checks that Optimization.getCurrentOptimizationAlgo()
is not null
, then
calls IOptimizationAlgorithm.requestProgress()
.
void requestExportState(OutputStream output, String executionId)
output
- the outputexecutionId
- the execution idvoid requestExportState(OutputStream output, String executionId, Duration timeOut) throws TimeoutException
output
- the outputexecutionId
- the execution idtimeOut
- the time outTimeoutException
- the timeout exceptionvoid resetInitialEntity()
This methods helps to use an existing solution to be used only as data provider, ignoring an existing solution.
Optional<IOptimizationElement> getOptimizationElement(String id)
id
- the idOptional<IOptimizationElement> getOptimizationElement(String id, boolean includeUnassignedElements)
id
- the idincludeUnassignedElements
- the include unassigned elementsOptional<IOptimizationElement> getUnassignedElement(String id)
id
- the idboolean setOptimizationRunIdent(String ident)
ident
- the identString getOptimizationRunIdent()
boolean setOptimizationCreator(String creator)
Copyright © 2017–2023 DNA Evolutions GmbH. All rights reserved.