Optimizing the Ptolemaic Model of Planetary and Solar Motion