Polytypic Genetic Programming

  • Jerry SwanEmail author
  • Krzysztof Krawiec
  • Neil Ghani
Conference paper
Part of the Lecture Notes in Computer Science book series (LNCS, volume 10200)


Program synthesis via heuristic search often requires a great deal of ‘boilerplate’ code to adapt program APIs to the search mechanism. In addition, the majority of existing approaches are not type-safe: i.e. they can fail at runtime because the search mechanisms lack the strict type information often available to the compiler. In this article, we describe Polytope, a Scala framework that uses polytypic programming, a relatively recent advance in program abstraction. Polytope requires a minimum of boilerplate code and supports a form of strong-typing in which type rules are automatically enforced by the compiler, even for search operations such as mutation which are applied at runtime. By operating directly on language-native expressions, it provides an embeddable optimization procedure for existing code. We give a tutorial example of the specific polytypic approach we adopt and compare both runtime efficiency and required lines of code against the well-known EpochX GP framework, showing comparable performance in the former and the complete elimination of boilerplate for the latter.


Polytypic programming Datatype generic programming Genetic programming Functional programming Scala 



J. Swan would like to thank Miles Sabin and the contributors to the Scala ‘shapeless’ library. His work on this paper is funded by EPSRC grant EP/J017515/1 (DAASE). K. Krawiec acknowledges support from National Science Centre, Poland, grant 2014/15/B/ST6/05205.


  1. 1.
    Kannappan, K., Spector, L., Sipper, M., Helmuth, T., La Cava, W., Wisdom, J., Bernstein, O.: Analyzing a decade of human-competitive (“HUMIE”) winners: what can we learn? In: Riolo, R., Worzel, W.P., Kotanchek, M. (eds.) Genetic Programming Theory and Practice XII. Genetic and Evolutionary Computation, pp. 149–166. Springer, Heidelberg (2015)CrossRefGoogle Scholar
  2. 2.
    Luke, S.: The ECJ owner’s manual (2010).
  3. 3.
    Dawson-Howe, K.: A Practical Introduction to Computer Vision with OpenCV, 1st edn. Wiley Publishing, Chichester (2014)Google Scholar
  4. 4.
    Langdon, W.B., White, D.R., Harman, M., Jia, Y., Petke, J.: API-constrained genetic improvement. In: Sarro, F., Deb, K. (eds.) SSBSE 2016. LNCS, vol. 9962, pp. 224–230. Springer, Cham (2016). doi: 10.1007/978-3-319-47106-8_16Google Scholar
  5. 5.
    Krawiec, K., Bhanu, B.: Visual learning by coevolutionary feature synthesis. IEEE Trans. Syst. Man and Cybern. Part B 35(3), 409–425 (2005)Google Scholar
  6. 6.
    Harding, S., Leitner, J., Schmidhuber, J.: Cartesian genetic programming for image processing. In: Riolo, R., Vladislavleva, E., Ritchie, M.D., Moore, J.H. (eds.) Genetic Programming Theory and Practice X. Genetic and Evolutionary Computation. Springer, New York (2012)Google Scholar
  7. 7.
    Otero, F., Castle, T., Johnson, C.: EpochX: genetic programming in java with statistics and event monitoring. In: Proceedings of the 14th Annual Conference Companion on Genetic and Evolutionary Computation (GECCO 2012), pp. 93–100, New York, NY, USA. ACM (2012)Google Scholar
  8. 8.
    Fortin, F.-A., De Rainville, F.-M., Gardner, M.-A., Parizeau, M., Christian Gagné, D.: Evolutionary algorithms made easy. J. Mach. Learn. Res. 13, 2171–2175 (2012)Google Scholar
  9. 9.
    Harman, M., Jia, Y., Langdon, W.B., Petke, J., Moghadam, I.H., Yoo, S., Fan, W.: Genetic improvement for adaptive software engineering (keynote). In: Proceedings of the 9th International Symposium on Software Engineering for Adaptive and Self-Managing Systems (SEAMS 2014), pp. 1–4, New York, NY, USA. ACM (2014)Google Scholar
  10. 10.
    Swan, J., Burles, N.: Templar – a framework for template-method hyper-heuristics. In: Machado, P., Heywood, M.I., McDermott, J., Castelli, M., García-Sánchez, P., Burelli, P., Risi, S., Sim, K. (eds.) EuroGP 2015. LNCS, vol. 9025, pp. 205–216. Springer, Cham (2015). doi: 10.1007/978-3-319-16501-1_17Google Scholar
  11. 11.
    Swan, J., Epitropakis, M.G., Woodward, J.R.: Gen-O-Fix: an embeddable framework for dynamic adaptive genetic improvement programming. Technical report CSM-195, Computing Science and Mathematics, University of Stirling, Stirling FK9 4LA, Scotland, January 2014Google Scholar
  12. 12.
    Yeboah-Antwi, K., Baudry, B.: Embedding adaptivity in software systems using the ECSELR framework. In: Proceedings of the Companion Publication of the 2015 on Genetic and Evolutionary Computation Conference, pp. 839–844. ACM (2015)Google Scholar
  13. 13.
    Woodward, J.R., Swan, J.: Template method hyper-heuristics. In: Proceedings of the Companion Publication of the 2014 Annual Conference on Genetic and Evolutionary Computation (GECCO Comp 2014), pp. 1437–1438, New York, NY, USA. ACM (2014)Google Scholar
  14. 14.
    Burles, N., Swan, J., Bowles, E., Brownlee, A.E.I., Kocsis, Z.A., Veerapen, N.: Embedded dynamic improvement. In: Genetic and Evolutionary Computation Conference (GECCO 2015), Companion Material Proceedings, Madrid, Spain, 11–15 July 2015, pp. 831–832 (2015)Google Scholar
  15. 15.
    Montana, D.J.: Strongly typed genetic programming. Evol. Comput. 3(2), 199–230 (1995)CrossRefGoogle Scholar
  16. 16.
    Ryan, C., Collins, J.J., Neill, M.O.: Grammatical evolution: evolving programs for an arbitrary language. In: Banzhaf, W., Poli, R., Schoenauer, M., Fogarty, T.C. (eds.) EuroGP 1998. LNCS, vol. 1391, pp. 83–96. Springer, Heidelberg (1998). doi: 10.1007/BFb0055930CrossRefGoogle Scholar
  17. 17.
    Mitchell, J.C.: Concepts in Programming Languages. Cambridge University Press, Cambridge (2003)zbMATHGoogle Scholar
  18. 18.
    Milner, R., Morris, L., Newey, M.: A logic for computable functions with reflexive and polymorphic types. In: Proceedings of the Conference on Proving and Improving Programs, Arc-et-Senans (1975)Google Scholar
  19. 19.
    Gibbons, J.: Datatype-generic programming. In: Backhouse, R., Gibbons, J., Hinze, R., Jeuring, J. (eds.) SSDGP 2006. LNCS, vol. 4719, pp. 1–71. Springer, Heidelberg (2007). doi: 10.1007/978-3-540-76786-2_1CrossRefGoogle Scholar
  20. 20.
    Lämmel, R., Jones, S.P.: Scrap your boilerplate: a practical design pattern for generic programming. In: Proceedings of the 2003 ACM SIGPLAN International Workshop on Types in Languages Design and Implementation (TLDI 2003), pp. 26–37, New York, NY, USA. ACM (2003)Google Scholar
  21. 21.
    Oliveira, B.C.d.S., Gibbons, J.: Scala for generic programmers: comparing haskell and scala support for generic programming. J. Funct. Program. 20(3–4), 303–352 (2010)Google Scholar
  22. 22.
    Gibbons, J.: Origami programming. In: Gibbons, J., de Moor, O. (eds.) The Fun of Programming, Cornerstones in Computing, pp. 41–60. Palgrave, New York (2003)CrossRefGoogle Scholar
  23. 23.
    Moors, A., Piessens, F., Joosen, W.: An object-oriented approach to datatype-generic programming. In: Proceedings of the 2006 ACM SIGPLAN Workshop on Generic Programming (WGP 2006), pp. 96–106, New York, NY, USA. ACM (2006)Google Scholar
  24. 24.
    Hinze, R.: Generics for the masses. J. Funct. Program. 16(4–5), 451–483 (2006)Google Scholar
  25. 25.
    Sabin, M., et al.: Shapeless: generic programming for Scala, 2011–2016.
  26. 26.
    Gurnell, D.: The type astronaut’s guide to shapeless. Underscore consulting LLP (2016). ISBN 978-1-365-61352-4
  27. 27.
    Koza, J.R.: Genetic Programming: On the Programming of Computers by Means of Natural Selection. MIT Press, Cambridge (1992)zbMATHGoogle Scholar
  28. 28.
    Rechenberg, I.: Evolutionsstrategie: optimierung technischer Systeme nach Prinzipien der biologischen Evolution. Number 15 in Problemata. Frommann-Holzboog, Stuttgart-Bad Cannstatt (1973)Google Scholar
  29. 29.
    Luke, S.: Essentials of Metaheuristics, 2nd edn. Lulu, Raleigh (2013).
  30. 30.
    Miller, J.F., Thomson, P.: Cartesian genetic programming. In: Poli, R., Banzhaf, W., Langdon, W.B., Miller, J., Nordin, P., Fogarty, T.C. (eds.) EuroGP 2000. LNCS, vol. 1802, pp. 121–132. Springer, Heidelberg (2000). doi: 10.1007/978-3-540-46239-2_9CrossRefGoogle Scholar
  31. 31.
    Langdon, W.B., Harman, M.: Optimising existing software with genetic programming. IEEE Trans. Evol. Comput. 19(1), 118–135 (2015)CrossRefGoogle Scholar
  32. 32.
    Luke, S., Panait, L.: A comparison of bloat control methods for genetic programming. Evol. Comput. 14(3), 309–344 (2006)CrossRefGoogle Scholar
  33. 33.
    Keijzer, M., O’Reilly, U.-M., Lucas, S., Costa, E., Soule, T. (eds.): EuroGP 2004. LNCS, vol. 3003. Springer, Heidelberg (2004)Google Scholar
  34. 34.
    Le Goues, C., Nguyen, T.V., Forrest, S., Weimer, W.: GenProg: a generic method for automatic software repair. IEEE Trans. Softw. Eng. 38(1), 54–72 (2012)CrossRefGoogle Scholar
  35. 35.
    Swan, J., Kocsis, Z.A., Lisitsa, A.: The ‘representative’ metaheuristic design pattern. In: Proceedings of the Companion Publication of the 2014 Annual Conference on Genetic and Evolutionary Computation (GECCO Comp 2014), pp. 1435–1436, New York, NY, USA. ACM (2014)Google Scholar

Copyright information

© Springer International Publishing AG 2017

Authors and Affiliations

  1. 1.Computer ScienceUniversity of YorkYorkUK
  2. 2.Institute of Computing SciencePoznan University of TechnologyPoznańPoland
  3. 3.Department of Computer and Information SciencesUniversity of StrathclydeGlasgowScotland

Personalised recommendations