When Charlie discovers that Alan is sleepwalking, he believes it's related to his brother's lack of sex following his divorce, and comes up with a cure.