Cell Computing Model

Clone algorithm
The clone algorithm is used to implement the growth of the Cell Computing Model CCM. This
algorithm has following features:  

>    restart:
with(plots):
with(plottools):

#-----------------------------------------------
#Cells are defined as f::= [M,N], with
#   M = busy time, 0 = cell is not busy
#   N = life power, 0 = cell is dead
cells:= []:

Warning, the name changecoords has been redefined

Warning, the name arrow has been redefined

Simulation Functions

This section contains vaious functions to simulate the cell system

>    #************************************************
# Random function for generating non
# deterministic cell load (jobs)
#************************************************
randoMy := rand(1..30):

>    #************************************************
# This function generates jobs with a linear
# function.
# param x : job count of the queue
# param t : Time (steps)
#************************************************
generateJobsD:= proc(x, t, f)
local i;
  i:= evalf(x + f(t));
  i;
end:

>    #************************************************
# This function generates jobs in a non
# deterministic way.
# param x : job count of the queue
# param t : Time (steps)
#************************************************
generateJobsN:= proc(x, t)
local i;
  i:= x+ evalf(abs(sin(t)*randoMy()));
  i;
end:

>    #************************************************
# This function performs jobs.
# param x : job count of the queue
# param t : Time (steps)
#************************************************
killJobs:= proc(x, t, f)
local i, cell, k, m,j;
global cells, removalPower, addingPower, jobsRemoval;
  i:= x;

  for j from 1 to nops(cells)
  do
    #Check if cell is alive and not busy
    if (cells[j][2] > 0 and cells[j][1] = 0) then

      #Are there any jobs to perform
      if (i > 0) then
        i:= i - f(t);
        cells[j][2]:= cells[j][2] + addingPower:
      else
        cells[j][2] := cells[j][2] - removalPower:
      fi:

      #Check boundaries
      if (cells[j][2] > 100) then
        cells[j][2]:= 100:
      elif (cells[j][2] < 0) then
        cells[j][2]:= 0:
      fi:
    
    #decrement busy time
    elif (cells[j][1] > 0) then
      cells[j][1]:= cells[j][1] - 1;
    fi:
  od:

  if (i < 0) then i:= 0; fi;
  i;
end:

>   

Clone Functions

This section contains different clone functions.

>    #************************************************
# Ranomizer to remove a cell
#************************************************
removeRandom := rand(1..100):

>    #************************************************
# Function to calculate the probability to remove
# a cell
#************************************************
fp_remove:= x->100*exp(-x/20):

>    #************************************************
# Removes cells if the life power is zero
#************************************************
removeCellsD:= proc()
local j, p, r;
global cells;
  j:= 1;
  while (j <= nops(cells))
  do
    if (cells[j][2] <= 0) then
      cells:= [op(1..j-1,cells), op(j+1..nops(cells),cells)]:
    else
      j:= j + 1;
    fi:
  od:
end:

>    #************************************************
# Removes cells using a probability to the
# life power of the cell
#************************************************
removeCellsN:= proc()
local j, p, r;
global cells;
  j:= 1;
  while (j <= nops(cells))
  do
    #Calculate the probability to remove the cell
    p:= evalf(fp_remove(cells[j][2]));
    r:= removeRandom();
     
    if (r < p) then
      cells:= [op(1..j-1,cells), op(j+1..nops(cells),cells)]:
    else
      j:= j + 1;
    fi:
  od:
end:

>    #************************************************
# This function checks if a new cell is needed
# param jobs : count of jobs waiting in the queue
# param jobsdiff : difference to the last
#                  measurement
# param jobsdiffprev : last difference
#************************************************
cloneCell:= proc(jobs, jobsdiff, jobsdiffprev)
local cdiff;
global lim, reactlim, cells, createTimeConst;

  cdiff:= jobsdiff-jobsdiffprev;

  if (cdiff >= 0 and jobsdiff > 0 and jobs > reactlim) or (jobs > lim) then
    cells:= [op(cells), [ceateTimeConst,100]];
  fi:
end:

>    #************************************************
# Test of the removal function
#************************************************
fp_remove(0);
evalf(fp_remove(1));
evalf(fp_remove(100));

# X-Axis is the life power
# Y-Axis is the propability of a cell death.
plot(fp_remove(x), x=-2..100,y=-1..100);

100

95.12294245

.6737946999

[Maple Plot]

Simulation

Deterministic Simulation

The following simulation demonstrates a deterministic system. The load (jobs per minute) is stable
as well as the cloning and removing process.

>    #************************************************
# this is the runtime simulation of a cell system
# running as a deterministic system
# param t : Max measure time
# param fg : job generation function
# param fr : job removal function
# This function returns a list of following
# items:
# [1] : Job statistics
# [2] : Job grows statistics
# [3] : cell count statistics
#************************************************
simD:= proc(t,fg, fr)
local jobs, jobsprev, jobsdiff, jobsdiffprev, jobfunc, jobdifffunc, cellfunc, i;
global cells;

  jobs:= 0:
  jobsprev:= 0:
  jobsdiff:= 0:
  jobsdiffprev:= 0:
  jobfunc:= []:
  jobdifffunc:= []:
  cellfunc:= []:
  cells:= [[0,100]]:  #Generate one mother cell

  #Lifetime loop
  for i from 0 to t
  do
    #InputCell witch generates messages
    jobs:= generateJobsD(jobs, i, fg);

    #WorkCells
    jobs:= killJobs(jobs, i, fr);

    #Control cell grows
    jobsdiff:= jobs-jobsprev;
    cloneCell(jobs, jobsdiff, jobsdiffprev);

    #Try to remove dead cells
    removeCellsD();
  
    jobfunc:= [op(jobfunc), [i,jobs]];
    jobdifffunc:= [op(jobdifffunc), [i,jobsdiff]];
    cellfunc:= [op(cellfunc), [i,nops(cells)]];

    jobsprev:= jobs;
    jobsdiffprev:= jobsdiff;
  od:
  [jobfunc, jobdifffunc, cellfunc];
end:

Non deterministic Simulation

The following simulation demonstrates a non deterministic system. The load (jobs per minute) is instable
as well as the cloning and removing process.

>    #************************************************
# this is the runtime simulation of a cell system
# running as a non deterministic system
# This function returns a list of following
# items:
# param fr : job removal function
# [1] : Job statistics
# [2] : Job grows statistics
# [3] : cell count statistics
#************************************************
simN:= proc(t, fr)
local jobs, jobsprev, jobsdiff, jobsdiffprev, jobfunc, jobdifffunc, cellfunc, i;
global cells;

  jobs:= 0:
  jobsprev:= 0:
  jobsdiff:= 0:
  jobsdiffprev:= 0:
  jobfunc:= []:
  jobdifffunc:= []:
  cellfunc:= []:
  cells:= [[0,100]]:  #Generate one mother cell

  #Lifetime loop
  for i from 0 to t
  do
    #InputCell witch generates messages
    jobs:= generateJobsN(jobs, i);

    #WorkCells
    jobs:= killJobs(jobs, i, fr);

    #Control cell grows
    jobsdiff:= jobs-jobsprev;
    cloneCell(jobs, jobsdiff, jobsdiffprev);

    #Try to remove dead cells
    removeCellsN();
  
    jobfunc:= [op(jobfunc), [i,jobs]];
    jobdifffunc:= [op(jobdifffunc), [i,jobsdiff]];
    cellfunc:= [op(cellfunc), [i,nops(cells)]];

    jobsprev:= jobs;
    jobsdiffprev:= jobsdiff;
  od:
  [jobfunc, jobdifffunc, cellfunc];
end:

Demonstration

The first demo shows the simulation of a deterministic stable system.
The job generation and removal is done by defining the functions fg and fr, there are
different functions. Only one should be uncommented to test.
The upper limit of the queue size (stretchable) is 20 jobs.  
The time to create a cell is 2 steps long

>    #************************************************
# Settings of the simulation
#************************************************
lim:= 20:              #Limit of the queue size
reactlim:= 10:         #Reaction starts out of this limit
ceateTimeConst:= 2:    #Time of cell to get alife

#-----------------------------------------------
#Parameters for deterministic simulation
removalPower:= 1:      #Reducing cell life power if there is no job to be performed
addingPower:= 1:       #Growing of the cell life power for each performed job.

#-----------------------------------------------
# REGULATING
fg:= x->19:            #Generating function
fr:= x->7:             #Removal function
maxtime:= 20:          #Simulation time

#-----------------------------------------------
# REGULATING
#fg:= x->sin(x+1)/(x+1)*30:
#fr:= x->7:
#maxtime:= 1000:          #Simulation time

#-----------------------------------------------
# REGULATING
#fg:= x->ln(x+1)*10:
#fr:= x->7:
#maxtime:= 2000:          #Simulation time

#-----------------------------------------------
# NOT REGULATING
#fg:= x->tan(x) * 10:
#fr:= x->7:
#maxtime:= 1000:          #Simulation time

statistics := simD(maxtime,fg, fr):
plot([statistics[1], statistics[2], statistics[3]], x=0..maxtime,y=3*lim..-2*lim, color=[red,blue, green], title="Stable Cells", legend=["Job count", "Job growth", "Cell count"]);

[Maple Plot]

Example 1

The next demo shows a non deterministic system using instabil functions. This first example illustrates a standard implementation,
using 20 jobs as an upper limit, a constand life power management (increments and decrements by one) and a creation time of
2 steps  

>    #************************************************
# Settings of the simulation
#************************************************
lim:= 20:              #Limit of the queue size
reactlim:= 20:         #Reaction starts out of this limit

#-----------------------------------------------
#Parameters for non deterministic simulation
fr:= x->7:             #Jobs to be performed each step
removalPower:= 1:      #Reducing cell life power if there is no job to be performed
addingPower:= 1:       #Growing of the cell life power for each performed job.
ceateTimeConst:= 2:    #Time of cell to get alife
maxtime:= 1000:         #Simulation time

>    statistics := simN(maxtime, fr):
plot([statistics[3]], x=0..maxtime,y=10..-1, color=[green], title="Instable Cells", legend=["Cell count"]);

[Maple Plot]

>    plot([statistics[1], statistics[2], statistics[3]], x=0..maxtime,y=2*lim..-lim, color=[red,blue, green], title="Stable Cells", legend=["Job count", "Job growth", "Cell count"]);

[Maple Plot]

Example 2

This implementation of a instabil system is very smooth, because the life power removal is low and the increasing power if a cell has work to do is high.

>    #-----------------------------------------------
#Very smooth system
fr:= x->7:             #Jobs to be performed each step
removalPower:= 1:      #Reducing cell life power if there is no job to be performed
addingPower:= 25:       #Growing of the cell life power for each performed job.
ceateTimeConst:= 2:    #Time of cell to get alife
maxtime:= 1000:         #Simulation time

>    statistics := simN(maxtime, fr):
plot([statistics[3]], x=0..maxtime,y=10..-1, color=[green], title="Instable Cells", legend=["Cell count"]);

[Maple Plot]

>    plot([statistics[1], statistics[2], statistics[3]], x=0..maxtime,y=2*lim..-lim, color=[red,blue, green], title="Stable Cells", legend=["Job count", "Job growth", "Cell count"]);

[Maple Plot]

Example 3

This implementation of instabil system is very reacting, therefore the power removal is high and the power adding low

>    #-----------------------------------------------
#Very reacting system
fr:= x->7:             #Jobs to be performed each step
removalPower:= 5:      #Reducing cell life power if there is no job to be performed
addingPower:= 1:       #Growing of the cell life power for each performed job.
ceateTimeConst:= 2:    #Time of cell to get alife
maxtime:= 1000:         #Simulation time

>    statistics := simN(maxtime, fr):
plot([statistics[3]], x=0..maxtime,y=10..-1, color=[green], title="Instable Cells", legend=["Cell count"]);

[Maple Plot]

>    plot([statistics[1], statistics[2], statistics[3]], x=0..maxtime,y=2*lim..-lim, color=[red,blue, green], title="Stable Cells", legend=["Job count", "Job growth", "Cell count"]);

[Maple Plot]

Example 4

This examble illustrates, how the system reacts if the cell creating needs a lot of time. This means there is some delay to the needed performance.
Specially at the beginning of the lifetime, to many cells are created. But even during the lifetime, if the load increases abrubtly, the system will generate
to many cells. To avoid this we need to smooth the system as shown in the example 2.

>    #-----------------------------------------------
#System with reaction delay
fr:= x->7:             #Jobs to be performed each step
removalPower:= 1:      #Reducing cell life power if there is no job to be performed
addingPower:= 1:       #Growing of the cell life power for each performed job.
ceateTimeConst:= 6:    #Time of cell to get alife
maxtime:= 1000:         #Simulation time

>    statistics := simN(maxtime, fr):
plot([statistics[3]], x=0..maxtime,y=10..-1, color=[green], title="Instable Cells", legend=["Cell count"]);

[Maple Plot]

>    #-----------------------------------------------
#Smooth system with reaction delay
fr:= x->7:             #Jobs to be performed each step
removalPower:= 1:      #Reducing cell life power if there is no job to be performed
addingPower:= 15:       #Growing of the cell life power for each performed job.
ceateTimeConst:= 6:    #Time of cell to get alife
maxtime:= 1000:         #Simulation time

>    statistics := simN(maxtime, fr):
plot([statistics[3]], x=0..maxtime,y=10..-1, color=[green], title="Instable Cells", legend=["Cell count"]);

[Maple Plot]