Creating an algorithm - PhotonBursted/PIE GitHub Wiki
PIE has been set up in such a way that it offers a lot of support in creating new algorithms.
Many general cases have been placed in abstract classes or interfaces to help make this process as rigid as possible.
The general recipe for creating algorithms is the following:
-
A class extending AbstractLauncher.
This will ensure the algorithm can be started in an appropriate manner.
This class requires a type parameter though... -
...in the form of an extension of AbstractInputHandler.
This class aids in setting up the interaction between algorithm and user.
Looking into the InputStep might be important in order to understand how PIE parses this.In general though, it all revolves around building an array to pass into
.getSteps(InputStep[])
.
Calling.generate()
on the input handler's instance will then start requesting the user's input. -
The launching of the algorithm is underway; the implementation of that is best suited for extensions of AbstractAlgorithm.
In here, the actual working of the algorithm would be specified.
Basic things like time keeping, setting up the image and those sorts of things have already been handled, the only thing to worry about is functionality.In here, there's room for an initialization phase (
.init()
, in which the initial state of the algorithm can be prepared) before time is started and.generateImage()
is called. -
Right now, we're only missing one vital step: AbstractBuilder.
AbstractBuilder
's job is to construct the actual algorithm object from the user's input.
Inside ofAbstractBuilder
, some helper methods are already present. Which of those are needed differs per algorithm, but they are there if needed. -
Then, a small thing...
To register the algorithm for running by the user, you'll have to take a trip to the StartupLauncher.
In the static constructor of this class, it is quite essential you add the definition of your algorithm there, just like the one for FLOW.
And that's that! Implement these five components and you'll be pretty much ready to go to launch your own experiments, if you have them.
And if you don't, you now know exactly how the program is s structured!