RLPark 1.0.0
Reinforcement Learning Framework in Java
|
00001 package rlpark.plugin.rltoys.envio.observations; 00002 00003 import java.util.ArrayList; 00004 import java.util.Collections; 00005 import java.util.List; 00006 00007 import rlpark.plugin.rltoys.utils.Utils; 00008 00009 public class Legends { 00010 static private boolean isSelected(List<String> prefixes, String label, boolean excluded) { 00011 for (String currentLabel : prefixes) 00012 if (label.startsWith(currentLabel)) 00013 return !excluded; 00014 return excluded; 00015 } 00016 00017 public static int[] getSelectedIndexes(Legend legend, boolean excluded, List<String> prefixes) { 00018 List<Integer> indexes = new ArrayList<Integer>(); 00019 for (int i = 0; i < legend.nbLabels(); i++) 00020 if (isSelected(prefixes, legend.label(i), excluded)) 00021 indexes.add(i); 00022 Collections.sort(indexes); 00023 int[] result = new int[indexes.size()]; 00024 for (int i = 0; i < result.length; i++) 00025 result[i] = indexes.get(i); 00026 return result; 00027 } 00028 00029 public static int[] getSelectedIndexes(Legend legend, boolean excluded, String... prefixes) { 00030 return getSelectedIndexes(legend, excluded, Utils.asList(prefixes)); 00031 } 00032 00033 static private List<String> getLabelList(Legend legend, int[] selectedIndexes) { 00034 List<String> labelList = new ArrayList<String>(); 00035 for (Integer labelIndex : selectedIndexes) 00036 labelList.add(legend.label(labelIndex)); 00037 return labelList; 00038 } 00039 00040 static public List<String> getSelectedLabels(Legend legend, boolean excluded, String... prefixes) { 00041 int[] selectedIndexes = getSelectedIndexes(legend, excluded, prefixes); 00042 return getLabelList(legend, selectedIndexes); 00043 } 00044 00045 public static Legend createLegend(Legend legend, int[] selectedIndexes) { 00046 return new Legend(getLabelList(legend, selectedIndexes)); 00047 } 00048 }