RLPark 1.0.0
Reinforcement Learning Framework in Java

SSortedVector.java

Go to the documentation of this file.
00001 package rlpark.plugin.rltoys.math.vector.implementations;
00002 
00003 import rlpark.plugin.rltoys.math.vector.MutableVector;
00004 
00005 public class SSortedVector extends SVector {
00006   private static final long serialVersionUID = -4937311063174913162L;
00007 
00008   public SSortedVector(int size) {
00009     super(size);
00010   }
00011 
00012   public SSortedVector(SVector other) {
00013     this(other.size);
00014     for (int i = 0; i < other.nbActive; i++)
00015       setEntry(other.activeIndexes[i], other.values[i]);
00016   }
00017 
00018   public SSortedVector(BVector other, double value) {
00019     super(other, value);
00020   }
00021 
00022   @Override
00023   protected void updateEntry(int index, double value, int position) {
00024     removeEntry(position, index);
00025     insertEntry(index, value);
00026   }
00027 
00028   private void removeEntries(int startPosition, int length) {
00029     final int endPosition = startPosition + length;
00030     for (int position = startPosition; position < endPosition; position++)
00031       indexesPosition[activeIndexes[position]] = -1;
00032     for (int position = endPosition; position < nbActive; position++)
00033       indexesPosition[activeIndexes[position]] -= length;
00034     System.arraycopy(activeIndexes, endPosition, activeIndexes, startPosition, nbActive - endPosition);
00035     System.arraycopy(values, endPosition, values, startPosition, nbActive - endPosition);
00036     nbActive -= length;
00037   }
00038 
00039   @Override
00040   protected void removeEntry(int indexPosition, int index) {
00041     removeEntries(indexPosition, 1);
00042   }
00043 
00044   public void removeTail(int n) {
00045     removeEntries(0, n);
00046   }
00047 
00048   @Override
00049   public SVector copy() {
00050     return new SSortedVector(this);
00051   }
00052 
00053   @Override
00054   public MutableVector newInstance(int size) {
00055     return new SSortedVector(size);
00056   }
00057 }
 All Classes Namespaces Files Functions Variables Enumerations
Zephyr
RLPark