class events: time = None #Event time type = None #Event Type info = None #Ancillary info #############################################Main Program########################## # i # loop parameter */ # j # index for the next event */ nevents = 0 # number of events during the simulation */ nsearches = 0 # number of event list searches */ tnow = START # simulation clock */ # temp # used to find time of next event */ ReceiveRate = 1.0 / 120.0 # time to transmit a character */ event = [events() for i in range(0,N)] plantSeeds(0) tnow = START for i in range(0,N): event[i].time = GetThinkTime() event[i].type = 1 event[i].info = 0 while (tnow < STOP): nevents+= 1 temp = 100.0 * STOP for i in range(0,N): nsearches+= 1 if (event[i].time <= temp): temp = event[i].time j = i
selectStream(2) p1 = (c-a)/(b-a) u = random() variate = 0 if (u < p1): variate = a + (c-a)*pow(random(),.5) else: variate = b - (b-c)*pow((1-random()),.5) return(variate) ######################################Main Program################################### plantSeeds(123456789) runs = 10000 a = 4 b = 8 c = 7 # generate 1000 with inverse */ invArray = [None for i in range(0,runs)] sum = 0 for i in range(0,runs): invArray[i] = intri(a,b,c) sum += invArray[i] invMean = sum/runs
service = 0.0 #service times interarrival = -1.0 #interarrival times ##############################Main Program################################ index = 0 # job (machine failure) index */ arrival = START # time of arrival (failure) */ delay = -1.0 # delay in repair queue */ service = -1.0 # service (repair) time */ wait = -1.0 # delay + service */ departure = START # time of service completion */ m = 0 # machine index 0,1,...(M-1) */ failure = [] # list of next failure times */ sum = sumOf() plantSeeds(123456789) for m in range(0,M): # initial failures */ failure.append(START + GetFailure()) m = [m] #convert to list to become mutable when passing to NextFailure while (index < LAST): index += 1 arrival = NextFailure(failure,m) if (arrival < departure): delay = departure - arrival else: delay = 0.0
class time: demand = 0 # next demand time */ arrive = 0 # next order arrival time init with no order */ current = 0 # current time */ review = 0 # next inventory review time */ next = 0 # next (most imminent) event time */ ############################Main Program########################## inventory = MAXIMUM # current inventory level */ order = 0 # current order level */ t = time() sum = sumOf() plantSeeds(0) t.current = START t.demand = GetDemand() #/* schedule the first demand */ t.review = t.current + 1.0 #/* schedule the first review */ t.arrive = INFINITY #/* no order arrival pending */ while (t.current < STOP): t.next = Min(t.demand, t.review, t.arrive) if (inventory > 0): sum.holding += (t.next - t.current) * inventory else: sum.shortage -= (t.next - t.current) * inventory t.current = t.next