simulation routine and graph plotting