RLPark 1.0.0
Reinforcement Learning Framework in Java

IRobotLogFile.java

Go to the documentation of this file.
00001 package rlpark.plugin.irobot.logfiles;
00002 
00003 import java.util.ArrayList;
00004 import java.util.List;
00005 
00006 import rlpark.plugin.rltoys.envio.observations.Legend;
00007 import rlpark.plugin.rltoys.utils.Utils;
00008 import rlpark.plugin.robot.interfaces.RobotLog;
00009 import rlpark.plugin.robot.observations.ObservationVersatile;
00010 import rlpark.plugin.robot.observations.ObservationVersatileArray;
00011 import zephyr.plugin.core.api.internal.logfiles.LogFile;
00012 import zephyr.plugin.core.api.monitoring.abstracts.DataMonitor;
00013 import zephyr.plugin.core.api.monitoring.abstracts.MonitorContainer;
00014 import zephyr.plugin.core.api.monitoring.abstracts.Monitored;
00015 
00016 @SuppressWarnings("restriction")
00017 public class IRobotLogFile implements RobotLog, MonitorContainer {
00018   public static final String Extension = "irobotlog";
00019   ObservationVersatile lastReceived = null;
00020   private final LogFile logfile;
00021 
00022   public IRobotLogFile(String filepath) {
00023     logfile = LogFile.load(filepath);
00024   }
00025 
00026   public double[] lastReceivedObs() {
00027     return logfile.currentLine();
00028   }
00029 
00030   @Override
00031   public Legend legend() {
00032     List<String> labels = new ArrayList<String>();
00033     for (String label : logfile.labels())
00034       labels.add(label);
00035     return new Legend(labels);
00036   }
00037 
00038   public void step() {
00039     if (hasNextStep()) {
00040       logfile.step();
00041       lastReceived = new ObservationVersatile(-1, null, logfile.currentLine());
00042     } else
00043       lastReceived = null;
00044   }
00045 
00046   @Override
00047   public boolean hasNextStep() {
00048     return !logfile.eof();
00049   }
00050 
00051   public void close() {
00052     logfile.close();
00053   }
00054 
00055   public String filepath() {
00056     return logfile.filepath;
00057   }
00058 
00059   @Override
00060   public int observationPacketSize() {
00061     return 0;
00062   }
00063 
00064   @Override
00065   public ObservationVersatileArray nextStep() {
00066     step();
00067     return new ObservationVersatileArray(Utils.asList(lastReceived));
00068   }
00069 
00070   @Override
00071   public void addToMonitor(DataMonitor monitor) {
00072     String[] labels = logfile.labels();
00073     for (int i = 0; i < labels.length; i++) {
00074       final int index = i;
00075       monitor.add(labels[index], new Monitored() {
00076         @Override
00077         public double monitoredValue() {
00078           if (lastReceived == null)
00079             return 0;
00080           return lastReceived.doubleValues()[index];
00081         }
00082       });
00083     }
00084   }
00085 }
 All Classes Namespaces Files Functions Variables Enumerations
Zephyr
RLPark