0

Here is my situation: a company has x number of employees and x number of machines. When someone is sick, the program have to give the best possible solution of people on the machines. But the employees can't work on every machine. I need a code for making little groups of possible solutions.

this is a static example private int[][] arrayCompetenties={{0,0,1,0,1},{1,0,1,0,1},{1,1,0,0,1},{1,1,1,1,1},{0,0,0,0,1}}; => row is for the people and columns are for machines

 m1 m2 m3 m4 m5 m6 m7
p1 1 1 
p2 1 1 1 1 
p3 1 1 1
p4 1 1 1 
p5 1 1 1 1
p6 1 1 1 1
p7 1 1 1 1 1 1

my question => with what code do i connect all the people to machine in groups (all the posibilities)

like:

p1 -> m1 , p2->m2 , p3 -> m3 , p4->m4 , p5 -> m5 , p6->m6

p1 -> m1 , p2->m3 , p3 -> m3 , p4->m4 , p5 -> m5 , p6->m6

p1 -> m1 , p2->m4 , p3 -> m5 , p4->m4 , p5 -> m5 , p6->m6

p1 -> m1 , p2->m5 , p3 -> m3 , p4->m4 , p5 -> m5 , p6->m6

p1 -> m1 , p2->m2 , p3 -> m3 , p4->m4 , p5 -> m5 , p6->m6

....

i need a loop buth how? =D

thanks!

Karl Bielefeldt
149k38 gold badges284 silver badges485 bronze badges
asked Apr 7, 2012 at 17:41
1
  • here is the right table: m1 m2 m3 m4 m5 m6 m7 p1 1 0 0 0 1 0 0 p2 0 1 1 1 1 0 0 p3 0 0 1 0 1 0 1 p4 0 1 0 1 0 1 0 p5 1 0 1 0 1 0 1 p6 0 0 0 1 1 1 1 p7 1 0 1 1 1 1 1 Commented Apr 7, 2012 at 17:49

2 Answers 2

2

I think you're trying to to generate all permutations of machines and users. Take a look at that link, especially on the algorithms used to generate permutations.

Keep in mind that the number of permutations for n machines/users is n! (n factorial, or n * (n-1) * (n-2) * ... * 2 * 1), which grows extremely quickly -- for 10 users, 3.6 million possibilities, and for a company of 50 people, you're looking at 3.0 * 10^64 different combinations, which wouldn't fit on all the world's computers.

answered Apr 7, 2012 at 18:13
1

The easiest way to solve this is with recursion. The following is very pseudocode because the data structures aren't trivial, but you get the idea:

printMachineAssignments(person, assignedMachines)
 for every machine in person's competencies that's not in assignedMachines
 assign person to machine
 add machine to assignedMachines
 if no more people
 print assignments to the screen
 else
 printMachineAssignments(person + 1, assignedMachines)
answered Apr 7, 2012 at 18:53

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.