如何从simpy中的生成器函数返回值

时间:2019-01-25 10:50:57

标签: python generator simpy

我正在尝试使用simpy创建一个项目,其中有一个Customer类和Bike类,我想使用object在Customer类中使用Bike类的变量。但是我也想在中使用yield env.timeout()生成器函数如何将Bike_info的值从Bike类转换为Customer类。 (该代码是我编写的900行代码的一部分)

import simpy
import pandas
class Customer():
    def __init__(self):
        self.bike_id = int()
        self.interval = int()
        self.bike_X = float()
        self.bike_Y =float()
    def simulate(self,env):
        self.bike = Bike()#created an object of Bike
        self.bike_id,self.interval,self.bike_X,self.bike_Y =   self.bike.bike_info


class Bike():

    def __init__(self):
        self.bike_id =int()
        self.bike_coordinates = tuple()
        self.minimum_duration =int()
        self.bike_info = tuple()
    def select_bike(self,env):
        '''Calculate the minimum duration between station and nearest bike this is obtained using the google distance matrix api'''                
        self.minimum_duration = 5 #say
        self.bike_coordinates =48.8584, 2.294 # say x is latitude and y is longitude       
        self.bike_id =98 #say
        yield env.timeout(int(self.minimum_duration))

        self.bike_info = (self.bike_id,self.minimum_duration,self.bike_coordinates)

if __name__ == "__main__":
    env = simpy.Environment()
    c = Customer()
    c.simulate(env)

我希望将bike_info的价值纳入客户类 但是我出错了 ValueError:需要超过0个值才能解包

0 个答案:

没有答案