Normal Topic For i loop question (Read 995 times)
JimChet
Member
*
Offline


No personal text

Posts: 9
Location: Northern California
Joined: Mar 13th, 2006
For i loop question
May 4th, 2011 at 7:07am
Print Post Print Post  
I have an application consisting of 5 number LE's named Cut1, Cut2, Cut3, Cut4, Cut5, and 5 number LE's named Tag1, Tag2, Tag3, Tag4, and Tag5.
I want my application to scramble the five numbers in the Cut fields and place them in theTag fields.
I've been trying to use [For i = 1 to 5] programing along with Cut(i)= Tag(i) in order to move the contents of the Cut Fields into the Tag Fields.  However, the above programing will not work.
What am I doing wrong?  Thanks for any advice
  
Back to top
 
IP Logged
 
Acebanner
Full Member
***
Offline



Posts: 123
Location: New York City
Joined: Jan 23rd, 2008
Re: For i loop question
Reply #1 - May 4th, 2011 at 12:18pm
Print Post Print Post  
You might want to look into the @Field() command.
  
Back to top
IP Logged
 
The Cow
YaBB Administrator
*****
Offline



Posts: 2530
Joined: Nov 22nd, 2002
Re: For i loop question
Reply #2 - May 4th, 2011 at 12:59pm
Print Post Print Post  
I agree with the above. The @Field command will do what you want. But, in this case, since you only have 5 elements, for speed's sake you should probably just set each field without using a loop at all:

Code
Select All
Cut1 = Tag1
Cut2 = Tag2
Cut3 = Tag3
Cut4 = Tag4
Cut5 = Tag5
 



Using a loop and @field would be recommended if you had many more elements to set.

BTW: Just wondering - are some of these elements being used where variables might be a better fit? Remember, variables are hundreds of times faster than elements. Always use a variable over an element, if you can.
  

Mark Lasersohn&&Programmer&&Lantica Software, LLC
Back to top
IP Logged
 
JimChet
Member
*
Offline


No personal text

Posts: 9
Location: Northern California
Joined: Mar 13th, 2006
Re: For i loop question
Reply #3 - May 5th, 2011 at 12:38am
Print Post Print Post  
I'll try the @field() suggestion.  Does anyone know of an Inside Sesame Article I can purchase that explains the concept of @field() indirect reference to a field, in more depth than the Sesame Programming Guide?
Perhaps using variables is a beter idea.
My goal is to be able to input up to 25 numbers in the Cut Column Fields, transfer those numbers into the Tag Column Fields, then scramble the Tag Fields several hundred times, each time adding the Tag Fields up as I go, in an attempt to come out with a portion of the numbers closest to the number I desire.
This would be used to assign Cuts to a certain roll size.  
Should I have a 100 ft long roll of fabric and I have 20 cuts of various sizes, the sum of which is greater than 100 ft, I would want to know which Cuts to assign to the 100 ft roll that would have the least waste/excess.
My idea is to add up the Tag Fields until I hit < 100 ft, scramble the column and add them up again and again until I get the best combination of cuts to assign to the 100 ft roll.  Hope this make sense?
  
Back to top
 
IP Logged
 
Rick_R
Full Member
***
Offline



Posts: 243
Joined: Jan 29th, 2010
Re: For i loop question
Reply #4 - May 5th, 2011 at 2:22am
Print Post Print Post  
Two suggestions, one with Sesame, one more general.

First, it sounds like matrix algebra might work best.  I had a course on that about 40 years ago, so I don't remember the details.  It is used for maximum/minimum problems, e.g., if we have 10 different things, how many of each should we use to get the smallest or largest result?  Basically it solves several linear equations at once, e.g.:

2x + 4y + 2z = 0
5x + 7y + 6z = 0
7x + 10y + 3z = 0


Second:

Do your widths fall into certain groups or are they completely random?  For instance, will you routinely have cuts in the 45-55 foot range?  A lot in the 2-4 foot range?

If you have a lot of small sections, probably the best way would be to sort the numbers from low to high and then keep adding until you exceed your limit.  Then subtract the smallest number until you are within your limit.  Starting with the smallest numbers will allow you the best granularity.

An alternative would be to go from largest down and as soon as you exceed your limit subtract the last one and then start with the smallest.  Unless your sections routinely are completely random, you should quickly find that either the low-to-hi or hi-down-then-low-up method routinely produces the best result.
  
Back to top
 
IP Logged
 
Acebanner
Full Member
***
Offline



Posts: 123
Location: New York City
Joined: Jan 23rd, 2008
Re: For i loop question
Reply #5 - May 5th, 2011 at 5:41pm
Print Post Print Post  
I've tried to do something along these lines, in order to find the best way to 'nest' several rectangular shapes into an arrangement that minimizes waste. I gave up, LOL! But Rick's suggestion about matrix algebra sounds like a good place to start over.

I was originally interested in the idea of nesting because I had written a form to be used for generating estimates for my sales reps. My goal had been to calculate what the waste material would be on any given job. I just found a research paper on nesting algorithms that might be relevant:

http://www.google.com/url?sa=t&source=web&cd=12&ved=0CBsQFjABOAo&url=http%3A%2F%...

The algorithm in question is recursive (calls itself) -- is that possible in Sesame?
  
Back to top
IP Logged