473,387 Members | 1,420 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,387 software developers and data experts.

Problem with finding maximal sum of happiness

6
Hi, I have a problem to solve, and do not see any optimal solution :/ The problem is:

I have n workers and k jobs. Each job is to be done by specified number of workers, and each worker has his level of happines for each job. I have to to make a work schedule so that workers would be as happy as possible.
So, I have array a1 of int[n,k]. k-th column of i-th row contains preference (number from 0 to 10) of i-th worker for k-th job. I also have array a2 of int[k], where i-th element contains number of people who will be doing that job. I have to find maximal possible sum of happines, knowing that n >= min(a2).
My solution is to use recursion. Select first worker for first combination of jobs, add preferences to the sum, check if sum is higher then maximal already found, and if it is, go to the next worker. When back, check the next combination for the first worker etc. This works fine for small amount of workers, but has to high computational complexity to solve bigger problems. Have You got any idea for better solution?
Mar 13 '15 #1

✓ answered by Rabbit

What you have is called an assignment problem: http://en.wikipedia.org/wiki/Assignment_problem.

And that can be solved using the Hungarian Algorithm: http://en.wikipedia.org/wiki/Hungarian_algorithm

In your situation, your cost is "unhappiness" and you can use the algorithm to find the combination that will give you the least "unhappiness" in polynomial time.

10 3176
Rabbit
12,516 Expert Mod 8TB
What you have is called an assignment problem: http://en.wikipedia.org/wiki/Assignment_problem.

And that can be solved using the Hungarian Algorithm: http://en.wikipedia.org/wiki/Hungarian_algorithm

In your situation, your cost is "unhappiness" and you can use the algorithm to find the combination that will give you the least "unhappiness" in polynomial time.
Mar 13 '15 #2
MatHek
6
I do not see any way to comment Your answer, so I am writing as a 'reply'. This algorithm is very nice, but my problem is a little bit more complicated. The assumption in HA is that we have n people and n jobs. I have k jobs, where k >= n. What is more, one job is to be done exactly by specified number of people, so I cannot just duplicate workers, because one worker would be selected for one job multiple times...
Mar 13 '15 #3
Rabbit
12,516 Expert Mod 8TB
Perhaps you need to provide an example because I don't see any problem with using the algorithm. All you do is first use the algorithm on n jobs. Then use the algorithm again on the remaining k - n jobs.
Mar 13 '15 #4
MatHek
6
You are right, I have to think it out concerning my special case. Thank You for Your help, I will write when I get to know more.
Mar 13 '15 #5
Rabbit
12,516 Expert Mod 8TB
Let us know if you run into any problems implementing the algorithm. The base algorithm is described in the article and the links below that article have implementations in a bunch of different languages. So the base implemenation shouldn't be too difficult to work out. And it may benefit you to first do it as the simple version where n = k.

Once you're confident that's working, you can work on the more difficult part of expanding the algorithm to where n < k. Off the top of my head, my thought is that you can use an n x k matrix with a carefully crafted cost assignment to ensure mutual exclusivity on those jobs that require more than one person. Then, after running the algorithm once, you reassign costs to ensure mutual exclusivity to fill in the remaining k-n jobs.
Mar 13 '15 #6
MatHek
6
As far as I am concerned, Your idea is not right. Using algorithm on a part of jobs, and then on the next part, etc, requires assumption that nobody does more than one job in each part. That is why every combination of jobs in each part needs to be checked, which makes my algorithm NP. Similar problem raises up while trying to calculate one-personal jobs firstly. The best solution for all jobs does not have to contain the best solution for only a part of them.
There is also one more thing that I have forgotten to write about: I want all my workers to do the same amount of jobs (number of all workplaces is an integral multiple of number of workers)
Mar 14 '15 #7
Rabbit
12,516 Expert Mod 8TB
I still think an example would help. But if I understand the question correctly, you can still use the algorithm even if you don't want to run it multiple times. You just need to generalize it by removing the n=k restriction and use additional variables to keep track of assignments per job and assignments per worker.
Mar 14 '15 #8
MatHek
6
ok, here are arrays:
Expand|Select|Wrap|Line Numbers
  1.          job1 job2 job3 job4
  2. wokrer1    1    3    4    2
  3. worker2    9    8    1    2        
  4. worker3    6    7    8    9
  5.  
  6.        job1 job2 job3 job4
  7. count    1    2    2    1
  8.  
  9. example solution:
  10. worker1: job2, job3 (7)
  11. worker2: job1, job2 (17)
  12. worker3: job3, job4 (17)
  13.  
  14. sum: 41
  15.  
I still do not see any way to change the original algoritm, but I will try
Mar 14 '15 #9
Rabbit
12,516 Expert Mod 8TB
That helps make things clearer.

Yes, I believe you can still use the algorithm. The algorithm assigns the first created 0 to a worker to minimize costs. If you take that base algorithm, all you need to do is assign the first x zeroes, where x is an additional variable that keeps track of how many workers need to be on a job. That way it assigns the first 2 created zeroes to a job, i.e. the 2 lowest cost workers.

And if need be an additional variable to keep track of assignments per worker so you don't exceed the 2 jobs per worker limit you want to enforce.
Mar 14 '15 #10
MatHek
6
That sounds better, I will try to implement that
Mar 15 '15 #11

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

Similar topics

5
by: Matthew Robinson | last post by:
Can anybody see what is wrong with this code? apparently i have an 'empty delimiter' on the line that sets $pos - can anybody see what is wrong with it? $search_for = $_GET;...
1
by: Jorge Godoy | last post by:
Hi. I have created an interface where I have a QDataBrowser and all of its editing and navigating controls and one of the displayed controls is in a QSpinBox. I have the navigation from...
2
by: Jim Delany | last post by:
I have a project which when built and debugs looks for the source to atl here f:\vs70builds\3077\vc\mfcatl\ship\atlmfc\include\atlcomcli.h Has anyone seen this problem and hopefully know how to...
3
by: Rob | last post by:
You can find datagrid in page by refering the form. Gatagrid is a child control of Form. Here is the code ----------------- Dim ctl As New Control For Each ctl In...
1
by: Doug | last post by:
The html below shows DataList "DiscountList" nested within DataList "EventItemList". DiscountList contains a Label control. I'm trying to find the label, using FindControl, during...
2
by: ashmangat | last post by:
I'm trying to claculate the average number of characters per words but having some problems Every time i run this program, i get 0 as the average #include <iostream> #include <string> #include...
0
by: uber.boffin | last post by:
We are writing a custom function to parse the following XML structure: -<SX3_S1> -<HEADER> <REC_TYPE>H</REC_TYPE> <CONT_NAME>BTE</CONT_NAME> </HEADER> -<WORKS_ORDER> <REC_TYPE>W</REC_TYPE>...
1
by: Empyrean | last post by:
I'm attempting to make my first program that involves file input, but I'm running into problems finding the .txt file. I placed the file inside the same folder as the rest of the project, but it...
1
by: hrubesh | last post by:
Hi, I am having a problem finding the right location of a control if it is found on a form that is on an MDI parent. On mouse click, i want to bring out a "pop up window" that will display extra...
23
by: andersond | last post by:
I have a form with 31 questions each of which could cause an application to be rejected. I have 10 fields named issue 1...issue10. If a problem is found I want to save a message to the first empty...
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: 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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.