forked from evoplex/model-prisonersDilemma
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Marcos Cardinot
committed
Mar 20, 2023
1 parent
b0e3563
commit 43b1833
Showing
5 changed files
with
29 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
MIT License | ||
|
||
Copyright (c) 2018 - Marcos Cardinot <[email protected]> | ||
Copyright (c) 2023 - Marcos Cardinot <[email protected]> | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
|
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,19 @@ | ||
{ | ||
"type": "model", | ||
"uid": "prisonersDilemma", | ||
"uid": "prisonersDilemmaExtended", | ||
"version": 1, | ||
"title": "Prisoner's Dilemma Game", | ||
"title": "Extended Prisoner's Dilemma Game", | ||
"author": "Marcos Cardinot", | ||
"description": "It implements the experiment proposed by Nowak, M. A., & May, R. M. (1992). Evolutionary games and spatial chaos. Nature, 359(6398), 826. DOI: http://dx.doi.org/10.1038/359826a0", | ||
"description": "It implements a generalized version of the experiment proposed by Nowak, M. A., & May, R. M. (1992). Evolutionary games and spatial chaos. Nature, 359(6398), 826. DOI: http://dx.doi.org/10.1038/359826a0", | ||
"supportedGraphs": ["squareGrid","edgesFromFile"], | ||
"pluginAttributesScope": [ | ||
{"temptation": "double[1,2]"} | ||
{"cc": "double[-1000,1000]"}, | ||
{"cd": "double[-1000,1000]"}, | ||
{"dc": "double[-1000,1000]"}, | ||
{"dd": "double[-1000,1000]"} | ||
], | ||
"nodeAttributesScope": [ | ||
{"strategy": "int{0,1,2,3}"}, | ||
{"score": "double[0,16]"} | ||
{"score": "double[-100000,100000]"} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/** | ||
* Copyright (c) 2018 - Marcos Cardinot <[email protected]> | ||
* Copyright (c) 2023 - Marcos Cardinot <[email protected]> | ||
* | ||
* This source code is licensed under the MIT license found in | ||
* the LICENSE file in the root directory of this source tree. | ||
|
@@ -11,8 +11,16 @@ namespace evoplex { | |
|
||
bool PDGame::init() | ||
{ | ||
m_temptation = attr("temptation", -1.0).toDouble(); | ||
return m_temptation >=1.0 && m_temptation <= 2.0; | ||
const auto read = [this](auto& var, const auto& strategy) | ||
{ | ||
var = attr(strategy, -999999.).toDouble(); | ||
if (var < -1000. || var > 1000.) { | ||
qDebug() << "Invalid payoff! " << strategy << var; | ||
return false; | ||
} | ||
return true; | ||
}; | ||
return read(m_cc, "cc") && read(m_cd, "cd") && read(m_dc, "dc") && read(m_dd, "dd"); | ||
} | ||
|
||
bool PDGame::algorithmStep() | ||
|
@@ -62,10 +70,10 @@ bool PDGame::algorithmStep() | |
double PDGame::playGame(const int sX, const int sY) const | ||
{ | ||
switch (binarize(sX) * 2 + binarize(sY)) { | ||
case 0: return 1.0; // CC : Reward for mutual cooperation | ||
case 1: return 0.0; // CD : Sucker's payoff | ||
case 2: return m_temptation; // DC : Temptation to defect | ||
case 3: return 0.0; // DD : Punishment for mutual defection | ||
case 0: return m_cc; // CC : Reward for mutual cooperation | ||
case 1: return m_cd; // CD : Sucker's payoff | ||
case 2: return m_dc; // DC : Temptation to defect | ||
case 3: return m_dd; // DD : Punishment for mutual defection | ||
default: qFatal("Error! strategy should be 0 or 1!"); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/** | ||
* Copyright (c) 2018 - Marcos Cardinot <[email protected]> | ||
* Copyright (c) 2023 - Marcos Cardinot <[email protected]> | ||
* | ||
* This source code is licensed under the MIT license found in | ||
* the LICENSE file in the root directory of this source tree. | ||
|
@@ -20,7 +20,10 @@ class PDGame: public AbstractModel | |
private: | ||
enum NodeAttr { STRATEGY, SCORE }; | ||
|
||
double m_temptation; | ||
double m_cc; | ||
double m_cd; | ||
double m_dc; | ||
double m_dd; | ||
|
||
double playGame(const int sX, const int sY) const; | ||
int binarize(const int strategy) const; | ||
|