473,378 Members | 1,369 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Combinations in Access

Hello everyone,

I'm trying to create an MS Access 03 database to be used in optimizing flow for various tasks. The idea is I have a table with task names, duration of each task, and the name of a task that needs to be completed before the current task may commence.

A typical example would be:

AutoNumber / TaskName / Duration / GroupName
1 / Take out trash / 5 minutes / None
2 / Put in fresh bag / 1 minute / Group 2
3 / Watch TV / 30 minutes / None
4 / Eat Dinner / 20 minutes / None

I have a linked table (1 to many relationship) which has

TaskName / ContingentOn

which holds records such as:

Put in Fresh bag / Take out trash
Watch TV / Put in fresh bag

where task "putting in a fresh bag" may only be done once task "Take out trash" has been completed, and "Watch TV" can only be done once a fresh bag is put in.

Several tasks require that multiple previous tasks are complete before starting.

Here is where I need some help.

In order to handle the groups of items, my thought is to add the group as a task, then calculate the duration of the group of tasks. So, in the above example, I would simply add the time required to take out the trash to the time required to put in a fresh bag.

The trouble comes when multiple tasks can be completed at the same time. So, suppose you're packing for a trip and you have 5 bags (each requiring a differing amount of time to transport) to carry out to the car, and you have two people to carry them. How do you optimize which person carries what bag?

I would like to have Access put together all combinations of the two people moving the five bags, then test to find the smallest duration.

I am able to loop through my tables to extract duration values one by one, but I can't think of a way to come up with each of the combinations without putting them in by hand (which would be a real pain in the -ss... a small example of 5 objects with 2 people has 10 different combinations.)

Can anyone point me in the direction of some VBA code for calculating combinations of "n" objects in groups of "k"?

Any help would be much appreciated.

--Thanks!
Jan 23 '08 #1
9 3001
ADezii
8,834 Expert 8TB
Hello everyone,

I'm trying to create an MS Access 03 database to be used in optimizing flow for various tasks. The idea is I have a table with task names, duration of each task, and the name of a task that needs to be completed before the current task may commence.

A typical example would be:

AutoNumber / TaskName / Duration / GroupName
1 / Take out trash / 5 minutes / None
2 / Put in fresh bag / 1 minute / Group 2
3 / Watch TV / 30 minutes / None
4 / Eat Dinner / 20 minutes / None

I have a linked table (1 to many relationship) which has

TaskName / ContingentOn

which holds records such as:

Put in Fresh bag / Take out trash
Watch TV / Put in fresh bag

where task "putting in a fresh bag" may only be done once task "Take out trash" has been completed, and "Watch TV" can only be done once a fresh bag is put in.

Several tasks require that multiple previous tasks are complete before starting.

Here is where I need some help.

In order to handle the groups of items, my thought is to add the group as a task, then calculate the duration of the group of tasks. So, in the above example, I would simply add the time required to take out the trash to the time required to put in a fresh bag.

The trouble comes when multiple tasks can be completed at the same time. So, suppose you're packing for a trip and you have 5 bags (each requiring a differing amount of time to transport) to carry out to the car, and you have two people to carry them. How do you optimize which person carries what bag?

I would like to have Access put together all combinations of the two people moving the five bags, then test to find the smallest duration.

I am able to loop through my tables to extract duration values one by one, but I can't think of a way to come up with each of the combinations without putting them in by hand (which would be a real pain in the -ss... a small example of 5 objects with 2 people has 10 different combinations.)

Can anyone point me in the direction of some VBA code for calculating combinations of "n" objects in groups of "k"?

Any help would be much appreciated.

--Thanks!
I'm not sure that I understand your request exactly, but it seems like you are referring to Nested Loops using Arrays as in:
Expand|Select|Wrap|Line Numbers
  1. ' 5 Objects - 7 People
  2.  
  3. Dim astrObjects(1 To 5) As String, intObjectCounter As Integer
  4. Dim astrPeople(1 To 7) As String, intPeopleCounter As Integer
  5.  
  6. For intObjectCounter = 1 To UBound(astrObjects)
  7.   For intPeopleCounter = 1 To UBound(astrPeople)
  8.     Debug.Print "Object#" & Str(intObjectCounter) & " <==> Person#" & Str(intPeopleCounter)
  9.   Next
  10. Next
OUTPUT:
Expand|Select|Wrap|Line Numbers
  1. Object# 1 <==> Person# 1
  2. Object# 1 <==> Person# 2
  3. Object# 1 <==> Person# 3
  4. Object# 1 <==> Person# 4
  5. Object# 1 <==> Person# 5
  6. Object# 1 <==> Person# 6
  7. Object# 1 <==> Person# 7
  8. Object# 2 <==> Person# 1
  9. Object# 2 <==> Person# 2
  10. Object# 2 <==> Person# 3
  11. Object# 2 <==> Person# 4
  12. Object# 2 <==> Person# 5
  13. Object# 2 <==> Person# 6
  14. Object# 2 <==> Person# 7
  15. Object# 3 <==> Person# 1
  16. Object# 3 <==> Person# 2
  17. Object# 3 <==> Person# 3
  18. Object# 3 <==> Person# 4
  19. Object# 3 <==> Person# 5
  20. Object# 3 <==> Person# 6
  21. Object# 3 <==> Person# 7
  22. Object# 4 <==> Person# 1
  23. Object# 4 <==> Person# 2
  24. Object# 4 <==> Person# 3
  25. Object# 4 <==> Person# 4
  26. Object# 4 <==> Person# 5
  27. Object# 4 <==> Person# 6
  28. Object# 4 <==> Person# 7
  29. Object# 5 <==> Person# 1
  30. Object# 5 <==> Person# 2
  31. Object# 5 <==> Person# 3
  32. Object# 5 <==> Person# 4
  33. Object# 5 <==> Person# 5
  34. Object# 5 <==> Person# 6
  35. Object# 5 <==> Person# 7
Jan 24 '08 #2
Thanks for the reply, ADezii,

I created code similar to yours to do exactly what you have there -- that is, cycle through each record within each grouping (though, your code seems more elegant than mine...) but the problem I'm having is basically this.

Given 5 values: {1,2,3,4,5}, taken 2 at a time (A and B), how to I get out all the orders of those numbers? That is, I want the output of:

A: 1 2 3 4
B: 5

A: 1 2 3
B: 4 5

A: 1 2
B: 3 4 5

A: 1
B: 2 3 4 5

A: 1 3 4 5
B: 2

A: 1 3 4
B: 2 5

A: 1 3
B: 2 4 5

A: 1 2 4 5
B: 3

A: 1 2 4
B: 3 5

A: 1 2 3 5
B: 4

The idea is that there is no difference between A and B ( so 1,2,3 :: 4, 5 is the same as 4,5 :: 1, 2, 3) But every combination of those 5 numbers is divided among A and B.

Any help would be much appreciated.

Thanks!
Jan 24 '08 #3
ADezii
8,834 Expert 8TB
Thanks for the reply, ADezii,

I created code similar to yours to do exactly what you have there -- that is, cycle through each record within each grouping (though, your code seems more elegant than mine...) but the problem I'm having is basically this.

Given 5 values: {1,2,3,4,5}, taken 2 at a time (A and B), how to I get out all the orders of those numbers? That is, I want the output of:

A: 1 2 3 4
B: 5

A: 1 2 3
B: 4 5

A: 1 2
B: 3 4 5

A: 1
B: 2 3 4 5

A: 1 3 4 5
B: 2

A: 1 3 4
B: 2 5

A: 1 3
B: 2 4 5

A: 1 2 4 5
B: 3

A: 1 2 4
B: 3 5

A: 1 2 3 5
B: 4

The idea is that there is no difference between A and B ( so 1,2,3 :: 4, 5 is the same as 4,5 :: 1, 2, 3) But every combination of those 5 numbers is divided among A and B.

Any help would be much appreciated.

Thanks!
I'll get back to you on this and see if I can come up with something.
Jan 24 '08 #4
I'll get back to you on this and see if I can come up with something.

Thanks! I've been thinking about it, and it may turn out to be easier to use a bunch of completion flags (one for each event) and just go through the full set of discrete time intervals. So at minute 5 after taking out the trash has been complete, it sets flag "flg_taking_out_the_trash" to 1, which then allows an if statement starting the next task to begin.

If it were to check tasks by order of decreasing duration, I believe it would optimize it fairly efficiently, if perhaps not perfectly.

Thoughts?
Jan 24 '08 #5
jaxjagfan
254 Expert 100+
What about Task, Status, Person?

If you have 5 tasks to be acomplished but not assigned to a particular person

Beginning State:
Task_Status_Pers
01_00_00
02_00_00
03_00_00
04_00_00
05_00_00

In progress:
Task_Status_Pers
01_01_0A
02_01_0B
03_00_00
04_00_00
05_00_00

Completed:
Task_Status_Pers
01_01_0A
02_01_0B
03_01_0A
04_01_0A
05_01_0B

Loop thru each task and check status. Enable following task if previous is complete. Each time capturing who accomplished.
This is similar logic to game programming for multiplayer team tasks.

You could add a task group to the string and group status if you don't want another group to begin before the previous one is complete.

Just a thought here - Some tasks don't need to be done in order (Wash Dishes, Take Out Trash) but both need to be done before Watch TV can occur.
Jan 24 '08 #6
What about Task, Status, Person?

If you have 5 tasks to be acomplished but not assigned to a particular person

Beginning State:
Task_Status_Pers
01_00_00
02_00_00
03_00_00
04_00_00
05_00_00

In progress:
Task_Status_Pers
01_01_0A
02_01_0B
03_00_00
04_00_00
05_00_00

Completed:
Task_Status_Pers
01_01_0A
02_01_0B
03_01_0A
04_01_0A
05_01_0B

Loop thru each task and check status. Enable following task if previous is complete. Each time capturing who accomplished.
This is similar logic to game programming for multiplayer team tasks.

You could add a task group to the string and group status if you don't want another group to begin before the previous one is complete.

Just a thought here - Some tasks don't need to be done in order (Wash Dishes, Take Out Trash) but both need to be done before Watch TV can occur.
Hi jaxjagfan, thanks for responding.

I want to make sure I understand what you wrote above... You're basically saying to do what I proposed, which is have a flag change state when a task becomes complete. Then the code loops through again and re-evaluates whether each task may be completed. Am I about right?

I like it, and if ADezii doesn't have time/inclination to get back to me, I may just end up going that route. Thanks for the input.

The only down side to this setup is it doesn't truely optimize the order in which tasks are complete. Suppose you have 4 tasks, and two people to do them. The task lengths are (in minutes, say) 10, 9,2,1. If you simply start the next longest task as soon as the current one finishes, the two people would complete:

A: 10, 2
B: 9, 1

So it would take 12 minutes to complete all four tasks. However if the tasks were completed this way:

A: 10, 1
B: 9, 2

it would only take 11 minutes to do the task (which is ideal).

Can anyone think of a way to do this without checking each combination of user/tasks?
Jan 24 '08 #7
jaxjagfan
254 Expert 100+
Hi jaxjagfan, thanks for responding.

I want to make sure I understand what you wrote above... You're basically saying to do what I proposed, which is have a flag change state when a task becomes complete. Then the code loops through again and re-evaluates whether each task may be completed. Am I about right?

I like it, and if ADezii doesn't have time/inclination to get back to me, I may just end up going that route. Thanks for the input.

The only down side to this setup is it doesn't truely optimize the order in which tasks are complete. Suppose you have 4 tasks, and two people to do them. The task lengths are (in minutes, say) 10, 9,2,1. If you simply start the next longest task as soon as the current one finishes, the two people would complete:

A: 10, 2
B: 9, 1

So it would take 12 minutes to complete all four tasks. However if the tasks were completed this way:

A: 10, 1
B: 9, 2

it would only take 11 minutes to do the task (which is ideal).

Can anyone think of a way to do this without checking each combination of user/tasks?
Yea - thats sort of what I was thinking - Close enough anyhow.

You could end up with
A:10, 9
B: 1, 2

The way to get around that would be to have A and B available for task assigments. If A:10 is in progress then assign B:9. You may still end up with an A:2 but that will depend upon the task dependencies and ACTUAL completion times (what if garbage bag broke).

You also need to randomize the starting assignment so it will not always be A:10.

A & B may help each other out when idle. This would cut time required in half or double power-hours assigned (depending on how you look at it).
Jan 24 '08 #8
Yea - thats sort of what I was thinking - Close enough anyhow.

You could end up with
A:10, 9
B: 1, 2

The way to get around that would be to have A and B available for task assigments. If A:10 is in progress then assign B:9. You may still end up with an A:2 but that will depend upon the task dependencies and ACTUAL completion times (what if garbage bag broke).

You also need to randomize the starting assignment so it will not always be A:10.

A & B may help each other out when idle. This would cut time required in half or double power-hours assigned (depending on how you look at it).
Good thoughts, jaxjagfan, and thanks for the RE.

If I were to do this method I would have it search for the longest duration task to assign to the next available person in order to avoid it assigning one person the longest running tasks. Meaning, whenever a person completed a task, they would be assigned the next longest duration task. That way, overall, the tasks will come out to be all done at about the same time. Hopefully. Maybe...

I agree that in the example I gave A could help out B or vise versa if their assigned task were complete, however in my actual application this is not the case. Space and equipment considerations prohibit this. (For instance, if the task is loading a pallet using a fork lift, the task wouldn't go any faster with two forklifts.)

I do appreciate the thoughts/ideas though. Thank you.
Jan 24 '08 #9
I'll get back to you on this and see if I can come up with something.
Any additional thoughts, ADezii?
Feb 28 '08 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Jim Hubbard | last post by:
Does anyone have any code for doing combinations in VB.net or visual basic ? I'd like to be able to get an array of combinations (not permutations) of words from a base group of words while...
36
by: rbt | last post by:
Say I have a list that has 3 letters in it: I want to print all the possible 4 digit combinations of those 3 letters: 4^3 = 64 aaaa
7
by: Micheal Artindale | last post by:
I am looking at creating list of letter combinations. letters a-h 6 letters per combination letter can repeat its self in the combination, but not next to its self and, a series of letter can...
19
by: Thomas Cameron | last post by:
Hello all, I have an array of values which I would like to generate all possible combinations for. And example would be the values "a,b,c". This would produce the following: a ab abc ac
15
by: Thomas Cameron | last post by:
Hello all, I have an array of values which I would like to generate all possible combinations for. And example would be the values "a,b,c". This would produce the following: a ab abc ac b
3
by: Ryan | last post by:
I've been trying to find an algorithm that will output all of the possible combinations of items in an array. I know how to find the number of combinations for each set using nCr=n!/(r!(n-r)!) ...
1
by: brendan | last post by:
Hi, I'm not at all competent in ms-sql, nor vb, as we work in Oracle and Mysql .... however, we need to port a couple of db queries to ms-access (2000) and I'm having a heck of a time trying to...
2
by: The Frog | last post by:
Hello everyone, I am trying to find way of writing an SQL query that can produce missing record combinations across a many to many type setup in Access. The three tables used are as follows:...
5
by: Bails | last post by:
Hi all I have a theory for a lotto system and need help on how to code it. I want to create 1 massive database with EVERY combination of numbers possible in a given lotto system, then remove all...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.