RLPark 1.0.0
Reinforcement Learning Framework in Java

Horde.java

Go to the documentation of this file.
00001 package rlpark.plugin.rltoys.horde;
00002 
00003 import java.io.Serializable;
00004 import java.util.ArrayList;
00005 import java.util.List;
00006 
00007 import rlpark.plugin.rltoys.envio.actions.Action;
00008 import rlpark.plugin.rltoys.envio.observations.Observation;
00009 import rlpark.plugin.rltoys.horde.HordeScheduler.Context;
00010 import rlpark.plugin.rltoys.horde.demons.Demon;
00011 import rlpark.plugin.rltoys.horde.functions.HordeUpdatable;
00012 import rlpark.plugin.rltoys.math.vector.RealVector;
00013 import zephyr.plugin.core.api.labels.Labels;
00014 import zephyr.plugin.core.api.monitoring.annotations.LabelProvider;
00015 import zephyr.plugin.core.api.monitoring.annotations.Monitor;
00016 
00017 @Monitor
00018 public class Horde implements Serializable {
00019   private static final long serialVersionUID = -437180206156496271L;
00020   final List<HordeUpdatable> beforeFunctions = new ArrayList<HordeUpdatable>();
00021   final List<Demon> demons = new ArrayList<Demon>();
00022   final List<HordeUpdatable> afterFunctions = new ArrayList<HordeUpdatable>();
00023   private final HordeScheduler scheduler;
00024 
00025   public Horde() {
00026     this(new HordeScheduler());
00027   }
00028 
00029   public Horde(HordeScheduler scheduler) {
00030     this.scheduler = scheduler;
00031   }
00032 
00033   @LabelProvider(ids = { "demons" })
00034   public String demonLabel(int i) {
00035     return Labels.label(demons.get(i));
00036   }
00037 
00038   @LabelProvider(ids = { "beforeFunctions" })
00039   public String beforeFunctionLabel(int i) {
00040     return Labels.label(beforeFunctions.get(i));
00041   }
00042 
00043   @LabelProvider(ids = { "afterFunctions" })
00044   public String afterFunctionLabel(int i) {
00045     return Labels.label(afterFunctions.get(i));
00046   }
00047 
00048   public void update(final Observation o_tp1, final RealVector x_t, final Action a_t, final RealVector x_tp1) {
00049     scheduler.update(new Context() {
00050       @Override
00051       public void updateElement(int index) {
00052         beforeFunctions.get(index).update(o_tp1, x_t, a_t, x_tp1);
00053       }
00054 
00055       @Override
00056       public int nbElements() {
00057         return beforeFunctions.size();
00058       }
00059     });
00060     scheduler.update(new Context() {
00061       @Override
00062       public void updateElement(int index) {
00063         demons.get(index).update(x_t, a_t, x_tp1);
00064       }
00065 
00066       @Override
00067       public int nbElements() {
00068         return demons.size();
00069       }
00070     });
00071     scheduler.update(new Context() {
00072       @Override
00073       public void updateElement(int index) {
00074         afterFunctions.get(index).update(o_tp1, x_t, a_t, x_tp1);
00075       }
00076 
00077       @Override
00078       public int nbElements() {
00079         return afterFunctions.size();
00080       }
00081     });
00082   }
00083 
00084   public List<HordeUpdatable> beforeFunctions() {
00085     return beforeFunctions;
00086   }
00087 
00088   public List<HordeUpdatable> afterFunctions() {
00089     return afterFunctions;
00090   }
00091 
00092   public List<Demon> demons() {
00093     return demons;
00094   }
00095 
00096   public boolean addBeforeFunction(HordeUpdatable function) {
00097     return beforeFunctions.add(function);
00098   }
00099 
00100   public boolean addAfterFunction(HordeUpdatable function) {
00101     return afterFunctions.add(function);
00102   }
00103 
00104   public boolean addDemon(Demon demon) {
00105     return demons.add(demon);
00106   }
00107 }
 All Classes Namespaces Files Functions Variables Enumerations
Zephyr
RLPark