Skip to content

Commit

Permalink
corrects a bug where vendors were setting negative prices
Browse files Browse the repository at this point in the history
  • Loading branch information
liamlaverty committed May 14, 2023
1 parent 5e56200 commit 01b4c0a
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions Macodiac.ML/multiagentenvironment.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ def __init__(self):
self.demand = 1
self.utility = 0
self.money = 0
self.total_consumed = 0

class MultiAgentMacodiacEnvironment(Env):
"""
Expand Down Expand Up @@ -76,9 +77,10 @@ def set_agent_action(self, action, agent, actionSpace):
# agent.state is the percentage price diff from the
# wholesale price
agent.state = action - 100
agentBaseVendingPrice = self.env_wholesale_price * (agent.state / 100)
agentMarginalCostAddedVendingPrice = agentBaseVendingPrice + self.env_agent_marginal_cost
agent.vendingPrice = agentMarginalCostAddedVendingPrice
agentBaseVendingPriceAdjust = self.env_wholesale_price * (agent.state / 100)
baseAgentVendingPrice = self.env_wholesale_price + agentBaseVendingPriceAdjust
#agentMarginalCostAddedVendingPrice = agentBaseVendingPriceAdjust + self.env_agent_marginal_cost
agent.vendingPrice = baseAgentVendingPrice
# print(f'agent vending price was {agent.vendingPrice}')

def step_agent(self, agent):
Expand Down Expand Up @@ -152,14 +154,15 @@ def set_consumer_purchases(self, agents_arr, consumer):
"""
lowestPriceAgnetIndex = 0

for i, agent in agents_arr:
if agent.vendingPrice < agents_arr[lowestPriceAgnetIndex]:
for i, agent in enumerate(agents_arr):
if agent.vendingPrice < agents_arr[lowestPriceAgnetIndex].vendingPrice:
lowestPriceAgnetIndex = i

while consumer.money > 0:
if lowestPriceAgnetIndex.vendingPrice < consumer.money:
if agents_arr[lowestPriceAgnetIndex].vendingPrice < consumer.money:
agents_arr[lowestPriceAgnetIndex].reward += agents_arr[lowestPriceAgnetIndex].vendingPrice
consumer.money -= agents_arr[lowestPriceAgnetIndex].vendingPrice
consumer.total_consumed += 1
else:
# set the consumer's money to 0 if the vend price
# is less than the remaining money (stops infinite loop)
Expand Down

0 comments on commit 01b4c0a

Please sign in to comment.