## Distributing the Fitness: A1_reactive_fitness.sci

//********************************************
// A1_reactive_fitness.sci
//
//**********************************
// AUTHORs: Gerd Doeben-Henisch
// First: unknown
// Last: Nov-19,2012,23:40h
//***************************************************
// Management of the old actions
// The actual action will be positioned at position 1, the predecessors are shifted back 1 position each
// Log the action with classifier index in ANIMAT

function [ANIMAT,OLDACTIONS]=manageOldActs(IDXM,CAND,OLDACTIONS,ACTIONSET,ANIMAT,FOODIDX,MAXREWARD,SHOW)

// Shift all classifiers one position 'down' by one position

d=ANIMAT(9)

for i=1:(d-1),OLDACTIONS(d+1-i,1)=OLDACTIONS(d-i,1),OLDACTIONS(d+1-i,2)=OLDACTIONS(d-i,2),end

// Find index for new classifier
[r,c]=size(ANIMAT(8))

i=1, while (i<r+1) do if (strcmp(ANIMAT(8)(i),ACTIONSET(1,1))==0 & (ANIMAT(8)(i,3)==ACTIONSET(1,3) )) then OLDACTIONS(1,1)=i, OLDACTIONS(1,2)=0, i=r+1
else i=i+1
end,
end

if SHOW==5 then printf("OLDACTIONS WITHOUT FITNESS = ")
disp(OLDACTIONS)
end

// Distribute values in old actions, if there was a fitness value >0

if ANIMAT(15)>0 then

s=0

for i=1:ANIMAT(9) //ACTDEPTH
s=s+i
end

fitshare= (FOODIDX/s)/FOODIDX

for i=1:ANIMAT(9)
OLDACTIONS(i,2)=OLDACTIONS(i,2)+((ANIMAT(9)+1-i)*fitshare)
//if OLDACTIONS(i,2)>MAXREWARD then OLDACTIONS(i,2)=MAXREWARD
//end
end

if SHOW==5 then printf("OLDACTIONS WITHFITNESS = ")
disp(OLDACTIONS)
end

//Update fitness values in CLASSIF

for i=1:ANIMAT(9)

if OLDACTIONS(i,1)>0 then
ANIMAT(8)(OLDACTIONS(i,1),4) =sci2exp(eval(ANIMAT(8)(OLDACTIONS(i,1),4))+OLDACTIONS(i,2)),
if eval(ANIMAT(8)(OLDACTIONS(i,1),4)) > MAXREWARD then ANIMAT(8)(OLDACTIONS(i,1),4)=sci2exp(1),end
end
end

if SHOW==5 then printf("UPDATE OF CLASSIFIER Fitness = ")
disp(ANIMAT(8))

end

ANIMAT(15)=0 //Set fitness Flag back to zero

end //End of case new fitness value
endfunction

Gerd Doeben-Henisch 2013-01-14