public interface IAlgorithm
extends com.net2plan.internal.IExternal
Contract that must be fulfilled such that an algorithm can be run in Net2Plan
.
New algorithms can be implemented as Java classes (.class/.jar files) with
a given signature. Integration of algorithms simply requires saving them in any
directory of the computer, although it is a good practice to store them in the
\workspace
directory.
Important: When algorithms are implemented as Java .class
files,
the full path to the class must follow the package name of the class, in order
to successfully load the algorithm. For example, if we create an algorithm
named testAlgorithm
in the package test.myAlgorithms
, the full
path to the class must be like ...{any}.../test/myAlgorithms/testAlgorithm.class
.
For .jar
files there is not any restriction on the full path,
they can be stored at any folder.
In order to improve the user experience, kernel is able to catch any exception
thrown by algorithms. Those exceptions are introduced in a Java error console
(see 'Help file' for more information). For example, exceptions allow users to
check if their algorithms are well-programmed (i.e. no null-pointers), thus in
the error console they got a full trace of the error (files, line numbers...).
However, when input parameters are wrong or an error within the algorithm is
returned (i.e. an optimization problem is unable to find feasible solutions),
we recommend to throw exceptions using the
Net2PlanException
class,
since it allows users to see the error in a small dialog in which the only
information is the error message (i.e. "A feasible solution was not found")
instead of the full error trace in the error console (i.e.
RuntimeException: A feasible solution was not found (MyAlgorithm.java:35), ...
).
Modifier and Type | Method and Description |
---|---|
String |
executeAlgorithm(NetPlan netPlan,
Map<String,String> algorithmParameters,
Map<String,String> net2planParameters)
Execute the algorithm.
|
String |
getDescription()
Returns the description.
|
List<Triple<String,String,String>> |
getParameters()
Returns the list of required parameters, where the first item of each element
is the parameter name, the second one is the parameter value, and the third
one is the parameter description.
|
String executeAlgorithm(NetPlan netPlan, Map<String,String> algorithmParameters, Map<String,String> net2planParameters)
netPlan
- A network plan which serves as input and outputalgorithmParameters
- A key-value map with specific algorithm parameters.Important: The algorithm developer is responsible to convert values from String to their respective type, and to check that values
net2planParameters
- A key-value map with Net2Plan
-wide configuration optionsString
String getDescription()
getDescription
in interface com.net2plan.internal.IExternal
List<Triple<String,String,String>> getParameters()
Returns the list of required parameters, where the first item of each element is the parameter name, the second one is the parameter value, and the third one is the parameter description.
It is possible to define type-specific parameters if the default value is set according to the following rules (but user is responsible of checking in its own code):
.class
or .jar
file where the code is located, the class name,
and a set of parameters (pair of key-values separated by commas, where individual
key and value are separated with an equal symbol. The same applies to reports (#report#),
event generators (#eventGenerator#) and event processors (#eventProcessor#).getParameters
in interface com.net2plan.internal.IExternal
Copyright © 2018. All rights reserved.