Optimal urban bus routing with scheduling flexibilities