-1

I need help to create an algorithm to control a machine which will do something very similar of what a multi-head weigher does. I will have a array of 192 available "heads" to make combinations.

I don't need to find all availabe combinations. The machine will take some time to process the combinations so if I find, let's say, 30 combinations every time it will be enought.

I want to optimize it and use first the combinations thar need to use 1 head only, then the combinations of 2 heads only and then 3 heads and so on so the machine output will be higher as possible.

This will be implemented on a PLC so I don't have "unlimited" resourses like a PC. Recursion for example is a problem.

I will be using codesys to program

I'd like to see a suggestion on how to implement this

For example the machine need to outup 3KG to 3.2KG loads. And I have up to 192 weights ranging from 0.5 to 4KG (yes, it can have overloads). I need to find the 30 best combos every time.

EX

Combo 1 = HEAD1 = 3.1Kg Combo 2 = HEAD5 (1.5) + Head8 (1.6) = 3.1Kg

1 Answers1

2

The problem you are describing sounds similar to the Knapsack problem with some modifications.

GeeksforGeeks has a few implementations in different languages with different complexity and memory footprint. I'd try choosing one of those and modifying it according to your problem and porting the code to CODESYS.

If the exact solution comes out to be too slow for your system, you may try an Approximation algorithms for Knapsack instead.

If that also doesn't cut it, perhaps consider using a faster PLC.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Guiorgy
  • 1,405
  • 9
  • 26
  • Thank you. I read about the Knapsack problem and it doesn't look too much similar to my problem. It's also based on recursion wich is a problem to use on a PLC with limited memory resources.... But anyway, it gave me a few more ideias on how to implement. – Giulio Sarmento Barbieri Jun 22 '23 at 22:01
  • The recursion approach is the inefficient one, the preferred solution is the Dynamic Programming Approach, and if even that is too much, the approximation algorithm uses a simple n (number of weights) length array and a single loop. The Knapsack problem is the base that can be modified to solve different similar problems. In you case, you have an additional requirement that top head (eg. 2,1) can only be used after using the bottom head (eg. 1,1), you also want an answer closest to W instead of at most W, and the value is based on the layer the head is located on (bottom heads higher value) – Guiorgy Jun 23 '23 at 09:33
  • Not exactly.... The machine doesnt' have heads really. I gave this example only to ilustratre what the logic is. But the "heads", in this case containers, are all independant and can be used in any order... – Giulio Sarmento Barbieri Jun 26 '23 at 22:16