in reply to Re (tilly) 1: Baseball line up (best rotation)
in thread Baseball line up (best rotation)

Setting it up as Tilly suggests, this also might be a good problem for a genetic algorithm. First, create and fill a hundred or so random lineups from all available teams. Each step of the interation will require playing each line up as randomly as tilly suggests for a game, assigning the total number of runs won as the 'value' of that lineup. For each line up, you could run the game multiple times, the value being the total sum of all scores. When all lineups have been done, sort this set based on scores; remove those lineups that did not perform well (say, less than 2*number of games played*number of innings), and for those that did perform well (say, better than 4*number of games played*number of innings), copy and mutate them. The mutation would be one of two things: either randomly switch the order or two consecutive players on the team, or switch a random player with a random player not currently on the lineup. Clear out all the current 'values' and rerun. After several iterations of this, the top 10 or so lineups should have outstanding results, which you can then compare to the current lineup with.

To make this work better, you should generate a large array of random numbers that would be regenerated on each step, but within each step, each tested lineup would use the same random numbers in the same order, if only to remove a potental bias.

(Yes, I know this is serious overkill, but it's an interesting thought ...)


Dr. Michael K. Neylon - mneylon-pm@masemware.com || "You've left the lens cap of your mind on again, Pinky" - The Brain
  • Comment on Re: Re (tilly) 1: Baseball line up (best rotation)

Replies are listed 'Best First'.
Re: Re: Re (tilly) 1: Baseball line up (best rotation)
by aijin (Monk) on May 17, 2001 at 22:39 UTC
    Just to supplement Masem's reply...

    First, you might consider doing a crossover in addition to a mutation to ensure that you properly explore the line-up space. You'll need to do a partially matched crossover (PMX) to ensure that you don't duplicate the team members. You could do a mutation as suggested by Masem either on each lineup or on each member of a lineup 1-5% of the time.

    Secondly you could experiment with various types of selection algorithms for determining who breeds and who dies. Masem suggested the Percentage model, but there's also the Roulette and Tournament models.

    Third, it would be really neat to take your top lineup from one run and stick it into a new run of the GA to see how it fares.

    Check out Genetic Algorithms with Perl for more guidance and inspiration.

    Enjoy!

    Addendum: I just realized the page didn't actually link to the code.