⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 env.c

📁 XCS is a new algorithm for artificial intelligent
💻 C
字号:
/*
/       (XCS)
/	------------------------------------
/	Learning Classifier System based on accuracy
/
/     by Martin Butz
/     University of Wuerzburg / University of Illinois at Urbana/Champaign
/     butz@illigal.ge.uiuc.edu
/     Last modified: 10-17-99
/
/     The Multiplexer environment
*/

#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <math.h>
#include "env.h"

void resetState(char *state)
{
  int i;
  
  /* generate a random state */
  for(i=0;i<CONDITION_LENGTH;i++){
    state[i]=(char)(((double) rand() / (RAND_MAX+1.0))*2)+'0';
  }
}

/* execute the action act in the current state, state, and write in correct if it was the correct action,
 * return the given reward */
double doAction(char *state,char *act,int *correct)
{
  int place=NRBITS,i;
  double reward;
 
  /* get the place of the by the first index bits referenced spot */
  for(i=0,place=NRBITS;i<NRBITS;i++){
    if(state[i]=='1')
      place+=pow(2,NRBITS-1-i);
  }
  /* determine the corresponding reward and set 'correct' */
  if(act[0]==state[place]){
    /* the right action was chosen */
    *correct=1;
    if(PAYOFF_LANDSCAPE)
      reward= 300.+(double)(((place-NRBITS)*200)+100*(int)(state[place]-'0'));
    else
      reward = PAYMENT_RANGE;
  }else{
    /* the wrong action was chosen */
    *correct=0;
    if(PAYOFF_LANDSCAPE)
      reward= 0.+(double)(((place-NRBITS)*200)+100*(int)(state[place]-'0'));
    else
      reward = 0;
  }
  /* return the perceived reward */
  return reward;
}

/* initialize the environment -> do nothing in the multiplexer environment */
int initEnv(FILE *fp)
{
  return 1;
}

void freeEnv()
{
  return;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -