-
Notifications
You must be signed in to change notification settings - Fork 5
/
Agent.py
executable file
·745 lines (604 loc) · 27.1 KB
/
Agent.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
# Agent.py
from Tools import *
from agTools import *
from random import *
import graphicDisplayGlobalVarAndFunctions as gvf
import commonVar as common
import numpy.random as npr
def mySort(ag):
if ag == []:
return []
numAg = []
for a in ag:
numAg.append((a.number, a))
numAg.sort()
agSorted = []
for i in range(len(numAg)):
agSorted.append(numAg[i][1])
return agSorted
class Agent(SuperAgent):
def __init__(self, number, myWorldState,
xPos=0, yPos=0, agType=""):
# print xPos,yPos
# the graph
if gvf.getGraph() == 0:
gvf.createGraph()
common.g.add_node(self)
# the environment
self.agOperatingSets = []
self.number = number
self.agType = agType
self.numOfWorkers = 0 # never use it directly to make calculations
self.profit = 0
self.plannedProduction = 0
self.consumption = 0
self.employed = False
self.extraCostsResidualDuration = 0
if agType == 'workers':
common.orderedListOfNodes.append(self)
# use to keep the order
# in output (ex. adjacency matrix)
# colors at http://www.w3schools.com/html/html_colornames.asp
gvf.colors[self] = "OrangeRed"
self.employed = False
self.workTroubles = 0
if agType == 'entrepreneurs':
common.orderedListOfNodes.append(self)
# use to keep the order
# in output (ex. adjacency matrix)
# colors at http://www.w3schools.com/html/html_colornames.asp
gvf.colors[self] = "LawnGreen"
self.employed = True
self.plannedProduction = -100 # not used in plots if -100
self.hasTroubles = 0
self.myWorldState = myWorldState
self.agType = agType
# the agents
if common.verbose:
print("agent of type", self.agType,
"#", self.number, "has been created at", xPos, ",", yPos)
gvf.pos[self] = (xPos, yPos)
if common.nodeNumbersInGraph:
common.g_labels[self] = str(number)
# to be used to clone (if any)
self.xPos = xPos
self.yPos = yPos
# talk
def talk(self):
print(self.agType, self.number)
# reset values, redefining the method of agTools.py in $$slapp$$
def setNewCycleValues(self):
# the if is to save time, given that the order is arriving to
# all the agents (in principle, to reset local variables)
if not common.agent1existing:
print("At least one of the agents has to have number==1")
print("Missing that agent, all the agents are resetting common values")
if self.number == 1 or not common.agent1existing:
common.totalProductionInA_TimeStep = 0
common.totalPlannedConsumptionInValueInA_TimeStep = 0
common.totalProfit = 0
common.totalPlannedProduction = 0
# troubles related variables
if self.agType == "entrepreneurs":
self.hasTroubles = 0
if self.agType == "workers":
self.workTroubles = 0
# hireIfProfit
def hireIfProfit(self):
# workers do not hire
if self.agType == "workers":
return
if self.profit <= common.hiringThreshold:
return
tmpList = []
for ag in self.agentList:
if ag != self:
if ag.agType == "workers" and not ag.employed:
tmpList.append(ag)
if len(tmpList) > 0:
hired = tmpList[randint(0, len(tmpList) - 1)]
hired.employed = True
gvf.colors[hired] = "Aqua"
gvf.createEdge(self, hired) # self, here, is the hiring firm
# count edges (workers) of the firm, after hiring (the values is
# recorded, but not used directly)
self.numOfWorkers = gvf.nx.degree(common.g, nbunch=self)
# nbunch : iterable container, optional (default=all nodes)
# A container of nodes. The container will be iterated through once.
print("entrepreneur", self.number, "has",
self.numOfWorkers, "edge/s after hiring")
def hireFireWithProduction(self):
# workers do not hire/fire
if self.agType == "workers":
return
# to decide to hire/fire we need to know the number of employees
# the value is calcutated on the fly, to be sure of accounting for
# modifications coming from outside
# (nbunch : iterable container, optional (default=all nodes)
# A container of nodes. The container will be iterated through once.)
laborForce0 = gvf.nx.degree(common.g, nbunch=self) + \
1 # +1 to account for the entrepreneur herself
# required labor force
laborForceRequired = int(
self.plannedProduction / common.laborProductivity)
#???????????????????
# countUnemployed=0
# for ag in self.agentList:
# if not ag.employed: countUnemployed+=1
# print "I'm entrepreneur %d laborForce %d and required %d unemployed are %d" %\
#(self.number, laborForce0, laborForceRequired, countUnemployed)
# no action
if laborForce0 == laborForceRequired:
return
# hire
if laborForce0 < laborForceRequired:
n = laborForceRequired - laborForce0
tmpList = []
for ag in self.agentList:
if ag != self:
if ag.agType == "workers" and not ag.employed:
tmpList.append(ag)
if len(tmpList) > 0:
k = min(n, len(tmpList))
shuffle(tmpList)
for i in range(k):
hired = tmpList[i]
hired.employed = True
gvf.colors[hired] = "Aqua"
gvf.createEdge(self, hired)
# self, here, is the hiring firm
# count edges (workers) of the firm, after hiring (the values is
# recorded, but not used directly)
self.numOfWorkers = gvf.nx.degree(common.g, nbunch=self)
# nbunch : iterable container, optional (default=all nodes)
# A container of nodes. The container will be iterated through
# once.
print(
"entrepreneur",
self.number,
"is applying prod. plan and has",
self.numOfWorkers,
"edge/s after hiring")
# fire
if laborForce0 > laborForceRequired:
n = laborForce0 - laborForceRequired
# the list of the employees of the firm
entrepreneurWorkers = gvf.nx.neighbors(common.g, self)
# print "entrepreneur", self.number, "could fire",
# entrepreneurWorkers
# the list returnes by nx is unstable as order
entrepreneurWorkers = mySort(entrepreneurWorkers)
if len(entrepreneurWorkers) > 0: # has to be, but ...
shuffle(entrepreneurWorkers)
for i in range(n):
fired = entrepreneurWorkers[i]
gvf.colors[fired] = "OrangeRed"
fired.employed = False
# common.g_edge_labels.pop((self,fired)) no labels in edges
common.g.remove_edge(self, fired)
# count edges (workers) after firing (recorded, but not used
# directly)
self.numOfWorkers = gvf.nx.degree(common.g, nbunch=self)
# nbunch : iterable container, optional (default=all nodes)
# A container of nodes. The container will be iterated through
# once.
print(
"entrepreneur",
self.number,
"is applying prod. plan and has",
self.numOfWorkers,
"edge/s after firing")
# fireIfProfit
def fireIfProfit(self):
# workers do not fire
if self.agType == "workers":
return
if self.profit >= common.firingThreshold:
return
# the list of the employees of the firm
entrepreneurWorkers = gvf.nx.neighbors(common.g, self)
# print "entrepreneur", self.number, "could fire", entrepreneurWorkers
# the list returnes by nx is unstable as order
entrepreneurWorkers = mySort(entrepreneurWorkers)
if len(entrepreneurWorkers) > 0:
fired = entrepreneurWorkers[randint(
0, len(entrepreneurWorkers) - 1)]
gvf.colors[fired] = "OrangeRed"
fired.employed = False
# common.g_edge_labels.pop((self,fired)) no label in edges
common.g.remove_edge(self, fired)
# count edges (workers) after firing (recorded, but not used
# directly)
self.numOfWorkers = gvf.nx.degree(common.g, nbunch=self)
# nbunch : iterable container, optional (default=all nodes)
# A container of nodes. The container will be iterated through
# once.
print("entrepreneur", self.number, "has",
self.numOfWorkers, "edge/s after firing")
# produce
def produce(self):
# this is an entrepreneur action
if self.agType == "workers":
return
# to produce we need to know the number of employees
# the value is calcutated on the fly, to be sure of accounting for
# modifications coming from outside
# (nbunch : iterable container, optional (default=all nodes)
# A container of nodes. The container will be iterated through once.)
laborForce = gvf.nx.degree(common.g, nbunch=self) + \
1 # +1 to account for the entrepreneur herself
print("I'm entrepreneur", self.number, "my laborforce is", laborForce)
# productivity is set to 1 in the benginning from common space
self.production = common.laborProductivity * \
laborForce
# totalProductionInA_TimeStep
common.totalProductionInA_TimeStep += self.production
# having a copy, that is update after each agent's action
common.totalProductionInPrevious_TimeStep = common.totalProductionInA_TimeStep
# produce
def produceV5(self):
# this is an entrepreneur action
if self.agType == "workers":
return
# to produce we need to know the number of employees
# the value is calcutated on the fly, to be sure of accounting for
# modifications coming from outside
# (nbunch : iterable container, optional (default=all nodes)
# A container of nodes. The container will be iterated through once.)
laborForce = gvf.nx.degree(common.g, nbunch=self) + \
1 # +1 to account for the entrepreneur herself
print("I'm entrepreneur", self.number, "my laborforce is", laborForce)
# productivity is set to 1 in the benginning from common space
self.production = common.laborProductivity * \
laborForce
# print "I'm entrepreneur",self.number,"production before correction is",\
# self.production
# correction for work troubles, if any
# self.hasTroubles is 0 if no troubles
self.production *= (1. - self.hasTroubles)
# print "I'm entrepreneur",self.number,"production after correction is",\
# self.production
# totalProductionInA_TimeStep
common.totalProductionInA_TimeStep += self.production
# having a copy, that is update after each agent's action
common.totalProductionInPrevious_TimeStep = common.totalProductionInA_TimeStep
# makeProductionPlan
def makeProductionPlan(self):
# this is an entrepreneur action
if self.agType == "workers":
return
if common.projectVersion >= "3" and common.cycle == 1:
nEntrepreneurs = 0
for ag in self.agentList:
if ag.agType == "entrepreneurs":
nEntrepreneurs += 1
# print nEntrepreneurs
nWorkersPlus_nEntrepreneurs = len(self.agentList)
# print nWorkersPlus_nEntrepreneurs
common.nu = (
common.rho * nWorkersPlus_nEntrepreneurs) / nEntrepreneurs
# print common.rho, common.nu
if (common.projectVersion >= "3" and common.cycle == 1) or \
common.projectVersion < "3":
self.plannedProduction = npr.poisson(
common.nu, 1)[0] # 1 is the number
# of element of the returned matrix (vector)
# print self.plannedProduction
common.totalPlannedProduction += self.plannedProduction
# print "entrepreneur", self.number, "plan", self.plannedProduction,\
# "total", common.totalPlannedProduction
# adaptProductionPlan
def adaptProductionPlan(self):
if common.cycle > 1:
nEntrepreneurs = 0
for ag in self.agentList:
if ag.agType == "entrepreneurs":
nEntrepreneurs += 1
# previous period price
#print ("++++++++++++++++++++++", common.ts_df.price.values[-1])
#print ("&&&&&&&&&&&&&&&&&&&&&&",len(common.ts_df.price.values))
if len(common.ts_df.price.values) == 1:
previuosPrice = common.ts_df.price.values[-1] # t=2
if len(common.ts_df.price.values) > 1:
previuosPrice = common.ts_df.price.values[-2] # t>2
# NB adapt acts from t>1
self.plannedProduction = (common.totalDemandInPrevious_TimeStep /
previuosPrice) \
/ nEntrepreneurs
#self.plannedProduction += gauss(0,self.plannedProduction/10)
shock = uniform(
-common.randomComponentOfPlannedProduction,
common.randomComponentOfPlannedProduction)
if shock >= 0:
self.plannedProduction *= (1. + shock)
if shock < 0:
shock *= -1.
self.plannedProduction /= (1. + shock)
# print self.number, self.plannedProduction
common.totalPlannedProduction += self.plannedProduction
# print "entrepreneur", self.number, "plan", self.plannedProduction,\
# "total", common.totalPlannedProduction
# calculateProfit V0
def evaluateProfitV0(self):
# this is an entrepreneur action
if self.agType == "workers":
return
# the number of producing workers is obtained indirectly via
# production/laborProductivity
# print self.production/common.laborProductivity
self.profit = (self.production / common.laborProductivity) * \
(common.revenuesOfSalesForEachWorker -
common.wage) + gauss(0, 0.05)
# calculateProfit
def evaluateProfit(self):
# this is an entrepreneur action
if self.agType == "workers":
return
# backward compatibily to version 1
try:
XC = common.newEntrantExtraCosts
except BaseException:
XC = 0
try:
k = self.extraCostsResidualDuration
except BaseException:
k = 0
if k == 0:
XC = 0
if k > 0:
self.extraCostsResidualDuration -= 1
# the number of pruducing workers is obtained indirectly via
# production/laborProductivity
# print self.production/common.laborProductivity
self.costs = common.wage * \
(self.production / common.laborProductivity) + XC
# the entrepreur sells her production, which is cotributing - via
# totalActualProductionInA_TimeStep, to price formation
self.profit = common.price * self.production - self.costs
common.totalProfit += self.profit
# calculateProfit
def evaluateProfitV5(self):
# this is an entrepreneur action
if self.agType == "workers":
return
# backward compatibily to version 1
try:
XC = common.newEntrantExtraCosts
except BaseException:
XC = 0
try:
k = self.extraCostsResidualDuration
except BaseException:
k = 0
if k == 0:
XC = 0
if k > 0:
self.extraCostsResidualDuration -= 1
# the number of pruducing workers is obtained indirectly via
# production/laborProductivity
# print self.production/common.laborProductivity
# how many workers, not via productvity due to possible troubles
# in production
laborForce = gvf.nx.degree(common.g, nbunch=self) + \
1 # +1 to account for the entrepreneur herself
# the followin if/else structure is for control reasons because if
# not common.wageCutForWorkTroubles we do not take in account
# self.workTroubles also if != 0; if = 0 is non relevant in any case
if common.wageCutForWorkTroubles:
self.costs = (common.wage - self.hasTroubles) \
* (laborForce - 1) \
+ common.wage * 1 + \
XC
# above, common.wage * 1 is for the entrepreur herself
else:
self.costs = common.wage * laborForce + \
XC
# print "I'm entrepreur", self.number, "costs are",self.costs
# penalty Value
pv = 0
if self.hasTroubles > 0:
pv = common.penaltyValue
# the entrepreur sells her production, which is cotributing - via
# totalActualProductionInA_TimeStep, to price formation
self.profit = common.price * (1. - pv) * self.production - self.costs
print("I'm entrepreur", self.number, "my price is ",
common.price * (1. - pv))
common.totalProfit += self.profit
# compensation
def planConsumptionInValue(self):
self.consumption = 0
#case (1)
# Y1=profit(t-1)+wage NB no negative consumption if profit(t-1) < 0
# this is an entrepreneur action
if self.agType == "entrepreneurs":
self.consumption = common.a1 + \
common.b1 * (self.profit + common.wage) + \
gauss(0, common.consumptionRandomComponentSD)
if self.consumption < 0:
self.consumption = 0
# profit, in V2, is at time -1 due to the sequence in schedule2.xls
#case (2)
# Y2=wage
if self.agType == "workers" and self.employed:
self.consumption = common.a2 + \
common.b2 * common.wage + \
gauss(0, common.consumptionRandomComponentSD)
#case (3)
# Y3=socialWelfareCompensation
if self.agType == "workers" and not self.employed:
self.consumption = common.a3 + \
common.b3 * common.socialWelfareCompensation + \
gauss(0, common.consumptionRandomComponentSD)
# update totalPlannedConsumptionInValueInA_TimeStep
common.totalPlannedConsumptionInValueInA_TimeStep += self.consumption
# print "C sum", common.totalPlannedConsumptionInValueInA_TimeStep
# compensation
def planConsumptionInValueV5(self):
self.consumption = 0
#case (1)
# Y1=profit(t-1)+wage NB no negative consumption if profit(t-1) < 0
# this is an entrepreneur action
if self.agType == "entrepreneurs":
self.consumption = common.a1 + \
common.b1 * (self.profit + common.wage) + \
gauss(0, common.consumptionRandomComponentSD)
if self.consumption < 0:
self.consumption = 0
# profit, in V2, is at time -1 due to the sequence in schedule2.xls
#case (2)
# Y2=wage
if self.agType == "workers" and self.employed:
# the followin if/else structure is for control reasons because if
# not common.wageCutForWorkTroubles we do not take in account
# self.workTroubles also if != 0; if = 0 is non relevant in any
# case
if common.wageCutForWorkTroubles:
self.consumption = common.a2 + \
common.b2 * common.wage * (1. - self.workTroubles) + \
gauss(0, common.consumptionRandomComponentSD)
# print "worker", self.number, "wage x",(1.-self.workTroubles)
else:
self.consumption = common.a2 + \
common.b2 * common.wage + \
gauss(0, common.consumptionRandomComponentSD)
#case (3)
# Y3=socialWelfareCompensation
if self.agType == "workers" and not self.employed:
self.consumption = common.a3 + \
common.b3 * common.socialWelfareCompensation + \
gauss(0, common.consumptionRandomComponentSD)
# update totalPlannedConsumptionInValueInA_TimeStep
common.totalPlannedConsumptionInValueInA_TimeStep += self.consumption
# print "C sum", common.totalPlannedConsumptionInValueInA_TimeStep
# to entrepreneur
def toEntrepreneur(self):
if self.agType != "workers" or not self.employed:
return
myEntrepreneur = gvf.nx.neighbors(common.g, self)[0]
myEntrepreneurProfit = myEntrepreneur.profit
if myEntrepreneurProfit >= common.thresholdToEntrepreneur:
print("I'm worker %2.0f and myEntrepreneurProfit is %4.2f" %
(self.number, myEntrepreneurProfit))
common.g.remove_edge(myEntrepreneur, self)
# originally, it was a worker
if self.xPos > 0:
gvf.pos[self] = (self.xPos - 15, self.yPos)
# originally, it was an entrepreneur
else:
gvf.pos[self] = (self.xPos, self.yPos)
# colors at http://www.w3schools.com/html/html_colornames.asp
gvf.colors[self] = "LawnGreen"
self.agType = "entrepreneurs"
self.employed = True
self.extraCostsResidualDuration = common.extraCostsDuration
# to entrepreneurV3
def toEntrepreneurV3(self):
if self.agType != "workers" or not self.employed:
return
# print float(common.absoluteBarrierToBecomeEntrepreneur)/ \
# len(self.agentList)
if random() <= float(common.absoluteBarrierToBecomeEntrepreneur) / \
len(self.agentList):
myEntrepreneur = gvf.nx.neighbors(common.g, self)[0]
myEntrepreneurProfit = myEntrepreneur.profit
myEntrepreneurCosts = myEntrepreneur.costs
if myEntrepreneurProfit / myEntrepreneurCosts >= \
common.thresholdToEntrepreneur:
print(
"Worker %2.0f is now an entrepreneur (previous firm relative profit %4.2f)" %
(self.number, myEntrepreneurProfit / myEntrepreneurCosts))
common.g.remove_edge(myEntrepreneur, self)
# originally, it was a worker
if self.xPos > 0:
gvf.pos[self] = (self.xPos - 15, self.yPos)
# originally, it was an entrepreneur
else:
gvf.pos[self] = (self.xPos, self.yPos)
# colors at http://www.w3schools.com/html/html_colornames.asp
gvf.colors[self] = "LawnGreen"
self.agType = "entrepreneurs"
self.employed = True
self.extraCostsResidualDuration = common.extraCostsDuration
# to workers
def toWorker(self):
if self.agType != "entrepreneurs":
return
if self.profit <= common.thresholdToWorker:
print("I'm entrepreneur %2.0f and my profit is %4.2f" %
(self.number, self.profit))
# the list of the employees of the firm, IF ANY
entrepreneurWorkers = gvf.nx.neighbors(common.g, self)
print("entrepreneur", self.number, "has", len(entrepreneurWorkers),
"workers to be fired")
if len(entrepreneurWorkers) > 0:
for aWorker in entrepreneurWorkers:
gvf.colors[aWorker] = "OrangeRed"
aWorker.employed = False
common.g.remove_edge(self, aWorker)
self.numOfWorkers = 0
# originally, it was an entrepreneur
if self.xPos < 0:
gvf.pos[self] = (self.xPos + 15, self.yPos)
# originally, it was a worker
else:
gvf.pos[self] = (self.xPos, self.yPos)
# colors at http://www.w3schools.com/html/html_colornames.asp
gvf.colors[self] = "OrangeRed"
self.agType = "workers"
self.employed = False
# to workersV3
def toWorkerV3(self):
if self.agType != "entrepreneurs":
return
# check for newborn firms
try:
self.costs
except BaseException:
return
if self.profit / self.costs <= common.thresholdToWorker:
print("I'm entrepreneur %2.0f and my relative profit is %4.2f" %
(self.number, self.profit / self.costs))
# the list of the employees of the firm, IF ANY
entrepreneurWorkers = gvf.nx.neighbors(common.g, self)
print("entrepreneur", self.number, "has", len(entrepreneurWorkers),
"workers to be fired")
if len(entrepreneurWorkers) > 0:
for aWorker in entrepreneurWorkers:
gvf.colors[aWorker] = "OrangeRed"
aWorker.employed = False
common.g.remove_edge(self, aWorker)
self.numOfWorkers = 0
# originally, it was an entrepreneur
if self.xPos < 0:
gvf.pos[self] = (self.xPos + 15, self.yPos)
# originally, it was a worker
else:
gvf.pos[self] = (self.xPos, self.yPos)
# colors at http://www.w3schools.com/html/html_colornames.asp
gvf.colors[self] = "OrangeRed"
self.agType = "workers"
self.employed = False
# work troubles
def workTroubles(self):
# NB this method acts with the probability set in the schedule.txt
# file
if self.agType != "entrepreneurs":
return
# production shock due to work troubles
psiShock = uniform(common.productionCorrectionPsi / 2,
common.productionCorrectionPsi)
self.hasTroubles = psiShock
print("Entrepreneur", self.number, "is suffering a reduction of "
"production of", psiShock * 100, "%, due to work troubles")
if common.wageCutForWorkTroubles:
# the list of the employees of the firm
entrepreneurWorkers = gvf.nx.neighbors(common.g, self)
for aWorker in entrepreneurWorkers:
# avoiding the entrepreneur herself, as we are refering to her
# network of workers
aWorker.workTroubles = psiShock
# print "Worker ", aWorker.number, "is suffering a reduction of "\
# "wage of", psiShock*100, "%, due to work troubles"
# get graph
def getGraph(self):
return common.g