I created a function with an if flow control, I am wondering a few things about it.
class Supplier(Process):
def weeklySupply(self):
global D1Vals
xMeet = D1Vals[0]
lead = 0
capac = 150.0
supply = 0
if stocked.amount >= 15000:
supply = 0
yield put, self, stocked, supply
S1Vals.append(0)
elif supply >= capac:
supply = capac
yield put, self, stocked, supply
S1Vals.append(capac)
else:
supply = random.triangular(.70 * xMeet , xMeet , xMeet * 1.05)
yield put, self, stocked, supply
print ('Week:'+'%6.0f:Supplied: %6.0f units. CurSupply = %6.0f' %
(now() + 1., supply, stocked.amount))
yield hold, self, lead
S1Vals.append(supply)
del D1Vals[0]
What I though I coded was:
-
If the amount in the stocked object was >= 15000, then the object generates zero supply
or if a supply value was generated which was greater than a predefined ‘capac’ amount, then the supply value = ‘capac’. -
If non of the above were true then the supply value was generated as a random distribution. When I get my output though, the supply value does exceed the ‘capac’ value of 150.
Have I misunderstood how to do the flow?
Do not mixup the
if elifconstruct with some kind oforas you did in your question. Theelifcondition will only be evaluated if theifcondition isFalse.I think, what you really want is:
But this would only work, if
supplyis not initialised with 0 at the beginning of the function.