ECSI

Logic required for product weight selections

7 posts in this topic

So let's say I have 10 containers with random weights of product in them, 1.1 lbs, 1.4 lbs, 1.6 lbs, 1.2 lbs, 2.1 lbs, 1.0 lbs, ....etc.

How would I begin to write the logic for selecting the proper containers that their total weight would add up to a target weight of 5 lbs and dump their product into a bag.  Ideally I need to be just over the target weight, but cannot be under.  There are so many combinations....where does one start with the programming logic? :shrug:  Surely I wouldn't have to do a math equation for every combination of containers...would I?

In the end this process will be repeating every 2-3 seconds, so possibly I will have to lock out selecting the containers that just dumped until they refill again.  The next selection would ignore these containers that just dumped.

I'm just looking for ideas here.  I'd like to use an Omron PLC for this project.  There are machines out there that do this now.  I'm just trying to get my head around the logic in these machines.

Thanks

Share this post


Link to post
Share on other sites

Interesting project.

I don't know how I would do this, but maybe I would start  with ST in a Function Block. 

Share this post


Link to post
Share on other sites

Not a fully fleshed out thought, but have you thought about Find Maximum(MAX) and Find Minimum(MIN).

Look at your table and Find Minimum.  Reset your table to exclude the smallest weight and Find Minimum again.  Add the two weights together and check for target weight and keep finding minimum until you hit your target.  Probably some hiccups in this process, but food for thought.

Share this post


Link to post
Share on other sites

i would sort it first (only 10 elements so even bubble sort of insertion sort will be fine).

then using loop add the biggest weights until you exceed the total (so you are still safe). 

after that do the optimization part with goal to minimize oversize... consider swapping the last added one with one of remaining weights as long as you are still safe (small list, so even linear search will be fine).

dump the selected ones and start all over...

if needed you may consider second pass optimization...

 

Share this post


Link to post
Share on other sites
5 hours ago, panic mode said:

i would sort it first (only 10 elements so even bubble sort of insertion sort will be fine).

then using loop add the biggest weights until you exceed the total (so you are still safe). 

after that do the optimization part with goal to minimize oversize... consider swapping the last added one with one of remaining weights as long as you are still safe (small list, so even linear search will be fine).

dump the selected ones and start all over...

if needed you may consider second pass optimization...

 

What do you mean by bubble or insertion sort?

12 hours ago, Jay Anthony said:

Not a fully fleshed out thought, but have you thought about Find Maximum(MAX) and Find Minimum(MIN).

Look at your table and Find Minimum.  Reset your table to exclude the smallest weight and Find Minimum again.  Add the two weights together and check for target weight and keep finding minimum until you hit your target.  Probably some hiccups in this process, but food for thought.

MAX and MIN were the first instructions that I considered but the more I think about it the more I think it's not the best way.  If there are ten containers then the 3 or 4 or whatever number that gives me the closest to target (and just over), may not include the ones with minimum or maximum weights.  Also, if I keep using MIN to reach my target then the container(s) with maximum weight may never empty.  This would be a problem over time.

Hmmmm....Maybe a combination of 1. Select a random container or maybe two of them to start.  2. Find MAX and add it in.  3. Find MIN and add it in.  4. Fine tune add MIN until close to target.  4. When close to target find which container remaining will put me just over target....

A lot to think about for sure.  The reason I am looking at this is there is a vegetable grower with a machine that hasn't worked properly from day one.  The company that he bought it from built two of them, both different, and then went bankrupt.  He's getting no support and needs help.  His program is written in C++ on an industrial PC with remote IO (modbus I believe).  I don't believe I can get access to the programming, not that I know anything about C++ anyway.  If I can come up with a plan for PLC control then he may be interested.

Thanks for the input!

Share this post


Link to post
Share on other sites

It seems to be a know problem (subset-sum problem), if you search on the Internet you will most likely find a few applicable solutions. Depending on the computational resources you can either try to find the best solution using all the individual weights as inputs, or sort them first and then utilize just a subset of these.

I wrote a control program for a multi-head weigher (16 heads) a few years ago, I will have a look and see if I can find it.

Edited by Eradicated

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now