question

Che-Wei Chou avatar image
0 Likes"
Che-Wei Chou asked Che-Wei Chou commented

Connecting to External Code

Hi,

I've tried to practice this example to connect external python code by the following line:

https://answers.flexsim.com/questions/110833/future-python-and-flexsim-integration.html

However, it seemed to have a bug here.

Could you help to clarify it?

Thanks

Wade


1679783649795.png

TestFlexsimPy.py

Pull_from_Queue.fsm

FlexSim 22.2.0
connect to external code
1679783649795.png (290.9 KiB)
pull-from-queue.fsm (30.1 KiB)
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

1 Answer

·
Felix Möhlmann avatar image
0 Likes"
Felix Möhlmann answered Che-Wei Chou commented

You defined the code to call python in a user command but in the Pull Strategy code you call a label "CallPython" that does not exist on the processor instead. Either actually use the user command or move the code to call python to the label.

Your python code won't work because:

- you don't pass the jobs array to python when you call "evaluate()".

- options is not defined anywhere in the python code

- you didn't add fields that contain the queue name and item rank to the list, so the entries of the jobs array only contain four elements, not six like the python code assumes in the return value

Also be aware that the Pull Strategy code will not refire automatically. It executes on reset (which will not return a valid item since the queues are all still empty) and when an item leaves the processor. To "kickstart" the processor you will have to execute the code manully when items become available (by evaluating the node the code is defined on in the variables attributes of the processor.

1679903992333.png


1679903992333.png (13.4 KiB)
· 3
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Che-Wei Chou avatar image Che-Wei Chou commented ·

Hi Felix,

Thanks for your comments. However, I still have some questions that I can't understand that address below:

1. How do I call python (CallPython) to the label?

2. Is "you don't pass the jobs array to python when you call "evaluate()"." sloved by call python code?

3. I can't understand what's meaning of "options is not defined anywhere in the python code"

4. I try to define "queuename" and "itemrank" in the list, however, I don't this definition, could you help provide the definition?

5. How to set this, "To "kickstart" the processor you will have to execute the code manully when items become available" ?

Thanks for your patiention.

Wade

0 Likes 0 ·
Felix Möhlmann avatar image Felix Möhlmann Che-Wei Chou commented ·

1. You add a FlexScript type label and add the same expression to it as in the user command.

2. You pass in the jobs array as a parameter into the evaluate command (...evaluate(jobs))

3. In the python code you wrote "random.choice(options)" without options being declared in the code prior to that.

4. queuename: "value.up.name" (value -> item, value.up -> queue)
rank: "value.rank"

5. Get a reference to the node and call evaluate on it to execute the Pull Strategy again.

pull-from-queue_fm.fsm

testflexsimpy.py

0 Likes 0 ·
Che-Wei Chou avatar image Che-Wei Chou Felix Möhlmann commented ·
Hi Felix,

Thanks for your great support always.

Wade

0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.