Tech.Appendix: LCS as ZCS1

The following code describes an agent of type $ ANIMAT^{1}$ with a simple perception of type 'birds-view' and with a fixed evaluation schema using a classifier structure without evolutionary learning. Thus ANIMAT1 represents a 'fixed character' whose reactive responses are optimized to look first for food, then selecting available spaces, and -if this all does not work- then to stay at the old position before trying again. Furthermore it is here assume that the ANIMAT1 consumes energy depending from time (= cycles). Doing 'nothing' decrements energy by '-1', moving without finding food decrements by '-2' and finding food increments by '1000'. Thus depending from its energy budget and depending from the environment has this agent some chance or no chance at all. Looking to its behavior one can observe that this agent, if he has found some food, he will get stuck to this food as long as the food does not disappear.

//**************************************************************
// File: zcs1.sce
// Authors: Gerd Doeben-Henisch
// Version Start: May-18, 2010
//---------------------------------
// Update May-19-2010-1459
// Update May-19-10-2343
// Update May-20-10-0637
//**********************************************************
// diary('H:\fh\scilab\histories\Date.txt')
//diary('/home/gerd/public_html/uffmm/science-technology/single/themes/computer-science/personal-sites/doeben-henisch/KNOW/GBBLT/SCILAB/HISTORIES/May20-10-1032.txt')
//******************************************************************
// CONTENT: Necessary code for an ANIMAT1-agent, the successor of the
// ANIMAT0-agent.
// The difference from A...0 to A...1 is that the the A...1
// uses a 'birds-view' perception and evaluates
// dirctly the 'positive' properties based on
// some 'prewired' knowledge.
//
//***************************************************


//**********************************
// GRID 'WOOD1' 
//
// Y = r=1...15, X = c=1...55
// The Y-axis is from above (north) to bottom (south), the X-axis is from left (west) to right (east)
// '.' := No Food; encoded '00'
// 'O' := Object (Rock); encoded '10'
// Attention: scilab assumes GRID(Y,X) columns first and then rows!


//********************************************************************
// DYNAMIC GRID GENERATION
// Using the wood1-structure as building blocks
//
// YYMAX := Max number of rows multiplied by 5
// XMAX := Max number of columnsXNtiplied by 5


function[GRID]=gridgen(YYMAX,XXMAX)
  
  if (YYMAX < 1) | (XXMAX < 1) then printf("gridgen:ERROR WITH YYMAX, XXMAX\n\n"), end
  
  for k=1:5:5*YYMAX
  i=k
    for j=1:5*XXMAX, GRID(i+0,j)='.',end
  i=k+1
  for j=1:5:5*XXMAX, 
    GRID(i,j+0)='.'
    GRID(i,j+1)='O'
    GRID(i,j+2)='O'
    GRID(i,j+3)='F'
    GRID(i,j+4)='.'
  end
  i=k+2
  for j=1:5:5*XXMAX, 
    GRID(i,j+0)='.'
    GRID(i,j+1)='O'
    GRID(i,j+2)='O'
    GRID(i,j+3)='O'
    GRID(i,j+4)='.'
  end
  
  i=k+3
  for j=1:5:5*XXMAX, 
    GRID(i,j+0)='.'
    GRID(i,j+1)='O'
    GRID(i,j+2)='O'
    GRID(i,j+3)='O'
    GRID(i,j+4)='.'
  end
  i=k+4
  for j=1:5*XXMAX, GRID(i+0,j)='.',end
  end
  
   
endfunction

//********************************************************************
// DYNAMIC GRID GENERATION
// Using theextended  wood1-structure as building block
//
// Allows less food cells in the world
//
// YYMAX := Max number of rows multiplied by 5
// XMAX := Max number of columnsXNtiplied by 5
// S := Inverse scaling to lower the density of food


function [GRID]=gridgen2(YYMAX,XXMAX,S)
  
  if (YYMAX < 1) | (XXMAX < 1) then printf("gridgen:ERROR WITH YYMAX, XXMAX\n\n"), end
  
  r=0
  for k=1:5:5*YYMAX
  i=k
    for j=1:5*XXMAX, GRID(i+0,j)='.',end
  i=k+1
  for j=1:5:5*XXMAX, 
    GRID(i,j+0)='.'
    GRID(i,j+1)='O'
    GRID(i,j+2)='O'
    
    if (S>0) & (r==S) then  GRID(i,j+3)='F', r=0, else  GRID(i,j+3)='O', r=r+1,end
    
    GRID(i,j+4)='.'
  end
  i=k+2
  for j=1:5:5*XXMAX, 
    GRID(i,j+0)='.'
    GRID(i,j+1)='O'
    GRID(i,j+2)='O'
    GRID(i,j+3)='O'
    GRID(i,j+4)='.'
  end
  
  i=k+3
  for j=1:5:5*XXMAX, 
    GRID(i,j+0)='.'
    GRID(i,j+1)='O'
    GRID(i,j+2)='O'
    GRID(i,j+3)='O'
    GRID(i,j+4)='.'
  end
  i=k+4
  for j=1:5*XXMAX, GRID(i+0,j)='.',end
  end
  
   
 endfunction
 
 
//********************************************************************
// TESTGRIDS WITH OBJECTS
// 
//

GD3O2F1=['.' '.' '.'; 'O' 'O' '.'; '.' 'F' '.' ]

GD3O2F0=['.' '.' '.'; 'O' 'O' '.'; '.' '.' '.' ]


GD3O2F12=['.' '.' '.'; '.' 'O' 'O'; '.' 'F' '.' ]

GD3O2F13=['.' '.' '.'; '.' 'O' '.'; '.' 'F' '.' ]
   
//*************************************************
// AUTOMATIC GENERATION OF TRANSITION TABLE
// Takes every cell of a given GRID and computes the transition probabilities
// with regard to every possible direction 1 ... 8
//


function [TGRID]=transprob(GRID)
  
[r,c]=size(GRID)
TGRID=zeros()
N=r*c

MAX=9
Y=0
  while(Y<N)
    for y=1:r,
      
      for x=1:c, Y=Y+1
        
      
     // printf("\n---------------Y = %d----------------------\n\n",Y)
   
      m=1
      
      //Catch wrong indices and evaluate cases
        
        if  (y-1)<1 then m=m+1, elseif GRID(y-1, x) == 'O' then TGRID(Y,(y-1)*c+x)=0, m=m+1,else  TGRID(Y,(y-1-1)*c+x)=1/MAX, end
        if  (y-1)<1|(x+1)>c then m=m+1,elseif GRID(y-1, x+1) == 'O' then  TGRID(Y,(y-1)*c+x)=0,m=m+1,else  TGRID(Y,(y-1-1)*c+x+1)=1/MAX, end
        if  (x+1)>c then m=m+1,elseif GRID(y, x+1) == 'O' then  TGRID(Y,(y-1)*c+x)=0,m=m+1,else  TGRID(Y,(y-1)*c+x+1)=1/MAX, end
        if  (y+1)>r|(x+1)>c then m=m+1,elseif GRID(y+1, x+1) == 'O' then  TGRID(Y,(y-1)*c+x)=0,m=m+1,else  TGRID(Y,(y-1+1)*c+x+1)=1/MAX, end
        if  (y+1)>r then m=m+1,elseif GRID(y+1, x) == 'O' then  TGRID(Y,(y-1)*c+x)=0,m=m+1,else  TGRID(Y,(y-1+1)*c+x)=1/MAX,  end
        if  (y+1)>r|(x-1)<1 then m=m+1,elseif GRID(y+1, x-1) == 'O' then  TGRID(Y,(y-1)*c+x)=0,m=m+1,else  TGRID(Y,(y-1+1)*c+x-1)=1/MAX, end
        if   (x-1)<1 then m=m+1,elseif GRID(y, x-1) == 'O' then  TGRID(Y,(y-1)*c+x)=0,m=m+1,else  TGRID(Y,(y-1)*c+x-1)=1/MAX, end
        if  (y-1)<1|(x-1)<1 then m=m+1,elseif GRID(y-1, x-1) == 'O' then  TGRID(Y,(y-1)*c+x)=0,m=m+1,else  TGRID(Y,(y-1-1)*c+x-1)=1/MAX, end
        
        if GRID(y, x)=='O' then  for z=1:N,TGRID(Y,z)=0,end
            else TGRID(Y,Y)=m/MAX, end
          
     
    
    end //x
  end //y
  end //Y
 
endfunction

//*************************************************
// AUTOMATIC GENERATION OF TRANSITION TABLE
// Takes every cell of a given GRID and computes the transition probabilities
// with regard to every possible direction 1 ... 8
//


function [TGRID]=transprob_tst(GRID)
  
[r,c]=size(GRID)
TGRID=zeros()
N=r*c

MAX=9
Y=0
  while(Y<N)
    for y=1:r,
      
      for x=1:c, Y=Y+1
        
      
      printf("\n---------------Y = %d----------------------\n\n",Y)
   
      m=1
      
      //Catch wrong indices and evaluate cases
        
        if  (y-1)<1 then printf(" __BORDER__"), m=m+1, elseif GRID(y-1, x) == 'O' then printf(" __OBJECT__"),TGRID(Y,(y-1)*c+x)=0, m=m+1,else  printf(" __MOVE__"),TGRID(Y,(y-1-1)*c+x)=1/MAX, printf("(y,x) = (%d,%d) with m = %d TG(Y,Y) = (%d,%d) = %f\n",y,x,m,Y,(y-1-1)*c+x, TGRID(Y,(y-1-1)*c+x)), end
        if  (y-1)<1|(x+1)>c then printf(" __BORDER__"), m=m+1,elseif GRID(y-1, x+1) == 'O' then printf(" __OBJECT__"), TGRID(Y,(y-1)*c+x)=0,m=m+1,else  printf(" __MOVE__"),TGRID(Y,(y-1-1)*c+x+1)=1/MAX, printf("(y,x) = (%d,%d) with m = %d TG(Y,Y) = (%d,%d) = %f\n",y,x,m,Y,(y-1-1)*c+x+1,TGRID(Y,(y-1-1)*c+x+1)), end
        if  (x+1)>c then printf(" __BORDER__"), m=m+1,elseif GRID(y, x+1) == 'O' then printf(" __OBJECT__"), TGRID(Y,(y-1)*c+x)=0,m=m+1,else  printf(" __MOVE__"),TGRID(Y,(y-1)*c+x+1)=1/MAX, printf("(y,x) = (%d,%d) with m = %d TG(Y,Y) = (%d,%d) = %f\n",y,x,m,Y,(y-1)*c+x+1,TGRID(Y,(y-1)*c+x+1)), end
        if  (y+1)>r|(x+1)>c then printf(" __BORDER__"), m=m+1,elseif GRID(y+1, x+1) == 'O' then printf(" __OBJECT__"), TGRID(Y,(y-1)*c+x)=0,m=m+1,else  printf(" __MOVE__"),TGRID(Y,(y-1+1)*c+x+1)=1/MAX, printf("(y,x) = (%d,%d) with m = %d TG(Y,Y)  = (%d,%d) = %f\n",y,x,m,Y,(y-1+1)*c+x+1,TGRID(Y,(y-1+1)*c+x+1)), end
        if  (y+1)>r then printf(" __BORDER__"), m=m+1,elseif GRID(y+1, x) == 'O' then printf(" __OBJECT__"), TGRID(Y,(y-1)*c+x)=0,m=m+1,else  printf(" __MOVE__"),TGRID(Y,(y-1+1)*c+x)=1/MAX,  printf("(y,x) = (%d,%d) with m = %d TG(Y,Y) = (%d,%d) = %f\n",y,x,m,Y,(y-1+1)*c+x,TGRID(Y,(y-1+1)*c+x)), end
        if  (y+1)>r|(x-1)<1 then printf(" __BORDER__"), m=m+1,elseif GRID(y+1, x-1) == 'O' then printf(" __OBJECT__"), TGRID(Y,(y-1)*c+x)=0,m=m+1,else  printf(" __MOVE__"),TGRID(Y,(y-1+1)*c+x-1)=1/MAX, printf("(y,x) = (%d,%d) with m = %d TG(Y,Y)  = (%d,%d) = %f\n",y,x,m,Y,(y-1+1)*c+x-1,TGRID(Y,(y-1+1)*c+x-1)), end
        if   (x-1)<1 then printf(" __BORDER__"), m=m+1,elseif GRID(y, x-1) == 'O' then printf(" __OBJECT__"), TGRID(Y,(y-1)*c+x)=0,m=m+1,else  printf(" __MOVE__"),TGRID(Y,(y-1)*c+x-1)=1/MAX, printf("(y,x) = (%d,%d) with m = %d TG(Y,Y)  = (%d,%d) = %f\n",y,x,m,Y,(y-1)*c+x-1,TGRID(Y,(y-1)*c+x-1)), end
        if  (y-1)<1|(x-1)<1 then printf(" __BORDER__"), m=m+1,elseif GRID(y-1, x-1) == 'O' then printf(" __OBJECT__"), TGRID(Y,(y-1)*c+x)=0,m=m+1,else  printf(" __MOVE__"),TGRID(Y,(y-1-1)*c+x-1)=1/MAX, printf("(y,x) = (%d,%d) with m = %d TG(Y,Y)  = (%d,%d) = %f\n",y,x,m,Y,(y-1-1)*c+x-1,TGRID(Y,(y-1-1)*c+x-1)), end
        
        if GRID(y, x)=='O' then  for z=1:N,TGRID(Y,z)=0,end
            else TGRID(Y,Y)=m/MAX, end
          
     
    
    end //x
  end //y
  end //Y
 
endfunction

//**********************************
// RANDOM TEST WORLD FOR BENCHMARKING 
//
// This world has one food cell with 'F' in the center and
// has a fixed diameter d according to the distance which
// shall be explored.


function[GRID]=testgrid(DISTANCE)
  
  D=DISTANCE
  //Generate normal empty space '.'
  for j=1:(2*D)+1,
    for i=1:(2*D)+1 
      GRID(i,j)='.',
    end
  end
  
  //Locate the food in the center
  GRID(D+1,D+1)='F'

endfunction


//***********************************
// BEHAVIOR FUNCTION WITH CLASSIFIERS
//

CLASSIFIERS = [
'11##############' '0001' '000'; 
'##11############' '0010' '000'; 
'####11##########' '0011' '000'; 
'######11########' '0100' '000'; 
'########11######' '0101' '000'; 
'##########11####' '0110' '000'; 
'############11##' '0111' '000'; 
'##############11' '1000' '000';
'00##############' '0001' '000'; 
'##00############' '0010' '000'; 
'####00##########' '0011' '000'; 
'######00########' '0100' '000'; 
'########00######' '0101' '000'; 
'##########00####' '0110' '000'; 
'############00##' '0111' '000'; 
'##############00' '1000' '000'
]


CLASSIF = [
'11##############' '1' '000'; 
'##11############' '2' '000'; 
'####11##########' '3' '000'; 
'######11########' '4' '000'; 
'########11######' '5' '000'; 
'##########11####' '6' '000'; 
'############11##' '7' '000'; 
'##############11' '8' '000';
'00##############' '1' '000'; 
'##00############' '2' '000'; 
'####00##########' '3' '000'; 
'######00########' '4' '000'; 
'########00######' '5' '000'; 
'##########00####' '6' '000'; 
'############00##' '7' '000'; 
'##############00' '8' '000'
]

//*************************************************
// ANIMAT STRUCTURE
// The ANIMAT has a POSITION = (Yanimat, Xanimat)
// has a memory for the REWARD (FITNESS) RewTotal and RewActual
// and has a set of CLASSIFIERS as his 
// PREWIRED KNOWLEDGE connecting perceived PROPERTIES
// with a proposed ACTION
// The FITNESS within ANIMAT1 is not yet  used
// (only for a measurement protocol)
// NEW: the ANIMAT1 has an ENERGY level which is controlled
// by TIME and by ACTIVITY
// Passiv, no move --> '-1'
// Move without food --> '-2'
// Move with food --> '-2' + '1000'

Xanimat = 3
Yanimat = 5
RewTotal = 0
RewActual = 0
Energy = 1000 //Start value, could be differently

ANIMAT = list(Xanimat, Yanimat, RewTotal, RewActual, CLASSIF, Energy)

//****************************************************
// HISTORY
// Collecting data during one life-cycle
// 1 := Cycle number k
// 2 := Object before move
// 3 := X-Pos
// 4 := Y-Pos
// 5 := REWTotal
// 6 := eNERGY

HISTORY =[]


//***************************************************
// Function to decode the content of a cell
// NEW for ANIMAT1
//
// Only change: Border 'BB' is replaced by value '01'

function[CELLVALUE]=decode(YI,X,GRID,SHOW)
  
  [YMAX, XMAX]=size(GRID)
  
  if (SHOW==1) then printf("decode: SIZE OF GRID (X,Y) = (%d,%d)\n",XMAX,YMAX),end
  
  CELLVALUE=[]
  
  
  if (SHOW==1) then printf("decode: YMAX=%d, XMAX=%d,YI= %d, X= %d\n",YMAX, XMAX,YI,X),end
  if (X > XMAX) | (X < 1) | (YI > YMAX) | (YI <1) then CELLVALUE='01'
    elseif GRID(YI,X) =='.' then CELLVALUE='00'
    elseif GRID(YI,X) =='O' then CELLVALUE='10'
    elseif  GRID(YI,X) =='F' then CELLVALUE='11'
    else printf("decode:ERROR AT CELL =( %d,%d)\n",X,YI)
    end
    
endfunction

//*************************************************
// SENSING ENVIRONMENT
// Function ainp(POS,DISTANCE) from ANIMAT1-agent
//
// Loocking to the 'north' the Animat can see the content of all it's neighbouring cells clockwise around.
// Enhancing the distance by 1 extends the field to the next 'circle'
// The encoding is as follows:
// '.' := Empty space encoded '00'
// Border := has to be encoded as '01'
// 'O' := Object Rock encoded '10'
// 'F' := Object Food encoded '11'


function [PERC]=ainp(YI,X,GRID,SHOW)
  
  //Having a 'number' version of the input
  SENSINPUT=[]
  PERC=""
  
//The cells will be searched from 'north' in clockwise order
// The coordinates below are relativ to the actual position of the ANIMAT

  P=[-1,0; -1,1; 0,1; 1,1; 1,0; 1, -1; 0,-1; -1,-1 ]
  
[r,c]=size(P)
for j=1:r, SENSINPUT(j)=decode(YI+P(j,1),X+P(j,2),GRID),
  PERC=PERC+string(SENSINPUT(j))
end

if (SHOW==1) then
  printf("Sens Input: %s\n\n",PERC)
  end
    
  endfunction
  
  
  

//*************************************************
// MATCH
// match: PERC x CLASSIFIERS ---> {INDX, .... }
//
// match1 is a highly specialized function which computes the index
// INDXCL of a classifier which shall be activated.
// It takes the position of food or space in the perceptional string
// PERC and then maps this position to a classifier which has to be
// prepared in an appropriate way.
// 
// If INDXCL is either '0' then there is no action ACT, otherwise the
// index INDXCL is the number of an appropriate classifier  

function [INDXCL,REWARD]=match1(PERC, CLASSIF,SHOW)
  
  [r,c]=size(CLASSIF)
  m=[]
  f=-1
  
  if(strindex(PERC,'11')<>[]) then
    
    f=1, REWARD=1000-2
    k=strindex(PERC,'11'),
    v=floor(modulo(k+1,2))
    j=1,
    for i=1:length(v), if v(i)==0 then m(j)=(k(i)+1)/2,j=j+1,end,end
    
   elseif(strindex(PERC,'00')<>[]) then
     
     f=0,  REWARD=-2
    k=strindex(PERC,'00'),
    v=floor(modulo(k+1,2))
    j=1,
    for i=1:length(v), if v(i)==0 then m(j)=(k(i)+1)/2,j=j+1,end,end
    
    else  REWARD=-1
   
 end
 
 maxR=length(m)
 INDX=floor(maxR*rand())+1
 INDXCL=m(INDX)
 
 if (f==1) then INDXCL=INDXCL
 elseif (f==0) then INDXCL=INDXCL+8
else INDXCL=0
 end

endfunction


//***************************************************
// Function to fetch the action out of the classifier set
// 

function [ACT]=action1(CLASSIF, INDXCL)
  
  ACT=CLASSIF(INDXCL,2)

endfunction


//*************************************************
// MAP ACT into POS
// Function aout: ACT --> POS

function [YN, XN]=aout(ACT,SHOW, YO, XO)
  
  // The coordinates below are relativ to the actual position of the ANIMAT
  //They work 'clockwise' around beginning with 'north'

  P=[-1,0; -1,1; 0,1; 1,1; 1,0; 1, -1; 0,-1; -1,-1 ]
  
  YN=YO+P(evstr(ACT),1), 
  XN=XO+P(evstr(ACT),2)

endfunction


//*************************************************
// UPDATE ANIMAT
//
// Either keep position or move.
// Summarize reward


function [ANIMAT] = updateAnim(ANIMAT,REWARD,XN,YN,SHOW)
  
  // Update Energy
  ANIMAT(6) =ANIMAT(6)+REWARD
  
  if (ANIMAT(6) < 0) then printf("update: ANIMAT HAS NO MORE ENERGY!!!\n"),
  elseif (REWARD <> -1) then ANIMAT(1) = XN, ANIMAT(2) = YN,  ANIMAT(4) = REWARD, ANIMAT(3)=ANIMAT(3)+REWARD
     else ANIMAT(4) = REWARD, ANIMAT(3)=ANIMAT(3)+REWARD
     end
     
     if (SHOW==1) then
     printf("update ANIMAT: POS(y,x) = (%d,%d), REW = %d, REW-TOTAL = %d, ENERGY=%d\n\n", ANIMAT(2),ANIMAT(1), ANIMAT(4), ANIMAT(3), ANIMAT(6))
   end
   
  endfunction

//***************************************************
// SIMPLE AUTOMATED TEST FRAMEWORK FOR ZCS
//
// Automatic testing for a certain GRID with given numers of runs
//
// ANIMAT := Structure OF ANIMAT system
// HISTORY := Protocol of movements and cumulated rewards
// GRID := Content of environment
// MODE := random (=0), non-random (=1)
// YYMAX := Number of rows times 5
// XXMAX := Number of columns times 5
// RUNS := How many cycles the simulation shall run. 1 cycle means one action
// S := scaling factor in the sparse food case
// GRID := Fixed GRID from external source
// DISTANCE := General distance from food in test field

//Prepare some parameters for liveR()

function [ANIMAT,GRID]=liveR1prep(ANIMAT,YYMAX, XXMAX, S,GRID,DISTANCE,CLASSIF, ENERGY, SHOW)
  
    
  //GENERATE FIXED TEST GRID
  if (S==-1) then [GRID]=testgrid(DISTANCE),
  
  //GENERATE dynamic GRID
  elseif (S == 0) then [GRID]=gridgen(YYMAX, XXMAX),
  
  //GENERATE dynamic GRID with sparse food
elseif (S == 1) then [GRID]=gridgen2(YYMAX,XXMAX,S),

  // USE external GRID
else S =2,
  
end

ANIMAT(5)=CLASSIF
ANIMAT(6) = ENERGY
  
endfunction


function [ANIMAT,HISTORY,GRID,FOOD]=liveR1(ANIMAT,GRID, RUNS,HISTORY,SHOW)
  
  if (RUNS<0) then error('RUNS is not specified'),end

  
  //SET GLOBAL VARIABLES TO ZERO
  HISTORY=[]
  ANIMAT(3)=0
  f=1 //Index to store in which cycle food has been found
  FOOD=[] //Storage for differences
  FOLD=0
  FNEW=0


  k=1
  while(k < RUNS+1),
    
    if (SHOW==1) then
    printf("-----CYCLE %d---------------------------------------------------\n\n",k)
    end
  
  [YMAX,XMAX]= size(GRID)
  //printf("DIMENSION OF GRID - ROWS = %d, COLUMNS = %d\n\n",ZMAX,XMAX)
  
  // (1) Get actual position (XO,YO) from Animat 
  // Is given with argument ANIMAT(1) = rows and ANIMAT(2) = columns
  
  XO= ANIMAT(1)
  YO= ANIMAT(2)

// Get SENSINPUT as string: PERC

[PERC]=ainp(YO,XO,GRID,SHOW)

// Match PERC into an appropriate classifier

[INDXCL,REWARD]=match1(PERC, CLASSIF,SHOW)

//Generate new move
[ACT]=action1(CLASSIF, INDXCL)

//Generate new POSITION (YN,XN)
[YN, XN]=aout(ACT,SHOW, YO, XO)

if (SHOW==1) then
  printf("NEW POSITION PROPOSED=(YN,XN)= (%d, %d)\n\n",YN,XN),
  end


  // Decode the content of new position
  
  [CELLVALUE]=decode(YN,XN,GRID,SHOW)
  
   if (SHOW==1) then,
     printf("CONTENT OF NEW POSITION= %s\n\n",CELLVALUE),
     end
  
  // Update ANIMAT
  
  [ANIMAT] = updateAnim(ANIMAT,REWARD,XN,YN,SHOW)
  
  if  (REWARD>900) then FNEW=k,FOOD(f,1)=FNEW-FOLD, FOLD=FNEW, f=f+1, end
  if (SHOW==1) & (REWARD>900) then  printf("FOOD in CYCLE = %d\n\n",k),end
  
  // Update PATHHISTORY
  
  [r,c]=size(HISTORY)
  
  //INDEX
  
  HISTORY(r+1,1)=k
  
  //CONTENT
  
  HISTORY(r+1,2)=evstr(CELLVALUE)
  
  // POSITION
  HISTORY(r+1,3)=XN, HISTORY(r+1,4)=YN
  
  //REWARDTOTAL
  HISTORY(r+1,5)=ANIMAT(3)
  
  //ENERGY
  HISTORY(r+1,6)=ANIMAT(6)
  
  //Update while loop
  
  
  k=k+1,
  
end

MEAN=mean(FOOD)

if (SHOW==1) then
  printf("ENERGY = %d, REWSUM/1000 = %f\n, TIMES FOOD = %f, MEAN LENGHT = %f\n\n",ANIMAT(6), ceil((ANIMAT(3)/1000)),length(FOOD),MEAN)
  end

endfunction


//***************************************************
// SIMPLE AUTOMATED TEST FRAMEWORK FOR ZCS
// WITH REPETITION
//
// ANIMAT := Structure OF ANIMAT system
// HISTORY := Protocol of movements and cumulated rewards
// RUNS := How many cycles the simulation shall run. 1 cycle means one action
// GRID := Fixed GRID from external source
// N:= Number of repetitions of an experiment with RUNS-many actions
// FOODHITS := List of food hits per repetition
// MEAN := statistical mean
// STD := standard deviation
// YS, XS := start position
// ENERGYS := start value



function [FOODHITS,MEAN, STD]=experiment1(ANIMAT,YS, XS,ENERGYS, GRID, RUNS,HISTORY,SHOW,N)
  
  FOODHITS=[]
  
  for i=1:N,
    
    [ANIMAT,HISTORY,GRID,FOOD]=liveR1(ANIMAT,GRID, RUNS,HISTORY,SHOW)
 
  
   
  [r,c]=size(FOODHITS),
  
  //INDEX
  
  FOODHITS(r+1,1)=length(FOOD),
  ANIMAT(1) = XS, ANIMAT(2)=YS, ANIMAT(6) = ENERGYS
  
  end //for N


MEAN=mean(FOODHITS)
STD=st_deviation(FOODHITS)


endfunction



Subsections

Gerd Doeben-Henisch 2012-03-31