Analysis and Optimization of Pedestrian Flows