Class OnTheFlyLegionMove

  • All Implemented Interfaces:
    java.lang.Iterable<LegionMove>, java.util.Collection<LegionMove>

    public class OnTheFlyLegionMove
    extends java.lang.Object
    implements java.util.Collection<LegionMove>
    On-the-fly generation of the Collection of all possible LegionMove. This doesn't fully respect the Collection interface: The random generation may fail before all elements have been returned, so to iterators may return different subsets of the entire collection. Also, this may cause size() to return a value higher than what is really accessible.
    Author:
    Romain Dolbeau
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.util.List<java.util.List<CritterMove>> allCritterMoves  
      private static int GOOD_PARENT_TOP_PERCENT
      Percentage from the top (of the already avaluated space) to pick a 'good' parent.
      private static java.util.logging.Logger LOGGER  
      private static long MIN_MEMORY_REFILL
      Amount of memory needed before a refill.
      private static int MIN_PARENT_CHOICE
      Minimum number of possible 'good' parents.
      private int mysize  
      private static int RANDOM_GENE_PERCENT
      Percentage that a gene will be random instead of inherited.
      private static int RANDOM_MAX_TRY
      Maximum number of try before giving up generating a new element.
      private static int RANDOM_PARENT_PERCENT
      Percentage of a randomly chosen parent.
      private static int REFILL_SIZE
      number of elements to put in each new batch of element.
      private static int SPONTANEOUS_GENERATION_PERCENT
      Percentage of fully random new elements This helps diversifying the gene pool.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean add​(LegionMove o)  
      boolean addAll​(java.util.Collection<? extends LegionMove> c)  
      void clear()  
      boolean contains​(java.lang.Object o)  
      boolean containsAll​(java.util.Collection<?> c)  
      boolean equals​(java.lang.Object o)  
      (package private) int getDim()  
      int hashCode()  
      boolean isEmpty()  
      java.util.Iterator<LegionMove> iterator()  
      boolean remove​(java.lang.Object o)  
      boolean removeAll​(java.util.Collection<?> c)  
      boolean retainAll​(java.util.Collection<?> c)  
      int size()  
      java.lang.Object[] toArray()  
      <T> T[] toArray​(T[] a)  
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface java.util.Collection

        parallelStream, removeIf, spliterator, stream, toArray
      • Methods inherited from interface java.lang.Iterable

        forEach
    • Field Detail

      • RANDOM_MAX_TRY

        private static final int RANDOM_MAX_TRY
        Maximum number of try before giving up generating a new element. Ideally this is only a safety belt.
        See Also:
        Constant Field Values
      • REFILL_SIZE

        private static final int REFILL_SIZE
        number of elements to put in each new batch of element. From my experiments, should be about 1-3 second worth of evaluation.
        See Also:
        Constant Field Values
      • RANDOM_GENE_PERCENT

        private static final int RANDOM_GENE_PERCENT
        Percentage that a gene will be random instead of inherited. Low will densify exploration around the current maximums. High will widen the explorated space around the current maximums.
        See Also:
        Constant Field Values
      • RANDOM_PARENT_PERCENT

        private static final int RANDOM_PARENT_PERCENT
        Percentage of a randomly chosen parent. Another parameter to avoid inbreeding and missing not-yet-detected local maximums.
        See Also:
        Constant Field Values
      • GOOD_PARENT_TOP_PERCENT

        private static final int GOOD_PARENT_TOP_PERCENT
        Percentage from the top (of the already avaluated space) to pick a 'good' parent. Low will pick parent only from very near the local maximums. High will give not-so-good parents a chance.to breed.
        See Also:
        Constant Field Values
      • MIN_PARENT_CHOICE

        private static final int MIN_PARENT_CHOICE
        Minimum number of possible 'good' parents. For small exploration space, this avoid excessive inbreeding.
        See Also:
        Constant Field Values
      • SPONTANEOUS_GENERATION_PERCENT

        private static final int SPONTANEOUS_GENERATION_PERCENT
        Percentage of fully random new elements This helps diversifying the gene pool.
        See Also:
        Constant Field Values
      • MIN_MEMORY_REFILL

        private static final long MIN_MEMORY_REFILL
        Amount of memory needed before a refill. This avoid crashing low-mem JVM. The constant part is of the pulled-out-of-a-hat variety.
        See Also:
        Constant Field Values
      • LOGGER

        private static final java.util.logging.Logger LOGGER
      • allCritterMoves

        private final java.util.List<java.util.List<CritterMove>> allCritterMoves
      • mysize

        private final int mysize
    • Constructor Detail

      • OnTheFlyLegionMove

        public OnTheFlyLegionMove​(java.util.List<java.util.List<CritterMove>> acm)
    • Method Detail

      • getDim

        int getDim()
      • add

        public boolean add​(LegionMove o)
        Specified by:
        add in interface java.util.Collection<LegionMove>
      • addAll

        public boolean addAll​(java.util.Collection<? extends LegionMove> c)
        Specified by:
        addAll in interface java.util.Collection<LegionMove>
      • clear

        public void clear()
        Specified by:
        clear in interface java.util.Collection<LegionMove>
      • contains

        public boolean contains​(java.lang.Object o)
        Specified by:
        contains in interface java.util.Collection<LegionMove>
      • containsAll

        public boolean containsAll​(java.util.Collection<?> c)
        Specified by:
        containsAll in interface java.util.Collection<LegionMove>
      • equals

        public boolean equals​(java.lang.Object o)
        Specified by:
        equals in interface java.util.Collection<LegionMove>
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Specified by:
        hashCode in interface java.util.Collection<LegionMove>
        Overrides:
        hashCode in class java.lang.Object
      • isEmpty

        public boolean isEmpty()
        Specified by:
        isEmpty in interface java.util.Collection<LegionMove>
      • iterator

        public java.util.Iterator<LegionMove> iterator()
        Specified by:
        iterator in interface java.util.Collection<LegionMove>
        Specified by:
        iterator in interface java.lang.Iterable<LegionMove>
      • remove

        public boolean remove​(java.lang.Object o)
        Specified by:
        remove in interface java.util.Collection<LegionMove>
      • removeAll

        public boolean removeAll​(java.util.Collection<?> c)
        Specified by:
        removeAll in interface java.util.Collection<LegionMove>
      • retainAll

        public boolean retainAll​(java.util.Collection<?> c)
        Specified by:
        retainAll in interface java.util.Collection<LegionMove>
      • size

        public int size()
        Specified by:
        size in interface java.util.Collection<LegionMove>
      • toArray

        public java.lang.Object[] toArray()
        Specified by:
        toArray in interface java.util.Collection<LegionMove>
      • toArray

        public <T> T[] toArray​(T[] a)
        Specified by:
        toArray in interface java.util.Collection<LegionMove>