question

shaon S avatar image
0 Likes"
shaon S asked Kavika F commented

Some functions cannot return normal values when Python is called

Hello, as you can see in this video, when I call Python, some functions do not return values properly. Would you please help me see what the problem is, and I would appreciate it.

Relevant attachments have been uploaded(PythonFunction)

FlexSim 22.2.1
pythonusercommand
pythonfunction.mp4 (9.4 MiB)
· 1
5 |100000

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

shaon S avatar image shaon S commented ·

I'm trying to write an Astar algorithm myself, but I found that the model was slow when there was a lot of kiva and the map was large. So I want to see if calling Python scripts could evaluate paths faster and thus speed up the model. Could you give me some suggestions? Thanks again!

0 Likes 0 ·

1 Answer

Kavika F avatar image
0 Likes"
Kavika F answered Kavika F commented

Hey @shaon S, I think I found the problem. When using "range" in a for loop, the value passed in must be an int. num1 is a double, and so when trying to calculate range, it was working incorrectly. I tried casting num1 to an int in the range function and my FlexSim function works fine now.

1663619064350.png

1663619097054.png

(I was messing around with some values for testing, so I'm appending a random value and then the value num1 that many times. It should work fine with our code)


1663619064350.png (2.6 KiB)
1663619097054.png (11.1 KiB)
· 2
5 |100000

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

shaon S avatar image shaon S commented ·

Thank you for your help. I have another question.When Flexsim needs to call Python frequently, can Python enable multithreading for processing and return values?Thanks again.

0 Likes 0 ·
Kavika F avatar image Kavika F ♦ shaon S commented ·
As long as FlexSim accessors/returners are only being used on the main thread and the multithreaded Python code all waits to return a value on the main thread, then you can do whatever you want with multithreading.

On another note, I don't think that a custom Python AStar algorithm that FlexSim calls repeatedly will be any faster on a large model with many Kivas, especially since the original AStar algorithm is built in C++. I suggest finding other ways to minimize resource allocation in the model. For example, if you have racks with many flowitems, you can turn on virtualization.

0 Likes 0 ·