RLPark 1.0.0
Reinforcement Learning Framework in Java

ColisionDetection.java

Go to the documentation of this file.
00001 package rlpark.plugin.rltoys.algorithms.representations.tilescoding.hashing;
00002 
00003 import java.util.Random;
00004 
00005 import zephyr.plugin.core.api.monitoring.annotations.Monitor;
00006 
00007 public class ColisionDetection implements Hashing {
00008   private static final long serialVersionUID = -3173836756531431009L;
00009   private final int[] memoryToHashing;
00010   @Monitor
00011   private int nbCollisions;
00012   private final Hashing hashing;
00013   private final UNH referenceHashing = new UNH(new Random(-1), Integer.MAX_VALUE / 4);
00014 
00015   public ColisionDetection(Hashing hashing) {
00016     this.hashing = hashing;
00017     memoryToHashing = new int[hashing.memorySize()];
00018   }
00019 
00020   @Override
00021   public int hash(Tiling tiling, int[] inputs) {
00022     int result = hashing.hash(tiling, inputs);
00023     int[] coordinates = AbstractHashing.toCoordinates(tiling, inputs);
00024     int hash = referenceHashing.hash(coordinates);
00025     if (memoryToHashing[result] != 0 && memoryToHashing[result] != hash)
00026       nbCollisions++;
00027     memoryToHashing[result] = hash;
00028     return result;
00029   }
00030 
00031   public int nbCollisions() {
00032     return nbCollisions;
00033   }
00034 
00035   @Override
00036   public int memorySize() {
00037     return hashing.memorySize();
00038   }
00039 }
 All Classes Namespaces Files Functions Variables Enumerations
Zephyr
RLPark