The authors of the paper:

Rakowski F, Karbowski J (2017) Optimal synaptic signaling connectome for locomotory behavior in Caenorhabditis elegans: Design minimizing energy cost. PLoS Comput Biol 13:e1005834
http://dx.doi.org/10.1371/journal.pcbi.1005834

Have made their Java code available at these github repositories:

https://github.com/hpdcj/elegans-simulation

https://github.com/hpdcj/evolutionary-algorithm

https://github.com/hpdcj/elegans-optimisation

and a Mathematica notebook in a pdf in the papers appendix:

https://ndownloader.figshare.com/files/9884602