'; echo ' Shapley Value Calculator '; // This is the reference to our CSS style sheet.' echo ''; echo ''; echo '

Shapley Value Calculator

'; ## Pointer to this file $thisFile = "publicGoodsGame.php"; ## Power set of all players $numPlayers = 6; ## Initially, the number of players is 6. for($n = 1; $n <= $numPlayers; $n++){ $setOfPlayers[$n] = $n; } $powerSet = powerSet($setOfPlayers); $i = 0; foreach($powerSet as $set){ $powerSetAsStrings[$i] = setToString($set); $i++; } ## Check if the thing has been posted $getContributionPlayer = $_POST['ContributionPlayer']?? -1; $getMultiplier = $_POST['Multiplier'] ?? -1; if($getContributionPlayer == -1){ ## Get the contributions of each player to the common pot echo '
'; echo '
'; echo ''; $i = 0; for($i = 0; $i<$numPlayers; $i++){ echo '

'; echo ''; echo ''; echo '

'; } echo '


'; echo '

'; echo ''; echo ''; echo '

'; echo '
'; echo '
'; echo ''; echo '
'; }else{ echo '
'; echo '
'; echo ''; $i = 0; for($i = 0; $i<$numPlayers; $i++){ echo '

'; echo ''; echo ''; echo '

'; } echo '


'; echo '

'; echo ''; echo ''; echo '

'; echo '
'; echo '
'; echo ''; echo '
'; ## Now, the Shapley value in a public good game is simply going to be contribution*multiplier ## The classical reward is simply aggregate*multiplier/number of players. ## Let D = Shapley value - Classical reward ## Then it would be interesting to check what happens when the payout is ## P = Classical Reward + Alpha*D, ## Where alpha ranges from 0 to 1. ## I think that just comparing alpha = 0, alpha = 1/3, alpha = 2/3, (alpha = 1) would be interesting. $sumContributions = array_sum($getContributionPlayer); echo '

'; echo 'Sum of the contributions =  '.$sumContributions; echo '

'; echo '

'; echo 'Sum*Multiplier =  '.($sumContributions*$getMultiplier); echo '

'; echo '

'; $payout = ($sumContributions*$getMultiplier/$numPlayers); echo 'Payout = Sum*Multiplier/ Number of Players =  '.$payout; echo '

'; ## What is the difference between the payout and the Shapley value? echo '
'; echo '

'; echo "

For each player, what is the difference between the payout and the Shapley value?

"; for($i = 0; $i<$numPlayers; $i++){ echo '

'; echo 'Difference for Player #'.($i+1).'  = '.($getMultiplier*$getContributionPlayer[$i]-$payout); echo '

'; } echo '

'; echo '
'; } ## Footer echo '

Go back


'; echo ''; echo ''; ## Functions function powerSet($array){ $results = array(array()); foreach($array as $element){ foreach($results as $combination){ array_push($results, array_merge(array($element), $combination)); } } return $results; // https://docstore.mik.ua/orelly/webprog/pcook/ch04_25.htm } function setToString($set){ $size = sizeof($set); if($size == 0){ return "{}"; }else{ $return = "{"; for($i=0; $i<$size-1; $i++){ $return .= $set[$i].", "; } $return .= $set[$i]."}"; return $return; } } function factorial($n){ if($n == 0){ return 1; }else{ $f = 1; for($i=$n; $i>=1;$i--){ $f *= $i; } return $f; } } function choose($m, $n){ // Choose n objects among m choices return factorial($n) / (factorial($m)*factorial($n-$m)); }