Bugfixes for cover_rectangle example
This commit is contained in:
@@ -72,7 +72,7 @@
|
||||
"id": "description",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Fill a 72x37 rectangle by a minimum number of non-overlapping squares.\n",
|
||||
"Fill a 60x50 rectangle by a minimum number of non-overlapping squares.\n",
|
||||
"\n"
|
||||
]
|
||||
},
|
||||
@@ -88,8 +88,8 @@
|
||||
"\n",
|
||||
"def cover_rectangle(num_squares):\n",
|
||||
" \"\"\"Try to fill the rectangle with a given number of squares.\"\"\"\n",
|
||||
" size_x = 72\n",
|
||||
" size_y = 37\n",
|
||||
" size_x = 60\n",
|
||||
" size_y = 50\n",
|
||||
"\n",
|
||||
" model = cp_model.CpModel()\n",
|
||||
"\n",
|
||||
@@ -112,7 +112,7 @@
|
||||
" interval_y = model.NewIntervalVar(start_y, size, end_y, 'iy_%i' % i)\n",
|
||||
"\n",
|
||||
" area = model.NewIntVar(1, size_y * size_y, 'area_%i' % i)\n",
|
||||
" model.AddProdEquality(area, [size, size])\n",
|
||||
" model.AddMultiplicationEquality(area, [size, size])\n",
|
||||
"\n",
|
||||
" areas.append(area)\n",
|
||||
" x_intervals.append(interval_x)\n",
|
||||
@@ -169,12 +169,12 @@
|
||||
"\n",
|
||||
" for line in range(size_y):\n",
|
||||
" print(' '.join(display[line]))\n",
|
||||
" return status == cp_model.FEASIBLE\n",
|
||||
" return status == cp_model.OPTIMAL\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"for num in range(1, 15):\n",
|
||||
" print('Trying with size =', num)\n",
|
||||
" if cover_rectangle(num):\n",
|
||||
"for num_squares in range(1, 15):\n",
|
||||
" print('Trying with size =', num_squares)\n",
|
||||
" if cover_rectangle(num_squares):\n",
|
||||
" break\n",
|
||||
"\n"
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user