-2

I want to get many items from FilterStore .

factory.stock_part.items

FilterStore is list type

[{'order_id': 534066215, 'id': 0}, {'order_id': 534066215, 'id': 1}, {'order_id': 534066215, 'id': 2}, {'order_id': 534066215, 'id': 3}, {'order_id': 534066215, 'id': 4}, {'order_id': 534066215, 'id': 5}, {'order_id': 534066215, 'id': 6}, {'order_id': 534066215, 'id': 7}, {'order_id': 534066215, 'id': 8}]

and I want to use: factory.stock_part.get()

to get five items

factory.stock_part.get(5)

is not work.

How do I resolve this? Here's the full code:

import simpy


class Factory():
    def __init__(self, env):
        self.stock_part = simpy.FilterStore(env, capacity = 100000)
        


def stock_out(env,factory):
    while True:
        yield env.timeout(10)

        #in here I hope the inventory reduce 3,but one of the following 3 lines is not work
        factory.stock_part.get(5)
        factory.stock_part.get()[0:3]
        factory.stock_part.get(factory.stock_part.items[0:3])
        
        
            
            
    
env = simpy.Environment()

factory = Factory(env)

#create inventory list
factory.stock_part.put({'id':1})
factory.stock_part.put({'id':2})
factory.stock_part.put({'id':3})
factory.stock_part.put({'id':4})
factory.stock_part.put({'id':5})


on_process = env.process(stock_out(env, factory))

print('start')
env.run(until = 300)
print('end')
Edric
  • 24,639
  • 13
  • 81
  • 91
Stjnu
  • 11
  • 2
  • What is the error message? If it is a simple list, you can use list slicing: `factory.stock_part[:5]` to get the first 5. What has FilterStore to do with the code you have shown? [mre]! – Patrick Artner Mar 10 '21 at 08:28
  • factory.stock_part.get(factory.stock_part[:2]) *** TypeError: 'FilterStore' object is not subscriptable – Stjnu Mar 10 '21 at 08:38
  • factory.stock_part.get(factory.stock_part.items[0:5]) *** TypeError: 'list' object is not callable – Stjnu Mar 10 '21 at 08:41
  • Please post a [mre] that we can run that mimics your datastructure so we can help.Curerntly this is a guessing game nobody benefits from. – Patrick Artner Mar 10 '21 at 08:42
  • Thanks for your response.But factory.stock_part.get(factory.stock_part[:2]) or factory.stock_part.get(factory.stock_part.items[0:5]) is not work. – Stjnu Mar 10 '21 at 08:42
  • I have posted a minimal code in answer list.Thanks – Stjnu Mar 10 '21 at 08:54

1 Answers1

0

Where is your eval function?

If you are using a filterStore, then don't need to pass in a function that will evaluate each resource and returns True when it finds a match?

something like

part = yield factory.stock_part.get(lambda part: part['id'] == 5)

filter stores only return one element at a time

Michael
  • 1,671
  • 2
  • 4
  • 8