Skip to content

Commit

Permalink
update GTFunction #758
Browse files Browse the repository at this point in the history
  • Loading branch information
steveyuwono committed Dec 7, 2023
1 parent c9829db commit 0ff58b8
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 6 deletions.
7 changes: 5 additions & 2 deletions src/mlpro/gt/native/basics.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class GTFunction (Persistent):


## -------------------------------------------------------------------------------------------------
def __init__(self, p_func_type:int, p_dim_elems:list=None, p_logging=Log.C_LOG_ALL):
def __init__(self, p_func_type:int, p_dim_elems:list=None, p_num_coalisions:int=None, p_logging=Log.C_LOG_ALL):

super().__init__(p_id=None, p_logging=p_logging)

Expand All @@ -79,8 +79,11 @@ def __init__(self, p_func_type:int, p_dim_elems:list=None, p_logging=Log.C_LOG_A

if p_dim_elems is None:
raise ParamError("p_dim_elems is not defined!")

if p_num_coalisions is None:
raise ParamError("p_num_coalisions is not defined!")

self._num_coals = len(p_dim_elems)
self._num_coals = p_num_coalisions
dim_elems = [self._num_coals]
dim_elems.extend(p_dim_elems)

Expand Down
3 changes: 2 additions & 1 deletion src/mlpro/gt/pool/native/games/prisonersdilemma_2p.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,8 @@ def _setup(self, p_mode, p_ada:bool, p_visualize:bool, p_logging) -> Model:
self._payoff = GTPayoffMatrix(
p_function=PayoffFunction_PD2P(
p_func_type=GTFunction.C_FUNC_PAYOFF_MATRIX,
p_dim_elems=[2,2]
p_dim_elems=[2,2],
p_num_coalisions=2
),
p_player_ids=coal_ids
)
Expand Down
7 changes: 4 additions & 3 deletions src/mlpro/gt/pool/native/games/prisonersdilemma_3p.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def _setup(self, p_mode, p_ada:bool, p_visualize:bool, p_logging) -> Model:
p_logging=p_logging
)

p2 = GTPlayer(
p3 = GTPlayer(
p_solver=[solver3a,solver3b],
p_name="Player of Prisoner 3",
p_visualize=p_visualize,
Expand All @@ -173,7 +173,7 @@ def _setup(self, p_mode, p_ada:bool, p_visualize:bool, p_logging) -> Model:
p_name="Coalition of Prisoner 3",
p_coalition_type=GTCoalition.C_COALITION_SUM
)
coal2.add_player(p3)
coal3.add_player(p3)


competition = GTCompetition(
Expand All @@ -189,7 +189,8 @@ def _setup(self, p_mode, p_ada:bool, p_visualize:bool, p_logging) -> Model:
self._payoff = GTPayoffMatrix(
p_function=PayoffFunction_PD3P(
p_func_type=GTFunction.C_FUNC_PAYOFF_MATRIX,
p_dim_elems=[2,2,2]
p_dim_elems=[2,4],
p_num_coalisions=3
),
p_player_ids=coal_ids
)
Expand Down
56 changes: 56 additions & 0 deletions test/howtos/gt/howto_gt_native_002_prisonners_dilemma_3p.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
## -------------------------------------------------------------------------------------------------
## -- Project : MLPro - A Synoptic Framework for Standardized Machine Learning Tasks
## -- Package : mlpro.gt.examples
## -- Module : howto_gt_native_002_prisonners_dilemma_3p.py
## -------------------------------------------------------------------------------------------------
## -- History :
## -- yyyy-mm-dd Ver. Auth. Description
## -- 2023-12-07 0.0.0 SY Creation
## -- 2023-12-07 1.0.0 SY Release of first version
## -------------------------------------------------------------------------------------------------

"""
Ver. 1.0.0 (2023-12-07)
This module shows how to run a game, namely 3P Prisoners' Dilemma with two solvers, such as random
solver and min greedy policy.
You will learn:
1) How to set up a game, including solver, competition, coalition, payoff, and more
2) How to run the game
3) How to analyse the game
"""

from mlpro.gt.native.basics import *
from mlpro.gt.pool.native.games.prisonersdilemma_3p import *
from pathlib import Path



if __name__ == "__main__":
cycle_limit = 10
logging = Log.C_LOG_ALL
visualize = False
path = str(Path.home())

else:
cycle_limit = 1
logging = Log.C_LOG_NOTHING
visualize = False
path = None

PD2P_Game = PrisonersDilemma3PGame()

training = GTTraining(
p_game_cls=PrisonersDilemma3PGame,
p_cycle_limit=cycle_limit,
p_path=path,
p_visualize=visualize,
p_logging=logging
)

training.run()

0 comments on commit 0ff58b8

Please sign in to comment.