Skip to content

Instantly share code, notes, and snippets.

@jbn
Created September 14, 2010 22:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jbn/579918 to your computer and use it in GitHub Desktop.
Save jbn/579918 to your computer and use it in GitHub Desktop.
import java.util.LinkedList;
/*
Curves:
probabilityOfHavingChild(deltaWealth, inflation)
wealth/inflation
consumptionCurve(deltaWealth, inflation)
adolesentConsumptionRequirements
adulthoodBetsowment
adulthoodYearlyExpense
*/
public class Individual{
public static void main(String[] args){
Individual individual = new Individual(40, 10000000.0);
for(int i=0; i<100; ++i){
individual.ageOneYear(Math.random()/10.0 - 0.05);
System.out.println(individual.getWealth());
}
}
private int age;
private double wealth;
private LinkedList<Individual> children;
public Individual(){
this(0,0.0);
}
public Individual(int age, double wealth){
this.age = age;
this.wealth = wealth;
children = new LinkedList<Individual>();
}
public double getWealth(){
return wealth;
}
void inheritWealth(double inheritance){
wealth += inheritance;
}
/**
@param returnOnWealth [-1,1] as %return/100
*/
public void ageOneYear(double returnOnWealth){
++age;
wealth *= 1.0+returnOnWealth;
for(Individual individual : children){
ageOneYear(returnOnWealth);
}
}
protected boolean hasDied(){
if(age+Math.random()*10 > 70 && Math.random() < 0.1){
double amountPerChild = wealth / children.size();
for(Individual child : children)
child.inheritWealth(amountPerChild);
wealth = 0.0;
}
return true;
}
protected boolean hasChild(){
if(age > 20 && children.size() < 5 && Math.random() < 0.01666){
double trustFund = 0.05 * wealth;
wealth = 0.95 * wealth;
children.add(new Individual(0, wealth));
return true;
}
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment