A Generalized Framework of Optimal Two-Stage Designs for Exploratory Basket Trials