All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.chen0040.rl.actionselection.AbstractActionSelectionStrategy Maven / Gradle / Ivy

package com.github.chen0040.rl.actionselection;

import com.github.chen0040.rl.utils.IndexValue;
import com.github.chen0040.rl.models.QModel;
import com.github.chen0040.rl.models.UtilityModel;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;


/**
 * Created by xschen on 9/27/2015 0027.
 */
public abstract class AbstractActionSelectionStrategy implements ActionSelectionStrategy {

    private String prototype;
    protected Map attributes = new HashMap();

    public String getPrototype(){
        return prototype;
    }

    public IndexValue selectAction(int stateId, QModel model, Set actionsAtState) {
        return new IndexValue();
    }

    public IndexValue selectAction(int stateId, UtilityModel model, Set actionsAtState) {
        return new IndexValue();
    }

    public AbstractActionSelectionStrategy(){
        prototype = this.getClass().getCanonicalName();
    }


    public AbstractActionSelectionStrategy(HashMap attributes){
        this.attributes = attributes;
        if(attributes.containsKey("prototype")){
            this.prototype = attributes.get("prototype");
        }
    }

    public Map getAttributes(){
        return attributes;
    }

    @Override
    public boolean equals(Object obj) {
        ActionSelectionStrategy rhs = (ActionSelectionStrategy)obj;
        if(!prototype.equalsIgnoreCase(rhs.getPrototype())) return false;
        for(Map.Entry entry : rhs.getAttributes().entrySet()) {
            if(!attributes.containsKey(entry.getKey())) {
                return false;
            }
            if(!attributes.get(entry.getKey()).equals(entry.getValue())){
                return false;
            }
        }
        for(Map.Entry entry : attributes.entrySet()) {
            if(!rhs.getAttributes().containsKey(entry.getKey())) {
                return false;
            }
            if(!rhs.getAttributes().get(entry.getKey()).equals(entry.getValue())){
                return false;
            }
        }
        return true;
    }

    @Override
    public abstract Object clone();
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy