?? env.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 + -