Genetic Algorithms implementation

3 次查看(过去 30 天)
Jin
Jin 2011-3-28
编辑: TED MOSBY 2025-5-13
Hi, I'm currently having a problem in using genetic algorithms for the implementation of the iterated prisoner dilemma.
The main issues lies in the introduction of strategies to player, I.e. tit for tat and grim. I understand that the original genetic algorithms uses chromosomes as a way to stipulate agents strategy by telling them to cooperate or defect in specific period but do not tell them to play current period using outcomes from previous period.
Hence the question, can someone kindly point me in a direction where i can get started? Should i start paying attention to the chromosomes or should i pay attention to the strategy function? Thanks

回答(1 个)

TED MOSBY
TED MOSBY 2025-5-12
编辑:TED MOSBY 2025-5-13
Hi,
Your have to (1) choose an encoding that can express the kinds of memory‑based strategies (TitforTat, Grim, etc.), and (2) write a decoder that turns each chromosome into a callable strategy function.
You can follow the roadmap below to get started on iterative prisoners dilemma startegy using genetic algorithm in MATLAB:
  1. Chromosome design – Use a 5‑bit vector [g1 g2 g3 g4 g5] where g1= first move and g2–g5= moves for CC,CD,DC,DD (previous round).
  2. Decoder – A tiny function consults the chromosome to decide the next move. If there is no history yet, returng₁. Otherwise map the last round’s outcome to one of the remaining four genes and return that gene value. Decoder never changes.
  3. Define the payoff environment – Select the Prisoner’s Dilemma payoff numbers (e.g. Temptation=5, Reward=3, Punishment=1) and a game length (e.g. 150 rounds). All candidates will be evaluated under exactly the same conditions.
  4. Define the fitness function – For a given chromosome; Run a match against each benchmark opponent, summing your pay‑off each round. Average those pay‑offs.Return the negative of that average (MATLAB’s "ga" minimises the objective, so negating the score converts “high payoff is good” into “low objective is good”).
  5. Genetic loop – Initialise a random population of chromosomes; then for each generation: evaluation → selection → crossover → mutation (small bit‑flips) → next population.
  6. Stop condition – When best score plateaus or after a set number of generations.
  7. Read result – Inspect the best 5‑bit vector; it encodes a full memory‑1 strategy (e.g.,11010 = Tit‑for‑Tat, 11000 = Grim).
Here is more information on MATLAB's function"ga":
Hope this helps!

类别

Help CenterFile Exchange 中查找有关 Genetic Algorithm 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by