Skip to content

Commit

Permalink
Clean code
Browse files Browse the repository at this point in the history
  • Loading branch information
alifa98 committed Jul 6, 2022
1 parent 7c7aba8 commit be5dd69
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
14 changes: 7 additions & 7 deletions gamekit/algorithms/bankruptcy.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from gamekit import NegativeNumberException


def constrained_equal_awards(claims: list, asset: float) -> list:
def constrained_equal_awards(claims: list, asset: float) -> tuple[list, float]:
"""
This function returns a list of allocations based onthe constrained equal allocation method.
If the asset is larger than the sum of claims, returns the claims list itself.
Expand All @@ -16,7 +16,7 @@ def constrained_equal_awards(claims: list, asset: float) -> list:
Parameters:
claims (list): list of claims (list of non-negative float numbers)
asset (float): total amount of our assets (non-negative)
Returns:
list: list of allocations
r: the r value in the $a_i = min(r, c_i) $ (if sum of claims become less than asset, then the r-value would be the asset itself.)
Expand All @@ -29,24 +29,24 @@ def constrained_equal_awards(claims: list, asset: float) -> list:
if asset < 0:
raise NegativeNumberException("Asset cannot be a negative number.")

if(sum(claims) <= asset):
if sum(claims) <= asset:
return claims, asset
else:

equal_alloc = asset/len(claims)

if all(c >= equal_alloc for c in claims):
return [equal_alloc for c in range(len(claims))], equal_alloc
return [equal_alloc for _ in range(len(claims))], equal_alloc

else:
r = min(claims)
allocations = [r for i in range(len(claims))]
allocations = [r for _ in range(len(claims))]

while(asset > sum(allocations)):
while asset > sum(allocations):

remained_claims = [c - r for c in claims]

# r_prime: the next best amount to to allocate to all
# r_prime: the next best amount to allocate to all
r_prime = min(c for c in remained_claims if c > 0)
positive_remained_claim_length = len(
list(filter(lambda x: (x > 0), remained_claims))
Expand Down
2 changes: 1 addition & 1 deletion gamekit/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

class NegativeNumberException(object):
class NegativeNumberException(Exception):

message = "Numbers should not be negative."

Expand Down

0 comments on commit be5dd69

Please sign in to comment.