I have a working microeconomic model running with 10 modules 2000 agents, for up to 10 years. The program was running fast, providing results, output and graphics in a matter of seconds.
However, when I implemented a non-linear Cobb-Douglas production function to update the quantity to be produced in the firms, the program slowed to produce results in 3 minutes, depending on the parameters.
Does anybody know how I could expedite the calculation and get back to fast results?
Here is the code of the function: ALPHA = 0.5
def update_product_quantity(self):
if len(self.employees) > 0 and self.total_balance > 0:
dummy_quantity = self.total_balance ** parameters.ALPHA * \
self.get_sum_qualification() ** (1 - parameters.ALPHA)
for key in self.inventory.keys():
while dummy_quantity > 0:
self.inventory[key].quantity += 1
dummy_quantity -= 1
The previous linear function that was working fast was:
def update_product_quantity(self):
if len(self.employees) > 0:
dummy_quantity = self.get_sum_qualification()
for key in self.inventory.keys():
while dummy_quantity > 0:
self.inventory[key].quantity += 1
dummy_quantity -= 1