Skip to content

Commit

Permalink
Bugfixes and file rename
Browse files Browse the repository at this point in the history
  • Loading branch information
foarsitter committed Feb 20, 2017
1 parent e4aeede commit 75b4dfb
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
2 changes: 1 addition & 1 deletion model-gui.py → decide-gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ def run(self):
Externalities(event_handler, model, data_set_name)
ExchangesWriter(event_handler, model, data_set_name)
HistoryWriter(event_handler, model, data_set_name)
InitialExchanges(event_handler)
InitialExchanges(event_handler, model, data_set_name)
event_handler.notify(Observable.LOG, message="Parsed file {0}".format(self.input_file.get()))

model_loop = ModelLoop(model, event_handler)
Expand Down
5 changes: 4 additions & 1 deletion model/calculations.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ def calc_nbs(actor_issues, denominator):

def nbs_variance(actor_issues, nbs):

return sum([(ai.position - nbs)**2 for ai in actor_issues])
t = (1 / len(actor_issues))
t2 = sum([(ai.position - nbs) ** 2 for ai in actor_issues])

return t * t2


def calc_nbs_denominator(actor_issues):
Expand Down
22 changes: 14 additions & 8 deletions model/equalgain.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ def __init__(self, model, actor_name, demand, supply, group):


class EqualGainExchange(AbstractExchange):

def calculate(self):
# TODO REWRITE
# smaller functions
Expand Down Expand Up @@ -74,6 +75,8 @@ class EqualGainModel(AbstractModel):
Equal Gain implementation
"""

ALLOW_RANDOM = True # there can be a random component added tot the model but this gives not equal outcomes for testing purpose

def sort_exchanges(self):
"""
Overrides Abstract
Expand All @@ -90,14 +93,17 @@ def highest_gain(self):
realize = self.Exchanges.pop(0)

if len(self.Exchanges) > 0:
next_exchange = self.Exchanges.pop(0)

if abs(realize.gain - next_exchange.gain) < 1e-10:
if random() >= 0.5:
self.Exchanges.append(realize)
realize = next_exchange
else:
self.Exchanges.append(next_exchange)

if EqualGainModel.ALLOW_RANDOM:

next_exchange = self.Exchanges[0]

if abs(realize.gain - next_exchange.gain) < 1e-10:
if random() >= 0.5:
self.Exchanges.append(realize)
realize = self.Exchanges.pop(0)
else:
self.Exchanges.append(next_exchange)

return realize

Expand Down

0 comments on commit 75b4dfb

Please sign in to comment.