class SelfishSim extends Simulation
{
	boolean shouldSwap (Node a, Node b)
	{
		// Does the first node agree to the swap?
		double before = 1.0, after = 1.0;
		for (Node c : a.neighbours) before *= distance (a, c);
		for (Node c : a.neighbours) after *= distance (b, c);
		if (after > before && Math.random() >= before / after)
			return false;
		
		// If the first node agreed, does the second node agree?
		before = after = 1.0;
		for (Node d : b.neighbours) before *= distance (b, d);
		for (Node d : b.neighbours) after *= distance (a, d);
		if (after > before && Math.random() >= before / after)
			return false;
		
		return true;
	}
	
	public static void main (String[] args)
	{
		new SelfishSim();
	}
}
