SimPy 모듈과 함께 Python2.7을 처음 사용하고 있습니다. 나는이 두 가지를 모두 배우기 때문에 이것을 정확하게 설명하기를 바랍니다. 내 프로그램의 목표 : 수요 개체를 생성하고 매주 숫자를 생성하십시오. 목록에 저장하십시오. Demand 개체에서 만든 번호를 기반으로 Supply 개체를 만들고 매주 한 번씩 번호를 생성합니다. 52 번호를 만들고 목록에 추가 할 수있는 것처럼 보이지만 Supply 개체를 통해 목록을 읽을 수는 없습니다. 다음과 같이 내 코드는 : 내 프로그램을 실행하면, 내 수요를 생성하고 콘솔에 주간 및 누적 값을 출력Python 2.7 : 목록 액세스 기능
from SimPy.Simulation import *
import pylab as pyl
from random import Random
import matplotlib.mlab as mlab
import matplotlib.pyplot as plt
# Model components
runLength = 51
## Lists for examination
D1Vals = []
S1Vals = []
.... other code lines
class Demander(Process):
# This object creates the demand, and stores the values in the 'D1Vals' list above
def weeklyDemand(self): # Demand Weekly
while True:
lead = 1.0 # time between demand requests
demand = random.triangular(20,110,370) # amount demanded each increment
#yield put, self, orderBook, delivery
print('Week'+'%6.0f: Need %6.0f units: Total Demand = %6.0f' %
(now(), demand, orderBook.amount))
yield hold, self, lead
yield put, self, orderBook, demand
D1Vals.append(demand)
# This object is trying to read each value iteratively in D1Vals,
and create a supply value and store in a list 'S1Vals'
class Supplier(Process):
def supply_rate(self):
lead = 1.0
for x in D1Vals:
supply = random.triangular(x - 30, x , x + 30)
yield put, self, stocked, supply
print('Week'+'%6.0f: Gave %6.0f units: Inv. Created = %6.0f' %
(now(), supply,stocked.amount))
yield hold, self, lead
S1Vals.append(stocked.amount)
..... other misc coding .....
# Model
demand_1 = Demander()
activate(demand_1, demand_1.weeklyDemand())
supply_1 = Supplier()
activate(supply_1, supply_1.supply_rate())
simulate(until=runLength)
나 비어 있지 있는지, 그것은 또한 D1Vals의 목록을 인쇄 .
누구든지 공급 업체 개체 및 기능에서 목록을 성공적으로 읽으려면 올바른 경로로 안내 할 수 있습니까? 감사합니다. 파이썬에 대한 내 명확한 '새로운'전망을 변명하십시오.)
supply_rate() 및 weeklyDemand() 메소드의 들여 쓰기가 엉망입니다. –