-
-
Save karlnapf/8c4dd90b9c2cfe9efe5fda507ec52887 to your computer and use it in GitHub Desktop.
Clash free schedule for hackathon topics
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": 1, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [], | |
"source": [ | |
"import numpy as np\n", | |
"import tqdm as tqdm" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 2, | |
"metadata": { | |
"collapsed": false, | |
"scrolled": true | |
}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"['website' 'gsoc' 'modernise' 'api' 'doc' 'devops' 'governance' 'blog'\n", | |
" 'future' 'bsd' 'issues'] 11\n" | |
] | |
} | |
], | |
"source": [ | |
"# questionnaire results\n", | |
"selections = {\n", | |
" \"lea\": [\"future\", \"devops\", \"website\", \"governance\", \"gsoc\", \"doc\", \"blog\"],\n", | |
" \"heiko\": [\"future\", \"api\", \"governance\", \"gsoc\", \"bsd\"],\n", | |
" \"viktor\": [\"modernise\", \"future\", \"api\", \"governance\", \"gsoc\", \"bsd\"],\n", | |
" \"fernando\": [\"future\", \"devops\", \"issues\"],\n", | |
" \"giovanni\": [\"future\", \"api\", \"governance\", \"doc\", \"bsd\"],\n", | |
" \"esben\": [\"future\", \"issues\", \"doc\"],\n", | |
" \"sergey\": [\"modernise\", \"future\", \"api\", \"website\"],\n", | |
" \"soeren\": [\"future\", \"doc\"],\n", | |
" \"marcus\": [\"modernise\", \"devops\", \"api\", \"governance\", \"issues\"],\n", | |
" \"michele\": [\"api\", \"gsoc\", \"issues\"],\n", | |
" \"pan\": [\"modernise\", \"future\", \"devops\", \"api\", \"governance\", \"gsoc\"], \n", | |
" \n", | |
"}\n", | |
"for name, choices in selections.items():\n", | |
" selections[name] = set(choices)\n", | |
"\n", | |
"# find all topics\n", | |
"topics = []\n", | |
"for choices in selections.values():\n", | |
" topics += choices\n", | |
"topics = np.array(list(set(topics)))\n", | |
"num_topics = len(topics)\n", | |
"\n", | |
"print topics, num_topics" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 3, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"[array(['website', 'gsoc', 'modernise'], \n", | |
" dtype='|S10'), array(['api', 'doc', 'devops'], \n", | |
" dtype='|S10'), array(['governance', 'blog', 'future'], \n", | |
" dtype='|S10'), array(['bsd', 'issues'], \n", | |
" dtype='|S10')]\n" | |
] | |
} | |
], | |
"source": [ | |
"# assume that adjacent topics run in parallel\n", | |
"num_sessions = 4\n", | |
"\n", | |
"print np.array_split(np.array(topics), num_sessions)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 4, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"name": "stderr", | |
"output_type": "stream", | |
"text": [ | |
"\r", | |
" 0%| | 0/1000 [00:00<?, ?it/s]" | |
] | |
}, | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"new best schedule, 1 clashes\n", | |
"schedule: ['doc' 'bsd' 'modernise' 'issues' 'governance' 'gsoc' 'blog' 'future' 'api'\n", | |
" 'website' 'devops']\n", | |
"clashes: {'lea': 1, 'viktor': 0, 'giovanni': 0, 'michele': 0, 'fernando': 0, 'sergey': 0, 'esben': 0, 'marcus': 0, 'soeren': 0, 'heiko': 0, 'pan': 0}\n", | |
"====================================\n", | |
"new best schedule, 0 clashes\n", | |
"schedule: ['modernise' 'doc' 'governance' 'api' 'bsd' 'gsoc' 'website' 'future'\n", | |
" 'devops' 'blog' 'issues']\n" | |
] | |
}, | |
{ | |
"name": "stderr", | |
"output_type": "stream", | |
"text": [ | |
"\n" | |
] | |
} | |
], | |
"source": [ | |
"best_clash_count = np.inf\n", | |
"best_state = np.array(topics)\n", | |
"best_clashes = {}\n", | |
"\n", | |
"print_state = False\n", | |
"\n", | |
"np.random.seed(0)\n", | |
"\n", | |
"for iteration in tqdm.tqdm(range(1000)):\n", | |
" state = np.array(topics)[np.random.permutation(len(topics))]\n", | |
" #print state\n", | |
" \n", | |
" # count number of clashes for current state\n", | |
" clashes = {}\n", | |
" schedule = np.array_split(state, num_sessions)\n", | |
" for parallel in schedule:\n", | |
" if print_state:\n", | |
" print \"parallel session %d\" % (i+1), parallel\n", | |
"\n", | |
" # for each name, check for clashes\n", | |
" # a clash is if both parallel topics are in a name's choices\n", | |
" for name,choices in selections.items():\n", | |
" clashes[name] = np.max((0,len(choices.intersection(parallel))-1))\n", | |
" \n", | |
" \n", | |
" if print_state:\n", | |
" print \"clashes:\", clashes\n", | |
" for name,c in clashes.items():\n", | |
" if c>0:\n", | |
" print \"choices\", name, selections[name]\n", | |
" \n", | |
"\n", | |
" clash_count = 0\n", | |
" for c in clashes.values():\n", | |
" clash_count+=c\n", | |
" \n", | |
" if print_state:\n", | |
" print \"Total number of clashes:\", clash_count\n", | |
" \n", | |
" if best_clash_count > clash_count:\n", | |
" best_clash_count = clash_count\n", | |
" best_state = state\n", | |
" best_clashes = clashes\n", | |
" print \"new best schedule, %d clashes\" % clash_count\n", | |
" print \"schedule:\", state\n", | |
" if best_clash_count == 0:\n", | |
" break\n", | |
" print \"clashes:\", clashes\n", | |
" print \"====================================\"\n", | |
"\n" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 5, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"['modernise' 'doc' 'governance']\n", | |
"['api' 'bsd' 'gsoc']\n", | |
"['website' 'future' 'devops']\n", | |
"['blog' 'issues']\n" | |
] | |
} | |
], | |
"source": [ | |
"for session in schedule:\n", | |
" print session" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 2", | |
"language": "python", | |
"name": "python2" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 2 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython2", | |
"version": "2.7.13" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 2 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment