Skip to content

Commit

Permalink
updated some examples, fixed SwapPositon function
Browse files Browse the repository at this point in the history
  • Loading branch information
torococo committed Oct 17, 2019
1 parent e8bbaf0 commit e350acf
Show file tree
Hide file tree
Showing 17 changed files with 450 additions and 72 deletions.
2 changes: 1 addition & 1 deletion Examples/PopulationTumor/PopTumor.java
Expand Up @@ -199,7 +199,7 @@ public void Step(int idraw) {
}

public static void main(String[] args) {
PopTumor ft = new PopTumor(150, 0.02, 0.001, 0.003, 100000, 2e-6, 2e-6, 0, 2, 100);
PopTumor ft = new PopTumor(150, 0.015, 0.001, 0.004, 100000, 2e-6, 2e-6, 0, 2, 100);
ft.Init(100);
int idraw = -1;
for (int i = 0; i < 4001; i++) {
Expand Down
11 changes: 5 additions & 6 deletions Examples/_3OffLatticeExample/ExampleOffLattice.java
Expand Up @@ -22,7 +22,7 @@ public void Init(int color){
if(overlap<0) {
return 0;//if cells aren't actually overlapping, then there is no force response
}
return Math.pow(G.FORCE_SCALER*overlap, G.FORCE_EXPONENT);
return G.FORCE_SCALER*overlap;//this constant scaling of the overlap is called Hooke's law!
}
public void CalcMove(){
//sets x and y velocity components of cell
Expand All @@ -47,15 +47,14 @@ public void MoveDiv(){

public class ExampleOffLattice extends AgentGrid2D<CellOL> {
static final int WHITE=RGB256(248,255,252), PURPLE =RGB256(77,0,170), PINK =RGB256(222,0,109),CYTOPLASM=RGB256(191,156,147);
double RADIUS=0.5;
double RADIUS=0.25;

double FORCE_EXPONENT=2;//these constants have been found to be rather stable, but tweak them and see what happens!
double FORCE_SCALER=0.7;
double FORCE_SCALER=0.25;//this constant was found to be rather stable, but tweak it and see what happens!
double FRICTION=0.5;

double PURP_DIV_BIAS =0.01;//grid holds onto phenotype differences, if drift were included these would probably be moved to individual cells.
double PINK_DIV_BIAS =0.02;
double PURP_INHIB_WEIGHT =0.015;
double PURP_INHIB_WEIGHT =0.02;
double PINK_INHIB_WEIGHT =0.05;
ArrayList<CellOL> neighborList=new ArrayList<>();
ArrayList<double[]> neighborInfo=new ArrayList<>();
Expand All @@ -72,7 +71,7 @@ public ExampleOffLattice(int x, int y,String outFileName) {
out=new FileIO(outFileName,"w");
}
public static void main(String[] args) {
int x=60,y=60;
int x=30,y=30;
//to record output, call the constructor with an output filename
ExampleOffLattice ex=new ExampleOffLattice(x,y,"PopOut.csv");
//ExampleOffLattice ex=new ExampleOffLattice(x,y);
Expand Down
1 change: 1 addition & 0 deletions HAL/GridsAndAgents/Agent2DBase.java
Expand Up @@ -138,5 +138,6 @@ public double DistSquared(double x,double y){
double dy = DispY(y);
return NormSquared(dx,dy);
}

}

19 changes: 0 additions & 19 deletions HAL/GridsAndAgents/AgentBaseSpatial.java
Expand Up @@ -18,25 +18,6 @@ public int Isq() {
return iSq;
}

/**
* swaps the positions of two agents. useful mostly for the AgentSQ2unstackable and AgentSQ3unstackable classes,
* which don't allow stacking of agents, making this maneuver otherwise difficult.
*/
public void SwapPosition(AgentBaseSpatial other) {
if (!alive || !other.alive) {
throw new RuntimeException("attempting to move dead agent");
}
if (other.G != G) {
throw new IllegalStateException("can't swap positions between agents on different grids!");
}
int iOther = other.Isq();
int iThis = Isq();
other.RemSQ();
this.RemSQ();
other.MoveSQ(iThis);
this.MoveSQ(iOther);
}

/**
* moves the agent to the middle of the square at the indices/index specified
*/
Expand Down
20 changes: 20 additions & 0 deletions HAL/GridsAndAgents/AgentSQ1Dunstackable.java
Expand Up @@ -120,6 +120,26 @@ void Setup(int i) {
iSq=i;
AddSQ(i);
}
/**
* swaps the positions of two agents. useful for the AgentSQunstackable classes,
* which don't allow stacking of agents, making this maneuver otherwise impossible.
*/
public void SwapPosition(AgentSQ1Dunstackable<T> other) {
if (!alive || !other.alive) {
throw new RuntimeException("attempting to move dead agent");
}
if (other.G != G) {
throw new IllegalStateException("can't swap positions between agents on different grids!");
}
other.RemSQ();
this.RemSQ();
int iThis = this.iSq;
this.iSq = other.iSq;
other.iSq=iThis;
other.AddSQ(other.iSq);
this.AddSQ(this.iSq);
}


@Override
void Setup(int x, int y) {
Expand Down
26 changes: 26 additions & 0 deletions HAL/GridsAndAgents/AgentSQ2Dunstackable.java
Expand Up @@ -164,6 +164,32 @@ public int Isq() {
return iSq;
}

/**
* swaps the positions of two agents. useful for the AgentSQunstackable classes,
* which don't allow stacking of agents, making this maneuver otherwise impossible.
*/
public void SwapPosition(AgentSQ2Dunstackable<T> other) {
if (!alive || !other.alive) {
throw new RuntimeException("attempting to move dead agent");
}
if (other.G != G) {
throw new IllegalStateException("can't swap positions between agents on different grids!");
}
other.RemSQ();
this.RemSQ();
int xThis=this.xSq;
int yThis=this.ySq;
int iThis = this.iSq;
this.xSq = other.xSq;
this.ySq = other.ySq;
this.iSq = other.iSq;
other.xSq=xThis;
other.ySq=yThis;
other.iSq=iThis;
other.AddSQ(other.iSq);
this.AddSQ(this.iSq);
}

void Setup(double i) {
Setup((int) i);
}
Expand Down
30 changes: 30 additions & 0 deletions HAL/GridsAndAgents/AgentSQ3Dunstackable.java
Expand Up @@ -181,6 +181,36 @@ void Setup(double x, double y) {

}

/**
* swaps the positions of two agents. useful for the AgentSQunstackable classes,
* which don't allow stacking of agents, making this maneuver otherwise impossible.
*/
public void SwapPosition(AgentSQ3Dunstackable<T> other) {
if (!alive || !other.alive) {
throw new RuntimeException("attempting to move dead agent");
}
if (other.G != G) {
throw new IllegalStateException("can't swap positions between agents on different grids!");
}
other.RemSQ();
this.RemSQ();
int xThis=this.xSq;
int yThis=this.ySq;
int zThis=this.zSq;
int iThis = this.iSq;
this.xSq = other.xSq;
this.ySq = other.ySq;
this.zSq=other.zSq;
this.iSq = other.iSq;
other.xSq=xThis;
other.ySq=yThis;
other.zSq=zThis;
other.iSq=iThis;
other.AddSQ(other.iSq);
this.AddSQ(this.iSq);
}


@Override
void Setup(int xSq, int ySq, int zSq) {
this.xSq = xSq;
Expand Down
13 changes: 13 additions & 0 deletions HAL/GridsAndAgents/PDEGrid1D.java
Expand Up @@ -52,27 +52,40 @@ public PDEGrid1D(int xDim, boolean wrapX) {
public double Get(int x) {
return field[x];
}
public double Get(double x) {
return Get((int)x);
}

/**
* sets the prev field value at the specified coordinates
*/
public void Set(int x, double val) {
deltas[x] = val-field[x];
}
public void Set(double x, double val) {
Set((int)x,val);
}


/**
* adds to the prev field value at the specified index
*/
public void Add(int x, double val) {
deltas[x] += val;
}
public void Add(double x, double val) {
Add((int)x,val);
}

/**
* multiplies a value in the “current field” and adds the change to the “delta field”
*/
public void Mul(int x, double val) {
deltas[x] += field[x] * val;
}
public void Mul(double x, double val) {
Mul((int)x,val);
}

/**
* adds the delta field into the current field, also increments the tick.
Expand Down
25 changes: 24 additions & 1 deletion HAL/GridsAndAgents/PDEGrid2D.java
Expand Up @@ -176,7 +176,9 @@ public static void Diffusion2DADIBetweenAction(double[]field, double[]scratch,do
public double Get(int x, int y) {
return field[x * yDim + y];
}

public double Get(double x, double y) {
return Get((int)x,(int)y);
}
/**
* gets the prev field value at the specified index
*/
Expand All @@ -190,6 +192,9 @@ public double Get(int i) {
public void Set(int x, int y, double val) {
deltas[x * yDim + y] = val - field[x * yDim + y];
}
public void Set(double x, double y, double val) {
Set((int)x,(int)y,val);
}

/**
* sets the prev field value at the specified index
Expand All @@ -204,6 +209,9 @@ public void Set(int i, double val) {
public void Add(int x, int y, double val) {
deltas[x * yDim + y] += val;
}
public void Add(double x, double y, double val) {
Add((int)x,(int)y,val);
}

/**
* adds to the prev field value at the specified index
Expand All @@ -218,6 +226,9 @@ public void Add(int i, double val) {
public void Mul(int x, int y, double val) {
deltas[x * yDim + y] += field[x * yDim + y] * val;
}
public void Mul(double x, double y, double val) {
Mul((int)x,(int)y,val);
}

/**
* multiplies a value in the “current field” and adds the change to the “delta field”
Expand Down Expand Up @@ -488,6 +499,9 @@ public double GradientX(int x, int y) {
double right = PDEequations.DisplacedX2D(field,x + 1, y, xDim, yDim,wrapX,(X,Y)->Get(X-1,Y));
return right - left;
}
public double GradientX(double x, double y) {
return GradientX((int)x,(int)y);
}

/**
* returns the gradient of the diffusible in the Y direction at the coordinates specified
Expand All @@ -497,6 +511,9 @@ public double GradientY(int x, int y) {
double up = PDEequations.DisplacedY2D(field,x, y+1, xDim, yDim,wrapX,(X,Y)->Get(X,Y-1));
return up - down;
}
public double GradientY(double x, double y) {
return GradientY((int)x,(int)y);
}

/**
* returns the gradient of the diffusible in the X direction at the coordinates specified, will use the boundary
Expand All @@ -507,6 +524,9 @@ public double GradientX(int x, int y, double boundaryCond) {
double right = PDEequations.DisplacedX2D(field,x + 1, y, xDim, yDim,wrapX,(X,Y)->boundaryCond);
return right - left;
}
public double GradientX(double x, double y, double boundaryCond) {
return GradientX((int)x,(int)y,boundaryCond);
}

/**
* returns the gradient of the diffusible in the Y direction at the coordinates specified, will use the boundary
Expand All @@ -517,6 +537,9 @@ public double GradientY(int x, int y, double boundaryCond) {
double up = PDEequations.DisplacedY2D(field,x, y+1, xDim, yDim,wrapX,(X,Y)->boundaryCond);
return up - down;
}
public double GradientY(double x, double y, double boundaryCond) {
return GradientY((int)x,(int)y,boundaryCond);
}

/**
* ensures that all values will be non-negative on the next timestep, call before Update
Expand Down

0 comments on commit e350acf

Please sign in to comment.