mirror of
https://github.com/fverdugo/XM_40017.git
synced 2025-11-24 09:24:32 +01:00
Clear outputs
This commit is contained in:
@@ -38,21 +38,10 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 43,
|
||||
"execution_count": null,
|
||||
"id": "7e93809a",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"tsp_check_3 (generic function with 1 method)"
|
||||
]
|
||||
},
|
||||
"execution_count": 43,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"using Printf\n",
|
||||
"function answer_checker(answer,solution)\n",
|
||||
@@ -194,18 +183,10 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 25,
|
||||
"execution_count": null,
|
||||
"id": "ce2f2c8a",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"It's not correct. Keep trying! 💪\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"answer = -1 # Replace this with any positive integer value\n",
|
||||
"tsp_check_1(answer)"
|
||||
@@ -231,21 +212,10 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 9,
|
||||
"execution_count": null,
|
||||
"id": "a50706bc",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"sort_neighbors (generic function with 1 method)"
|
||||
]
|
||||
},
|
||||
"execution_count": 9,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"function sort_neighbors(C)\n",
|
||||
" n = size(C,1)\n",
|
||||
@@ -260,25 +230,10 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 3,
|
||||
"execution_count": null,
|
||||
"id": "2eeecdd6",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"4×4 Matrix{Int64}:\n",
|
||||
" 0 2 3 2\n",
|
||||
" 2 0 4 1\n",
|
||||
" 3 4 0 3\n",
|
||||
" 2 1 3 0"
|
||||
]
|
||||
},
|
||||
"execution_count": 3,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"C = [\n",
|
||||
" 0 2 3 2\n",
|
||||
@@ -298,25 +253,10 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 4,
|
||||
"execution_count": null,
|
||||
"id": "6dd0288e",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"4-element Vector{Vector{Tuple{Int64, Int64}}}:\n",
|
||||
" [(1, 0), (2, 2), (4, 2), (3, 3)]\n",
|
||||
" [(2, 0), (4, 1), (1, 2), (3, 4)]\n",
|
||||
" [(3, 0), (1, 3), (4, 3), (2, 4)]\n",
|
||||
" [(4, 0), (2, 1), (1, 2), (3, 3)]"
|
||||
]
|
||||
},
|
||||
"execution_count": 4,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"C_sorted = sort_neighbors(C)"
|
||||
]
|
||||
@@ -331,27 +271,12 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 5,
|
||||
"execution_count": null,
|
||||
"id": "00608e1d",
|
||||
"metadata": {
|
||||
"scrolled": true
|
||||
},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"4-element Vector{Tuple{Int64, Int64}}:\n",
|
||||
" (3, 0)\n",
|
||||
" (1, 3)\n",
|
||||
" (4, 3)\n",
|
||||
" (2, 4)"
|
||||
]
|
||||
},
|
||||
"execution_count": 5,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"city = 3\n",
|
||||
"C_sorted[city]"
|
||||
@@ -390,21 +315,10 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 6,
|
||||
"execution_count": null,
|
||||
"id": "2ddc2ec1",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"visit_all_paths_recursive! (generic function with 1 method)"
|
||||
]
|
||||
},
|
||||
"execution_count": 6,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"function visit_all_paths(C_sorted,city)\n",
|
||||
" # Initialize path\n",
|
||||
@@ -438,23 +352,10 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 7,
|
||||
"execution_count": null,
|
||||
"id": "723a0f1a",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"[1, 2, 4, 3]\n",
|
||||
"[1, 2, 3, 4]\n",
|
||||
"[1, 4, 2, 3]\n",
|
||||
"[1, 4, 3, 2]\n",
|
||||
"[1, 3, 4, 2]\n",
|
||||
"[1, 3, 2, 4]\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"city = 1\n",
|
||||
"visit_all_paths(C_sorted,city)"
|
||||
@@ -487,21 +388,10 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 8,
|
||||
"execution_count": null,
|
||||
"id": "5989f0ac",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"tsp_serial_no_prune_recursive! (generic function with 1 method)"
|
||||
]
|
||||
},
|
||||
"execution_count": 8,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"function tsp_serial_no_prune(C_sorted,city)\n",
|
||||
" num_cities = length(C_sorted)\n",
|
||||
@@ -540,21 +430,10 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 9,
|
||||
"execution_count": null,
|
||||
"id": "d1be2bfc",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"6"
|
||||
]
|
||||
},
|
||||
"execution_count": 9,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"city = 1\n",
|
||||
"min_distance = tsp_serial_no_prune(C_sorted,city)"
|
||||
@@ -587,21 +466,10 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 38,
|
||||
"execution_count": null,
|
||||
"id": "8241e0df",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"tsp_serial_recursive! (generic function with 1 method)"
|
||||
]
|
||||
},
|
||||
"execution_count": 38,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"function tsp_serial(C_sorted,city)\n",
|
||||
" num_cities = length(C_sorted)\n",
|
||||
@@ -644,21 +512,10 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 11,
|
||||
"execution_count": null,
|
||||
"id": "998087f2",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"6"
|
||||
]
|
||||
},
|
||||
"execution_count": 11,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"city = 1\n",
|
||||
"min_distance = tsp_serial(C_sorted,city)"
|
||||
@@ -675,25 +532,10 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 41,
|
||||
"execution_count": null,
|
||||
"id": "e1eb74d8",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"ename": "LoadError",
|
||||
"evalue": "UndefVarError: `tsp_serial_no_prune` not defined",
|
||||
"output_type": "error",
|
||||
"traceback": [
|
||||
"UndefVarError: `tsp_serial_no_prune` not defined",
|
||||
"",
|
||||
"Stacktrace:",
|
||||
" [1] top-level scope",
|
||||
" @ .\\timing.jl:273 [inlined]",
|
||||
" [2] top-level scope",
|
||||
" @ .\\In[41]:0"
|
||||
]
|
||||
}
|
||||
],
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"n = 12 # It is safe to test up to n=12\n",
|
||||
"using Random\n",
|
||||
@@ -837,18 +679,10 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 2,
|
||||
"execution_count": null,
|
||||
"id": "95e952af",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"It's not correct. Keep trying! 💪\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"answer = -1 # Replace with any integer value \n",
|
||||
"tsp_check_2(answer)"
|
||||
@@ -879,18 +713,10 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 46,
|
||||
"execution_count": null,
|
||||
"id": "fff58498",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"It's not correct. Keep trying! 💪\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"answer = \"x\" # Replace x with a,b,c or d\n",
|
||||
"tsp_check_3(answer)"
|
||||
@@ -940,7 +766,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 10,
|
||||
"execution_count": null,
|
||||
"id": "354f5abb",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
@@ -950,7 +776,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 11,
|
||||
"execution_count": null,
|
||||
"id": "7f8f6702",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
@@ -972,7 +798,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 15,
|
||||
"execution_count": null,
|
||||
"id": "5c0603a1",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
@@ -1048,26 +874,10 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 32,
|
||||
"execution_count": null,
|
||||
"id": "02801b66",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"path = [1, 2, 0, 0]\n",
|
||||
"path = [1, 4, 0, 0]\n",
|
||||
"path = [1, 3, 0, 0]\n",
|
||||
" From worker 2:\tpath = [1, 2, 4, 3]\n",
|
||||
" From worker 3:\tpath = [1, 4, 2, 3]\n",
|
||||
" From worker 4:\tpath = [1, 3, 4, 2]\n",
|
||||
" From worker 4:\tpath = [1, 3, 2, 4]\n",
|
||||
" From worker 2:\tpath = [1, 2, 3, 4]\n",
|
||||
" From worker 3:\tpath = [1, 4, 3, 2]\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"C = [\n",
|
||||
" 0 2 3 2\n",
|
||||
@@ -1117,24 +927,10 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 34,
|
||||
"execution_count": null,
|
||||
"id": "d0303392",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
" From worker 3:\tmin_distance = 9223372036854775807\n",
|
||||
" From worker 3:\tdistance = 10\n",
|
||||
" From worker 2:\tmin_distance = 10\n",
|
||||
" From worker 2:\tdistance = 5\n",
|
||||
" From worker 4:\tmin_distance = 5\n",
|
||||
" From worker 4:\tdistance = 6\n",
|
||||
"min_distance = 5\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"buffer = 1 # Very important\n",
|
||||
"min_distance_chnl = RemoteChannel(()->Channel{Int}(buffer))\n",
|
||||
@@ -1166,7 +962,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 35,
|
||||
"execution_count": null,
|
||||
"id": "96c649b7",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
@@ -1260,21 +1056,10 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 36,
|
||||
"execution_count": null,
|
||||
"id": "67888155",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"6"
|
||||
]
|
||||
},
|
||||
"execution_count": 36,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"city = 1\n",
|
||||
"max_hops = 2\n",
|
||||
@@ -1292,32 +1077,10 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 42,
|
||||
"execution_count": null,
|
||||
"id": "9d950905",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Sequential time = 39.7130992\n",
|
||||
"Parallel time = 17.0584423\n",
|
||||
"Speedup = 2.328061290801447\n",
|
||||
"Optimal speedup = 3\n",
|
||||
"Efficiency = 77.6020430267149%\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"\u001b[32m\u001b[1mTest Passed\u001b[22m\u001b[39m"
|
||||
]
|
||||
},
|
||||
"execution_count": 42,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"n = 18 # Safe to run up to 18\n",
|
||||
"using Random\n",
|
||||
|
||||
Reference in New Issue
Block a user