Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

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!

share|improve this question
    
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 –  user51447 Apr 7 '12 at 17:49

2 Answers 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.

share|improve this answer

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)
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.