
com.github.chen0040.rl.actionselection.ActionSelectionStrategyFactory Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of java-reinforcement-learning Show documentation
Show all versions of java-reinforcement-learning Show documentation
Classical RL algorithms implemented in Java, including Q-Learn, R-Learn, SARSA, Actor-Critic
package com.github.chen0040.rl.actionselection;
import java.util.HashMap;
import java.util.Map;
/**
* Created by xschen on 9/27/2015 0027.
*/
public class ActionSelectionStrategyFactory {
public static ActionSelectionStrategy deserialize(String conf){
String[] comps = conf.split(";");
HashMap attributes = new HashMap();
for(int i=0; i < comps.length; ++i){
String comp = comps[i];
String[] field = comp.split("=");
String fieldname = field[0].trim();
String fieldvalue = field[1].trim();
attributes.put(fieldname, fieldvalue);
}
String prototype = attributes.get("prototype");
if(prototype.equals(GreedyActionSelectionStrategy.class.getCanonicalName())){
return new GreedyActionSelectionStrategy();
} else if(prototype.equals(SoftMaxActionSelectionStrategy.class.getCanonicalName())){
return new SoftMaxActionSelectionStrategy();
} else if(prototype.equals(EpsilonGreedyActionSelectionStrategy.class.getCanonicalName())){
return new EpsilonGreedyActionSelectionStrategy(attributes);
} else if(prototype.equals(GibbsSoftMaxActionSelectionStrategy.class.getCanonicalName())){
return new GibbsSoftMaxActionSelectionStrategy();
}
return null;
}
public static String serialize(ActionSelectionStrategy strategy){
HashMap attributes = strategy.getAttributes();
attributes.put("prototype", strategy.getPrototype());
StringBuilder sb = new StringBuilder();
boolean first = true;
for(Map.Entry entry : attributes.entrySet()){
if(first){
first = false;
}
else{
sb.append(";");
}
sb.append(entry.getKey()+"="+entry.getValue());
}
return sb.toString();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy