ATTENTION

This FlexSim Community Forum is read-only. Please post any new questions, ideas, or discussions to our new community (we call it Answers) at https://answers.flexsim.com/. Our new Question & Answer site brings a modern, mobile-friendly interface and more focus on getting answers quickly. There are a few differences between how our new Q&A community works vs. a classic, threaded-conversation-style forum like the one below, so be sure to read our Answers Best Practices.


flexsim.com

Go Back   FlexSim Community Forum > FlexSim Software > Q&A
Downloads

Q&A Using Flexsim and building models

  #1  
Old 11-06-2008
Joe Allen Joe Allen is offline
Flexsim User
 
Join Date: Jul 2008
Posts: 80
Downloads: 2
Uploads: 0
Thanks: 34
Thanked 5 Times in 3 Posts
Rep Power: 151
Joe Allen is on a distinguished road
Default Flexsim Please Help - 99 Variable Limit

I just ran up against a serious limitation in flexscript that I was not aware of before. I just finished writing code after many days of work and dropped it into a user command and hit the compile button. I got the following error:
syntax error, unexpected $undefined, expecting;

After a little testing I came to realize that there is a limit of 99 variable declarations in flexscript. If this is a true limitation it will mean I have to come up with a generic variable name workaround to this problem. I don't look forward to spending many hours of non-value added work

Can anyone let me know if there is a way to overcome this limit other than going into my code and re-writing everything?

I found another forum post from a few months ago on this as well and posted there as well:
http://www.flexsim.com/community/for...read.php?t=511
  #2  
Old 11-06-2008
Phil BoBo's Avatar
Phil BoBo Phil BoBo is offline
Flexsim Development
 
Join Date: Jan 2008
Posts: 756
Downloads: 109
Uploads: 18
Thanks: 385
Thanked 1,483 Times in 525 Posts
Rep Power: 1174
Phil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond repute
Default

Yes. There is currently a limit on the number of variable declarations in Flexscript.

With some testing, I've found that it is still capped in the Flexsim 4.5 Beta (capped at 125 for some reason; not sure why), but it will be fixed before the final 4.5 release.

Personally, I'm confused why you would write many days of code without testing it. Also, I'm confused why you would need 100 local variables in one function anyways. But to each his own I guess.

You can use arrays. Each array in Flexsim 4.32 can have 10000 elements so technically, you can have 1,000,000 local variables currently. For some obviously this is not enough!! It will be increased in Flexsim 4.5 due to the comments on the forum.

Defining so many variables takes a lot of memory. If you max out the memory on your machine, Flexsim is going to start running really slowly. You've been warned.

Also, you can use #defines. I'm not sure exactly what you are trying to do, but I'm almost positive there is a better way to do it than what would throw you into this problem.

Last edited by Phil BoBo; 11-06-2008 at 05:53 PM. Reason: typo
  #3  
Old 11-06-2008
Joe Allen Joe Allen is offline
Flexsim User
 
Join Date: Jul 2008
Posts: 80
Downloads: 2
Uploads: 0
Thanks: 34
Thanked 5 Times in 3 Posts
Rep Power: 151
Joe Allen is on a distinguished road
Default

The reason I couldn't test until the end is kind of a long answer so I didn't include it in the original post. Essentially I wrote code in modular text files that simulates PLC logic. One text file for Main Line PLC logic that controls each conveyor motor on the production line and one text file for PLC logic that controls each Machine Center. The execution of the code blocks in the text files needs to happen in an order that is not easily represented. It is branch-like logic. I had to organize the execution of the code blocks in excel in matrices. I then wrote some VBA code making use of my own class objects and collections of objects to house the data for the execution (arrays wouldn't cut it since the logic was branch-like in nature). The code pulls in the flexscript from the text files as needed and assembles a main procedure around the skeleton of a Switch Statement which gets written into a string. When the string is complete, it gets written out to a final text file as a completed user defined command (in Flexscript) for Flexsim. During the time I spend translating PLC to Flexscript in the text files, I tested each code block in Flexsim of course without any problems. It wasn't until my VBA code assembled the main procedure for me was I able to copy and paste it into a user defined command in Flexsim that the moment of truth arrived. It's a little difficult to explain what I have done over a forum post. I could do it much better if you were sitting at my desk but alas that is not possible. Thanks for you interest. By the way, when does 4.5 come out?
  #4  
Old 11-06-2008
Joe Allen Joe Allen is offline
Flexsim User
 
Join Date: Jul 2008
Posts: 80
Downloads: 2
Uploads: 0
Thanks: 34
Thanked 5 Times in 3 Posts
Rep Power: 151
Joe Allen is on a distinguished road
Default

I forgot to mention. The reason that I need many variables is that each variable contains the name of a sensor on our production line. I followed the nomenclature that our Controls Engineers used when they set up the PLC logic on our lines because I want them to be able to read the code that I wrote and clearly understand what is going on. For example, one of their photo eyes is named MC_ML09_01A. In the PLC this photo eye could be blocked or gapped. They represent this in PLC with a variable like this: MC_ML09_01A_Blocked or MC_ML09_01A_Gap. I used variables very similar so they can clearly read my code. That way understand the code when they encounter:
if(iMC_ML09_01A_Blocked == 1)
Do Something
I'm modeling over 100 sensors and also need another 25 or so other variables for other thins in the code. Storing 150 or so integer values is really not going to impact memory, but having the variable names be distinctly related to actual sensors on our line brings a lot of value to my model, especially when an engineer can interpret and/or modify code outside of the model in a text file witout the need for a Flexsim license and I can then import the altered logic and run it.
  #5  
Old 11-06-2008
Phil BoBo's Avatar
Phil BoBo Phil BoBo is offline
Flexsim Development
 
Join Date: Jan 2008
Posts: 756
Downloads: 109
Uploads: 18
Thanks: 385
Thanked 1,483 Times in 525 Posts
Rep Power: 1174
Phil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond repute
Default

That's more understandable if you are trying to make your code look similar to PLC ladder logic for readability.


Perhaps this idea might help:

intarray joe = makearray(1000);

#define PLC_CODE_NAME_R75 joe[2]

PLC_CODE_NAME_R75 = 5;
pd(PLC_CODE_NAME_R75);pr();
PLC_CODE_NAME_R75 = 15;
pd(PLC_CODE_NAME_R75);pr();
The Following 3 Users Say Thank You to Phil BoBo For This Useful Post:
Joe Allen (11-07-2008)
  #6  
Old 11-06-2008
Phil BoBo's Avatar
Phil BoBo Phil BoBo is offline
Flexsim Development
 
Join Date: Jan 2008
Posts: 756
Downloads: 109
Uploads: 18
Thanks: 385
Thanked 1,483 Times in 525 Posts
Rep Power: 1174
Phil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond repute
Default

The 4.5 beta is already released. We have no set release date for the final release of 4.5 at this time. It will be released when all the documentation is up to date and all the changes and bug fixes are made based on the comments that we have/will receive.

By the way, after reading your short description of what you've done, it sounds intriguing. It would be nice to be sitting at your desk to see it. Creative.
The Following User Says Thank You to Phil BoBo For This Useful Post:
Joe Allen (11-06-2008)
  #7  
Old 11-07-2008
Brandon Peterson's Avatar
Brandon Peterson Brandon Peterson is offline
The Flexsim Consultant
 
Join Date: Jul 2007
Location: Salt Lake City, Utah
Posts: 382
Downloads: 29
Uploads: 6
Thanks: 192
Thanked 516 Times in 235 Posts
Rep Power: 490
Brandon Peterson has a brilliant futureBrandon Peterson has a brilliant futureBrandon Peterson has a brilliant futureBrandon Peterson has a brilliant futureBrandon Peterson has a brilliant futureBrandon Peterson has a brilliant futureBrandon Peterson has a brilliant futureBrandon Peterson has a brilliant futureBrandon Peterson has a brilliant futureBrandon Peterson has a brilliant futureBrandon Peterson has a brilliant future
Default

Phil,

Thanks for the post about the #define use. I find it more and more amazing everyday with the many different ways that #defines can be used, especially in C++. Do you know if there are any plans to allow for the use of #defines as functions like in C++? For Example:

#define DIST(a, b, c) \
c = sqrt(sqr(a) + sqr(b))

DIST(3, 4, myval);
__________________
thats not normal.
  #8  
Old 11-07-2008
Joe Allen Joe Allen is offline
Flexsim User
 
Join Date: Jul 2008
Posts: 80
Downloads: 2
Uploads: 0
Thanks: 34
Thanked 5 Times in 3 Posts
Rep Power: 151
Joe Allen is on a distinguished road
Default

I didn't know that I could use a #define as a local variable. I thought that I was confined to using these in the Global Macros section. Thanks a bunch Phil! This will expand on what I can do in my code a great deal. I find myself wishing that I had this knowledge before I wrote all that code but hey, I'll take it any way I can get it. A great learning experience.

Thanks again Phil.
  #9  
Old 11-07-2008
Phil BoBo's Avatar
Phil BoBo Phil BoBo is offline
Flexsim Development
 
Join Date: Jan 2008
Posts: 756
Downloads: 109
Uploads: 18
Thanks: 385
Thanked 1,483 Times in 525 Posts
Rep Power: 1174
Phil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond repute
Default

Brandon,

Anthony wants to implement function macros in the future, but there are no current set-in-stone plans to do it anytime soon.
  #10  
Old 11-07-2008
Joe Allen Joe Allen is offline
Flexsim User
 
Join Date: Jul 2008
Posts: 80
Downloads: 2
Uploads: 0
Thanks: 34
Thanked 5 Times in 3 Posts
Rep Power: 151
Joe Allen is on a distinguished road
Default

I took the suggestion that you made Phil and it only took about an hour to get back to where I left off. This saved me a lot of time

Going through a #define variable however has added some additional overhead. I tested 1,000,000 reads and 1,000,000 writes on an int variable and the same on the #define variable as described by Phil's post above to compare the performance difference. Surprisingly, using a #define and an array adds only 12% more processing time on average. I sampled each method about 20 times due to some noticeable variability in CPU performance on each run.
The Following 2 Users Say Thank You to Joe Allen For This Useful Post:
Phil BoBo (11-10-2008)
  #11  
Old 11-14-2008
Kris Geisberger Kris Geisberger is offline
Flexsim Canada, Forum Moderator
 
Join Date: Aug 2007
Location: Canada
Posts: 209
Downloads: 54
Uploads: 1
Thanks: 99
Thanked 389 Times in 133 Posts
Rep Power: 451
Kris Geisberger has much to be proud ofKris Geisberger has much to be proud ofKris Geisberger has much to be proud ofKris Geisberger has much to be proud ofKris Geisberger has much to be proud ofKris Geisberger has much to be proud ofKris Geisberger has much to be proud ofKris Geisberger has much to be proud ofKris Geisberger has much to be proud ofKris Geisberger has much to be proud of
Default define vs int

Joe,

The attached xls contains 3 speed tests, the first two show the speed improvement of a #define over an int in simple declare and read situations. Test3 involves the intarray + define concept from this thread to use defines as variables. Like you found, this concept is slower than int variables alone, but I got a 28% processing time increase, while you reported a 12% increase.

Any thoughts on what we did differently?
The xls contains the code I used.

Kris
Attached Files
File Type: zip Speed Testing - define vs int.zip (109.9 KB, 257 views)
  #12  
Old 11-19-2008
Joe Allen Joe Allen is offline
Flexsim User
 
Join Date: Jul 2008
Posts: 80
Downloads: 2
Uploads: 0
Thanks: 34
Thanked 5 Times in 3 Posts
Rep Power: 151
Joe Allen is on a distinguished road
Default

Kris - I noticed some very significant variability in speed between tests of the same method. Because of this I sampled (tested) each method 20 times and averaged the results. If you only tested once I could see getting a very different result than I did. If you tested multiple times for each method though and averaged your results, I'm not really sure where we would be reporting such a large difference.
  #13  
Old 11-19-2008
Joe Allen Joe Allen is offline
Flexsim User
 
Join Date: Jul 2008
Posts: 80
Downloads: 2
Uploads: 0
Thanks: 34
Thanked 5 Times in 3 Posts
Rep Power: 151
Joe Allen is on a distinguished road
Default

My apologies Kris. I should have opened the excel file you attached before posting a reply. I used essentially the same code that you did with a write followed immediately by a read inside of a for loop. I'll see if I can dig up the code that I used.
  #14  
Old 11-19-2008
Kris Geisberger Kris Geisberger is offline
Flexsim Canada, Forum Moderator
 
Join Date: Aug 2007
Location: Canada
Posts: 209
Downloads: 54
Uploads: 1
Thanks: 99
Thanked 389 Times in 133 Posts
Rep Power: 451
Kris Geisberger has much to be proud ofKris Geisberger has much to be proud ofKris Geisberger has much to be proud ofKris Geisberger has much to be proud ofKris Geisberger has much to be proud ofKris Geisberger has much to be proud ofKris Geisberger has much to be proud ofKris Geisberger has much to be proud ofKris Geisberger has much to be proud ofKris Geisberger has much to be proud of
Default

Cliff and I have found that closing all other applications and services helps reduce the variability of the trials. I usually unplug my network connection and closed any security services I have running.


Thread Thread Starter Forum Replies Last Post
Global variable as experiment variable Matthias Hofmann Q&A 3 09-08-2009 09:42 AM
Edit Value of Variable in Flexscript Node Joe Allen Q&A 19 09-17-2008 05:39 PM
Limit in the completion hints? Global Tables, Global Variables, etc.? Tom David Gripes and Goodies 6 09-09-2008 04:05 PM
Assign an array to a variable AlanZhang Q&A 6 04-24-2008 01:59 PM
Display Global Variable Sung Kim Q&A 4 02-24-2008 11:24 PM


All times are GMT -6.
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2020, vBulletin Solutions Inc.
Copyright 1993-2018 FlexSim Software Products, Inc.