assigning algorithm/pseudocode
Im building web application in which Im trying to assign users to groups based on their preferences. In my application I have 1 table where users infos are stored, and 1 table where users choices are stored.
Users must pick at least one choice from 10.
I`m trying to write algorithm that will satisfy these rules:
1. there must be from 4 to 8 users in a group 2. each user must be at most in one group 3. every user in the group, have at least one preferred choice in common 4. and preferably each user belongs to the group / as many as possiblebut with no luck yet. Have anybody any idea how开发者_C百科 to find such a solution? Also algorithm which will find good solution (not best), will be much appreciated.
This problem is similar to the Miss Manners 2009 example of Drools Planner, which is about assigning guests (= users) to tables (= groups) and make sure guests sitting next to each other have the same preferences.
I don't see why you need a algorithm to enforce this.
Users must pick at least one choice from 10.
This should be enforced at the UI. You probably want to give the user just a listbox of the valid options, if its a free text box, validate it immediately after the user submits the value.
I`m trying to write algorithm that will satisfy these rules: 1. there must be from 4 to 8 users in a group 2. each user must be at most in one group 3. every user in the group, have at least one preferred choice in common 4. and preferably each user belongs to the group / as many as possible
I would write each rule as a SQL statement and based on the requirement, trigger these SQL statements after each update on the database. If you are perform conscious, schedule to run all this rules in a stored procedure as a nightly batch job.
精彩评论