Skip to content

Commit

Permalink
LAB3: updated tsp lab to decribe objective function objects.
Browse files Browse the repository at this point in the history
  • Loading branch information
TomMonks committed Dec 17, 2020
1 parent 5314a65 commit ef3cdc9
Show file tree
Hide file tree
Showing 4 changed files with 119 additions and 646 deletions.
34 changes: 27 additions & 7 deletions optimisation/03_routing_and_scheduling_part1.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,16 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"# Calculating the length of a tour"
"# Calculating the length of a tour\n",
"\n",
"To calculate the length of a tour you can use either `SimpleTSPObjective` or `OptimisedSimpleTSPObjective`. For larger problems (e.g. a 70 city) problem you should find that `OptimisedSimpleTSPObjective` offers an efficiency boost (it runs quicker). But for smaller problems the overhead to set up the optimised approach means that `SimpleTSPObjective` is more efficient!\n",
"\n",
"The code below illustrates how to create each type of objective and how to use them to cost a tour. If you are interested try changing the tour size (up to a max of 70) and executing the code. It will report an average runtime.\n",
"\n",
"```python\n",
"#create a tour with 8 cities.\n",
"tour = np.arange(8)\n",
"```"
]
},
{
Expand All @@ -278,8 +287,11 @@
"metadata": {},
"outputs": [],
"source": [
"objective = SimpleTSPObjective(matrix)\n",
"objective.evaluate(tour)"
"#create a tour\n",
"rng = np.random.default_rng(seed=42)\n",
"tour = np.arange(8)\n",
"rng.shuffle(tour)\n",
"tour"
]
},
{
Expand All @@ -288,10 +300,9 @@
"metadata": {},
"outputs": [],
"source": [
"rng = np.random.default_rng(seed=42)\n",
"tour = np.arange(8)\n",
"rng.shuffle(tour)\n",
"tour"
"#create an instance of an objective object and cost a tour.\n",
"objective = SimpleTSPObjective(matrix)\n",
"objective.evaluate(tour)"
]
},
{
Expand All @@ -309,10 +320,19 @@
"metadata": {},
"outputs": [],
"source": [
"#create an instance of an optimised objective function\n",
"objective2 = OptimisedSimpleTSPObjective(matrix)\n",
"objective2.evaluate(tour)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The following code run the `evaluate` method multiple times and reports average execution speed.\n",
"This will vary by the system you are using and by the size of the problem instance."
]
},
{
"cell_type": "code",
"execution_count": null,
Expand Down
Loading

0 comments on commit ef3cdc9

Please sign in to comment.