Results 1 to 5 of 5

Thread: Equally divide tasks

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jul 2006
    Posts
    178

    Equally divide tasks

    Hi,

    I have a problem with dividing tasks between people. I have 4 tasks, and somewhere between 4 and 11 people to do these tasks on a weekly basis. If there are 11 people, you can just loop through the tasks and the people, and everyone does every task the same amount of times. However, if you have 10 people and loop through the chores, every person gets the same two tasks over and over again, which is unfair. What would be the correct way of dividing the tasks for the even amount of people?

    Regards,
    Mindstorms

  2. #2
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,538

    Re: Equally divide tasks

    Record who you started with, and each time you start, start with the next person.... so the first time:
    1,2,3,4,5,6,7,8,9,10... then the next time, start with person 2... 2,3,4,5,6,7,8,9,10,1... and then 3... and so on,...

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jul 2006
    Posts
    178

    Re: Equally divide tasks

    Interesting point. I should have mentioned that I would also like to divide the workload equally in time. That is, not doing chores for weeks in a row and then weeks of nothing. With 11 people, the scheme now looks like:

    Time Person 1 Person 2 Person 3 Person 4 Person 5 Person 6 Person 7 Person 8 Person 9 Person 10 Person 11
    Week 1 Task A Task B Task C Task D
    Week 2 Task A Task B Task C Task D
    Week 3 Task D Task A Task B Task C
    Week 4 Task A Task B Task C Task D
    Week 5 Task A Task B Task C Task D
    Week 6 Task C Task D Task A Task B
    Week 7 Task A Task B Task C Task D
    Week 8 Task A Task B Task C Task D
    Week 9 Task A
    Week 10 Task B Task C Task D
    Week 11 Task A Task B Task C Task D
    Week 12 Task A Task B Task C Task D

    But if you have an even amount of people, you have to somehow swap some tasks to recreate this sort of scheme.

  4. #4
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    6,582

    Re: Equally divide tasks

    Well, there may be some easier way to do it, but off the top of my head I would create a list for each person containing the tasks they can do.
    Then I would loop through the people, and inside that loop, loop through the tasks to be done. If the person can do one of the tasks (i.e. it is still in his list of tasks) then assign the task to that person.
    That would spread the tasks, and a given person wouldn't do the same task again until he has done all of them.

    Example code that prints out the person (0 to x) and task (1 to 4) for each person on one line.
    It arbitrarily prints 10 lines of schedule for the number of persons selected (in the immediate or output window, depending on your IDE setup) so you can see the pattern of tasks being assigned.
    Code:
      Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        Dim taskLists(10) As List(Of Integer)
        Dim selectedTask As Integer
    
        For i As Integer = 0 To 10  'create 11 lists for up to 11 people to be tasked
          taskLists(i) = New List(Of Integer)
        Next
    
        Dim currenttasks As New List(Of Integer)  'tasks to be scheduled
        currenttasks.AddRange({1, 2, 3, 4})
    
        Dim NumOfPeople As Integer = 10   'Change this from 4 to 11 to create a schedule
    
        For k As Integer = 1 To 10   'arbitrary, generates 10 lines of schedule for NumOfPeople
          For i As Integer = 0 To NumOfPeople - 1
            If taskLists(i).Count = 0 Then taskLists(i).AddRange({1, 2, 3, 4}) 'If a person has no tasks available, refresh his list
            For Each task As Integer In currenttasks                          'for the four tasks to be scheduled
              If taskLists(i).Contains(task) Then                             '  If the current person hasn't done this task yet this cycle
                taskLists(i).Remove(task)                                     '    Remove this task from the persons list
                currenttasks.Remove(task)                                     '    Remove this task from the list of tasks to be completed
                selectedTask = task                                           '    Note the task to be done by this person for the printout
                Exit For
              End If
            Next
            If currenttasks.Count = 0 Then currenttasks.AddRange({1, 2, 3, 4}) 'If all tasks have been scheduled, refresh the task list
            Debug.Write(String.Format("{0},{1} : ", i, selectedTask))          'Write which person is doing what task
          Next
          Debug.WriteLine("")                                                  'All persons have been assign a task, start a new line
        Next
      End Sub
    Change the Dim NumOfPeople line to try different numbers of people.
    Example output with 10 people
    Code:
    0,1 : 1,2 : 2,3 : 3,4 : 4,1 : 5,2 : 6,3 : 7,4 : 8,1 : 9,2 : 
    0,3 : 1,4 : 2,1 : 3,2 : 4,3 : 5,4 : 6,1 : 7,2 : 8,3 : 9,4 : 
    0,2 : 1,1 : 2,4 : 3,3 : 4,2 : 5,1 : 6,4 : 7,3 : 8,2 : 9,1 : 
    0,4 : 1,3 : 2,2 : 3,1 : 4,4 : 5,3 : 6,2 : 7,1 : 8,4 : 9,3 : 
    0,1 : 1,2 : 2,3 : 3,4 : 4,1 : 5,2 : 6,3 : 7,4 : 8,1 : 9,2 : 
    0,3 : 1,4 : 2,1 : 3,2 : 4,3 : 5,4 : 6,1 : 7,2 : 8,3 : 9,4 : 
    0,2 : 1,1 : 2,4 : 3,3 : 4,2 : 5,1 : 6,4 : 7,3 : 8,2 : 9,1 : 
    0,4 : 1,3 : 2,2 : 3,1 : 4,4 : 5,3 : 6,2 : 7,1 : 8,4 : 9,3 : 
    0,1 : 1,2 : 2,3 : 3,4 : 4,1 : 5,2 : 6,3 : 7,4 : 8,1 : 9,2 : 
    0,3 : 1,4 : 2,1 : 3,2 : 4,3 : 5,4 : 6,1 : 7,2 : 8,3 : 9,4 :
    Of course, you're not limited to 4 to 11 people, here is the print out for 3 and 2 people
    Code:
    0,1 : 1,2 : 2,3 : 
    0,4 : 1,1 : 2,2 : 
    0,3 : 1,4 : 2,1 : 
    0,2 : 1,3 : 2,4 : 
    0,1 : 1,2 : 2,3 : 
    0,4 : 1,1 : 2,2 : 
    0,3 : 1,4 : 2,1 : 
    0,2 : 1,3 : 2,4 : 
    0,1 : 1,2 : 2,3 : 
    0,4 : 1,1 : 2,2 :
     
    0,1 : 1,2 : 
    0,3 : 1,4 : 
    0,2 : 1,1 : 
    0,4 : 1,3 : 
    0,1 : 1,2 : 
    0,3 : 1,4 : 
    0,2 : 1,1 : 
    0,4 : 1,3 : 
    0,1 : 1,2 : 
    0,3 : 1,4 :
    p.s. I'll leave it to you to figure out how to print it out by weeks.
    Last edited by passel; Jan 29th, 2018 at 04:34 PM.

  5. #5
    Fanatic Member 2kaud's Avatar
    Join Date
    May 2014
    Location
    England
    Posts
    1,000

    Re: Equally divide tasks

    This doesn't take into account task (what?) preferences (if relevant?). Someone might like doing tasks A, B but not D, E but another may prefer C, E. Also nothing seems to be mentioned re the time constraints (person assigned has time to do it) or length of time (are they all the same?) for the various tasks. It also doesn't take into account the workload of the people. You might need one person to do more than one task one week - or to be able to move a scheduled task from say Person 1 to Person 7. What about holidays, absences etc etc? This sounds quite easy in theory, but in practice can get quite complicated!
    All advice is offered in good faith only. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/

    C++23 Compiler: Microsoft VS2022 (17.6.5)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width