Suppose we want to compare NSGA-II and NSGA-III on the DTLZ2 problem. In
general, you will want to run each algorithm several times on the problem
with different random number generator seeds. Instead of having to write
many for loops to run each algorithm for every seed, we can use the
experiment function. The experiment function accepts a list of algorithms,
a list of problems, and several other arguments that configure the experiment,
such as the number of seeds and number of function evaluations. It then
evaluates every algorithm against every problem and returns the data in a
JSON-like dictionary.

Afterwards, we can use the calculate function to calculate one or more
performance indicators for the results. The result is another JSON-like
dictionary storing the numeric indicator values. We finish by pretty printing
the results using display.

fromplatypusimportNSGAII,NSGAIII,DTLZ2,Hypervolume,experiment,calculate,displayif__name__=="__main__":algorithms=[NSGAII,(NSGAIII,{"divisions_outer":12})]problems=[DTLZ2(3)]# run the experimentresults=experiment(algorithms,problems,nfe=10000,seeds=10)# calculate the hypervolume indicatorhyp=Hypervolume(minimum=[0,0,0],maximum=[1,1,1])hyp_result=calculate(results,hyp)display(hyp_result,ndigits=3)

Once this data is collected, we can then use statistical tests to determine if
there is any statistical difference between the results. In this case, we
may want to use the Mann-Whitney U test from scipy.stats.mannwhitneyu.

Note how we listed the algorithms: [NSGAII,(NSGAIII,{"divisions_outer":12})].
Normally you just need to provide the algorithm type, but if you want to
customize the algorithm, you can also provide optional arguments. To do so,
you need to pass a tuple with the values (type,dict), where dict is a
dictionary containing the arguments. If you want to test the same algorithm
with different parameters, pass in a three-element tuple containing
(type,dict,name). The name element provides a custom name for the
algorithm that will appear in the output. For example, we could use
(NSGAIII,{"divisions_outer":24},"NSGAIII_24"). The names must be unique.

One of the major advantages to using the experimenter is that it supports
parallelization. In Python, there are several standards for running parallel
jobs, such as the map function. Platypus abstracts these different standards
using the Evaluator class. The default evaluator is the MapEvaluator,
but parallel versions such as MultiprocessingEvaluator for Python 2 and
ProcessPoolEvaluator for Python 3.

When using these evaluators, one must also follow any requirements of the
underlying library. For example, MultiprocessingEvaluator uses the
multiprocessing module available on Python 2, which requires the users to
invoke freeze_support() first.

Extending the previous examples, we can perform a full comparison of all
supported algorithms on the DTLZ2 problem and display the results visually.
Note that several algorithms, such as NSGA-III, CMAES, OMOPSO, and EpsMOEA,
require additional parameters.

fromplatypusimport*importmatplotlib.pyplotaspltfrommpl_toolkits.mplot3dimportAxes3Dif__name__=='__main__':# setup the experimentproblem=DTLZ2(3)algorithms=[NSGAII,(NSGAIII,{"divisions_outer":12}),(CMAES,{"epsilons":[0.05]}),GDE3,IBEA,(MOEAD,{"weight_generator":normal_boundary_weights,"divisions_outer":12}),(OMOPSO,{"epsilons":[0.05]}),SMPSO,SPEA2,(EpsMOEA,{"epsilons":[0.05]})]# run the experiment using Python 3's concurrent futures for parallel evaluationwithProcessPoolEvaluator()asevaluator:results=experiment(algorithms,problem,seeds=1,nfe=10000,evaluator=evaluator)# display the resultsfig=plt.figure()fori,algorithminenumerate(six.iterkeys(results)):result=results[algorithm]["DTLZ2"][0]ax=fig.add_subplot(2,5,i+1,projection='3d')ax.scatter([s.objectives[0]forsinresult],[s.objectives[1]forsinresult],[s.objectives[2]forsinresult])ax.set_title(algorithm)ax.set_xlim([0,1.1])ax.set_ylim([0,1.1])ax.set_zlim([0,1.1])ax.view_init(elev=30.0,azim=15.0)ax.locator_params(nbins=4)plt.show()