polygon_generator.hpp 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #ifndef POLYGON_GENERATOR_HPP
  2. #define POLYGON_GENRATOR_HPP
  3. #include "polygon.hpp"
  4. //********************
  5. //* PolygonGenerator *
  6. //********************
  7. //! Generates all self avoidinfg polygon upto length max_len.
  8. //! The class contains a unique instance of a polygon. We use
  9. //! a stack to store each Step of the exploration.
  10. class PolygonGenerator{
  11. private:
  12. //! A stack of Step
  13. stack<Step> s;
  14. //! The unique polygon
  15. Polygon poly;
  16. public:
  17. //! The id of the next step
  18. size_t n;
  19. //! Empty constructor
  20. PolygonGenerator();
  21. //! Explore until the next self avoiding polygon
  22. //! Return is such a polygon exists and false otherwise.
  23. bool next();
  24. //! Return a reference to the current self avoiding polygon.
  25. const Polygon& get() const;
  26. //! Set the current self avoiding polygon to P
  27. void set(Polygon& P) const;
  28. };
  29. //********************
  30. //* Inline functions *
  31. //********************
  32. inline
  33. PolygonGenerator::PolygonGenerator(){
  34. n=1;
  35. poly.init();
  36. s.emplace(2,poly.head,Polygon::right(poly.head),n);
  37. }
  38. inline const Polygon&
  39. PolygonGenerator::get() const{
  40. return poly;
  41. }
  42. inline void
  43. PolygonGenerator::set(Polygon& P) const{
  44. P=poly;
  45. }
  46. #endif