Created
April 7, 2020 14:53
-
-
Save Vini2/f13a1fc6776319416982a7105844dc27 to your computer and use it in GitHub Desktop.
Python-igraph Example
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": "markdown", | |
"metadata": {}, | |
"source": [ | |
"# Python-igraph Example\n", | |
"## 1. Creating a graph" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 1, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"from igraph import *\n", | |
"\n", | |
"# Create graph\n", | |
"g = Graph(directed=True)\n", | |
"\n", | |
"# Add 5 vertices\n", | |
"g.add_vertices(5)\n", | |
"\n", | |
"# Add ids and labels to vertices\n", | |
"for i in range(len(g.vs)):\n", | |
" g.vs[i][\"id\"]= i\n", | |
" g.vs[i][\"label\"]= str(i)\n", | |
"\n", | |
"# Add edges\n", | |
"g.add_edges([(0,2),(0,1),(0,3),(1,2),(1,3),(2,4),(3,4)])\n", | |
"\n", | |
"# Add weights and edge labels\n", | |
"weights = [8,6,3,5,6,4,9]\n", | |
"g.es['weight'] = weights\n", | |
"g.es['label'] = weights" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"## 2. Visualising the graph" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 3, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"image/svg+xml": [ | |
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n", | |
"<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"400pt\" height=\"400pt\" viewBox=\"0 0 400 400\" version=\"1.1\">\n", | |
"<defs>\n", | |
"<g>\n", | |
"<symbol overflow=\"visible\" id=\"glyph0-0\">\n", | |
"<path style=\"stroke:none;\" d=\"\"/>\n", | |
"</symbol>\n", | |
"<symbol overflow=\"visible\" id=\"glyph0-1\">\n", | |
"<path style=\"stroke:none;\" d=\"M 5.953125 -15.382812 C 7.941406 -15.382812 9.382812 -14.5625 10.269531 -12.921875 C 10.957031 -11.65625 11.300781 -9.917969 11.300781 -7.710938 C 11.300781 -5.621094 10.988281 -3.890625 10.367188 -2.523438 C 9.464844 -0.5625 7.988281 0.417969 5.941406 0.417969 C 4.09375 0.417969 2.71875 -0.382812 1.816406 -1.988281 C 1.0625 -3.328125 0.6875 -5.125 0.6875 -7.378906 C 0.6875 -9.125 0.914062 -10.628906 1.363281 -11.882812 C 2.210938 -14.214844 3.738281 -15.382812 5.953125 -15.382812 Z M 5.929688 -1.34375 C 6.933594 -1.34375 7.730469 -1.785156 8.324219 -2.675781 C 8.917969 -3.5625 9.21875 -5.21875 9.21875 -7.636719 C 9.21875 -9.382812 9 -10.824219 8.570312 -11.949219 C 8.140625 -13.078125 7.308594 -13.640625 6.070312 -13.640625 C 4.929688 -13.640625 4.097656 -13.105469 3.570312 -12.035156 C 3.046875 -10.964844 2.78125 -9.390625 2.78125 -7.304688 C 2.78125 -5.734375 2.949219 -4.476562 3.289062 -3.523438 C 3.804688 -2.070312 4.683594 -1.34375 5.929688 -1.34375 Z M 5.929688 -1.34375 \"/>\n", | |
"</symbol>\n", | |
"<symbol overflow=\"visible\" id=\"glyph0-2\">\n", | |
"<path style=\"stroke:none;\" d=\"M 2.105469 -10.890625 L 2.105469 -12.375 C 3.5 -12.511719 4.476562 -12.738281 5.027344 -13.058594 C 5.578125 -13.375 5.992188 -14.128906 6.261719 -15.320312 L 7.789062 -15.320312 L 7.789062 0 L 5.726562 0 L 5.726562 -10.890625 Z M 2.105469 -10.890625 \"/>\n", | |
"</symbol>\n", | |
"<symbol overflow=\"visible\" id=\"glyph0-3\">\n", | |
"<path style=\"stroke:none;\" d=\"M 0.6875 0 C 0.757812 -1.324219 1.03125 -2.476562 1.507812 -3.460938 C 1.984375 -4.441406 2.914062 -5.332031 4.296875 -6.132812 L 6.359375 -7.328125 C 7.28125 -7.863281 7.929688 -8.320312 8.304688 -8.703125 C 8.890625 -9.296875 9.183594 -9.976562 9.183594 -10.742188 C 9.183594 -11.636719 8.914062 -12.347656 8.378906 -12.875 C 7.84375 -13.402344 7.125 -13.664062 6.230469 -13.664062 C 4.90625 -13.664062 3.988281 -13.164062 3.480469 -12.160156 C 3.207031 -11.625 3.058594 -10.878906 3.03125 -9.925781 L 1.0625 -9.925781 C 1.085938 -11.265625 1.332031 -12.355469 1.804688 -13.203125 C 2.640625 -14.691406 4.121094 -15.4375 6.242188 -15.4375 C 8.003906 -15.4375 9.289062 -14.960938 10.101562 -14.007812 C 10.914062 -13.054688 11.320312 -11.996094 11.320312 -10.828125 C 11.320312 -9.597656 10.890625 -8.542969 10.023438 -7.671875 C 9.523438 -7.164062 8.621094 -6.546875 7.328125 -5.820312 L 5.855469 -5.007812 C 5.152344 -4.621094 4.601562 -4.25 4.199219 -3.898438 C 3.484375 -3.277344 3.03125 -2.585938 2.847656 -1.828125 L 11.246094 -1.828125 L 11.246094 0 Z M 0.6875 0 \"/>\n", | |
"</symbol>\n", | |
"<symbol overflow=\"visible\" id=\"glyph0-4\">\n", | |
"<path style=\"stroke:none;\" d=\"M 5.714844 0.417969 C 3.894531 0.417969 2.578125 -0.0820312 1.757812 -1.078125 C 0.9375 -2.078125 0.527344 -3.292969 0.527344 -4.726562 L 2.546875 -4.726562 C 2.632812 -3.730469 2.816406 -3.007812 3.105469 -2.554688 C 3.605469 -1.746094 4.511719 -1.34375 5.820312 -1.34375 C 6.839844 -1.34375 7.65625 -1.613281 8.273438 -2.160156 C 8.886719 -2.703125 9.195312 -3.40625 9.195312 -4.265625 C 9.195312 -5.324219 8.871094 -6.066406 8.222656 -6.488281 C 7.574219 -6.910156 6.675781 -7.121094 5.523438 -7.121094 C 5.394531 -7.121094 5.261719 -7.121094 5.128906 -7.117188 C 4.996094 -7.113281 4.863281 -7.109375 4.726562 -7.101562 L 4.726562 -8.808594 C 4.925781 -8.789062 5.09375 -8.773438 5.230469 -8.765625 C 5.367188 -8.757812 5.515625 -8.753906 5.671875 -8.753906 C 6.394531 -8.753906 6.988281 -8.871094 7.453125 -9.097656 C 8.269531 -9.5 8.679688 -10.214844 8.679688 -11.246094 C 8.679688 -12.011719 8.40625 -12.605469 7.863281 -13.019531 C 7.320312 -13.433594 6.683594 -13.640625 5.960938 -13.640625 C 4.671875 -13.640625 3.78125 -13.210938 3.289062 -12.351562 C 3.015625 -11.878906 2.859375 -11.207031 2.824219 -10.335938 L 0.914062 -10.335938 C 0.914062 -11.480469 1.140625 -12.453125 1.601562 -13.257812 C 2.390625 -14.6875 3.773438 -15.40625 5.757812 -15.40625 C 7.328125 -15.40625 8.539062 -15.054688 9.398438 -14.355469 C 10.257812 -13.65625 10.6875 -12.648438 10.6875 -11.320312 C 10.6875 -10.375 10.433594 -9.609375 9.925781 -9.023438 C 9.609375 -8.65625 9.203125 -8.371094 8.703125 -8.164062 C 9.511719 -7.941406 10.140625 -7.515625 10.597656 -6.878906 C 11.050781 -6.246094 11.28125 -5.472656 11.28125 -4.554688 C 11.28125 -3.085938 10.796875 -1.890625 9.828125 -0.96875 C 8.863281 -0.0429688 7.492188 0.417969 5.714844 0.417969 Z M 5.714844 0.417969 \"/>\n", | |
"</symbol>\n", | |
"<symbol overflow=\"visible\" id=\"glyph0-5\">\n", | |
"<path style=\"stroke:none;\" d=\"M 7.273438 -5.445312 L 7.273438 -12.417969 L 2.34375 -5.445312 Z M 7.304688 0 L 7.304688 -3.757812 L 0.558594 -3.757812 L 0.558594 -5.648438 L 7.605469 -15.425781 L 9.238281 -15.425781 L 9.238281 -5.445312 L 11.503906 -5.445312 L 11.503906 -3.757812 L 9.238281 -3.757812 L 9.238281 0 Z M 7.304688 0 \"/>\n", | |
"</symbol>\n", | |
"<symbol overflow=\"visible\" id=\"glyph1-0\">\n", | |
"<path style=\"stroke:none;\" d=\"\"/>\n", | |
"</symbol>\n", | |
"<symbol overflow=\"visible\" id=\"glyph1-1\">\n", | |
"<path style=\"stroke:none;\" d=\"M 3.265625 -4.875 C 3.730469 -4.875 4.09375 -5.003906 4.351562 -5.265625 C 4.613281 -5.523438 4.746094 -5.835938 4.746094 -6.195312 C 4.746094 -6.507812 4.621094 -6.792969 4.371094 -7.054688 C 4.121094 -7.316406 3.742188 -7.445312 3.226562 -7.445312 C 2.71875 -7.445312 2.351562 -7.316406 2.125 -7.054688 C 1.898438 -6.792969 1.789062 -6.484375 1.789062 -6.132812 C 1.789062 -5.738281 1.933594 -5.429688 2.226562 -5.210938 C 2.519531 -4.988281 2.867188 -4.875 3.265625 -4.875 Z M 3.328125 -0.71875 C 3.816406 -0.71875 4.222656 -0.851562 4.542969 -1.117188 C 4.867188 -1.378906 5.027344 -1.773438 5.027344 -2.296875 C 5.027344 -2.839844 4.859375 -3.25 4.53125 -3.53125 C 4.199219 -3.8125 3.773438 -3.953125 3.25 -3.953125 C 2.746094 -3.953125 2.335938 -3.8125 2.019531 -3.523438 C 1.699219 -3.238281 1.539062 -2.839844 1.539062 -2.332031 C 1.539062 -1.894531 1.6875 -1.515625 1.976562 -1.199219 C 2.269531 -0.878906 2.71875 -0.71875 3.328125 -0.71875 Z M 1.828125 -4.46875 C 1.535156 -4.59375 1.304688 -4.742188 1.140625 -4.910156 C 0.832031 -5.222656 0.679688 -5.628906 0.679688 -6.128906 C 0.679688 -6.753906 0.90625 -7.289062 1.359375 -7.742188 C 1.8125 -8.191406 2.453125 -8.414062 3.289062 -8.414062 C 4.09375 -8.414062 4.722656 -8.203125 5.179688 -7.777344 C 5.636719 -7.355469 5.867188 -6.859375 5.867188 -6.292969 C 5.867188 -5.769531 5.734375 -5.34375 5.46875 -5.023438 C 5.320312 -4.839844 5.085938 -4.65625 4.773438 -4.484375 C 5.121094 -4.324219 5.398438 -4.140625 5.59375 -3.929688 C 5.964844 -3.539062 6.152344 -3.03125 6.152344 -2.40625 C 6.152344 -1.667969 5.90625 -1.042969 5.40625 -0.53125 C 4.910156 -0.015625 4.210938 0.242188 3.304688 0.242188 C 2.488281 0.242188 1.796875 0.0195312 1.234375 -0.425781 C 0.667969 -0.867188 0.386719 -1.511719 0.386719 -2.355469 C 0.386719 -2.851562 0.507812 -3.28125 0.75 -3.640625 C 0.992188 -4.003906 1.351562 -4.28125 1.828125 -4.46875 Z M 1.828125 -4.46875 \"/>\n", | |
"</symbol>\n", | |
"<symbol overflow=\"visible\" id=\"glyph1-2\">\n", | |
"<path style=\"stroke:none;\" d=\"M 3.507812 -8.425781 C 4.445312 -8.425781 5.101562 -8.183594 5.46875 -7.695312 C 5.839844 -7.210938 6.023438 -6.710938 6.023438 -6.195312 L 4.980469 -6.195312 C 4.917969 -6.527344 4.820312 -6.785156 4.679688 -6.972656 C 4.425781 -7.324219 4.042969 -7.5 3.527344 -7.5 C 2.9375 -7.5 2.46875 -7.226562 2.121094 -6.683594 C 1.773438 -6.136719 1.578125 -5.359375 1.539062 -4.34375 C 1.78125 -4.699219 2.085938 -4.960938 2.453125 -5.140625 C 2.789062 -5.296875 3.164062 -5.375 3.578125 -5.375 C 4.28125 -5.375 4.898438 -5.148438 5.421875 -4.699219 C 5.945312 -4.25 6.203125 -3.578125 6.203125 -2.6875 C 6.203125 -1.925781 5.957031 -1.253906 5.460938 -0.664062 C 4.964844 -0.078125 4.257812 0.21875 3.339844 0.21875 C 2.554688 0.21875 1.875 -0.0820312 1.304688 -0.675781 C 0.734375 -1.273438 0.453125 -2.273438 0.453125 -3.6875 C 0.453125 -4.730469 0.578125 -5.613281 0.832031 -6.339844 C 1.320312 -7.730469 2.210938 -8.425781 3.507812 -8.425781 Z M 3.433594 -0.71875 C 3.988281 -0.71875 4.402344 -0.90625 4.679688 -1.28125 C 4.953125 -1.652344 5.09375 -2.09375 5.09375 -2.601562 C 5.09375 -3.03125 4.96875 -3.441406 4.722656 -3.828125 C 4.476562 -4.21875 4.03125 -4.414062 3.382812 -4.414062 C 2.929688 -4.414062 2.53125 -4.261719 2.1875 -3.960938 C 1.847656 -3.660156 1.675781 -3.207031 1.675781 -2.601562 C 1.675781 -2.070312 1.832031 -1.625 2.140625 -1.261719 C 2.453125 -0.902344 2.882812 -0.71875 3.433594 -0.71875 Z M 3.433594 -0.71875 \"/>\n", | |
"</symbol>\n", | |
"<symbol overflow=\"visible\" id=\"glyph1-3\">\n", | |
"<path style=\"stroke:none;\" d=\"M 3.117188 0.226562 C 2.125 0.226562 1.40625 -0.0429688 0.957031 -0.589844 C 0.511719 -1.132812 0.289062 -1.796875 0.289062 -2.578125 L 1.390625 -2.578125 C 1.4375 -2.035156 1.539062 -1.640625 1.695312 -1.394531 C 1.96875 -0.953125 2.460938 -0.734375 3.175781 -0.734375 C 3.730469 -0.734375 4.175781 -0.882812 4.511719 -1.179688 C 4.847656 -1.476562 5.015625 -1.859375 5.015625 -2.328125 C 5.015625 -2.90625 4.839844 -3.308594 4.484375 -3.539062 C 4.132812 -3.769531 3.640625 -3.882812 3.011719 -3.882812 C 2.941406 -3.882812 2.871094 -3.882812 2.796875 -3.882812 C 2.726562 -3.878906 2.652344 -3.875 2.578125 -3.875 L 2.578125 -4.804688 C 2.6875 -4.792969 2.78125 -4.785156 2.851562 -4.78125 C 2.925781 -4.777344 3.007812 -4.773438 3.09375 -4.773438 C 3.488281 -4.773438 3.8125 -4.835938 4.066406 -4.960938 C 4.511719 -5.179688 4.734375 -5.570312 4.734375 -6.132812 C 4.734375 -6.550781 4.585938 -6.875 4.289062 -7.101562 C 3.992188 -7.328125 3.648438 -7.441406 3.25 -7.441406 C 2.546875 -7.441406 2.0625 -7.207031 1.792969 -6.738281 C 1.644531 -6.480469 1.5625 -6.113281 1.539062 -5.636719 L 0.5 -5.636719 C 0.5 -6.261719 0.625 -6.792969 0.875 -7.230469 C 1.304688 -8.011719 2.058594 -8.402344 3.140625 -8.402344 C 3.996094 -8.402344 4.65625 -8.210938 5.125 -7.832031 C 5.59375 -7.449219 5.828125 -6.898438 5.828125 -6.175781 C 5.828125 -5.660156 5.691406 -5.242188 5.414062 -4.921875 C 5.242188 -4.722656 5.019531 -4.566406 4.746094 -4.453125 C 5.1875 -4.332031 5.53125 -4.097656 5.78125 -3.753906 C 6.027344 -3.40625 6.152344 -2.984375 6.152344 -2.484375 C 6.152344 -1.683594 5.890625 -1.03125 5.359375 -0.527344 C 4.832031 -0.0234375 4.085938 0.226562 3.117188 0.226562 Z M 3.117188 0.226562 \"/>\n", | |
"</symbol>\n", | |
"<symbol overflow=\"visible\" id=\"glyph1-4\">\n", | |
"<path style=\"stroke:none;\" d=\"M 1.484375 -2.140625 C 1.554688 -1.539062 1.832031 -1.121094 2.320312 -0.890625 C 2.570312 -0.773438 2.859375 -0.714844 3.1875 -0.714844 C 3.8125 -0.714844 4.273438 -0.914062 4.578125 -1.3125 C 4.878906 -1.710938 5.027344 -2.152344 5.027344 -2.636719 C 5.027344 -3.222656 4.847656 -3.675781 4.492188 -3.996094 C 4.132812 -4.316406 3.703125 -4.476562 3.203125 -4.476562 C 2.839844 -4.476562 2.53125 -4.40625 2.269531 -4.265625 C 2.011719 -4.125 1.789062 -3.929688 1.605469 -3.679688 L 0.691406 -3.734375 L 1.328125 -8.25 L 5.6875 -8.25 L 5.6875 -7.230469 L 2.121094 -7.230469 L 1.765625 -4.898438 C 1.960938 -5.046875 2.144531 -5.15625 2.320312 -5.234375 C 2.632812 -5.363281 2.992188 -5.425781 3.40625 -5.425781 C 4.175781 -5.425781 4.828125 -5.179688 5.359375 -4.679688 C 5.894531 -4.183594 6.164062 -3.554688 6.164062 -2.796875 C 6.164062 -2.003906 5.917969 -1.304688 5.429688 -0.695312 C 4.9375 -0.0898438 4.15625 0.210938 3.082031 0.210938 C 2.398438 0.210938 1.792969 0.0195312 1.269531 -0.367188 C 0.742188 -0.75 0.449219 -1.34375 0.386719 -2.140625 Z M 1.484375 -2.140625 \"/>\n", | |
"</symbol>\n", | |
"<symbol overflow=\"visible\" id=\"glyph1-5\">\n", | |
"<path style=\"stroke:none;\" d=\"M 3.96875 -2.96875 L 3.96875 -6.773438 L 1.277344 -2.96875 Z M 3.984375 0 L 3.984375 -2.050781 L 0.304688 -2.050781 L 0.304688 -3.082031 L 4.148438 -8.414062 L 5.039062 -8.414062 L 5.039062 -2.96875 L 6.273438 -2.96875 L 6.273438 -2.050781 L 5.039062 -2.050781 L 5.039062 0 Z M 3.984375 0 \"/>\n", | |
"</symbol>\n", | |
"<symbol overflow=\"visible\" id=\"glyph1-6\">\n", | |
"<path style=\"stroke:none;\" d=\"M 1.59375 -2.027344 C 1.625 -1.445312 1.851562 -1.042969 2.265625 -0.820312 C 2.480469 -0.703125 2.726562 -0.644531 2.992188 -0.644531 C 3.496094 -0.644531 3.929688 -0.855469 4.28125 -1.273438 C 4.636719 -1.695312 4.890625 -2.546875 5.039062 -3.832031 C 4.804688 -3.460938 4.515625 -3.199219 4.167969 -3.050781 C 3.824219 -2.898438 3.453125 -2.824219 3.054688 -2.824219 C 2.246094 -2.824219 1.605469 -3.078125 1.132812 -3.578125 C 0.664062 -4.082031 0.429688 -4.734375 0.429688 -5.523438 C 0.429688 -6.285156 0.660156 -6.957031 1.125 -7.535156 C 1.589844 -8.113281 2.273438 -8.402344 3.179688 -8.402344 C 4.402344 -8.402344 5.25 -7.851562 5.710938 -6.75 C 5.96875 -6.144531 6.101562 -5.386719 6.101562 -4.476562 C 6.101562 -3.449219 5.945312 -2.539062 5.636719 -1.746094 C 5.125 -0.425781 4.257812 0.234375 3.035156 0.234375 C 2.214844 0.234375 1.59375 0.0195312 1.164062 -0.410156 C 0.738281 -0.839844 0.527344 -1.378906 0.527344 -2.027344 Z M 3.195312 -3.75 C 3.613281 -3.75 3.992188 -3.886719 4.339844 -4.164062 C 4.683594 -4.4375 4.859375 -4.921875 4.859375 -5.609375 C 4.859375 -6.226562 4.703125 -6.683594 4.390625 -6.988281 C 4.082031 -7.289062 3.6875 -7.441406 3.203125 -7.441406 C 2.6875 -7.441406 2.28125 -7.269531 1.976562 -6.921875 C 1.675781 -6.578125 1.523438 -6.117188 1.523438 -5.539062 C 1.523438 -4.992188 1.65625 -4.554688 1.921875 -4.234375 C 2.1875 -3.910156 2.609375 -3.75 3.195312 -3.75 Z M 3.195312 -3.75 \"/>\n", | |
"</symbol>\n", | |
"</g>\n", | |
"</defs>\n", | |
"<g id=\"surface43\">\n", | |
"<rect x=\"0\" y=\"0\" width=\"400\" height=\"400\" style=\"fill:rgb(100%,100%,100%);fill-opacity:1;stroke:none;\"/>\n", | |
"<path style=\"fill:none;stroke-width:1;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(26.666667%,26.666667%,26.666667%);stroke-opacity:1;stroke-miterlimit:10;\" d=\"M 219.792969 373 L 349.632812 215.277344 \"/>\n", | |
"<path style=\" stroke:none;fill-rule:nonzero;fill:rgb(26.666667%,26.666667%,26.666667%);fill-opacity:1;\" d=\"M 358.699219 204.261719 L 353.210938 218.222656 L 346.054688 212.328125 L 358.699219 204.261719 \"/>\n", | |
"<path style=\"fill:none;stroke-width:1;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(26.666667%,26.666667%,26.666667%);stroke-opacity:1;stroke-miterlimit:10;\" d=\"M 219.792969 373 L 208.976562 277.585938 \"/>\n", | |
"<path style=\" stroke:none;fill-rule:nonzero;fill:rgb(26.666667%,26.666667%,26.666667%);fill-opacity:1;\" d=\"M 207.371094 263.410156 L 213.582031 277.0625 L 204.371094 278.105469 L 207.371094 263.410156 \"/>\n", | |
"<path style=\"fill:none;stroke-width:1;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(26.666667%,26.666667%,26.666667%);stroke-opacity:1;stroke-miterlimit:10;\" d=\"M 219.792969 373 L 55.28125 236.34375 \"/>\n", | |
"<path style=\" stroke:none;fill-rule:nonzero;fill:rgb(26.666667%,26.666667%,26.666667%);fill-opacity:1;\" d=\"M 44.308594 227.226562 L 58.242188 232.777344 L 52.320312 239.910156 L 44.308594 227.226562 \"/>\n", | |
"<path style=\"fill:none;stroke-width:1;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(26.666667%,26.666667%,26.666667%);stroke-opacity:1;stroke-miterlimit:10;\" d=\"M 204.835938 241.054688 L 338.003906 198.160156 \"/>\n", | |
"<path style=\" stroke:none;fill-rule:nonzero;fill:rgb(26.666667%,26.666667%,26.666667%);fill-opacity:1;\" d=\"M 351.582031 193.789062 L 339.425781 202.574219 L 336.582031 193.75 L 351.582031 193.789062 \"/>\n", | |
"<path style=\"fill:none;stroke-width:1;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(26.666667%,26.666667%,26.666667%);stroke-opacity:1;stroke-miterlimit:10;\" d=\"M 204.835938 241.054688 L 63.3125 218.609375 \"/>\n", | |
"<path style=\" stroke:none;fill-rule:nonzero;fill:rgb(26.666667%,26.666667%,26.666667%);fill-opacity:1;\" d=\"M 49.222656 216.375 L 64.039062 214.03125 L 62.585938 223.1875 L 49.222656 216.375 \"/>\n", | |
"<path style=\"fill:none;stroke-width:1;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(26.666667%,26.666667%,26.666667%);stroke-opacity:1;stroke-miterlimit:10;\" d=\"M 373 186.890625 L 208.3125 50.457031 \"/>\n", | |
"<path style=\" stroke:none;fill-rule:nonzero;fill:rgb(26.666667%,26.666667%,26.666667%);fill-opacity:1;\" d=\"M 197.328125 41.355469 L 211.269531 46.886719 L 205.355469 54.023438 L 197.328125 41.355469 \"/>\n", | |
"<path style=\"fill:none;stroke-width:1;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(26.666667%,26.666667%,26.666667%);stroke-opacity:1;stroke-miterlimit:10;\" d=\"M 27 212.851562 L 156.632812 55.382812 \"/>\n", | |
"<path style=\" stroke:none;fill-rule:nonzero;fill:rgb(26.666667%,26.666667%,26.666667%);fill-opacity:1;\" d=\"M 165.699219 44.371094 L 160.210938 58.332031 L 153.054688 52.4375 L 165.699219 44.371094 \"/>\n", | |
"<path style=\"fill-rule:nonzero;fill:rgb(100%,100%,100%);fill-opacity:1;stroke-width:1;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-miterlimit:10;\" d=\"M 242.292969 373 C 242.292969 385.425781 232.21875 395.5 219.792969 395.5 C 207.367188 395.5 197.292969 385.425781 197.292969 373 C 197.292969 360.574219 207.367188 350.5 219.792969 350.5 C 232.21875 350.5 242.292969 360.574219 242.292969 373 \"/>\n", | |
"<path style=\"fill-rule:nonzero;fill:rgb(100%,100%,100%);fill-opacity:1;stroke-width:1;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-miterlimit:10;\" d=\"M 227.335938 241.054688 C 227.335938 253.480469 217.261719 263.554688 204.835938 263.554688 C 192.410156 263.554688 182.335938 253.480469 182.335938 241.054688 C 182.335938 228.625 192.410156 218.554688 204.835938 218.554688 C 217.261719 218.554688 227.335938 228.625 227.335938 241.054688 \"/>\n", | |
"<path style=\"fill-rule:nonzero;fill:rgb(100%,100%,100%);fill-opacity:1;stroke-width:1;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-miterlimit:10;\" d=\"M 395.5 186.890625 C 395.5 199.316406 385.425781 209.390625 373 209.390625 C 360.574219 209.390625 350.5 199.316406 350.5 186.890625 C 350.5 174.464844 360.574219 164.390625 373 164.390625 C 385.425781 164.390625 395.5 174.464844 395.5 186.890625 \"/>\n", | |
"<path style=\"fill-rule:nonzero;fill:rgb(100%,100%,100%);fill-opacity:1;stroke-width:1;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-miterlimit:10;\" d=\"M 49.5 212.851562 C 49.5 225.277344 39.425781 235.351562 27 235.351562 C 14.574219 235.351562 4.5 225.277344 4.5 212.851562 C 4.5 200.425781 14.574219 190.351562 27 190.351562 C 39.425781 190.351562 49.5 200.425781 49.5 212.851562 \"/>\n", | |
"<path style=\"fill-rule:nonzero;fill:rgb(100%,100%,100%);fill-opacity:1;stroke-width:1;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-miterlimit:10;\" d=\"M 202.5 27 C 202.5 39.425781 192.429688 49.5 180 49.5 C 167.574219 49.5 157.5 39.425781 157.5 27 C 157.5 14.574219 167.574219 4.5 180 4.5 C 192.429688 4.5 202.5 14.574219 202.5 27 \"/>\n", | |
"<g style=\"fill:rgb(0%,0%,0%);fill-opacity:1;\">\n", | |
" <use xlink:href=\"#glyph0-1\" x=\"213.800781\" y=\"383.222656\"/>\n", | |
"</g>\n", | |
"<g style=\"fill:rgb(0%,0%,0%);fill-opacity:1;\">\n", | |
" <use xlink:href=\"#glyph0-2\" x=\"199.890625\" y=\"251.242188\"/>\n", | |
"</g>\n", | |
"<g style=\"fill:rgb(0%,0%,0%);fill-opacity:1;\">\n", | |
" <use xlink:href=\"#glyph0-3\" x=\"366.996094\" y=\"197.136719\"/>\n", | |
"</g>\n", | |
"<g style=\"fill:rgb(0%,0%,0%);fill-opacity:1;\">\n", | |
" <use xlink:href=\"#glyph0-4\" x=\"21.097656\" y=\"223.082031\"/>\n", | |
"</g>\n", | |
"<g style=\"fill:rgb(0%,0%,0%);fill-opacity:1;\">\n", | |
" <use xlink:href=\"#glyph0-5\" x=\"173.96875\" y=\"37.242188\"/>\n", | |
"</g>\n", | |
"<g style=\"fill:rgb(0%,0%,0%);fill-opacity:1;\">\n", | |
" <use xlink:href=\"#glyph1-1\" x=\"290.246094\" y=\"285.53125\"/>\n", | |
"</g>\n", | |
"<g style=\"fill:rgb(0%,0%,0%);fill-opacity:1;\">\n", | |
" <use xlink:href=\"#glyph1-2\" x=\"206.109375\" y=\"312.621094\"/>\n", | |
"</g>\n", | |
"<g style=\"fill:rgb(0%,0%,0%);fill-opacity:1;\">\n", | |
" <use xlink:href=\"#glyph1-3\" x=\"117.246094\" y=\"304.925781\"/>\n", | |
"</g>\n", | |
"<g style=\"fill:rgb(0%,0%,0%);fill-opacity:1;\">\n", | |
" <use xlink:href=\"#glyph1-4\" x=\"282.753906\" y=\"208.855469\"/>\n", | |
"</g>\n", | |
"<g style=\"fill:rgb(0%,0%,0%);fill-opacity:1;\">\n", | |
" <use xlink:href=\"#glyph1-2\" x=\"109.710938\" y=\"238.953125\"/>\n", | |
"</g>\n", | |
"<g style=\"fill:rgb(0%,0%,0%);fill-opacity:1;\">\n", | |
" <use xlink:href=\"#glyph1-5\" x=\"270.226562\" y=\"118.945312\"/>\n", | |
"</g>\n", | |
"<g style=\"fill:rgb(0%,0%,0%);fill-opacity:1;\">\n", | |
" <use xlink:href=\"#glyph1-6\" x=\"97.402344\" y=\"125.507812\"/>\n", | |
"</g>\n", | |
"</g>\n", | |
"</svg>\n" | |
], | |
"text/plain": [ | |
"<igraph.drawing.Plot at 0x10a79b9e8>" | |
] | |
}, | |
"execution_count": 3, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"visual_style = {}\n", | |
"\n", | |
"out_name = \"graph.png\"\n", | |
"\n", | |
"# Set bbox and margin\n", | |
"visual_style[\"bbox\"] = (400,400)\n", | |
"visual_style[\"margin\"] = 27\n", | |
"\n", | |
"# Set vertex colours\n", | |
"visual_style[\"vertex_color\"] = 'white'\n", | |
"\n", | |
"# Set vertex size\n", | |
"visual_style[\"vertex_size\"] = 45\n", | |
"\n", | |
"# Set vertex lable size\n", | |
"visual_style[\"vertex_label_size\"] = 22\n", | |
"\n", | |
"# Don't curve the edges\n", | |
"visual_style[\"edge_curved\"] = False\n", | |
"\n", | |
"# Set the layout\n", | |
"my_layout = g.layout_lgl()\n", | |
"visual_style[\"layout\"] = my_layout\n", | |
"\n", | |
"# Plot the graph\n", | |
"plot(g, out_name, **visual_style)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 4, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"image/svg+xml": [ | |
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n", | |
"<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"400pt\" height=\"400pt\" viewBox=\"0 0 400 400\" version=\"1.1\">\n", | |
"<defs>\n", | |
"<g>\n", | |
"<symbol overflow=\"visible\" id=\"glyph0-0\">\n", | |
"<path style=\"stroke:none;\" d=\"\"/>\n", | |
"</symbol>\n", | |
"<symbol overflow=\"visible\" id=\"glyph0-1\">\n", | |
"<path style=\"stroke:none;\" d=\"M 5.953125 -15.382812 C 7.941406 -15.382812 9.382812 -14.5625 10.269531 -12.921875 C 10.957031 -11.65625 11.300781 -9.917969 11.300781 -7.710938 C 11.300781 -5.621094 10.988281 -3.890625 10.367188 -2.523438 C 9.464844 -0.5625 7.988281 0.417969 5.941406 0.417969 C 4.09375 0.417969 2.71875 -0.382812 1.816406 -1.988281 C 1.0625 -3.328125 0.6875 -5.125 0.6875 -7.378906 C 0.6875 -9.125 0.914062 -10.628906 1.363281 -11.882812 C 2.210938 -14.214844 3.738281 -15.382812 5.953125 -15.382812 Z M 5.929688 -1.34375 C 6.933594 -1.34375 7.730469 -1.785156 8.324219 -2.675781 C 8.917969 -3.5625 9.21875 -5.21875 9.21875 -7.636719 C 9.21875 -9.382812 9 -10.824219 8.570312 -11.949219 C 8.140625 -13.078125 7.308594 -13.640625 6.070312 -13.640625 C 4.929688 -13.640625 4.097656 -13.105469 3.570312 -12.035156 C 3.046875 -10.964844 2.78125 -9.390625 2.78125 -7.304688 C 2.78125 -5.734375 2.949219 -4.476562 3.289062 -3.523438 C 3.804688 -2.070312 4.683594 -1.34375 5.929688 -1.34375 Z M 5.929688 -1.34375 \"/>\n", | |
"</symbol>\n", | |
"<symbol overflow=\"visible\" id=\"glyph0-2\">\n", | |
"<path style=\"stroke:none;\" d=\"M 2.105469 -10.890625 L 2.105469 -12.375 C 3.5 -12.511719 4.476562 -12.738281 5.027344 -13.058594 C 5.578125 -13.375 5.992188 -14.128906 6.261719 -15.320312 L 7.789062 -15.320312 L 7.789062 0 L 5.726562 0 L 5.726562 -10.890625 Z M 2.105469 -10.890625 \"/>\n", | |
"</symbol>\n", | |
"<symbol overflow=\"visible\" id=\"glyph0-3\">\n", | |
"<path style=\"stroke:none;\" d=\"M 0.6875 0 C 0.757812 -1.324219 1.03125 -2.476562 1.507812 -3.460938 C 1.984375 -4.441406 2.914062 -5.332031 4.296875 -6.132812 L 6.359375 -7.328125 C 7.28125 -7.863281 7.929688 -8.320312 8.304688 -8.703125 C 8.890625 -9.296875 9.183594 -9.976562 9.183594 -10.742188 C 9.183594 -11.636719 8.914062 -12.347656 8.378906 -12.875 C 7.84375 -13.402344 7.125 -13.664062 6.230469 -13.664062 C 4.90625 -13.664062 3.988281 -13.164062 3.480469 -12.160156 C 3.207031 -11.625 3.058594 -10.878906 3.03125 -9.925781 L 1.0625 -9.925781 C 1.085938 -11.265625 1.332031 -12.355469 1.804688 -13.203125 C 2.640625 -14.691406 4.121094 -15.4375 6.242188 -15.4375 C 8.003906 -15.4375 9.289062 -14.960938 10.101562 -14.007812 C 10.914062 -13.054688 11.320312 -11.996094 11.320312 -10.828125 C 11.320312 -9.597656 10.890625 -8.542969 10.023438 -7.671875 C 9.523438 -7.164062 8.621094 -6.546875 7.328125 -5.820312 L 5.855469 -5.007812 C 5.152344 -4.621094 4.601562 -4.25 4.199219 -3.898438 C 3.484375 -3.277344 3.03125 -2.585938 2.847656 -1.828125 L 11.246094 -1.828125 L 11.246094 0 Z M 0.6875 0 \"/>\n", | |
"</symbol>\n", | |
"<symbol overflow=\"visible\" id=\"glyph0-4\">\n", | |
"<path style=\"stroke:none;\" d=\"M 5.714844 0.417969 C 3.894531 0.417969 2.578125 -0.0820312 1.757812 -1.078125 C 0.9375 -2.078125 0.527344 -3.292969 0.527344 -4.726562 L 2.546875 -4.726562 C 2.632812 -3.730469 2.816406 -3.007812 3.105469 -2.554688 C 3.605469 -1.746094 4.511719 -1.34375 5.820312 -1.34375 C 6.839844 -1.34375 7.65625 -1.613281 8.273438 -2.160156 C 8.886719 -2.703125 9.195312 -3.40625 9.195312 -4.265625 C 9.195312 -5.324219 8.871094 -6.066406 8.222656 -6.488281 C 7.574219 -6.910156 6.675781 -7.121094 5.523438 -7.121094 C 5.394531 -7.121094 5.261719 -7.121094 5.128906 -7.117188 C 4.996094 -7.113281 4.863281 -7.109375 4.726562 -7.101562 L 4.726562 -8.808594 C 4.925781 -8.789062 5.09375 -8.773438 5.230469 -8.765625 C 5.367188 -8.757812 5.515625 -8.753906 5.671875 -8.753906 C 6.394531 -8.753906 6.988281 -8.871094 7.453125 -9.097656 C 8.269531 -9.5 8.679688 -10.214844 8.679688 -11.246094 C 8.679688 -12.011719 8.40625 -12.605469 7.863281 -13.019531 C 7.320312 -13.433594 6.683594 -13.640625 5.960938 -13.640625 C 4.671875 -13.640625 3.78125 -13.210938 3.289062 -12.351562 C 3.015625 -11.878906 2.859375 -11.207031 2.824219 -10.335938 L 0.914062 -10.335938 C 0.914062 -11.480469 1.140625 -12.453125 1.601562 -13.257812 C 2.390625 -14.6875 3.773438 -15.40625 5.757812 -15.40625 C 7.328125 -15.40625 8.539062 -15.054688 9.398438 -14.355469 C 10.257812 -13.65625 10.6875 -12.648438 10.6875 -11.320312 C 10.6875 -10.375 10.433594 -9.609375 9.925781 -9.023438 C 9.609375 -8.65625 9.203125 -8.371094 8.703125 -8.164062 C 9.511719 -7.941406 10.140625 -7.515625 10.597656 -6.878906 C 11.050781 -6.246094 11.28125 -5.472656 11.28125 -4.554688 C 11.28125 -3.085938 10.796875 -1.890625 9.828125 -0.96875 C 8.863281 -0.0429688 7.492188 0.417969 5.714844 0.417969 Z M 5.714844 0.417969 \"/>\n", | |
"</symbol>\n", | |
"<symbol overflow=\"visible\" id=\"glyph0-5\">\n", | |
"<path style=\"stroke:none;\" d=\"M 7.273438 -5.445312 L 7.273438 -12.417969 L 2.34375 -5.445312 Z M 7.304688 0 L 7.304688 -3.757812 L 0.558594 -3.757812 L 0.558594 -5.648438 L 7.605469 -15.425781 L 9.238281 -15.425781 L 9.238281 -5.445312 L 11.503906 -5.445312 L 11.503906 -3.757812 L 9.238281 -3.757812 L 9.238281 0 Z M 7.304688 0 \"/>\n", | |
"</symbol>\n", | |
"<symbol overflow=\"visible\" id=\"glyph1-0\">\n", | |
"<path style=\"stroke:none;\" d=\"\"/>\n", | |
"</symbol>\n", | |
"<symbol overflow=\"visible\" id=\"glyph1-1\">\n", | |
"<path style=\"stroke:none;\" d=\"M 3.265625 -4.875 C 3.730469 -4.875 4.09375 -5.003906 4.351562 -5.265625 C 4.613281 -5.523438 4.746094 -5.835938 4.746094 -6.195312 C 4.746094 -6.507812 4.621094 -6.792969 4.371094 -7.054688 C 4.121094 -7.316406 3.742188 -7.445312 3.226562 -7.445312 C 2.71875 -7.445312 2.351562 -7.316406 2.125 -7.054688 C 1.898438 -6.792969 1.789062 -6.484375 1.789062 -6.132812 C 1.789062 -5.738281 1.933594 -5.429688 2.226562 -5.210938 C 2.519531 -4.988281 2.867188 -4.875 3.265625 -4.875 Z M 3.328125 -0.71875 C 3.816406 -0.71875 4.222656 -0.851562 4.542969 -1.117188 C 4.867188 -1.378906 5.027344 -1.773438 5.027344 -2.296875 C 5.027344 -2.839844 4.859375 -3.25 4.53125 -3.53125 C 4.199219 -3.8125 3.773438 -3.953125 3.25 -3.953125 C 2.746094 -3.953125 2.335938 -3.8125 2.019531 -3.523438 C 1.699219 -3.238281 1.539062 -2.839844 1.539062 -2.332031 C 1.539062 -1.894531 1.6875 -1.515625 1.976562 -1.199219 C 2.269531 -0.878906 2.71875 -0.71875 3.328125 -0.71875 Z M 1.828125 -4.46875 C 1.535156 -4.59375 1.304688 -4.742188 1.140625 -4.910156 C 0.832031 -5.222656 0.679688 -5.628906 0.679688 -6.128906 C 0.679688 -6.753906 0.90625 -7.289062 1.359375 -7.742188 C 1.8125 -8.191406 2.453125 -8.414062 3.289062 -8.414062 C 4.09375 -8.414062 4.722656 -8.203125 5.179688 -7.777344 C 5.636719 -7.355469 5.867188 -6.859375 5.867188 -6.292969 C 5.867188 -5.769531 5.734375 -5.34375 5.46875 -5.023438 C 5.320312 -4.839844 5.085938 -4.65625 4.773438 -4.484375 C 5.121094 -4.324219 5.398438 -4.140625 5.59375 -3.929688 C 5.964844 -3.539062 6.152344 -3.03125 6.152344 -2.40625 C 6.152344 -1.667969 5.90625 -1.042969 5.40625 -0.53125 C 4.910156 -0.015625 4.210938 0.242188 3.304688 0.242188 C 2.488281 0.242188 1.796875 0.0195312 1.234375 -0.425781 C 0.667969 -0.867188 0.386719 -1.511719 0.386719 -2.355469 C 0.386719 -2.851562 0.507812 -3.28125 0.75 -3.640625 C 0.992188 -4.003906 1.351562 -4.28125 1.828125 -4.46875 Z M 1.828125 -4.46875 \"/>\n", | |
"</symbol>\n", | |
"<symbol overflow=\"visible\" id=\"glyph1-2\">\n", | |
"<path style=\"stroke:none;\" d=\"M 3.507812 -8.425781 C 4.445312 -8.425781 5.101562 -8.183594 5.46875 -7.695312 C 5.839844 -7.210938 6.023438 -6.710938 6.023438 -6.195312 L 4.980469 -6.195312 C 4.917969 -6.527344 4.820312 -6.785156 4.679688 -6.972656 C 4.425781 -7.324219 4.042969 -7.5 3.527344 -7.5 C 2.9375 -7.5 2.46875 -7.226562 2.121094 -6.683594 C 1.773438 -6.136719 1.578125 -5.359375 1.539062 -4.34375 C 1.78125 -4.699219 2.085938 -4.960938 2.453125 -5.140625 C 2.789062 -5.296875 3.164062 -5.375 3.578125 -5.375 C 4.28125 -5.375 4.898438 -5.148438 5.421875 -4.699219 C 5.945312 -4.25 6.203125 -3.578125 6.203125 -2.6875 C 6.203125 -1.925781 5.957031 -1.253906 5.460938 -0.664062 C 4.964844 -0.078125 4.257812 0.21875 3.339844 0.21875 C 2.554688 0.21875 1.875 -0.0820312 1.304688 -0.675781 C 0.734375 -1.273438 0.453125 -2.273438 0.453125 -3.6875 C 0.453125 -4.730469 0.578125 -5.613281 0.832031 -6.339844 C 1.320312 -7.730469 2.210938 -8.425781 3.507812 -8.425781 Z M 3.433594 -0.71875 C 3.988281 -0.71875 4.402344 -0.90625 4.679688 -1.28125 C 4.953125 -1.652344 5.09375 -2.09375 5.09375 -2.601562 C 5.09375 -3.03125 4.96875 -3.441406 4.722656 -3.828125 C 4.476562 -4.21875 4.03125 -4.414062 3.382812 -4.414062 C 2.929688 -4.414062 2.53125 -4.261719 2.1875 -3.960938 C 1.847656 -3.660156 1.675781 -3.207031 1.675781 -2.601562 C 1.675781 -2.070312 1.832031 -1.625 2.140625 -1.261719 C 2.453125 -0.902344 2.882812 -0.71875 3.433594 -0.71875 Z M 3.433594 -0.71875 \"/>\n", | |
"</symbol>\n", | |
"<symbol overflow=\"visible\" id=\"glyph1-3\">\n", | |
"<path style=\"stroke:none;\" d=\"M 3.117188 0.226562 C 2.125 0.226562 1.40625 -0.0429688 0.957031 -0.589844 C 0.511719 -1.132812 0.289062 -1.796875 0.289062 -2.578125 L 1.390625 -2.578125 C 1.4375 -2.035156 1.539062 -1.640625 1.695312 -1.394531 C 1.96875 -0.953125 2.460938 -0.734375 3.175781 -0.734375 C 3.730469 -0.734375 4.175781 -0.882812 4.511719 -1.179688 C 4.847656 -1.476562 5.015625 -1.859375 5.015625 -2.328125 C 5.015625 -2.90625 4.839844 -3.308594 4.484375 -3.539062 C 4.132812 -3.769531 3.640625 -3.882812 3.011719 -3.882812 C 2.941406 -3.882812 2.871094 -3.882812 2.796875 -3.882812 C 2.726562 -3.878906 2.652344 -3.875 2.578125 -3.875 L 2.578125 -4.804688 C 2.6875 -4.792969 2.78125 -4.785156 2.851562 -4.78125 C 2.925781 -4.777344 3.007812 -4.773438 3.09375 -4.773438 C 3.488281 -4.773438 3.8125 -4.835938 4.066406 -4.960938 C 4.511719 -5.179688 4.734375 -5.570312 4.734375 -6.132812 C 4.734375 -6.550781 4.585938 -6.875 4.289062 -7.101562 C 3.992188 -7.328125 3.648438 -7.441406 3.25 -7.441406 C 2.546875 -7.441406 2.0625 -7.207031 1.792969 -6.738281 C 1.644531 -6.480469 1.5625 -6.113281 1.539062 -5.636719 L 0.5 -5.636719 C 0.5 -6.261719 0.625 -6.792969 0.875 -7.230469 C 1.304688 -8.011719 2.058594 -8.402344 3.140625 -8.402344 C 3.996094 -8.402344 4.65625 -8.210938 5.125 -7.832031 C 5.59375 -7.449219 5.828125 -6.898438 5.828125 -6.175781 C 5.828125 -5.660156 5.691406 -5.242188 5.414062 -4.921875 C 5.242188 -4.722656 5.019531 -4.566406 4.746094 -4.453125 C 5.1875 -4.332031 5.53125 -4.097656 5.78125 -3.753906 C 6.027344 -3.40625 6.152344 -2.984375 6.152344 -2.484375 C 6.152344 -1.683594 5.890625 -1.03125 5.359375 -0.527344 C 4.832031 -0.0234375 4.085938 0.226562 3.117188 0.226562 Z M 3.117188 0.226562 \"/>\n", | |
"</symbol>\n", | |
"<symbol overflow=\"visible\" id=\"glyph1-4\">\n", | |
"<path style=\"stroke:none;\" d=\"M 1.484375 -2.140625 C 1.554688 -1.539062 1.832031 -1.121094 2.320312 -0.890625 C 2.570312 -0.773438 2.859375 -0.714844 3.1875 -0.714844 C 3.8125 -0.714844 4.273438 -0.914062 4.578125 -1.3125 C 4.878906 -1.710938 5.027344 -2.152344 5.027344 -2.636719 C 5.027344 -3.222656 4.847656 -3.675781 4.492188 -3.996094 C 4.132812 -4.316406 3.703125 -4.476562 3.203125 -4.476562 C 2.839844 -4.476562 2.53125 -4.40625 2.269531 -4.265625 C 2.011719 -4.125 1.789062 -3.929688 1.605469 -3.679688 L 0.691406 -3.734375 L 1.328125 -8.25 L 5.6875 -8.25 L 5.6875 -7.230469 L 2.121094 -7.230469 L 1.765625 -4.898438 C 1.960938 -5.046875 2.144531 -5.15625 2.320312 -5.234375 C 2.632812 -5.363281 2.992188 -5.425781 3.40625 -5.425781 C 4.175781 -5.425781 4.828125 -5.179688 5.359375 -4.679688 C 5.894531 -4.183594 6.164062 -3.554688 6.164062 -2.796875 C 6.164062 -2.003906 5.917969 -1.304688 5.429688 -0.695312 C 4.9375 -0.0898438 4.15625 0.210938 3.082031 0.210938 C 2.398438 0.210938 1.792969 0.0195312 1.269531 -0.367188 C 0.742188 -0.75 0.449219 -1.34375 0.386719 -2.140625 Z M 1.484375 -2.140625 \"/>\n", | |
"</symbol>\n", | |
"<symbol overflow=\"visible\" id=\"glyph1-5\">\n", | |
"<path style=\"stroke:none;\" d=\"M 3.96875 -2.96875 L 3.96875 -6.773438 L 1.277344 -2.96875 Z M 3.984375 0 L 3.984375 -2.050781 L 0.304688 -2.050781 L 0.304688 -3.082031 L 4.148438 -8.414062 L 5.039062 -8.414062 L 5.039062 -2.96875 L 6.273438 -2.96875 L 6.273438 -2.050781 L 5.039062 -2.050781 L 5.039062 0 Z M 3.984375 0 \"/>\n", | |
"</symbol>\n", | |
"<symbol overflow=\"visible\" id=\"glyph1-6\">\n", | |
"<path style=\"stroke:none;\" d=\"M 1.59375 -2.027344 C 1.625 -1.445312 1.851562 -1.042969 2.265625 -0.820312 C 2.480469 -0.703125 2.726562 -0.644531 2.992188 -0.644531 C 3.496094 -0.644531 3.929688 -0.855469 4.28125 -1.273438 C 4.636719 -1.695312 4.890625 -2.546875 5.039062 -3.832031 C 4.804688 -3.460938 4.515625 -3.199219 4.167969 -3.050781 C 3.824219 -2.898438 3.453125 -2.824219 3.054688 -2.824219 C 2.246094 -2.824219 1.605469 -3.078125 1.132812 -3.578125 C 0.664062 -4.082031 0.429688 -4.734375 0.429688 -5.523438 C 0.429688 -6.285156 0.660156 -6.957031 1.125 -7.535156 C 1.589844 -8.113281 2.273438 -8.402344 3.179688 -8.402344 C 4.402344 -8.402344 5.25 -7.851562 5.710938 -6.75 C 5.96875 -6.144531 6.101562 -5.386719 6.101562 -4.476562 C 6.101562 -3.449219 5.945312 -2.539062 5.636719 -1.746094 C 5.125 -0.425781 4.257812 0.234375 3.035156 0.234375 C 2.214844 0.234375 1.59375 0.0195312 1.164062 -0.410156 C 0.738281 -0.839844 0.527344 -1.378906 0.527344 -2.027344 Z M 3.195312 -3.75 C 3.613281 -3.75 3.992188 -3.886719 4.339844 -4.164062 C 4.683594 -4.4375 4.859375 -4.921875 4.859375 -5.609375 C 4.859375 -6.226562 4.703125 -6.683594 4.390625 -6.988281 C 4.082031 -7.289062 3.6875 -7.441406 3.203125 -7.441406 C 2.6875 -7.441406 2.28125 -7.269531 1.976562 -6.921875 C 1.675781 -6.578125 1.523438 -6.117188 1.523438 -5.539062 C 1.523438 -4.992188 1.65625 -4.554688 1.921875 -4.234375 C 2.1875 -3.910156 2.609375 -3.75 3.195312 -3.75 Z M 3.195312 -3.75 \"/>\n", | |
"</symbol>\n", | |
"</g>\n", | |
"</defs>\n", | |
"<g id=\"surface61\">\n", | |
"<rect x=\"0\" y=\"0\" width=\"400\" height=\"400\" style=\"fill:rgb(100%,100%,100%);fill-opacity:1;stroke:none;\"/>\n", | |
"<path style=\"fill:none;stroke-width:1;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(26.666667%,26.666667%,26.666667%);stroke-opacity:1;stroke-miterlimit:10;\" d=\"M 219.792969 373 L 349.632812 215.277344 \"/>\n", | |
"<path style=\" stroke:none;fill-rule:nonzero;fill:rgb(26.666667%,26.666667%,26.666667%);fill-opacity:1;\" d=\"M 358.699219 204.261719 L 353.210938 218.222656 L 346.054688 212.328125 L 358.699219 204.261719 \"/>\n", | |
"<path style=\"fill:none;stroke-width:1;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(26.666667%,26.666667%,26.666667%);stroke-opacity:1;stroke-miterlimit:10;\" d=\"M 219.792969 373 L 208.976562 277.585938 \"/>\n", | |
"<path style=\" stroke:none;fill-rule:nonzero;fill:rgb(26.666667%,26.666667%,26.666667%);fill-opacity:1;\" d=\"M 207.371094 263.410156 L 213.582031 277.0625 L 204.371094 278.105469 L 207.371094 263.410156 \"/>\n", | |
"<path style=\"fill:none;stroke-width:1;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(26.666667%,26.666667%,26.666667%);stroke-opacity:1;stroke-miterlimit:10;\" d=\"M 219.792969 373 L 55.28125 236.34375 \"/>\n", | |
"<path style=\" stroke:none;fill-rule:nonzero;fill:rgb(26.666667%,26.666667%,26.666667%);fill-opacity:1;\" d=\"M 44.308594 227.226562 L 58.242188 232.777344 L 52.320312 239.910156 L 44.308594 227.226562 \"/>\n", | |
"<path style=\"fill:none;stroke-width:1;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(26.666667%,26.666667%,26.666667%);stroke-opacity:1;stroke-miterlimit:10;\" d=\"M 204.835938 241.054688 L 338.003906 198.160156 \"/>\n", | |
"<path style=\" stroke:none;fill-rule:nonzero;fill:rgb(26.666667%,26.666667%,26.666667%);fill-opacity:1;\" d=\"M 351.582031 193.789062 L 339.425781 202.574219 L 336.582031 193.75 L 351.582031 193.789062 \"/>\n", | |
"<path style=\"fill:none;stroke-width:1;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(26.666667%,26.666667%,26.666667%);stroke-opacity:1;stroke-miterlimit:10;\" d=\"M 204.835938 241.054688 L 63.3125 218.609375 \"/>\n", | |
"<path style=\" stroke:none;fill-rule:nonzero;fill:rgb(26.666667%,26.666667%,26.666667%);fill-opacity:1;\" d=\"M 49.222656 216.375 L 64.039062 214.03125 L 62.585938 223.1875 L 49.222656 216.375 \"/>\n", | |
"<path style=\"fill:none;stroke-width:1;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(26.666667%,26.666667%,26.666667%);stroke-opacity:1;stroke-miterlimit:10;\" d=\"M 373 186.890625 L 208.3125 50.457031 \"/>\n", | |
"<path style=\" stroke:none;fill-rule:nonzero;fill:rgb(26.666667%,26.666667%,26.666667%);fill-opacity:1;\" d=\"M 197.328125 41.355469 L 211.269531 46.886719 L 205.355469 54.023438 L 197.328125 41.355469 \"/>\n", | |
"<path style=\"fill:none;stroke-width:1;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(26.666667%,26.666667%,26.666667%);stroke-opacity:1;stroke-miterlimit:10;\" d=\"M 27 212.851562 L 156.632812 55.382812 \"/>\n", | |
"<path style=\" stroke:none;fill-rule:nonzero;fill:rgb(26.666667%,26.666667%,26.666667%);fill-opacity:1;\" d=\"M 165.699219 44.371094 L 160.210938 58.332031 L 153.054688 52.4375 L 165.699219 44.371094 \"/>\n", | |
"<path style=\"fill-rule:nonzero;fill:rgb(100%,0%,0%);fill-opacity:1;stroke-width:1;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-miterlimit:10;\" d=\"M 242.292969 373 C 242.292969 385.425781 232.21875 395.5 219.792969 395.5 C 207.367188 395.5 197.292969 385.425781 197.292969 373 C 197.292969 360.574219 207.367188 350.5 219.792969 350.5 C 232.21875 350.5 242.292969 360.574219 242.292969 373 \"/>\n", | |
"<path style=\"fill-rule:nonzero;fill:rgb(0%,100%,0%);fill-opacity:1;stroke-width:1;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-miterlimit:10;\" d=\"M 227.335938 241.054688 C 227.335938 253.480469 217.261719 263.554688 204.835938 263.554688 C 192.410156 263.554688 182.335938 253.480469 182.335938 241.054688 C 182.335938 228.625 192.410156 218.554688 204.835938 218.554688 C 217.261719 218.554688 227.335938 228.625 227.335938 241.054688 \"/>\n", | |
"<path style=\"fill-rule:nonzero;fill:rgb(0%,0%,100%);fill-opacity:1;stroke-width:1;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-miterlimit:10;\" d=\"M 395.5 186.890625 C 395.5 199.316406 385.425781 209.390625 373 209.390625 C 360.574219 209.390625 350.5 199.316406 350.5 186.890625 C 350.5 174.464844 360.574219 164.390625 373 164.390625 C 385.425781 164.390625 395.5 174.464844 395.5 186.890625 \"/>\n", | |
"<path style=\"fill-rule:nonzero;fill:rgb(100%,100%,0%);fill-opacity:1;stroke-width:1;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-miterlimit:10;\" d=\"M 49.5 212.851562 C 49.5 225.277344 39.425781 235.351562 27 235.351562 C 14.574219 235.351562 4.5 225.277344 4.5 212.851562 C 4.5 200.425781 14.574219 190.351562 27 190.351562 C 39.425781 190.351562 49.5 200.425781 49.5 212.851562 \"/>\n", | |
"<path style=\"fill-rule:nonzero;fill:rgb(100%,64.705882%,0%);fill-opacity:1;stroke-width:1;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-miterlimit:10;\" d=\"M 202.5 27 C 202.5 39.425781 192.429688 49.5 180 49.5 C 167.574219 49.5 157.5 39.425781 157.5 27 C 157.5 14.574219 167.574219 4.5 180 4.5 C 192.429688 4.5 202.5 14.574219 202.5 27 \"/>\n", | |
"<g style=\"fill:rgb(0%,0%,0%);fill-opacity:1;\">\n", | |
" <use xlink:href=\"#glyph0-1\" x=\"213.800781\" y=\"383.222656\"/>\n", | |
"</g>\n", | |
"<g style=\"fill:rgb(0%,0%,0%);fill-opacity:1;\">\n", | |
" <use xlink:href=\"#glyph0-2\" x=\"199.890625\" y=\"251.242188\"/>\n", | |
"</g>\n", | |
"<g style=\"fill:rgb(0%,0%,0%);fill-opacity:1;\">\n", | |
" <use xlink:href=\"#glyph0-3\" x=\"366.996094\" y=\"197.136719\"/>\n", | |
"</g>\n", | |
"<g style=\"fill:rgb(0%,0%,0%);fill-opacity:1;\">\n", | |
" <use xlink:href=\"#glyph0-4\" x=\"21.097656\" y=\"223.082031\"/>\n", | |
"</g>\n", | |
"<g style=\"fill:rgb(0%,0%,0%);fill-opacity:1;\">\n", | |
" <use xlink:href=\"#glyph0-5\" x=\"173.96875\" y=\"37.242188\"/>\n", | |
"</g>\n", | |
"<g style=\"fill:rgb(0%,0%,0%);fill-opacity:1;\">\n", | |
" <use xlink:href=\"#glyph1-1\" x=\"290.246094\" y=\"285.53125\"/>\n", | |
"</g>\n", | |
"<g style=\"fill:rgb(0%,0%,0%);fill-opacity:1;\">\n", | |
" <use xlink:href=\"#glyph1-2\" x=\"206.109375\" y=\"312.621094\"/>\n", | |
"</g>\n", | |
"<g style=\"fill:rgb(0%,0%,0%);fill-opacity:1;\">\n", | |
" <use xlink:href=\"#glyph1-3\" x=\"117.246094\" y=\"304.925781\"/>\n", | |
"</g>\n", | |
"<g style=\"fill:rgb(0%,0%,0%);fill-opacity:1;\">\n", | |
" <use xlink:href=\"#glyph1-4\" x=\"282.753906\" y=\"208.855469\"/>\n", | |
"</g>\n", | |
"<g style=\"fill:rgb(0%,0%,0%);fill-opacity:1;\">\n", | |
" <use xlink:href=\"#glyph1-2\" x=\"109.710938\" y=\"238.953125\"/>\n", | |
"</g>\n", | |
"<g style=\"fill:rgb(0%,0%,0%);fill-opacity:1;\">\n", | |
" <use xlink:href=\"#glyph1-5\" x=\"270.226562\" y=\"118.945312\"/>\n", | |
"</g>\n", | |
"<g style=\"fill:rgb(0%,0%,0%);fill-opacity:1;\">\n", | |
" <use xlink:href=\"#glyph1-6\" x=\"97.402344\" y=\"125.507812\"/>\n", | |
"</g>\n", | |
"</g>\n", | |
"</svg>\n" | |
], | |
"text/plain": [ | |
"<igraph.drawing.Plot at 0x108103cf8>" | |
] | |
}, | |
"execution_count": 4, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"visual_style = {}\n", | |
"\n", | |
"out_name = \"graph_coloured.png\"\n", | |
"\n", | |
"# Set bbox and margin\n", | |
"visual_style[\"bbox\"] = (400,400)\n", | |
"visual_style[\"margin\"] = 27\n", | |
"\n", | |
"# Set vertex colours\n", | |
"g.vs[\"color\"] = [\"red\", \"green\", \"blue\", \"yellow\", \"orange\"]\n", | |
"\n", | |
"# Set vertex size\n", | |
"visual_style[\"vertex_size\"] = 45\n", | |
"\n", | |
"# Set vertex lable size\n", | |
"visual_style[\"vertex_label_size\"] = 22\n", | |
"\n", | |
"# Don't curve the edges\n", | |
"visual_style[\"edge_curved\"] = False\n", | |
"\n", | |
"# Set the layout\n", | |
"visual_style[\"layout\"] = my_layout\n", | |
"\n", | |
"# Plot the graph\n", | |
"plot(g, out_name, **visual_style)" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"## 3. Obtaining information on vertices and edges of the graph" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 5, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"Number of vertices in the graph: 5\n", | |
"Number of edges in the graph 7\n", | |
"Is the graph directed: True\n", | |
"Maximum degree in the graph: 3\n", | |
"Adjacency matrix:\n", | |
" [[0, 1, 1, 1, 0]\n", | |
" [0, 0, 1, 1, 0]\n", | |
" [0, 0, 0, 0, 1]\n", | |
" [0, 0, 0, 0, 1]\n", | |
" [0, 0, 0, 0, 0]]\n" | |
] | |
} | |
], | |
"source": [ | |
"print(\"Number of vertices in the graph:\", g.vcount())\n", | |
"print(\"Number of edges in the graph\", g.ecount())\n", | |
"print(\"Is the graph directed:\", g.is_directed())\n", | |
"print(\"Maximum degree in the graph:\", g.maxdegree())\n", | |
"print(\"Adjacency matrix:\\n\", g.get_adjacency())" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"## 4. Obtaining adjacent vertices to a vertex" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 6, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"neighbors(vertex, mode=ALL)\n", | |
"\n", | |
"Returns adjacent vertices to a given vertex.\n", | |
"\n", | |
"@param vertex: a vertex ID\n", | |
"@param mode: whether to return only successors (L{OUT}),\n", | |
" predecessors (L{IN}) or both (L{ALL}). Ignored for undirected\n", | |
" graphs.\n", | |
"[1, 2, 3]\n" | |
] | |
} | |
], | |
"source": [ | |
"print(g.neighbors.__doc__)\n", | |
"\n", | |
"print(g.neighbors(0, mode=ALL))" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"## 5. Breadth-first search (BFS) from a vertex" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 7, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"bfs(vid, mode=OUT)\n", | |
"\n", | |
"Conducts a breadth first search (BFS) on the graph.\n", | |
"\n", | |
"@param vid: the root vertex ID\n", | |
"@param mode: either L{IN} or L{OUT} or L{ALL}, ignored\n", | |
" for undirected graphs.\n", | |
"@return: a tuple with the following items:\n", | |
" - The vertex IDs visited (in order)\n", | |
" - The start indices of the layers in the vertex list\n", | |
" - The parent of every vertex in the BFS\n", | |
"\n", | |
"([0, 1, 2, 3, 4], [0, 1, 4, 5], [0, 0, 0, 0, 2])\n" | |
] | |
} | |
], | |
"source": [ | |
"print(g.bfs.__doc__)\n", | |
"print(g.bfs(0))" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"## 6. Determining shortest paths from a vertex" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 8, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"get_shortest_paths(v, to=None, weights=None, mode=OUT, output=\"vpath\")\n", | |
"\n", | |
"Calculates the shortest paths from/to a given node in a graph.\n", | |
"\n", | |
"@param v: the source/destination for the calculated paths\n", | |
"@param to: a vertex selector describing the destination/source for\n", | |
" the calculated paths. This can be a single vertex ID, a list of\n", | |
" vertex IDs, a single vertex name, a list of vertex names or a\n", | |
" L{VertexSeq} object. C{None} means all the vertices.\n", | |
"@param weights: edge weights in a list or the name of an edge attribute\n", | |
" holding edge weights. If C{None}, all edges are assumed to have\n", | |
" equal weight.\n", | |
"@param mode: the directionality of the paths. L{IN} means to\n", | |
" calculate incoming paths, L{OUT} means to calculate outgoing\n", | |
" paths, L{ALL} means to calculate both ones.\n", | |
"@param output: determines what should be returned. If this is\n", | |
" C{\"vpath\"}, a list of vertex IDs will be returned, one path\n", | |
" for each target vertex. For unconnected graphs, some of the list\n", | |
" elements may be empty. Note that in case of mode=L{IN}, the vertices\n", | |
" in a path are returned in reversed order. If C{output=\"epath\"},\n", | |
" edge IDs are returned instead of vertex IDs.\n", | |
"@return: see the documentation of the C{output} parameter.\n", | |
"\n", | |
"The shortest paths from vertex 0: [[0], [0, 1], [0, 2], [0, 3], [0, 2, 4]]\n", | |
"The shortest paths from vertex 0 to vertex 4: [[0, 2, 4]]\n" | |
] | |
} | |
], | |
"source": [ | |
"print(g.get_shortest_paths.__doc__)\n", | |
"\n", | |
"print(\"The shortest paths from vertex 0:\", g.get_shortest_paths(0))\n", | |
"print(\"The shortest paths from vertex 0 to vertex 4:\", g.get_shortest_paths(0, to=4))" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"## 7. Obtain the Laplacian matrix of a graph" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 9, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"laplacian(weights=None, normalized=False)\n", | |
"\n", | |
"Returns the Laplacian matrix of a graph.\n", | |
"\n", | |
"The Laplacian matrix is similar to the adjacency matrix, but the edges\n", | |
"are denoted with -1 and the diagonal contains the node degrees.\n", | |
"\n", | |
"Normalized Laplacian matrices have 1 or 0 in their diagonals (0 for vertices\n", | |
"with no edges), edges are denoted by 1 / sqrt(d_i * d_j) where d_i is the\n", | |
"degree of node i.\n", | |
"\n", | |
"Multiple edges and self-loops are silently ignored. Although it is\n", | |
"possible to calculate the Laplacian matrix of a directed graph, it does\n", | |
"not make much sense.\n", | |
"\n", | |
"@param weights: edge weights to be used. Can be a sequence or iterable or\n", | |
" even an edge attribute name. When edge weights are used, the degree\n", | |
" of a node is considered to be the weight of its incident edges.\n", | |
"@param normalized: whether to return the normalized Laplacian matrix.\n", | |
"@return: the Laplacian matrix.\n", | |
"\n", | |
"Laplacian matrix of a graph:\n", | |
" [[3, -1, -1, -1, 0], [0, 2, -1, -1, 0], [0, 0, 1, 0, -1], [0, 0, 0, 1, -1], [0, 0, 0, 0, 0]]\n" | |
] | |
} | |
], | |
"source": [ | |
"print(g.laplacian.__doc__)\n", | |
"print(\"Laplacian matrix of a graph:\\n\",g.laplacian())" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"## 8. Determine the maximum flow between the source and target vertices" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 10, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"maxflow(source, target, capacity=None)\n", | |
"\n", | |
" Returns a maximum flow between the given source and target vertices\n", | |
" in a graph.\n", | |
"\n", | |
" A maximum flow from I{source} to I{target} is an assignment of\n", | |
" non-negative real numbers to the edges of the graph, satisfying\n", | |
" two properties:\n", | |
"\n", | |
" 1. For each edge, the flow (i.e. the assigned number) is not\n", | |
" more than the capacity of the edge (see the I{capacity}\n", | |
" argument)\n", | |
"\n", | |
" 2. For every vertex except the source and the target, the\n", | |
" incoming flow is the same as the outgoing flow.\n", | |
"\n", | |
" The value of the flow is the incoming flow of the target or the\n", | |
" outgoing flow of the source (which are equal). The maximum flow\n", | |
" is the maximum possible such value.\n", | |
"\n", | |
" @param capacity: the edge capacities (weights). If C{None}, all\n", | |
" edges have equal weight. May also be an attribute name.\n", | |
" @return: a L{Flow} object describing the maximum flow\n", | |
" \n", | |
"A flow of a given graph.\n", | |
"\n", | |
" This is a simple class used to represent flows returned by\n", | |
" L{Graph.maxflow}. It has the following attributes:\n", | |
"\n", | |
" - C{graph} - the graph on which this flow is defined\n", | |
"\n", | |
" - C{value} - the value (capacity) of the flow \n", | |
"\n", | |
" - C{flow} - the flow values on each edge. For directed graphs,\n", | |
" this is simply a list where element M{i} corresponds to the\n", | |
" flow on edge M{i}. For undirected graphs, the direction of\n", | |
" the flow is not constrained (since the edges are undirected),\n", | |
" hence positive flow always means a flow from the smaller vertex\n", | |
" ID to the larger, while negative flow means a flow from the\n", | |
" larger vertex ID to the smaller.\n", | |
"\n", | |
" - C{cut} - edge IDs in the minimal cut corresponding to\n", | |
" the flow.\n", | |
"\n", | |
" - C{partition} - vertex IDs in the parts created\n", | |
" after removing edges in the cut\n", | |
"\n", | |
" - C{es} - an edge selector restricted to the edges\n", | |
" in the cut.\n", | |
"\n", | |
" This class is usually not instantiated directly, everything\n", | |
" is taken care of by L{Graph.maxflow}.\n", | |
"\n", | |
" Examples:\n", | |
"\n", | |
" >>> from igraph import Graph\n", | |
" >>> g = Graph.Ring(20)\n", | |
" >>> mf = g.maxflow(0, 10)\n", | |
" >>> print(mf.value)\n", | |
" 2.0\n", | |
" >>> mf.es[\"color\"] = \"red\"\n", | |
" \n", | |
"The maximum flow value: 13.0\n", | |
"The flow values on each edge: [4.0, 6.0, 3.0, 0.0, 6.0, 4.0, 9.0]\n", | |
"Tedge IDs in the minimal cut of the flow: [5, 6]\n", | |
"The vertex IDs in the parts created created by the cut: [[0, 1, 2, 3], [4]]\n" | |
] | |
} | |
], | |
"source": [ | |
"print(g.maxflow.__doc__)\n", | |
"print(g.maxflow(0,4,weights).__doc__)\n", | |
"\n", | |
"maxflow = g.maxflow(0,4,weights)\n", | |
"\n", | |
"print(\"The maximum flow value:\", maxflow.value)\n", | |
"print(\"The flow values on each edge:\", maxflow.flow)\n", | |
"print(\"Tedge IDs in the minimal cut of the flow:\", maxflow.cut)\n", | |
"print(\"The vertex IDs in the parts created created by the cut:\", maxflow.partition)" | |
] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 3", | |
"language": "python", | |
"name": "python3" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 3 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython3", | |
"version": "3.7.3" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 2 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment