|
122 | 122 | "best_their_ids = get_best_problem_ids(guillotine=False)" |
123 | 123 | ] |
124 | 124 | }, |
| 125 | + { |
| 126 | + "cell_type": "code", |
| 127 | + "execution_count": 37, |
| 128 | + "metadata": {}, |
| 129 | + "outputs": [], |
| 130 | + "source": [ |
| 131 | + "'''\n", |
| 132 | + "Output just problems to csvs\n", |
| 133 | + "'''\n", |
| 134 | + "g_problems = Result.objects.filter(problem_id__in=best_problem_ids, n_simulations=5000, \n", |
| 135 | + " improved_sel=True, strategy='max_depth', score__isnull=False\n", |
| 136 | + " ).values('rows', 'cols', 'tiles', 'n_tiles')\n", |
| 137 | + "\n", |
| 138 | + "b_problems = Result.objects.filter(their_id__in=best_their_ids, n_simulations=5000, \n", |
| 139 | + " improved_sel=True, strategy='max_depth', score__isnull=False\n", |
| 140 | + " ).values('rows', 'cols', 'tiles', 'n_tiles', 'their_id')\n", |
| 141 | + "\n", |
| 142 | + "def eliminate_duplicate_tiles(tiles):\n", |
| 143 | + " i = 0\n", |
| 144 | + " new_tiles = []\n", |
| 145 | + " while i < len(tiles):\n", |
| 146 | + " tile = tiles[i]\n", |
| 147 | + " tiles_without_current_tile = tiles[i + 1:]\n", |
| 148 | + " tile_pair_index = tiles_without_current_tile.index([tile[1], tile[0]]) + i + 1\n", |
| 149 | + " tiles = tiles[0: tile_pair_index] + tiles[tile_pair_index + 1:]\n", |
| 150 | + " i += 1 \n", |
| 151 | + " return tiles\n", |
| 152 | + " \n", |
| 153 | + "import csv, os\n", |
| 154 | + "for file_name, problems in [('problems_g.csv', g_problems), ('problems_b.csv', b_problems)]:\n", |
| 155 | + " with open(os.path.join('problems/', file_name), 'w') as csv_file:\n", |
| 156 | + " fieldnames = ['rows', 'cols', 'tiles', 'n_tiles']\n", |
| 157 | + " if file_name == 'problems_b.csv':\n", |
| 158 | + " fieldnames.append('external_id')\n", |
| 159 | + " csv_writer = csv.writer(csv_file, delimiter=';')\n", |
| 160 | + " csv_writer.writerow(fieldnames)\n", |
| 161 | + " for problem in problems:\n", |
| 162 | + " row = [problem['rows'], problem['cols'],\n", |
| 163 | + " str(eliminate_duplicate_tiles(problem['tiles'])), problem['n_tiles']]\n", |
| 164 | + " if file_name == 'problems_b.csv':\n", |
| 165 | + " row.append(problem['their_id'])\n", |
| 166 | + " csv_writer.writerow(row)" |
| 167 | + ] |
| 168 | + }, |
125 | 169 | { |
126 | 170 | "cell_type": "code", |
127 | 171 | "execution_count": 65, |
|
181 | 225 | "plt.xlabel('columns')" |
182 | 226 | ] |
183 | 227 | }, |
| 228 | + { |
| 229 | + "cell_type": "code", |
| 230 | + "execution_count": 76, |
| 231 | + "metadata": {}, |
| 232 | + "outputs": [ |
| 233 | + { |
| 234 | + "name": "stdout", |
| 235 | + "output_type": "stream", |
| 236 | + "text": [ |
| 237 | + "Count of squares in problems: defaultdict(<class 'int'>, {(1, 1): 5534, (4, 4): 242, (2, 2): 498, (8, 8): 42, (6, 6): 86, (3, 3): 132, (5, 5): 70, (7, 7): 34, (14, 14): 22, (20, 20): 2, (9, 9): 38, (10, 10): 16, (13, 13): 8, (16, 16): 16, (12, 12): 4, (24, 24): 2, (11, 11): 6, (15, 15): 8, (21, 21): 2, (22, 22): 2, (18, 18): 2, (17, 17): 2})\n" |
| 238 | + ] |
| 239 | + } |
| 240 | + ], |
| 241 | + "source": [ |
| 242 | + "tiles = Result.objects.filter(problem_id__in=best_problem_ids, n_simulations=5000, \n", |
| 243 | + " improved_sel=True, strategy='max_depth', score__isnull=False\n", |
| 244 | + " ).values('tiles')\n", |
| 245 | + "\n", |
| 246 | + "from collections import defaultdict\n", |
| 247 | + "tiles_count = defaultdict(int)\n", |
| 248 | + "for tile_dict in tiles:\n", |
| 249 | + " _tiles = tile_dict['tiles']\n", |
| 250 | + " for one_tile in _tiles:\n", |
| 251 | + " if one_tile[0] == one_tile[1]:\n", |
| 252 | + " tiles_count[(one_tile[0], one_tile[1])] += 1\n", |
| 253 | + " \n", |
| 254 | + "print('Count of squares in problems:', tiles_count)\n", |
| 255 | + "\n", |
| 256 | + " \n", |
| 257 | + " \n", |
| 258 | + " " |
| 259 | + ] |
| 260 | + }, |
184 | 261 | { |
185 | 262 | "cell_type": "code", |
186 | 263 | "execution_count": 7, |
|
0 commit comments