Skip to content

Instantly share code, notes, and snippets.

@DavoudTaghawiNejad
Created May 30, 2018 15:47
Show Gist options
  • Save DavoudTaghawiNejad/158b690c15ee4ef69f320aeb5c31a9d2 to your computer and use it in GitHub Desktop.
Save DavoudTaghawiNejad/158b690c15ee4ef69f320aeb5c31a9d2 to your computer and use it in GitHub Desktop.
import abce
class Endowment(abce.Agent):
def init(self, rounds):
self.last_round = rounds - 1
self.labor_endowment = 0
def Iconsume(self):
self.labor_endowment = self.time
assert self['labor'] == 5 * self.time, self['labor']
def all_tests_completed(self):
if self.round == self.last_round and self.id == 0:
print('Test declare_round_endowment:\t\t\tOK')
print('Test s.declare_perishable:\t\t\tOK')
def main(processes, rounds):
s = abce.Simulation(processes=processes, name='unittest')
endowment = s.build_agents(Endowment, 'endowment', 2, rounds=rounds)
for r in range(rounds):
s.time = r
endowment.refresh_services('labor', derived_from='labor_endowment', units=5)
endowment.Iconsume()
endowment.all_tests_completed()
s.finalize()
if __name__ == '__main__':
main(processes=1, rounds=5)
print('Iteration with 1 core finished')
main(processes=4, rounds=5)
print('Iteration with multiple processes finished')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment