PolicyAgent.cpp 1.77 KB
#include "PolicyAgent.h"

// PolicyAgent::PolicyAgent(int numFeatures, int numActions, double learningRate, double epsilon, FunctionApproximator *FA, char *loadWeightsFile, char *saveWeightsFile){
PolicyAgent::PolicyAgent(int numFeatures, int numActions, double learningRate, double epsilon, FunctionApproximator *FA1, FunctionApproximator *FA2, char *loadWeightsFile, char *saveWeightsFile){

  this->numFeatures = numFeatures;
  this->numActions = numActions;

  this->learningRate = learningRate;
  this->epsilon = epsilon;
  this->FA1 = FA1;
  this->FA2 = FA2;
  this->FA  = FA1;
  
  toLoadWeights = strlen(loadWeightsFile) > 0;
  if(toLoadWeights){
    strcpy(this->loadWeightsFile, loadWeightsFile);
    // loadWeights(loadWeightsFile);
  }

  toSaveWeights = strlen(saveWeightsFile) > 0;
  if(toSaveWeights){
    strcpy(this->saveWeightsFile, saveWeightsFile);
  }
}

PolicyAgent::~PolicyAgent(){
}

void PolicyAgent::switchToSecondFA(){
  this->FA = this->FA2;
  this->idCurrFA = 1;
}

void PolicyAgent::switchToFirstFA(){
  this->FA = this->FA1;
  this->idCurrFA = 0;
}

int PolicyAgent::getNumFeatures(){ 
  return numFeatures; 
}

int PolicyAgent::getNumActions(){ 
  return numActions;  
}

void PolicyAgent::loadWeights(char *fileName){
  // std::cout << "Loading Weights from " << fileName << std::endl;
  // std::cout << "Doing nothing. Check PolicyAgent.cpp." << std::endl;
  //  FA->read(fileName);
}

void PolicyAgent::saveWeights(char *fileName){
  // std::cout<< "Doing nothing. Check PolicyAgent.cpp." << std::endl;
  //  FA->write(fileName);
}

int  PolicyAgent::argmaxQ(double state[]){
  return ((int)(drand48() * getNumActions()) % getNumActions());
}

double PolicyAgent::computeQ(double state[], int action){
  std::cout<<"PolicyAgent ComputeQ being called"<<std::endl;
  return 0;
}