{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "using Random\n", "Random.seed!(2017); # make sure this tutorial is reproducible" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Graphs.jl\n", "\n", "## Overview\n", "\n", "`Graphs.jl` is the core package for graph algorithms in Julia. The purpose of this tutorial is to get you up and running with some of the basics and the design that we have adopted.\n", "\n", "## Installation\n", "\n", "Please install the package by typing the following in the Julia prompt:" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "\u001b[32m\u001b[1m Updating\u001b[22m\u001b[39m registry at `C:\\Users\\Thibaut\\.julia\\registries\\General`\n", "\u001b[32m\u001b[1m Updating\u001b[22m\u001b[39m git-repo `https://github.com/JuliaRegistries/General.git`\n", "\u001b[32m\u001b[1m Resolving\u001b[22m\u001b[39m package versions...\n", "\u001b[32m\u001b[1m No Changes\u001b[22m\u001b[39m to `C:\\Users\\Thibaut\\.julia\\environments\\v1.8\\Project.toml`\n", "\u001b[32m\u001b[1m No Changes\u001b[22m\u001b[39m to `C:\\Users\\Thibaut\\.julia\\environments\\v1.8\\Manifest.toml`\n" ] } ], "source": [ "] add Graphs" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "For this tutorial we will be using the [GraphPlot.jl](https://github.com/JuliaGraphs/GraphPlot.jl) package for graph visualization, please install it with:" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "\u001b[32m\u001b[1m Resolving\u001b[22m\u001b[39m package versions...\n", "\u001b[32m\u001b[1m No Changes\u001b[22m\u001b[39m to `C:\\Users\\Thibaut\\.julia\\environments\\v1.8\\Project.toml`\n", "\u001b[32m\u001b[1m No Changes\u001b[22m\u001b[39m to `C:\\Users\\Thibaut\\.julia\\environments\\v1.8\\Manifest.toml`\n" ] } ], "source": [ "] add GraphPlot" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## How to define a graph?\n", "\n", "The most common approach is to construct a graph with only vertices and add edges iteratively:" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "image/svg+xml": [ "\n", "\n", "\n", " \n", " \n", " \n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "\n", "\n", "\n", "\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "\n", "\n", " \n", " \n", " 1\n", " \n", " \n", " \n", " \n", " 2\n", " \n", " \n", " \n", " \n", " 3\n", " \n", " \n", "\n", "\n" ], "text/html": [ "\n", "\n", "\n", " \n", " \n", " \n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "\n", "\n", "\n", "\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "\n", "\n", " \n", " \n", " 1\n", " \n", " \n", " \n", " \n", " 2\n", " \n", " \n", " \n", " \n", " 3\n", " \n", " \n", "\n", "\n", "\n" ], "text/plain": [ "Compose.Context(Measures.BoundingBox{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}, Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}((0.0w, 0.0h), (1.0w, 1.0h)), Compose.UnitBox{Float64, Float64, Float64, Float64}(-1.2, -1.2, 2.4, 2.4, 0.0mm, 0.0mm, 0.0mm, 0.0mm), nothing, nothing, nothing, List([Compose.Context(Measures.BoundingBox{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}, Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}((0.0w, 0.0h), (1.0w, 1.0h)), nothing, nothing, nothing, nothing, List([]), List([Compose.Form{Compose.LinePrimitive}(Compose.LinePrimitive[Compose.LinePrimitive{Tuple{Measures.Measure, Measures.Measure}}(Tuple{Measures.Measure, Measures.Measure}[(-0.9227426389187701cx, 0.6899045394129739cy), (0.07084087295213191cx, -0.878079396769464cy)]), Compose.LinePrimitive{Tuple{Measures.Measure, Measures.Measure}}(Tuple{Measures.Measure, Measures.Measure}[(-0.8562970922142114cx, 0.8253457797306617cy), (0.8562970922142114cx, 0.9864793629128482cy)]), Compose.LinePrimitive{Tuple{Measures.Measure, Measures.Measure}}(Tuple{Measures.Measure, Measures.Measure}[(0.2046614564329478cx, -0.867207171861172cy), (0.943436777600414cx, 0.867207171861172cy)])], Symbol(\"\"))]), List([Compose.Property{Compose.LineWidthPrimitive}(Compose.LineWidthPrimitive[Compose.LineWidthPrimitive(1.7320508075688774mm)]), Compose.Property{Compose.FillPrimitive}(Compose.FillPrimitive[Compose.FillPrimitive(RGBA{Float64}(0.0,0.0,0.0,0.0))]), Compose.Property{Compose.StrokePrimitive}(Compose.StrokePrimitive[Compose.StrokePrimitive(RGBA{Float64}(0.8274509803921568,0.8274509803921568,0.8274509803921568,1.0))])]), 0, false, false, false, false, nothing, nothing, 0.0, Symbol(\"\")), Compose.Context(Measures.BoundingBox{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}, Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}((0.0w, 0.0h), (1.0w, 1.0h)), nothing, nothing, nothing, nothing, List([]), List([]), List([Compose.Property{Compose.LineWidthPrimitive}(Compose.LineWidthPrimitive[Compose.LineWidthPrimitive(1.7320508075688774mm)]), Compose.Property{Compose.StrokePrimitive}(Compose.StrokePrimitive[Compose.StrokePrimitive(RGBA{Float64}(0.8274509803921568,0.8274509803921568,0.8274509803921568,1.0))])]), 0, false, false, false, false, nothing, nothing, 0.0, Symbol(\"\")), Compose.Context(Measures.BoundingBox{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}, Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}((0.0w, 0.0h), (1.0w, 1.0h)), nothing, nothing, nothing, nothing, List([]), List([]), List([Compose.Property{Compose.FontSizePrimitive}(Compose.FontSizePrimitive[Compose.FontSizePrimitive(4.0mm)]), Compose.Property{Compose.StrokePrimitive}(Compose.StrokePrimitive[Compose.StrokePrimitive(RGBA{Float64}(0.0,0.0,0.0,0.0))]), Compose.Property{Compose.FillPrimitive}(Compose.FillPrimitive[Compose.FillPrimitive(RGBA{Float64}(0.0,0.0,0.0,1.0))])]), 0, false, false, false, false, nothing, nothing, 0.0, Symbol(\"\")), Compose.Context(Measures.BoundingBox{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}, Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}((0.0w, 0.0h), (1.0w, 1.0h)), nothing, nothing, nothing, nothing, List([]), List([Compose.Form{Compose.CirclePrimitive{Tuple{Measures.Measure, Measures.Measure}, Measures.Measure}}(Compose.CirclePrimitive{Tuple{Measures.Measure, Measures.Measure}, Measures.Measure}[Compose.CirclePrimitive{Tuple{Measures.Measure, Measures.Measure}, Measures.Measure}((-1.0cx, 0.8118251426435099cy), 0.05773502691896259w), Compose.CirclePrimitive{Tuple{Measures.Measure, Measures.Measure}, Measures.Measure}((0.14809823403336186cx, -1.0cy), 0.05773502691896259w), Compose.CirclePrimitive{Tuple{Measures.Measure, Measures.Measure}, Measures.Measure}((1.0cx, 1.0cy), 0.05773502691896259w)], Symbol(\"\"))]), List([Compose.Property{Compose.LineWidthPrimitive}(Compose.LineWidthPrimitive[Compose.LineWidthPrimitive(0.0mm)]), Compose.Property{Compose.StrokePrimitive}(Compose.StrokePrimitive[Compose.StrokePrimitive(RGBA{Float64}(0.0,0.0,0.0,0.0))]), Compose.Property{Compose.FillPrimitive}(Compose.FillPrimitive[Compose.FillPrimitive(RGBA{Float64}(0.25098039215686274,0.8784313725490196,0.8156862745098039,1.0))])]), 0, false, false, false, false, nothing, nothing, 0.0, Symbol(\"\")), Compose.Context(Measures.BoundingBox{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}, Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}((0.0w, 0.0h), (1.0w, 1.0h)), nothing, nothing, nothing, nothing, List([]), List([Compose.Form{Compose.TextPrimitive{Tuple{Measures.Length{:cx, Float64}, Measures.Length{:cy, Float64}}, Compose.Rotation{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}, Tuple{Measures.AbsoluteLength, Measures.AbsoluteLength}}}(Compose.TextPrimitive{Tuple{Measures.Length{:cx, Float64}, Measures.Length{:cy, Float64}}, Compose.Rotation{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}, Tuple{Measures.AbsoluteLength, Measures.AbsoluteLength}}[Compose.TextPrimitive{Tuple{Measures.Length{:cx, Float64}, Measures.Length{:cy, Float64}}, Compose.Rotation{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}, Tuple{Measures.AbsoluteLength, Measures.AbsoluteLength}}((-1.0cx, 0.8118251426435099cy), \"1\", Compose.HCenter(), Compose.VCenter(), Compose.Rotation{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}(0.0, (0.5w, 0.5h)), (0.0mm, 0.0mm)), Compose.TextPrimitive{Tuple{Measures.Length{:cx, Float64}, Measures.Length{:cy, Float64}}, Compose.Rotation{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}, Tuple{Measures.AbsoluteLength, Measures.AbsoluteLength}}((0.14809823403336186cx, -1.0cy), \"2\", Compose.HCenter(), Compose.VCenter(), Compose.Rotation{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}(0.0, (0.5w, 0.5h)), (0.0mm, 0.0mm)), Compose.TextPrimitive{Tuple{Measures.Length{:cx, Float64}, Measures.Length{:cy, Float64}}, Compose.Rotation{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}, Tuple{Measures.AbsoluteLength, Measures.AbsoluteLength}}((1.0cx, 1.0cy), \"3\", Compose.HCenter(), Compose.VCenter(), Compose.Rotation{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}(0.0, (0.5w, 0.5h)), (0.0mm, 0.0mm))], Symbol(\"\"))]), List([Compose.Property{Compose.FontSizePrimitive}(Compose.FontSizePrimitive[Compose.FontSizePrimitive(4.0mm)]), Compose.Property{Compose.StrokePrimitive}(Compose.StrokePrimitive[Compose.StrokePrimitive(RGBA{Float64}(0.0,0.0,0.0,0.0))]), Compose.Property{Compose.FillPrimitive}(Compose.FillPrimitive[Compose.FillPrimitive(RGBA{Float64}(0.0,0.0,0.0,1.0))])]), 0, false, false, false, false, nothing, nothing, 0.0, Symbol(\"\"))]), List([]), List([]), 0, false, false, false, false, nothing, nothing, 0.0, Symbol(\"\"))" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "using Graphs\n", "using GraphPlot\n", "\n", "G₁ = Graph(3) # graph with 3 vertices\n", "\n", "# make a triangle\n", "add_edge!(G₁, 1, 2)\n", "add_edge!(G₁, 1, 3)\n", "add_edge!(G₁, 2, 3)\n", "\n", "gplot(G₁, nodelabel=1:3)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Alternatively, one can construct a graph from its adjacency matrix:" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [], "source": [ "A = [\n", " 0 1 1\n", " 1 0 1\n", " 1 1 0\n", "]\n", "\n", "G₂ = Graph(A)\n", "\n", "@assert G₁ == G₂" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "It is also possible to construct a graph with random edges using:" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{3, 3} undirected simple Int64 graph" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "G = Graph(3, 3)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Notice that Graphs.jl checks the maximum number of edges for the given number of vertices, and throws an error if this maximum is not respected:" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "ename": "LoadError", "evalue": "AssertionError: Maximum number of edges for this graph is 3", "output_type": "error", "traceback": [ "AssertionError: Maximum number of edges for this graph is 3", "", "Stacktrace:", " [1] SimpleGraph{Int64}(nv::Int64, ne::Int64; rng::Nothing, seed::Nothing)", " @ Graphs.SimpleGraphs C:\\Users\\Thibaut\\.julia\\packages\\Graphs\\Me2H1\\src\\SimpleGraphs\\generators\\randgraphs.jl:28", " [2] #SimpleGraph#21", " @ C:\\Users\\Thibaut\\.julia\\packages\\Graphs\\Me2H1\\src\\SimpleGraphs\\generators\\randgraphs.jl:45 [inlined]", " [3] SimpleGraph(nv::Int64, ne::Int64)", " @ Graphs.SimpleGraphs C:\\Users\\Thibaut\\.julia\\packages\\Graphs\\Me2H1\\src\\SimpleGraphs\\generators\\randgraphs.jl:45", " [4] top-level scope", " @ In[7]:1", " [5] eval", " @ .\\boot.jl:368 [inlined]", " [6] include_string(mapexpr::typeof(REPL.softscope), mod::Module, code::String, filename::String)", " @ Base .\\loading.jl:1428" ] } ], "source": [ "Graph(3, 4)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The graphs just created are undirected, meaning that there is no sense of direction in the edges of the graph. To create a graph with directed edges, use:" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "image/svg+xml": [ "\n", "\n", "\n", " \n", " \n", " \n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "\n", "\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "\n", "\n", "\n", "\n" ], "text/html": [ "\n", "\n", "\n", " \n", " \n", " \n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "\n", "\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "\n", "\n", "\n", "\n", "\n" ], "text/plain": [ "Compose.Context(Measures.BoundingBox{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}, Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}((0.0w, 0.0h), (1.0w, 1.0h)), Compose.UnitBox{Float64, Float64, Float64, Float64}(-1.2, -1.2, 2.4, 2.4, 0.0mm, 0.0mm, 0.0mm, 0.0mm), nothing, nothing, nothing, List([Compose.Context(Measures.BoundingBox{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}, Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}((0.0w, 0.0h), (1.0w, 1.0h)), nothing, nothing, nothing, nothing, List([]), List([Compose.Form{Compose.LinePrimitive}(Compose.LinePrimitive[Compose.LinePrimitive{Tuple{Measures.Measure, Measures.Measure}}(Tuple{Measures.Measure, Measures.Measure}[(-0.8979379273840342cx, 0.8979379273840342cy), (-0.0945994499387792cx, 0.09459944993877921cy)]), Compose.LinePrimitive{Tuple{Measures.Measure, Measures.Measure}}(Tuple{Measures.Measure, Measures.Measure}[(0.10952469529315233cx, -0.10952469529315231cy), (0.8979379273840342cx, -0.8979379273840342cy)]), Compose.LinePrimitive{Tuple{Measures.Measure, Measures.Measure}}(Tuple{Measures.Measure, Measures.Measure}[(0.8979379273840342cx, -0.8979379273840342cy), (0.1095246952931523cx, -0.10952469529315235cy)])], Symbol(\"\"))]), List([Compose.Property{Compose.LineWidthPrimitive}(Compose.LineWidthPrimitive[Compose.LineWidthPrimitive(1.7320508075688774mm)]), Compose.Property{Compose.FillPrimitive}(Compose.FillPrimitive[Compose.FillPrimitive(RGBA{Float64}(0.0,0.0,0.0,0.0))]), Compose.Property{Compose.StrokePrimitive}(Compose.StrokePrimitive[Compose.StrokePrimitive(RGBA{Float64}(0.8274509803921568,0.8274509803921568,0.8274509803921568,1.0))])]), 0, false, false, false, false, nothing, nothing, 0.0, Symbol(\"\")), Compose.Context(Measures.BoundingBox{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}, Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}((0.0w, 0.0h), (1.0w, 1.0h)), nothing, nothing, nothing, nothing, List([]), List([Compose.Form{Compose.LinePrimitive}(Compose.LinePrimitive[Compose.LinePrimitive{Tuple{Measures.Measure, Measures.Measure}}(Tuple{Measures.Measure, Measures.Measure}[(-0.1852302286424442cx, 0.13686127611284915cy), (-0.0945994499387792cx, 0.09459944993877921cy), (-0.13686127611284915cx, 0.1852302286424442cy)]), Compose.LinePrimitive{Tuple{Measures.Measure, Measures.Measure}}(Tuple{Measures.Measure, Measures.Measure}[(0.8073071486803692cx, -0.8556761012099643cy), (0.8979379273840342cx, -0.8979379273840342cy), (0.8556761012099643cx, -0.8073071486803692cy)]), Compose.LinePrimitive{Tuple{Measures.Measure, Measures.Measure}}(Tuple{Measures.Measure, Measures.Measure}[(0.2001554739968173cx, -0.15178652146722232cy), (0.1095246952931523cx, -0.10952469529315235cy), (0.15178652146722224cx, -0.20015547399681738cy)])], Symbol(\"\"))]), List([Compose.Property{Compose.LineWidthPrimitive}(Compose.LineWidthPrimitive[Compose.LineWidthPrimitive(1.7320508075688774mm)]), Compose.Property{Compose.StrokePrimitive}(Compose.StrokePrimitive[Compose.StrokePrimitive(RGBA{Float64}(0.8274509803921568,0.8274509803921568,0.8274509803921568,1.0))])]), 0, false, false, false, false, nothing, nothing, 0.0, Symbol(\"\")), Compose.Context(Measures.BoundingBox{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}, Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}((0.0w, 0.0h), (1.0w, 1.0h)), nothing, nothing, nothing, nothing, List([]), List([]), List([Compose.Property{Compose.FontSizePrimitive}(Compose.FontSizePrimitive[Compose.FontSizePrimitive(4.0mm)]), Compose.Property{Compose.StrokePrimitive}(Compose.StrokePrimitive[Compose.StrokePrimitive(RGBA{Float64}(0.0,0.0,0.0,0.0))]), Compose.Property{Compose.FillPrimitive}(Compose.FillPrimitive[Compose.FillPrimitive(RGBA{Float64}(0.0,0.0,0.0,1.0))])]), 0, false, false, false, false, nothing, nothing, 0.0, Symbol(\"\")), Compose.Context(Measures.BoundingBox{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}, Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}((0.0w, 0.0h), (1.0w, 1.0h)), nothing, nothing, nothing, nothing, List([]), List([Compose.Form{Compose.CirclePrimitive{Tuple{Measures.Measure, Measures.Measure}, Measures.Measure}}(Compose.CirclePrimitive{Tuple{Measures.Measure, Measures.Measure}, Measures.Measure}[Compose.CirclePrimitive{Tuple{Measures.Measure, Measures.Measure}, Measures.Measure}((-1.0cx, 1.0cy), 0.05773502691896259w), Compose.CirclePrimitive{Tuple{Measures.Measure, Measures.Measure}, Measures.Measure}((0.007462622677186559cx, -0.007462622677186559cy), 0.05773502691896259w), Compose.CirclePrimitive{Tuple{Measures.Measure, Measures.Measure}, Measures.Measure}((1.0cx, -1.0cy), 0.05773502691896259w)], Symbol(\"\"))]), List([Compose.Property{Compose.LineWidthPrimitive}(Compose.LineWidthPrimitive[Compose.LineWidthPrimitive(0.0mm)]), Compose.Property{Compose.StrokePrimitive}(Compose.StrokePrimitive[Compose.StrokePrimitive(RGBA{Float64}(0.0,0.0,0.0,0.0))]), Compose.Property{Compose.FillPrimitive}(Compose.FillPrimitive[Compose.FillPrimitive(RGBA{Float64}(0.25098039215686274,0.8784313725490196,0.8156862745098039,1.0))])]), 0, false, false, false, false, nothing, nothing, 0.0, Symbol(\"\")), Compose.Context(Measures.BoundingBox{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}, Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}((0.0w, 0.0h), (1.0w, 1.0h)), nothing, nothing, nothing, nothing, List([]), List([]), List([Compose.Property{Compose.FontSizePrimitive}(Compose.FontSizePrimitive[Compose.FontSizePrimitive(4.0mm)]), Compose.Property{Compose.StrokePrimitive}(Compose.StrokePrimitive[Compose.StrokePrimitive(RGBA{Float64}(0.0,0.0,0.0,0.0))]), Compose.Property{Compose.FillPrimitive}(Compose.FillPrimitive[Compose.FillPrimitive(RGBA{Float64}(0.0,0.0,0.0,1.0))])]), 0, false, false, false, false, nothing, nothing, 0.0, Symbol(\"\"))]), List([]), List([]), 0, false, false, false, false, nothing, nothing, 0.0, Symbol(\"\"))" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "G = DiGraph(3,3)\n", "\n", "gplot(G)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Generators\n", "\n", "For convenience, Graphs.jl comes with a set of built-in functions for generating famous graphs in the literature or graphs that resemble basic shapes in real life. These graphs could be constructed manually as described in the previous section and have nothing special in terms of the type system.\n", "\n", "For constructing small graphs with simple shapes, one can use:" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "data": { "image/svg+xml": [ "\n", "\n", "\n", " \n", " \n", " \n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "\n", "\n", "\n", "\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "\n", "\n", "\n", "\n" ], "text/html": [ "\n", "\n", "\n", " \n", " \n", " \n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "\n", "\n", "\n", "\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "\n", "\n", "\n", "\n", "\n" ], "text/plain": [ "Compose.Context(Measures.BoundingBox{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}, Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}((0.0w, 0.0h), (1.0w, 1.0h)), Compose.UnitBox{Float64, Float64, Float64, Float64}(-1.2, -1.2, 2.4, 2.4, 0.0mm, 0.0mm, 0.0mm, 0.0mm), nothing, nothing, nothing, List([Compose.Context(Measures.BoundingBox{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}, Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}((0.0w, 0.0h), (1.0w, 1.0h)), nothing, nothing, nothing, nothing, List([]), List([Compose.Form{Compose.LinePrimitive}(Compose.LinePrimitive[Compose.LinePrimitive{Tuple{Measures.Measure, Measures.Measure}}(Tuple{Measures.Measure, Measures.Measure}[(0.9399948899564122cx, 0.2606265314789337cy), (0.6827079266723322cx, -0.14386514141390766cy)]), Compose.LinePrimitive{Tuple{Measures.Measure, Measures.Measure}}(Tuple{Measures.Measure, Measures.Measure}[(0.8886609551964397cx, 0.3651423412322544cy), (0.05916209554270713cx, 0.4409798439489693cy)]), Compose.LinePrimitive{Tuple{Measures.Measure, Measures.Measure}}(Tuple{Measures.Measure, Measures.Measure}[(0.5444894484007479cx, -0.15831009454881617cy), (0.026036418967143204cx, 0.3712674845472769cy)]), Compose.LinePrimitive{Tuple{Measures.Measure, Measures.Measure}}(Tuple{Measures.Measure, Measures.Measure}[(0.6677405967313382cx, -0.3405325305797067cy), (0.912947227301519cx, -0.8976691719791616cy)]), Compose.LinePrimitive{Tuple{Measures.Measure, Measures.Measure}}(Tuple{Measures.Measure, Measures.Measure}[(-0.14893006771062078cx, 0.5071843910415429cy), (-0.9032468815502324cx, 0.9439747015157863cy)])], Symbol(\"\"))]), List([Compose.Property{Compose.LineWidthPrimitive}(Compose.LineWidthPrimitive[Compose.LineWidthPrimitive(1.3416407864998738mm)]), Compose.Property{Compose.FillPrimitive}(Compose.FillPrimitive[Compose.FillPrimitive(RGBA{Float64}(0.0,0.0,0.0,0.0))]), Compose.Property{Compose.StrokePrimitive}(Compose.StrokePrimitive[Compose.StrokePrimitive(RGBA{Float64}(0.8274509803921568,0.8274509803921568,0.8274509803921568,1.0))])]), 0, false, false, false, false, nothing, nothing, 0.0, Symbol(\"\")), Compose.Context(Measures.BoundingBox{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}, Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}((0.0w, 0.0h), (1.0w, 1.0h)), nothing, nothing, nothing, nothing, List([]), List([]), List([Compose.Property{Compose.LineWidthPrimitive}(Compose.LineWidthPrimitive[Compose.LineWidthPrimitive(1.3416407864998738mm)]), Compose.Property{Compose.StrokePrimitive}(Compose.StrokePrimitive[Compose.StrokePrimitive(RGBA{Float64}(0.8274509803921568,0.8274509803921568,0.8274509803921568,1.0))])]), 0, false, false, false, false, nothing, nothing, 0.0, Symbol(\"\")), Compose.Context(Measures.BoundingBox{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}, Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}((0.0w, 0.0h), (1.0w, 1.0h)), nothing, nothing, nothing, nothing, List([]), List([]), List([Compose.Property{Compose.FontSizePrimitive}(Compose.FontSizePrimitive[Compose.FontSizePrimitive(4.0mm)]), Compose.Property{Compose.StrokePrimitive}(Compose.StrokePrimitive[Compose.StrokePrimitive(RGBA{Float64}(0.0,0.0,0.0,0.0))]), Compose.Property{Compose.FillPrimitive}(Compose.FillPrimitive[Compose.FillPrimitive(RGBA{Float64}(0.0,0.0,0.0,1.0))])]), 0, false, false, false, false, nothing, nothing, 0.0, Symbol(\"\")), Compose.Context(Measures.BoundingBox{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}, Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}((0.0w, 0.0h), (1.0w, 1.0h)), nothing, nothing, nothing, nothing, List([]), List([Compose.Form{Compose.CirclePrimitive{Tuple{Measures.Measure, Measures.Measure}, Measures.Measure}}(Compose.CirclePrimitive{Tuple{Measures.Measure, Measures.Measure}, Measures.Measure}[Compose.CirclePrimitive{Tuple{Measures.Measure, Measures.Measure}, Measures.Measure}((1.0cx, 0.35496309262389447cy), 0.044721359549995794w), Compose.CirclePrimitive{Tuple{Measures.Measure, Measures.Measure}, Measures.Measure}((0.6227028166287443cx, -0.2382017025588684cy), 0.044721359549995794w), Compose.CirclePrimitive{Tuple{Measures.Measure, Measures.Measure}, Measures.Measure}((-0.052176949260853145cx, 0.4511590925573292cy), 0.044721359549995794w), Compose.CirclePrimitive{Tuple{Measures.Measure, Measures.Measure}, Measures.Measure}((0.957985007404113cx, -1.0cy), 0.044721359549995794w), Compose.CirclePrimitive{Tuple{Measures.Measure, Measures.Measure}, Measures.Measure}((-1.0cx, 1.0cy), 0.044721359549995794w)], Symbol(\"\"))]), List([Compose.Property{Compose.LineWidthPrimitive}(Compose.LineWidthPrimitive[Compose.LineWidthPrimitive(0.0mm)]), Compose.Property{Compose.StrokePrimitive}(Compose.StrokePrimitive[Compose.StrokePrimitive(RGBA{Float64}(0.0,0.0,0.0,0.0))]), Compose.Property{Compose.FillPrimitive}(Compose.FillPrimitive[Compose.FillPrimitive(RGBA{Float64}(0.25098039215686274,0.8784313725490196,0.8156862745098039,1.0))])]), 0, false, false, false, false, nothing, nothing, 0.0, Symbol(\"\")), Compose.Context(Measures.BoundingBox{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}, Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}((0.0w, 0.0h), (1.0w, 1.0h)), nothing, nothing, nothing, nothing, List([]), List([]), List([Compose.Property{Compose.FontSizePrimitive}(Compose.FontSizePrimitive[Compose.FontSizePrimitive(4.0mm)]), Compose.Property{Compose.StrokePrimitive}(Compose.StrokePrimitive[Compose.StrokePrimitive(RGBA{Float64}(0.0,0.0,0.0,0.0))]), Compose.Property{Compose.FillPrimitive}(Compose.FillPrimitive[Compose.FillPrimitive(RGBA{Float64}(0.0,0.0,0.0,1.0))])]), 0, false, false, false, false, nothing, nothing, 0.0, Symbol(\"\"))]), List([]), List([]), 0, false, false, false, false, nothing, nothing, 0.0, Symbol(\"\"))" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "image/svg+xml": [ "\n", "\n", "\n", " \n", " \n", " \n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "\n", "\n", "\n", "\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "\n", "\n", "\n", "\n" ], "text/html": [ "\n", "\n", "\n", " \n", " \n", " \n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "\n", "\n", "\n", "\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "\n", "\n", "\n", "\n", "\n" ], "text/plain": [ "Compose.Context(Measures.BoundingBox{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}, Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}((0.0w, 0.0h), (1.0w, 1.0h)), Compose.UnitBox{Float64, Float64, Float64, Float64}(-1.2, -1.2, 2.4, 2.4, 0.0mm, 0.0mm, 0.0mm, 0.0mm), nothing, nothing, nothing, List([Compose.Context(Measures.BoundingBox{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}, Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}((0.0w, 0.0h), (1.0w, 1.0h)), nothing, nothing, nothing, nothing, List([]), List([Compose.Form{Compose.LinePrimitive}(Compose.LinePrimitive[Compose.LinePrimitive{Tuple{Measures.Measure, Measures.Measure}}(Tuple{Measures.Measure, Measures.Measure}[(-0.8881967318034483cx, 0.9971130644807894cy), (0.8881967318034483cx, 0.9998290597474914cy)]), Compose.LinePrimitive{Tuple{Measures.Measure, Measures.Measure}}(Tuple{Measures.Measure, Measures.Measure}[(-0.9933637408403019cx, 0.8853358517147463cy), (-0.9413287745430096cx, 0.010230089710069432cy)]), Compose.LinePrimitive{Tuple{Measures.Measure, Measures.Measure}}(Tuple{Measures.Measure, Measures.Measure}[(0.9947565068504286cx, 0.8883196267037471cy), (0.9536680778441714cx, 0.013183346617159683cy)]), Compose.LinePrimitive{Tuple{Measures.Measure, Measures.Measure}}(Tuple{Measures.Measure, Measures.Measure}[(-0.8228892471855839cx, -0.10120524332001872cy), (0.8366213164968724cx, -0.09866796616253952cy)]), Compose.LinePrimitive{Tuple{Measures.Measure, Measures.Measure}}(Tuple{Measures.Measure, Measures.Measure}[(-0.8535837450548662cx, -0.17832660434751846cy), (-0.0686164446392772cx, -0.9230495784559466cy)]), Compose.LinePrimitive{Tuple{Measures.Measure, Measures.Measure}}(Tuple{Measures.Measure, Measures.Measure}[(0.8679004338007686cx, -0.17605900913717304cy), (0.09301647658299937cx, -0.9224380175419202cy)])], Symbol(\"\"))]), List([Compose.Property{Compose.LineWidthPrimitive}(Compose.LineWidthPrimitive[Compose.LineWidthPrimitive(1.3416407864998738mm)]), Compose.Property{Compose.FillPrimitive}(Compose.FillPrimitive[Compose.FillPrimitive(RGBA{Float64}(0.0,0.0,0.0,0.0))]), Compose.Property{Compose.StrokePrimitive}(Compose.StrokePrimitive[Compose.StrokePrimitive(RGBA{Float64}(0.8274509803921568,0.8274509803921568,0.8274509803921568,1.0))])]), 0, false, false, false, false, nothing, nothing, 0.0, Symbol(\"\")), Compose.Context(Measures.BoundingBox{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}, Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}((0.0w, 0.0h), (1.0w, 1.0h)), nothing, nothing, nothing, nothing, List([]), List([]), List([Compose.Property{Compose.LineWidthPrimitive}(Compose.LineWidthPrimitive[Compose.LineWidthPrimitive(1.3416407864998738mm)]), Compose.Property{Compose.StrokePrimitive}(Compose.StrokePrimitive[Compose.StrokePrimitive(RGBA{Float64}(0.8274509803921568,0.8274509803921568,0.8274509803921568,1.0))])]), 0, false, false, false, false, nothing, nothing, 0.0, Symbol(\"\")), Compose.Context(Measures.BoundingBox{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}, Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}((0.0w, 0.0h), (1.0w, 1.0h)), nothing, nothing, nothing, nothing, List([]), List([]), List([Compose.Property{Compose.FontSizePrimitive}(Compose.FontSizePrimitive[Compose.FontSizePrimitive(4.0mm)]), Compose.Property{Compose.StrokePrimitive}(Compose.StrokePrimitive[Compose.StrokePrimitive(RGBA{Float64}(0.0,0.0,0.0,0.0))]), Compose.Property{Compose.FillPrimitive}(Compose.FillPrimitive[Compose.FillPrimitive(RGBA{Float64}(0.0,0.0,0.0,1.0))])]), 0, false, false, false, false, nothing, nothing, 0.0, Symbol(\"\")), Compose.Context(Measures.BoundingBox{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}, Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}((0.0w, 0.0h), (1.0w, 1.0h)), nothing, nothing, nothing, nothing, List([]), List([Compose.Form{Compose.CirclePrimitive{Tuple{Measures.Measure, Measures.Measure}, Measures.Measure}}(Compose.CirclePrimitive{Tuple{Measures.Measure, Measures.Measure}, Measures.Measure}[Compose.CirclePrimitive{Tuple{Measures.Measure, Measures.Measure}, Measures.Measure}((-1.0cx, 0.9969421242282808cy), 0.044721359549995794w), Compose.CirclePrimitive{Tuple{Measures.Measure, Measures.Measure}, Measures.Measure}((1.0cx, 1.0cy), 0.044721359549995794w), Compose.CirclePrimitive{Tuple{Measures.Measure, Measures.Measure}, Measures.Measure}((-0.9346925153833114cx, -0.10137618280346505cy), 0.044721359549995794w), Compose.CirclePrimitive{Tuple{Measures.Measure, Measures.Measure}, Measures.Measure}((0.9484245846946cx, -0.09849702667909321cy), 0.044721359549995794w), Compose.CirclePrimitive{Tuple{Measures.Measure, Measures.Measure}, Measures.Measure}((0.012492325689168027cx, -1.0cy), 0.044721359549995794w)], Symbol(\"\"))]), List([Compose.Property{Compose.LineWidthPrimitive}(Compose.LineWidthPrimitive[Compose.LineWidthPrimitive(0.0mm)]), Compose.Property{Compose.StrokePrimitive}(Compose.StrokePrimitive[Compose.StrokePrimitive(RGBA{Float64}(0.0,0.0,0.0,0.0))]), Compose.Property{Compose.FillPrimitive}(Compose.FillPrimitive[Compose.FillPrimitive(RGBA{Float64}(0.25098039215686274,0.8784313725490196,0.8156862745098039,1.0))])]), 0, false, false, false, false, nothing, nothing, 0.0, Symbol(\"\")), Compose.Context(Measures.BoundingBox{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}, Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}((0.0w, 0.0h), (1.0w, 1.0h)), nothing, nothing, nothing, nothing, List([]), List([]), List([Compose.Property{Compose.FontSizePrimitive}(Compose.FontSizePrimitive[Compose.FontSizePrimitive(4.0mm)]), Compose.Property{Compose.StrokePrimitive}(Compose.StrokePrimitive[Compose.StrokePrimitive(RGBA{Float64}(0.0,0.0,0.0,0.0))]), Compose.Property{Compose.FillPrimitive}(Compose.FillPrimitive[Compose.FillPrimitive(RGBA{Float64}(0.0,0.0,0.0,1.0))])]), 0, false, false, false, false, nothing, nothing, 0.0, Symbol(\"\"))]), List([]), List([]), 0, false, false, false, false, nothing, nothing, 0.0, Symbol(\"\"))" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "for shape in [\"bull\",\"house\"]\n", " G = smallgraph(shape)\n", " display(gplot(G))\n", "end" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Many other generators are provided that can be used to construct graphs with specific properties. For example, a graph with `4`-connected `3`-cliques can be quickly sketched with:" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "data": { "image/svg+xml": [ "\n", "\n", "\n", " \n", " \n", " \n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "\n", "\n", "\n", "\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "\n", "\n", "\n", "\n" ], "text/html": [ "\n", "\n", "\n", " \n", " \n", " \n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "\n", "\n", "\n", "\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "\n", "\n", "\n", "\n", "\n" ], "text/plain": [ "Compose.Context(Measures.BoundingBox{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}, Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}((0.0w, 0.0h), (1.0w, 1.0h)), Compose.UnitBox{Float64, Float64, Float64, Float64}(-1.2, -1.2, 2.4, 2.4, 0.0mm, 0.0mm, 0.0mm, 0.0mm), nothing, nothing, nothing, List([Compose.Context(Measures.BoundingBox{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}, Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}((0.0w, 0.0h), (1.0w, 1.0h)), nothing, nothing, nothing, nothing, List([]), List([Compose.Form{Compose.LinePrimitive}(Compose.LinePrimitive[Compose.LinePrimitive{Tuple{Measures.Measure, Measures.Measure}}(Tuple{Measures.Measure, Measures.Measure}[(-0.4856883665832443cx, -0.010073238099538709cy), (-0.90533004380425cx, -0.17513087023329027cy)]), Compose.LinePrimitive{Tuple{Measures.Measure, Measures.Measure}}(Tuple{Measures.Measure, Measures.Measure}[(-0.4896104404185089cx, 0.028817588694766798cy), (-0.9289175350685821cx, 0.10591389595213416cy)]), Compose.LinePrimitive{Tuple{Measures.Measure, Measures.Measure}}(Tuple{Measures.Measure, Measures.Measure}[(-0.3784559416813996cx, 0.07636432878565125cy), (-0.19214994008937789cx, 0.35542035110605275cy)]), Compose.LinePrimitive{Tuple{Measures.Measure, Measures.Measure}}(Tuple{Measures.Measure, Measures.Measure}[(-0.3468291807341273cx, 0.00812004906816087cy), (0.34388921898761193cx, -0.0710962293119036cy)]), Compose.LinePrimitive{Tuple{Measures.Measure, Measures.Measure}}(Tuple{Measures.Measure, Measures.Measure}[(-0.9786730328898848cx, -0.1296435935289188cy), (-0.9938174020105185cx, 0.04648506199042583cy)]), Compose.LinePrimitive{Tuple{Measures.Measure, Measures.Measure}}(Tuple{Measures.Measure, Measures.Measure}[(-0.14069780909380533cx, 0.4867076134662602cy), (-0.0701127831311641cx, 0.9287341124991614cy)]), Compose.LinePrimitive{Tuple{Measures.Measure, Measures.Measure}}(Tuple{Measures.Measure, Measures.Measure}[(-0.17794847845779843cx, 0.4828141745532337cy), (-0.34352375395959645cx, 0.9140072560622898cy)]), Compose.LinePrimitive{Tuple{Measures.Measure, Measures.Measure}}(Tuple{Measures.Measure, Measures.Measure}[(-0.1331847877928855cx, 0.34578985300405823cy), (0.053000125505169915cx, -0.34060439867401654cy)]), Compose.LinePrimitive{Tuple{Measures.Measure, Measures.Measure}}(Tuple{Measures.Measure, Measures.Measure}[(-0.1307721843261021cx, 0.9956821294835341cy), (-0.29735482774888905cx, 0.985697575166568cy)]), Compose.LinePrimitive{Tuple{Measures.Measure, Measures.Measure}}(Tuple{Measures.Measure, Measures.Measure}[(0.057049293464441014cx, -0.4808819784704326cy), (-0.037213801822451625cx, -0.9293742931649471cy)]), Compose.LinePrimitive{Tuple{Measures.Measure, Measures.Measure}}(Tuple{Measures.Measure, Measures.Measure}[(0.09410956962534775cx, -0.4789204413956182cy), (0.23309460339797264cx, -0.9084825621666973cy)]), Compose.LinePrimitive{Tuple{Measures.Measure, Measures.Measure}}(Tuple{Measures.Measure, Measures.Measure}[(0.12388000854650105cx, -0.36019920774923997cy), (0.36360124919004555cx, -0.12937619805616507cy)]), Compose.LinePrimitive{Tuple{Measures.Measure, Measures.Measure}}(Tuple{Measures.Measure, Measures.Measure}[(0.019912375740245916cx, -0.9946489257682385cy), (0.18334080093312194cx, -0.9824978061586972cy)]), Compose.LinePrimitive{Tuple{Measures.Measure, Measures.Measure}}(Tuple{Measures.Measure, Measures.Measure}[(0.4840121526100551cx, -0.056374188031419366cy), (0.8996676741160314cx, 0.08300927679173553cy)]), Compose.LinePrimitive{Tuple{Measures.Measure, Measures.Measure}}(Tuple{Measures.Measure, Measures.Measure}[(0.48608955462055664cx, -0.09474204138240586cy), (0.929498459120019cx, -0.1917421112515227cy)]), Compose.LinePrimitive{Tuple{Measures.Measure, Measures.Measure}}(Tuple{Measures.Measure, Measures.Measure}[(0.9754082295621846cx, 0.03415726351136664cy), (0.9926835834233264cx, -0.13536805904492857cy)])], Symbol(\"\"))]), List([Compose.Property{Compose.LineWidthPrimitive}(Compose.LineWidthPrimitive[Compose.LineWidthPrimitive(0.8660254037844387mm)]), Compose.Property{Compose.FillPrimitive}(Compose.FillPrimitive[Compose.FillPrimitive(RGBA{Float64}(0.0,0.0,0.0,0.0))]), Compose.Property{Compose.StrokePrimitive}(Compose.StrokePrimitive[Compose.StrokePrimitive(RGBA{Float64}(0.8274509803921568,0.8274509803921568,0.8274509803921568,1.0))])]), 0, false, false, false, false, nothing, nothing, 0.0, Symbol(\"\")), Compose.Context(Measures.BoundingBox{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}, Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}((0.0w, 0.0h), (1.0w, 1.0h)), nothing, nothing, nothing, nothing, List([]), List([]), List([Compose.Property{Compose.LineWidthPrimitive}(Compose.LineWidthPrimitive[Compose.LineWidthPrimitive(0.8660254037844387mm)]), Compose.Property{Compose.StrokePrimitive}(Compose.StrokePrimitive[Compose.StrokePrimitive(RGBA{Float64}(0.8274509803921568,0.8274509803921568,0.8274509803921568,1.0))])]), 0, false, false, false, false, nothing, nothing, 0.0, Symbol(\"\")), Compose.Context(Measures.BoundingBox{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}, Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}((0.0w, 0.0h), (1.0w, 1.0h)), nothing, nothing, nothing, nothing, List([]), List([]), List([Compose.Property{Compose.FontSizePrimitive}(Compose.FontSizePrimitive[Compose.FontSizePrimitive(4.0mm)]), Compose.Property{Compose.StrokePrimitive}(Compose.StrokePrimitive[Compose.StrokePrimitive(RGBA{Float64}(0.0,0.0,0.0,0.0))]), Compose.Property{Compose.FillPrimitive}(Compose.FillPrimitive[Compose.FillPrimitive(RGBA{Float64}(0.0,0.0,0.0,1.0))])]), 0, false, false, false, false, nothing, nothing, 0.0, Symbol(\"\")), Compose.Context(Measures.BoundingBox{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}, Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}((0.0w, 0.0h), (1.0w, 1.0h)), nothing, nothing, nothing, nothing, List([]), List([Compose.Form{Compose.CirclePrimitive{Tuple{Measures.Measure, Measures.Measure}, Measures.Measure}}(Compose.CirclePrimitive{Tuple{Measures.Measure, Measures.Measure}, Measures.Measure}[Compose.CirclePrimitive{Tuple{Measures.Measure, Measures.Measure}, Measures.Measure}((-0.418527975487091cx, 0.01634295392628249cy), 0.028867513459481294w), Compose.CirclePrimitive{Tuple{Measures.Measure, Measures.Measure}, Measures.Measure}((-0.9724904349004033cx, -0.20154706225911145cy), 0.028867513459481294w), Compose.CirclePrimitive{Tuple{Measures.Measure, Measures.Measure}, Measures.Measure}((-1.0cx, 0.1183885307206185cy), 0.028867513459481294w), Compose.CirclePrimitive{Tuple{Measures.Measure, Measures.Measure}, Measures.Measure}((-0.15207790628368656cx, 0.4154417259654215cy), 0.028867513459481294w), Compose.CirclePrimitive{Tuple{Measures.Measure, Measures.Measure}, Measures.Measure}((-0.05873268594128289cx, 1.0cy), 0.028867513459481294w), Compose.CirclePrimitive{Tuple{Measures.Measure, Measures.Measure}, Measures.Measure}((-0.36939432613370826cx, 0.981379704650102cy), 0.028867513459481294w), Compose.CirclePrimitive{Tuple{Measures.Measure, Measures.Measure}, Measures.Measure}((0.07189324399597097cx, -0.4102562716353798cy), 0.028867513459481294w), Compose.CirclePrimitive{Tuple{Measures.Measure, Measures.Measure}, Measures.Measure}((-0.05205775235398158cx, -1.0cy), 0.028867513459481294w), Compose.CirclePrimitive{Tuple{Measures.Measure, Measures.Measure}, Measures.Measure}((0.2553109290273494cx, -0.9771467319269357cy), 0.028867513459481294w), Compose.CirclePrimitive{Tuple{Measures.Measure, Measures.Measure}, Measures.Measure}((0.41558801374057563cx, -0.07931913417002523cy), 0.028867513459481294w), Compose.CirclePrimitive{Tuple{Measures.Measure, Measures.Measure}, Measures.Measure}((0.968091812985511cx, 0.1059542229303414cy), 0.028867513459481294w), Compose.CirclePrimitive{Tuple{Measures.Measure, Measures.Measure}, Measures.Measure}((1.0cx, -0.20716501846390334cy), 0.028867513459481294w)], Symbol(\"\"))]), List([Compose.Property{Compose.LineWidthPrimitive}(Compose.LineWidthPrimitive[Compose.LineWidthPrimitive(0.0mm)]), Compose.Property{Compose.StrokePrimitive}(Compose.StrokePrimitive[Compose.StrokePrimitive(RGBA{Float64}(0.0,0.0,0.0,0.0))]), Compose.Property{Compose.FillPrimitive}(Compose.FillPrimitive[Compose.FillPrimitive(RGBA{Float64}(0.25098039215686274,0.8784313725490196,0.8156862745098039,1.0))])]), 0, false, false, false, false, nothing, nothing, 0.0, Symbol(\"\")), Compose.Context(Measures.BoundingBox{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}, Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}((0.0w, 0.0h), (1.0w, 1.0h)), nothing, nothing, nothing, nothing, List([]), List([]), List([Compose.Property{Compose.FontSizePrimitive}(Compose.FontSizePrimitive[Compose.FontSizePrimitive(4.0mm)]), Compose.Property{Compose.StrokePrimitive}(Compose.StrokePrimitive[Compose.StrokePrimitive(RGBA{Float64}(0.0,0.0,0.0,0.0))]), Compose.Property{Compose.FillPrimitive}(Compose.FillPrimitive[Compose.FillPrimitive(RGBA{Float64}(0.0,0.0,0.0,1.0))])]), 0, false, false, false, false, nothing, nothing, 0.0, Symbol(\"\"))]), List([]), List([]), 0, false, false, false, false, nothing, nothing, 0.0, Symbol(\"\"))" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "G = CliqueGraph(3,4)\n", "\n", "gplot(G)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Please consult the documentation of Graphs.jl or the `src/generators` folder of the project for more generators. Contributions are very welcome." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Graph properties\n", "\n", "Now that we know how to construct graphs, let's query some basic properties from existing graphs, such as the number of vertices and edges, and compact matricial representations. Consider the simple house graph:" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "data": { "image/svg+xml": [ "\n", "\n", "\n", " \n", " \n", " \n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "\n", "\n", "\n", "\n", " \n", " \n", " 1\n", " \n", " \n", " \n", " \n", " 2\n", " \n", " \n", " \n", " \n", " 3\n", " \n", " \n", " \n", " \n", " 4\n", " \n", " \n", " \n", " \n", " 5\n", " \n", " \n", " \n", " \n", " 6\n", " \n", " \n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "\n", "\n", " \n", " \n", " 1\n", " \n", " \n", " \n", " \n", " 2\n", " \n", " \n", " \n", " \n", " 3\n", " \n", " \n", " \n", " \n", " 4\n", " \n", " \n", " \n", " \n", " 5\n", " \n", " \n", "\n", "\n" ], "text/html": [ "\n", "\n", "\n", " \n", " \n", " \n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "\n", "\n", "\n", "\n", " \n", " \n", " 1\n", " \n", " \n", " \n", " \n", " 2\n", " \n", " \n", " \n", " \n", " 3\n", " \n", " \n", " \n", " \n", " 4\n", " \n", " \n", " \n", " \n", " 5\n", " \n", " \n", " \n", " \n", " 6\n", " \n", " \n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "\n", "\n", " \n", " \n", " 1\n", " \n", " \n", " \n", " \n", " 2\n", " \n", " \n", " \n", " \n", " 3\n", " \n", " \n", " \n", " \n", " 4\n", " \n", " \n", " \n", " \n", " 5\n", " \n", " \n", "\n", "\n", "\n" ], "text/plain": [ "Compose.Context(Measures.BoundingBox{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}, Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}((0.0w, 0.0h), (1.0w, 1.0h)), Compose.UnitBox{Float64, Float64, Float64, Float64}(-1.2, -1.2, 2.4, 2.4, 0.0mm, 0.0mm, 0.0mm, 0.0mm), nothing, nothing, nothing, List([Compose.Context(Measures.BoundingBox{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}, Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}((0.0w, 0.0h), (1.0w, 1.0h)), nothing, nothing, nothing, nothing, List([]), List([Compose.Form{Compose.LinePrimitive}(Compose.LinePrimitive[Compose.LinePrimitive{Tuple{Measures.Measure, Measures.Measure}}(Tuple{Measures.Measure, Measures.Measure}[(-0.38304318561393325cx, 0.9771621589237096cy), (0.8905539721370661cx, 0.7114036837019417cy)]), Compose.LinePrimitive{Tuple{Measures.Measure, Measures.Measure}}(Tuple{Measures.Measure, Measures.Measure}[(-0.5417938321893799cx, 0.8996553211494813cy), (-0.9506953812874872cx, 0.06745956145859269cy)]), Compose.LinePrimitive{Tuple{Measures.Measure, Measures.Measure}}(Tuple{Measures.Measure, Measures.Measure}[(0.9420472425636898cx, 0.5929547663555446cy), (0.44537421867808996cx, -0.2264616767743459cy)]), Compose.LinePrimitive{Tuple{Measures.Measure, Measures.Measure}}(Tuple{Measures.Measure, Measures.Measure}[(-0.8905488909508046cx, -0.055698594283911204cy), (0.2779703521925843cx, -0.2992592761524675cy)]), Compose.LinePrimitive{Tuple{Measures.Measure, Measures.Measure}}(Tuple{Measures.Measure, Measures.Measure}[(-0.9727441461269571cx, -0.14131536423131735cy), (-0.7841544805278838cx, -0.8915697531606086cy)]), Compose.LinePrimitive{Tuple{Measures.Measure, Measures.Measure}}(Tuple{Measures.Measure, Measures.Measure}[(0.2912310002712142cx, -0.3790586742730344cy), (-0.6607081656842755cx, -0.9430140787714183cy)])], Symbol(\"\"))]), List([Compose.Property{Compose.LineWidthPrimitive}(Compose.LineWidthPrimitive[Compose.LineWidthPrimitive(1.3416407864998738mm)]), Compose.Property{Compose.FillPrimitive}(Compose.FillPrimitive[Compose.FillPrimitive(RGBA{Float64}(0.0,0.0,0.0,0.0))]), Compose.Property{Compose.StrokePrimitive}(Compose.StrokePrimitive[Compose.StrokePrimitive(RGBA{Float64}(0.8274509803921568,0.8274509803921568,0.8274509803921568,1.0))])]), 0, false, false, false, false, nothing, nothing, 0.0, Symbol(\"\")), Compose.Context(Measures.BoundingBox{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}, Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}((0.0w, 0.0h), (1.0w, 1.0h)), nothing, nothing, nothing, nothing, List([]), List([]), List([Compose.Property{Compose.LineWidthPrimitive}(Compose.LineWidthPrimitive[Compose.LineWidthPrimitive(1.3416407864998738mm)]), Compose.Property{Compose.StrokePrimitive}(Compose.StrokePrimitive[Compose.StrokePrimitive(RGBA{Float64}(0.8274509803921568,0.8274509803921568,0.8274509803921568,1.0))])]), 0, false, false, false, false, nothing, nothing, 0.0, Symbol(\"\")), Compose.Context(Measures.BoundingBox{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}, Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}((0.0w, 0.0h), (1.0w, 1.0h)), nothing, nothing, nothing, nothing, List([]), List([Compose.Form{Compose.TextPrimitive{Tuple{Measures.Length{:cx, Float64}, Measures.Length{:cy, Float64}}, Compose.Rotation{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}, Tuple{Measures.AbsoluteLength, Measures.AbsoluteLength}}}(Compose.TextPrimitive{Tuple{Measures.Length{:cx, Float64}, Measures.Length{:cy, Float64}}, Compose.Rotation{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}, Tuple{Measures.AbsoluteLength, Measures.AbsoluteLength}}[Compose.TextPrimitive{Tuple{Measures.Length{:cx, Float64}, Measures.Length{:cy, Float64}}, Compose.Rotation{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}, Tuple{Measures.AbsoluteLength, Measures.AbsoluteLength}}((0.25375539326156643cx, 0.8442829213128257cy), \"1\", Compose.HCenter(), Compose.VCenter(), Compose.Rotation{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}(0.0, (0.5w, 0.5h)), (0.0mm, 0.0mm)), Compose.TextPrimitive{Tuple{Measures.Length{:cx, Float64}, Measures.Length{:cy, Float64}}, Compose.Rotation{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}, Tuple{Measures.AbsoluteLength, Measures.AbsoluteLength}}((-0.7462446067384336cx, 0.483557441304037cy), \"2\", Compose.HCenter(), Compose.VCenter(), Compose.Rotation{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}(0.0, (0.5w, 0.5h)), (0.0mm, 0.0mm)), Compose.TextPrimitive{Tuple{Measures.Length{:cx, Float64}, Measures.Length{:cy, Float64}}, Compose.Rotation{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}, Tuple{Measures.AbsoluteLength, Measures.AbsoluteLength}}((0.6937107306208898cx, 0.18324654479059932cy), \"3\", Compose.HCenter(), Compose.VCenter(), Compose.Rotation{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}(0.0, (0.5w, 0.5h)), (0.0mm, 0.0mm)), Compose.TextPrimitive{Tuple{Measures.Length{:cx, Float64}, Measures.Length{:cy, Float64}}, Compose.Rotation{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}, Tuple{Measures.AbsoluteLength, Measures.AbsoluteLength}}((-0.30628926937911016cx, -0.17747893521818936cy), \"4\", Compose.HCenter(), Compose.VCenter(), Compose.Rotation{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}(0.0, (0.5w, 0.5h)), (0.0mm, 0.0mm)), Compose.TextPrimitive{Tuple{Measures.Length{:cx, Float64}, Measures.Length{:cy, Float64}}, Compose.Rotation{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}, Tuple{Measures.AbsoluteLength, Measures.AbsoluteLength}}((-0.8784493133274205cx, -0.516442558695963cy), \"5\", Compose.HCenter(), Compose.VCenter(), Compose.Rotation{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}(0.0, (0.5w, 0.5h)), (0.0mm, 0.0mm)), Compose.TextPrimitive{Tuple{Measures.Length{:cx, Float64}, Measures.Length{:cy, Float64}}, Compose.Rotation{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}, Tuple{Measures.AbsoluteLength, Measures.AbsoluteLength}}((-0.18473858270653065cx, -0.6610363765222264cy), \"6\", Compose.HCenter(), Compose.VCenter(), Compose.Rotation{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}(0.0, (0.5w, 0.5h)), (0.0mm, 0.0mm))], Symbol(\"\"))]), List([Compose.Property{Compose.FontSizePrimitive}(Compose.FontSizePrimitive[Compose.FontSizePrimitive(4.0mm)]), Compose.Property{Compose.StrokePrimitive}(Compose.StrokePrimitive[Compose.StrokePrimitive(RGBA{Float64}(0.0,0.0,0.0,0.0))]), Compose.Property{Compose.FillPrimitive}(Compose.FillPrimitive[Compose.FillPrimitive(RGBA{Float64}(0.0,0.0,0.0,1.0))])]), 0, false, false, false, false, nothing, nothing, 0.0, Symbol(\"\")), Compose.Context(Measures.BoundingBox{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}, Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}((0.0w, 0.0h), (1.0w, 1.0h)), nothing, nothing, nothing, nothing, List([]), List([Compose.Form{Compose.CirclePrimitive{Tuple{Measures.Measure, Measures.Measure}, Measures.Measure}}(Compose.CirclePrimitive{Tuple{Measures.Measure, Measures.Measure}, Measures.Measure}[Compose.CirclePrimitive{Tuple{Measures.Measure, Measures.Measure}, Measures.Measure}((-0.49248921347686714cx, 1.0cy), 0.044721359549995794w), Compose.CirclePrimitive{Tuple{Measures.Measure, Measures.Measure}, Measures.Measure}((1.0cx, 0.6885658426256513cy), 0.044721359549995794w), Compose.CirclePrimitive{Tuple{Measures.Measure, Measures.Measure}, Measures.Measure}((-1.0cx, -0.03288511739192601cy), 0.044721359549995794w), Compose.CirclePrimitive{Tuple{Measures.Measure, Measures.Measure}, Measures.Measure}((0.3874214612417797cx, -0.3220727530444527cy), 0.044721359549995794w), Compose.CirclePrimitive{Tuple{Measures.Measure, Measures.Measure}, Measures.Measure}((-0.756898626654841cx, -1.0cy), 0.044721359549995794w)], Symbol(\"\"))]), List([Compose.Property{Compose.LineWidthPrimitive}(Compose.LineWidthPrimitive[Compose.LineWidthPrimitive(0.0mm)]), Compose.Property{Compose.StrokePrimitive}(Compose.StrokePrimitive[Compose.StrokePrimitive(RGBA{Float64}(0.0,0.0,0.0,0.0))]), Compose.Property{Compose.FillPrimitive}(Compose.FillPrimitive[Compose.FillPrimitive(RGBA{Float64}(0.25098039215686274,0.8784313725490196,0.8156862745098039,1.0))])]), 0, false, false, false, false, nothing, nothing, 0.0, Symbol(\"\")), Compose.Context(Measures.BoundingBox{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}, Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}((0.0w, 0.0h), (1.0w, 1.0h)), nothing, nothing, nothing, nothing, List([]), List([Compose.Form{Compose.TextPrimitive{Tuple{Measures.Length{:cx, Float64}, Measures.Length{:cy, Float64}}, Compose.Rotation{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}, Tuple{Measures.AbsoluteLength, Measures.AbsoluteLength}}}(Compose.TextPrimitive{Tuple{Measures.Length{:cx, Float64}, Measures.Length{:cy, Float64}}, Compose.Rotation{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}, Tuple{Measures.AbsoluteLength, Measures.AbsoluteLength}}[Compose.TextPrimitive{Tuple{Measures.Length{:cx, Float64}, Measures.Length{:cy, Float64}}, Compose.Rotation{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}, Tuple{Measures.AbsoluteLength, Measures.AbsoluteLength}}((-0.49248921347686714cx, 1.0cy), \"1\", Compose.HCenter(), Compose.VCenter(), Compose.Rotation{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}(0.0, (0.5w, 0.5h)), (0.0mm, 0.0mm)), Compose.TextPrimitive{Tuple{Measures.Length{:cx, Float64}, Measures.Length{:cy, Float64}}, Compose.Rotation{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}, Tuple{Measures.AbsoluteLength, Measures.AbsoluteLength}}((1.0cx, 0.6885658426256513cy), \"2\", Compose.HCenter(), Compose.VCenter(), Compose.Rotation{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}(0.0, (0.5w, 0.5h)), (0.0mm, 0.0mm)), Compose.TextPrimitive{Tuple{Measures.Length{:cx, Float64}, Measures.Length{:cy, Float64}}, Compose.Rotation{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}, Tuple{Measures.AbsoluteLength, Measures.AbsoluteLength}}((-1.0cx, -0.03288511739192601cy), \"3\", Compose.HCenter(), Compose.VCenter(), Compose.Rotation{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}(0.0, (0.5w, 0.5h)), (0.0mm, 0.0mm)), Compose.TextPrimitive{Tuple{Measures.Length{:cx, Float64}, Measures.Length{:cy, Float64}}, Compose.Rotation{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}, Tuple{Measures.AbsoluteLength, Measures.AbsoluteLength}}((0.3874214612417797cx, -0.3220727530444527cy), \"4\", Compose.HCenter(), Compose.VCenter(), Compose.Rotation{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}(0.0, (0.5w, 0.5h)), (0.0mm, 0.0mm)), Compose.TextPrimitive{Tuple{Measures.Length{:cx, Float64}, Measures.Length{:cy, Float64}}, Compose.Rotation{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}, Tuple{Measures.AbsoluteLength, Measures.AbsoluteLength}}((-0.756898626654841cx, -1.0cy), \"5\", Compose.HCenter(), Compose.VCenter(), Compose.Rotation{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}(0.0, (0.5w, 0.5h)), (0.0mm, 0.0mm))], Symbol(\"\"))]), List([Compose.Property{Compose.FontSizePrimitive}(Compose.FontSizePrimitive[Compose.FontSizePrimitive(4.0mm)]), Compose.Property{Compose.StrokePrimitive}(Compose.StrokePrimitive[Compose.StrokePrimitive(RGBA{Float64}(0.0,0.0,0.0,0.0))]), Compose.Property{Compose.FillPrimitive}(Compose.FillPrimitive[Compose.FillPrimitive(RGBA{Float64}(0.0,0.0,0.0,1.0))])]), 0, false, false, false, false, nothing, nothing, 0.0, Symbol(\"\"))]), List([]), List([]), 0, false, false, false, false, nothing, nothing, 0.0, Symbol(\"\"))" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "G = smallgraph(\"house\")\n", "\n", "nvertices = nv(G) # number of vertices\n", "nedges = ne(G) # number of edges\n", "\n", "gplot(G, nodelabel=1:nvertices, edgelabel=1:nedges)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Notice from the numbering that the house was built from the floor to the roof, and that there are 5 vertices and 6 edges in the graph.\n", "\n", "One can easily loop over these elements with:" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "vertex 1\n", "vertex 2\n", "vertex 3\n", "vertex 4\n", "vertex 5\n" ] } ], "source": [ "for v in vertices(G)\n", " println(\"vertex $v\")\n", "end" ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "edge 1 - 2\n", "edge 1 - 3\n", "edge 2 - 4\n", "edge 3 - 4\n", "edge 3 - 5\n", "edge 4 - 5\n" ] } ], "source": [ "for e in edges(G)\n", " u, v = src(e), dst(e)\n", " println(\"edge $u - $v\")\n", "end" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Or obtain compact representations of the graph in matrix form:" ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "5×5 SparseArrays.SparseMatrixCSC{Int64, Int64} with 12 stored entries:\n", " ⋅ 1 1 ⋅ ⋅\n", " 1 ⋅ ⋅ 1 ⋅\n", " 1 ⋅ ⋅ 1 1\n", " ⋅ 1 1 ⋅ 1\n", " ⋅ ⋅ 1 1 ⋅" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "adjacency_matrix(G)" ] }, { "cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "5×6 SparseArrays.SparseMatrixCSC{Int64, Int64} with 12 stored entries:\n", " 1 1 ⋅ ⋅ ⋅ ⋅\n", " 1 ⋅ 1 ⋅ ⋅ ⋅\n", " ⋅ 1 ⋅ 1 1 ⋅\n", " ⋅ ⋅ 1 1 ⋅ 1\n", " ⋅ ⋅ ⋅ ⋅ 1 1" ] }, "execution_count": 15, "metadata": {}, "output_type": "execute_result" } ], "source": [ "incidence_matrix(G)" ] }, { "cell_type": "code", "execution_count": 16, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "5×5 SparseArrays.SparseMatrixCSC{Int64, Int64} with 17 stored entries:\n", " 2 -1 -1 ⋅ ⋅\n", " -1 2 ⋅ -1 ⋅\n", " -1 ⋅ 3 -1 -1\n", " ⋅ -1 -1 3 -1\n", " ⋅ ⋅ -1 -1 2" ] }, "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], "source": [ "laplacian_matrix(G)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Basic operations\n", "\n", "In the beginning of this tutorial, we have seen how graphs can be constructed from scratch by adding vertices and edges iteratively. For example, we can reconstruct the house graph using:" ] }, { "cell_type": "code", "execution_count": 17, "metadata": {}, "outputs": [ { "data": { "image/svg+xml": [ "\n", "\n", "\n", " \n", " \n", " \n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "\n", "\n", "\n", "\n", " \n", " \n", " 1\n", " \n", " \n", " \n", " \n", " 2\n", " \n", " \n", " \n", " \n", " 3\n", " \n", " \n", " \n", " \n", " 4\n", " \n", " \n", " \n", " \n", " 5\n", " \n", " \n", " \n", " \n", " 6\n", " \n", " \n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "\n", "\n", " \n", " \n", " 1\n", " \n", " \n", " \n", " \n", " 2\n", " \n", " \n", " \n", " \n", " 3\n", " \n", " \n", " \n", " \n", " 4\n", " \n", " \n", " \n", " \n", " 5\n", " \n", " \n", "\n", "\n" ], "text/html": [ "\n", "\n", "\n", " \n", " \n", " \n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "\n", "\n", "\n", "\n", " \n", " \n", " 1\n", " \n", " \n", " \n", " \n", " 2\n", " \n", " \n", " \n", " \n", " 3\n", " \n", " \n", " \n", " \n", " 4\n", " \n", " \n", " \n", " \n", " 5\n", " \n", " \n", " \n", " \n", " 6\n", " \n", " \n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "\n", "\n", " \n", " \n", " 1\n", " \n", " \n", " \n", " \n", " 2\n", " \n", " \n", " \n", " \n", " 3\n", " \n", " \n", " \n", " \n", " 4\n", " \n", " \n", " \n", " \n", " 5\n", " \n", " \n", "\n", "\n", "\n" ], "text/plain": [ "Compose.Context(Measures.BoundingBox{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}, Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}((0.0w, 0.0h), (1.0w, 1.0h)), Compose.UnitBox{Float64, Float64, Float64, Float64}(-1.2, -1.2, 2.4, 2.4, 0.0mm, 0.0mm, 0.0mm, 0.0mm), nothing, nothing, nothing, List([Compose.Context(Measures.BoundingBox{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}, Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}((0.0w, 0.0h), (1.0w, 1.0h)), nothing, nothing, nothing, nothing, List([]), List([Compose.Form{Compose.LinePrimitive}(Compose.LinePrimitive[Compose.LinePrimitive{Tuple{Measures.Measure, Measures.Measure}}(Tuple{Measures.Measure, Measures.Measure}[(-0.9296112385156093cx, 0.8882842240060786cy), (-0.9955744611541673cx, -0.7768537085341486cy)]), Compose.LinePrimitive{Tuple{Measures.Measure, Measures.Measure}}(Tuple{Measures.Measure, Measures.Measure}[(-0.8154985448750078cx, 0.9783498712930281cy), (0.03981020488349357cx, 0.8095284213145122cy)]), Compose.LinePrimitive{Tuple{Measures.Measure, Measures.Measure}}(Tuple{Measures.Measure, Measures.Measure}[(-0.8887879178725486cx, -0.9000530723331507cy), (-0.032070280060529754cx, -0.9885164121949193cy)]), Compose.LinePrimitive{Tuple{Measures.Measure, Measures.Measure}}(Tuple{Measures.Measure, Measures.Measure}[(0.14510113920385345cx, 0.6761613590408675cy), (0.08353802254133051cx, -0.8882830664333272cy)]), Compose.LinePrimitive{Tuple{Measures.Measure, Measures.Measure}}(Tuple{Measures.Measure, Measures.Measure}[(0.2208483964021523cx, 0.7018025726952091cy), (0.92864896327611cx, -0.15206649698339708cy)]), Compose.LinePrimitive{Tuple{Measures.Measure, Measures.Measure}}(Tuple{Measures.Measure, Measures.Measure}[(0.16528515363429191cx, -0.9287306308380631cy), (0.9138566484326297cx, -0.3094115860576653cy)])], Symbol(\"\"))]), List([Compose.Property{Compose.LineWidthPrimitive}(Compose.LineWidthPrimitive[Compose.LineWidthPrimitive(1.3416407864998738mm)]), Compose.Property{Compose.FillPrimitive}(Compose.FillPrimitive[Compose.FillPrimitive(RGBA{Float64}(0.0,0.0,0.0,0.0))]), Compose.Property{Compose.StrokePrimitive}(Compose.StrokePrimitive[Compose.StrokePrimitive(RGBA{Float64}(0.8274509803921568,0.8274509803921568,0.8274509803921568,1.0))])]), 0, false, false, false, false, nothing, nothing, 0.0, Symbol(\"\")), Compose.Context(Measures.BoundingBox{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}, Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}((0.0w, 0.0h), (1.0w, 1.0h)), nothing, nothing, nothing, nothing, List([]), List([]), List([Compose.Property{Compose.LineWidthPrimitive}(Compose.LineWidthPrimitive[Compose.LineWidthPrimitive(1.3416407864998738mm)]), Compose.Property{Compose.StrokePrimitive}(Compose.StrokePrimitive[Compose.StrokePrimitive(RGBA{Float64}(0.8274509803921568,0.8274509803921568,0.8274509803921568,1.0))])]), 0, false, false, false, false, nothing, nothing, 0.0, Symbol(\"\")), Compose.Context(Measures.BoundingBox{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}, Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}((0.0w, 0.0h), (1.0w, 1.0h)), nothing, nothing, nothing, nothing, List([]), List([Compose.Form{Compose.TextPrimitive{Tuple{Measures.Length{:cx, Float64}, Measures.Length{:cy, Float64}}, Compose.Rotation{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}, Tuple{Measures.AbsoluteLength, Measures.AbsoluteLength}}}(Compose.TextPrimitive{Tuple{Measures.Length{:cx, Float64}, Measures.Length{:cy, Float64}}, Compose.Rotation{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}, Tuple{Measures.AbsoluteLength, Measures.AbsoluteLength}}[Compose.TextPrimitive{Tuple{Measures.Length{:cx, Float64}, Measures.Length{:cy, Float64}}, Compose.Rotation{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}, Tuple{Measures.AbsoluteLength, Measures.AbsoluteLength}}((-0.9625928498348884cx, 0.05571525773596503cy), \"1\", Compose.HCenter(), Compose.VCenter(), Compose.Rotation{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}(0.0, (0.5w, 0.5h)), (0.0mm, 0.0mm)), Compose.TextPrimitive{Tuple{Measures.Length{:cx, Float64}, Measures.Length{:cy, Float64}}, Compose.Rotation{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}, Tuple{Measures.AbsoluteLength, Measures.AbsoluteLength}}((-0.38784416999575716cx, 0.8939391463037701cy), \"2\", Compose.HCenter(), Compose.VCenter(), Compose.Rotation{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}(0.0, (0.5w, 0.5h)), (0.0mm, 0.0mm)), Compose.TextPrimitive{Tuple{Measures.Length{:cx, Float64}, Measures.Length{:cy, Float64}}, Compose.Rotation{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}, Tuple{Measures.AbsoluteLength, Measures.AbsoluteLength}}((-0.46042909896653916cx, -0.944284742264035cy), \"3\", Compose.HCenter(), Compose.VCenter(), Compose.Rotation{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}(0.0, (0.5w, 0.5h)), (0.0mm, 0.0mm)), Compose.TextPrimitive{Tuple{Measures.Length{:cx, Float64}, Measures.Length{:cy, Float64}}, Compose.Rotation{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}, Tuple{Measures.AbsoluteLength, Measures.AbsoluteLength}}((0.11431958087259197cx, -0.10606085369622986cy), \"4\", Compose.HCenter(), Compose.VCenter(), Compose.Rotation{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}(0.0, (0.5w, 0.5h)), (0.0mm, 0.0mm)), Compose.TextPrimitive{Tuple{Measures.Length{:cx, Float64}, Measures.Length{:cy, Float64}}, Compose.Rotation{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}, Tuple{Measures.AbsoluteLength, Measures.AbsoluteLength}}((0.5747486798391311cx, 0.27486803785590597cy), \"5\", Compose.HCenter(), Compose.VCenter(), Compose.Rotation{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}(0.0, (0.5w, 0.5h)), (0.0mm, 0.0mm)), Compose.TextPrimitive{Tuple{Measures.Length{:cx, Float64}, Measures.Length{:cy, Float64}}, Compose.Rotation{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}, Tuple{Measures.AbsoluteLength, Measures.AbsoluteLength}}((0.5395709010334608cx, -0.6190711084478642cy), \"6\", Compose.HCenter(), Compose.VCenter(), Compose.Rotation{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}(0.0, (0.5w, 0.5h)), (0.0mm, 0.0mm))], Symbol(\"\"))]), List([Compose.Property{Compose.FontSizePrimitive}(Compose.FontSizePrimitive[Compose.FontSizePrimitive(4.0mm)]), Compose.Property{Compose.StrokePrimitive}(Compose.StrokePrimitive[Compose.StrokePrimitive(RGBA{Float64}(0.0,0.0,0.0,0.0))]), Compose.Property{Compose.FillPrimitive}(Compose.FillPrimitive[Compose.FillPrimitive(RGBA{Float64}(0.0,0.0,0.0,1.0))])]), 0, false, false, false, false, nothing, nothing, 0.0, Symbol(\"\")), Compose.Context(Measures.BoundingBox{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}, Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}((0.0w, 0.0h), (1.0w, 1.0h)), nothing, nothing, nothing, nothing, List([]), List([Compose.Form{Compose.CirclePrimitive{Tuple{Measures.Measure, Measures.Measure}, Measures.Measure}}(Compose.CirclePrimitive{Tuple{Measures.Measure, Measures.Measure}, Measures.Measure}[Compose.CirclePrimitive{Tuple{Measures.Measure, Measures.Measure}, Measures.Measure}((-0.9251856996697766cx, 1.0cy), 0.044721359549995794w), Compose.CirclePrimitive{Tuple{Measures.Measure, Measures.Measure}, Measures.Measure}((-1.0cx, -0.8885694845280699cy), 0.044721359549995794w), Compose.CirclePrimitive{Tuple{Measures.Measure, Measures.Measure}, Measures.Measure}((0.14949735967826228cx, 0.7878782926075403cy), 0.044721359549995794w), Compose.CirclePrimitive{Tuple{Measures.Measure, Measures.Measure}, Measures.Measure}((0.07914180206692167cx, -1.0cy), 0.044721359549995794w), Compose.CirclePrimitive{Tuple{Measures.Measure, Measures.Measure}, Measures.Measure}((1.0cx, -0.23814221689572834cy), 0.044721359549995794w)], Symbol(\"\"))]), List([Compose.Property{Compose.LineWidthPrimitive}(Compose.LineWidthPrimitive[Compose.LineWidthPrimitive(0.0mm)]), Compose.Property{Compose.StrokePrimitive}(Compose.StrokePrimitive[Compose.StrokePrimitive(RGBA{Float64}(0.0,0.0,0.0,0.0))]), Compose.Property{Compose.FillPrimitive}(Compose.FillPrimitive[Compose.FillPrimitive(RGBA{Float64}(0.25098039215686274,0.8784313725490196,0.8156862745098039,1.0))])]), 0, false, false, false, false, nothing, nothing, 0.0, Symbol(\"\")), Compose.Context(Measures.BoundingBox{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}, Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}((0.0w, 0.0h), (1.0w, 1.0h)), nothing, nothing, nothing, nothing, List([]), List([Compose.Form{Compose.TextPrimitive{Tuple{Measures.Length{:cx, Float64}, Measures.Length{:cy, Float64}}, Compose.Rotation{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}, Tuple{Measures.AbsoluteLength, Measures.AbsoluteLength}}}(Compose.TextPrimitive{Tuple{Measures.Length{:cx, Float64}, Measures.Length{:cy, Float64}}, Compose.Rotation{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}, Tuple{Measures.AbsoluteLength, Measures.AbsoluteLength}}[Compose.TextPrimitive{Tuple{Measures.Length{:cx, Float64}, Measures.Length{:cy, Float64}}, Compose.Rotation{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}, Tuple{Measures.AbsoluteLength, Measures.AbsoluteLength}}((-0.9251856996697766cx, 1.0cy), \"1\", Compose.HCenter(), Compose.VCenter(), Compose.Rotation{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}(0.0, (0.5w, 0.5h)), (0.0mm, 0.0mm)), Compose.TextPrimitive{Tuple{Measures.Length{:cx, Float64}, Measures.Length{:cy, Float64}}, Compose.Rotation{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}, Tuple{Measures.AbsoluteLength, Measures.AbsoluteLength}}((-1.0cx, -0.8885694845280699cy), \"2\", Compose.HCenter(), Compose.VCenter(), Compose.Rotation{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}(0.0, (0.5w, 0.5h)), (0.0mm, 0.0mm)), Compose.TextPrimitive{Tuple{Measures.Length{:cx, Float64}, Measures.Length{:cy, Float64}}, Compose.Rotation{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}, Tuple{Measures.AbsoluteLength, Measures.AbsoluteLength}}((0.14949735967826228cx, 0.7878782926075403cy), \"3\", Compose.HCenter(), Compose.VCenter(), Compose.Rotation{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}(0.0, (0.5w, 0.5h)), (0.0mm, 0.0mm)), Compose.TextPrimitive{Tuple{Measures.Length{:cx, Float64}, Measures.Length{:cy, Float64}}, Compose.Rotation{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}, Tuple{Measures.AbsoluteLength, Measures.AbsoluteLength}}((0.07914180206692167cx, -1.0cy), \"4\", Compose.HCenter(), Compose.VCenter(), Compose.Rotation{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}(0.0, (0.5w, 0.5h)), (0.0mm, 0.0mm)), Compose.TextPrimitive{Tuple{Measures.Length{:cx, Float64}, Measures.Length{:cy, Float64}}, Compose.Rotation{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}, Tuple{Measures.AbsoluteLength, Measures.AbsoluteLength}}((1.0cx, -0.23814221689572834cy), \"5\", Compose.HCenter(), Compose.VCenter(), Compose.Rotation{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}(0.0, (0.5w, 0.5h)), (0.0mm, 0.0mm))], Symbol(\"\"))]), List([Compose.Property{Compose.FontSizePrimitive}(Compose.FontSizePrimitive[Compose.FontSizePrimitive(4.0mm)]), Compose.Property{Compose.StrokePrimitive}(Compose.StrokePrimitive[Compose.StrokePrimitive(RGBA{Float64}(0.0,0.0,0.0,0.0))]), Compose.Property{Compose.FillPrimitive}(Compose.FillPrimitive[Compose.FillPrimitive(RGBA{Float64}(0.0,0.0,0.0,1.0))])]), 0, false, false, false, false, nothing, nothing, 0.0, Symbol(\"\"))]), List([]), List([]), 0, false, false, false, false, nothing, nothing, 0.0, Symbol(\"\"))" ] }, "execution_count": 17, "metadata": {}, "output_type": "execute_result" } ], "source": [ "G = Graph()\n", "add_vertices!(G, 5)\n", "add_edge!(G, 1, 2)\n", "add_edge!(G, 1, 3)\n", "add_edge!(G, 2, 4)\n", "add_edge!(G, 3, 4)\n", "add_edge!(G, 3, 5)\n", "add_edge!(G, 4, 5)\n", "\n", "gplot(G, nodelabel=1:nv(G), edgelabel=1:ne(G))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "In Graphs.jl, adding elements to a graph is **always** a safe operation in the sense that vertex and edge labels are preserved:" ] }, { "cell_type": "code", "execution_count": 18, "metadata": {}, "outputs": [ { "data": { "image/svg+xml": [ "\n", "\n", "\n", " \n", " \n", " \n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "\n", "\n", "\n", "\n", " \n", " \n", " 1\n", " \n", " \n", " \n", " \n", " 2\n", " \n", " \n", " \n", " \n", " 3\n", " \n", " \n", " \n", " \n", " 4\n", " \n", " \n", " \n", " \n", " 5\n", " \n", " \n", " \n", " \n", " 6\n", " \n", " \n", " \n", " \n", " 7\n", " \n", " \n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "\n", "\n", " \n", " \n", " 1\n", " \n", " \n", " \n", " \n", " 2\n", " \n", " \n", " \n", " \n", " 3\n", " \n", " \n", " \n", " \n", " 4\n", " \n", " \n", " \n", " \n", " 5\n", " \n", " \n", " \n", " \n", " 6\n", " \n", " \n", "\n", "\n" ], "text/html": [ "\n", "\n", "\n", " \n", " \n", " \n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "\n", "\n", "\n", "\n", " \n", " \n", " 1\n", " \n", " \n", " \n", " \n", " 2\n", " \n", " \n", " \n", " \n", " 3\n", " \n", " \n", " \n", " \n", " 4\n", " \n", " \n", " \n", " \n", " 5\n", " \n", " \n", " \n", " \n", " 6\n", " \n", " \n", " \n", " \n", " 7\n", " \n", " \n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "\n", "\n", " \n", " \n", " 1\n", " \n", " \n", " \n", " \n", " 2\n", " \n", " \n", " \n", " \n", " 3\n", " \n", " \n", " \n", " \n", " 4\n", " \n", " \n", " \n", " \n", " 5\n", " \n", " \n", " \n", " \n", " 6\n", " \n", " \n", "\n", "\n", "\n" ], "text/plain": [ "Compose.Context(Measures.BoundingBox{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}, Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}((0.0w, 0.0h), (1.0w, 1.0h)), Compose.UnitBox{Float64, Float64, Float64, Float64}(-1.2, -1.2, 2.4, 2.4, 0.0mm, 0.0mm, 0.0mm, 0.0mm), nothing, nothing, nothing, List([Compose.Context(Measures.BoundingBox{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}, Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}((0.0w, 0.0h), (1.0w, 1.0h)), nothing, nothing, nothing, nothing, List([]), List([Compose.Form{Compose.LinePrimitive}(Compose.LinePrimitive[Compose.LinePrimitive{Tuple{Measures.Measure, Measures.Measure}}(Tuple{Measures.Measure, Measures.Measure}[(-0.9045343999947417cx, 0.7322175190879914cy), (-0.2917946353903226cx, 0.9639031042566997cy)]), Compose.LinePrimitive{Tuple{Measures.Measure, Measures.Measure}}(Tuple{Measures.Measure, Measures.Measure}[(-0.92920270507959cx, 0.6226059329854223cy), (-0.4880749115546407cx, 0.1645464381090847cy)]), Compose.LinePrimitive{Tuple{Measures.Measure, Measures.Measure}}(Tuple{Measures.Measure, Measures.Measure}[(-0.13239517169196363cx, 0.9204441847509643cy), (0.2472991762786165cx, 0.44797323346837703cy)]), Compose.LinePrimitive{Tuple{Measures.Measure, Measures.Measure}}(Tuple{Measures.Measure, Measures.Measure}[(-0.3218956693490257cx, 0.12734910997161042cy), (0.21585109268651204cx, 0.3321000559975469cy)]), Compose.LinePrimitive{Tuple{Measures.Measure, Measures.Measure}}(Tuple{Measures.Measure, Measures.Measure}[(-0.3264540806795091cx, 0.04447262422554794cy), (0.3602727697635101cx, -0.3075660838153695cy)]), Compose.LinePrimitive{Tuple{Measures.Measure, Measures.Measure}}(Tuple{Measures.Measure, Measures.Measure}[(0.33062924924900294cx, 0.2682153537079831cy), (0.431700096440946cx, -0.2539231428282792cy)]), Compose.LinePrimitive{Tuple{Measures.Measure, Measures.Measure}}(Tuple{Measures.Measure, Measures.Measure}[(0.5171903625764491cx, -0.4318956536202742cy), (0.9339059431417827cx, -0.9222295537193632cy)])], Symbol(\"\"))]), List([Compose.Property{Compose.LineWidthPrimitive}(Compose.LineWidthPrimitive[Compose.LineWidthPrimitive(1.2247448713915892mm)]), Compose.Property{Compose.FillPrimitive}(Compose.FillPrimitive[Compose.FillPrimitive(RGBA{Float64}(0.0,0.0,0.0,0.0))]), Compose.Property{Compose.StrokePrimitive}(Compose.StrokePrimitive[Compose.StrokePrimitive(RGBA{Float64}(0.8274509803921568,0.8274509803921568,0.8274509803921568,1.0))])]), 0, false, false, false, false, nothing, nothing, 0.0, Symbol(\"\")), Compose.Context(Measures.BoundingBox{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}, Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}((0.0w, 0.0h), (1.0w, 1.0h)), nothing, nothing, nothing, nothing, List([]), List([]), List([Compose.Property{Compose.LineWidthPrimitive}(Compose.LineWidthPrimitive[Compose.LineWidthPrimitive(1.2247448713915892mm)]), Compose.Property{Compose.StrokePrimitive}(Compose.StrokePrimitive[Compose.StrokePrimitive(RGBA{Float64}(0.8274509803921568,0.8274509803921568,0.8274509803921568,1.0))])]), 0, false, false, false, false, nothing, nothing, 0.0, Symbol(\"\")), Compose.Context(Measures.BoundingBox{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}, Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}((0.0w, 0.0h), (1.0w, 1.0h)), nothing, nothing, nothing, nothing, List([]), List([Compose.Form{Compose.TextPrimitive{Tuple{Measures.Length{:cx, Float64}, Measures.Length{:cy, Float64}}, Compose.Rotation{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}, Tuple{Measures.AbsoluteLength, Measures.AbsoluteLength}}}(Compose.TextPrimitive{Tuple{Measures.Length{:cx, Float64}, Measures.Length{:cy, Float64}}, Compose.Rotation{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}, Tuple{Measures.AbsoluteLength, Measures.AbsoluteLength}}[Compose.TextPrimitive{Tuple{Measures.Length{:cx, Float64}, Measures.Length{:cy, Float64}}, Compose.Rotation{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}, Tuple{Measures.AbsoluteLength, Measures.AbsoluteLength}}((-0.5981645176925321cx, 0.8480603116723455cy), \"1\", Compose.HCenter(), Compose.VCenter(), Compose.Rotation{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}(0.0, (0.5w, 0.5h)), (0.0mm, 0.0mm)), Compose.TextPrimitive{Tuple{Measures.Length{:cx, Float64}, Measures.Length{:cy, Float64}}, Compose.Rotation{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}, Tuple{Measures.AbsoluteLength, Measures.AbsoluteLength}}((-0.7086388083171153cx, 0.3935761855472535cy), \"2\", Compose.HCenter(), Compose.VCenter(), Compose.Rotation{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}(0.0, (0.5w, 0.5h)), (0.0mm, 0.0mm)), Compose.TextPrimitive{Tuple{Measures.Length{:cx, Float64}, Measures.Length{:cy, Float64}}, Compose.Rotation{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}, Tuple{Measures.AbsoluteLength, Measures.AbsoluteLength}}((0.05745200229332642cx, 0.6842087091096707cy), \"3\", Compose.HCenter(), Compose.VCenter(), Compose.Rotation{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}(0.0, (0.5w, 0.5h)), (0.0mm, 0.0mm)), Compose.TextPrimitive{Tuple{Measures.Length{:cx, Float64}, Measures.Length{:cy, Float64}}, Compose.Rotation{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}, Tuple{Measures.AbsoluteLength, Measures.AbsoluteLength}}((-0.05302228833125683cx, 0.22972458298457865cy), \"4\", Compose.HCenter(), Compose.VCenter(), Compose.Rotation{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}(0.0, (0.5w, 0.5h)), (0.0mm, 0.0mm)), Compose.TextPrimitive{Tuple{Measures.Length{:cx, Float64}, Measures.Length{:cy, Float64}}, Compose.Rotation{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}, Tuple{Measures.AbsoluteLength, Measures.AbsoluteLength}}((0.016909344542000493cx, -0.13154672979491078cy), \"5\", Compose.HCenter(), Compose.VCenter(), Compose.Rotation{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}(0.0, (0.5w, 0.5h)), (0.0mm, 0.0mm)), Compose.TextPrimitive{Tuple{Measures.Length{:cx, Float64}, Measures.Length{:cy, Float64}}, Compose.Rotation{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}, Tuple{Measures.AbsoluteLength, Measures.AbsoluteLength}}((0.38116467284497446cx, 0.007146105439851946cy), \"6\", Compose.HCenter(), Compose.VCenter(), Compose.Rotation{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}(0.0, (0.5w, 0.5h)), (0.0mm, 0.0mm)), Compose.TextPrimitive{Tuple{Measures.Length{:cx, Float64}, Measures.Length{:cy, Float64}}, Compose.Rotation{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}, Tuple{Measures.AbsoluteLength, Measures.AbsoluteLength}}((0.7255481528591159cx, -0.6770626036698187cy), \"7\", Compose.HCenter(), Compose.VCenter(), Compose.Rotation{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}(0.0, (0.5w, 0.5h)), (0.0mm, 0.0mm))], Symbol(\"\"))]), List([Compose.Property{Compose.FontSizePrimitive}(Compose.FontSizePrimitive[Compose.FontSizePrimitive(4.0mm)]), Compose.Property{Compose.StrokePrimitive}(Compose.StrokePrimitive[Compose.StrokePrimitive(RGBA{Float64}(0.0,0.0,0.0,0.0))]), Compose.Property{Compose.FillPrimitive}(Compose.FillPrimitive[Compose.FillPrimitive(RGBA{Float64}(0.0,0.0,0.0,1.0))])]), 0, false, false, false, false, nothing, nothing, 0.0, Symbol(\"\")), Compose.Context(Measures.BoundingBox{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}, Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}((0.0w, 0.0h), (1.0w, 1.0h)), nothing, nothing, nothing, nothing, List([]), List([Compose.Form{Compose.CirclePrimitive{Tuple{Measures.Measure, Measures.Measure}, Measures.Measure}}(Compose.CirclePrimitive{Tuple{Measures.Measure, Measures.Measure}, Measures.Measure}[Compose.CirclePrimitive{Tuple{Measures.Measure, Measures.Measure}, Measures.Measure}((-1.0cx, 0.696120623344691cy), 0.04082482904638631w), Compose.CirclePrimitive{Tuple{Measures.Measure, Measures.Measure}, Measures.Measure}((-0.1963290353850643cx, 1.0cy), 0.04082482904638631w), Compose.CirclePrimitive{Tuple{Measures.Measure, Measures.Measure}, Measures.Measure}((-0.4172776166342308cx, 0.09103174774981593cy), 0.04082482904638631w), Compose.CirclePrimitive{Tuple{Measures.Measure, Measures.Measure}, Measures.Measure}((0.31123303997171714cx, 0.3684174182193414cy), 0.04082482904638631w), Compose.CirclePrimitive{Tuple{Measures.Measure, Measures.Measure}, Measures.Measure}((0.4510963057182318cx, -0.3541252073396375cy), 0.04082482904638631w), Compose.CirclePrimitive{Tuple{Measures.Measure, Measures.Measure}, Measures.Measure}((1.0cx, -1.0cy), 0.04082482904638631w)], Symbol(\"\"))]), List([Compose.Property{Compose.LineWidthPrimitive}(Compose.LineWidthPrimitive[Compose.LineWidthPrimitive(0.0mm)]), Compose.Property{Compose.StrokePrimitive}(Compose.StrokePrimitive[Compose.StrokePrimitive(RGBA{Float64}(0.0,0.0,0.0,0.0))]), Compose.Property{Compose.FillPrimitive}(Compose.FillPrimitive[Compose.FillPrimitive(RGBA{Float64}(0.25098039215686274,0.8784313725490196,0.8156862745098039,1.0))])]), 0, false, false, false, false, nothing, nothing, 0.0, Symbol(\"\")), Compose.Context(Measures.BoundingBox{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}, Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}((0.0w, 0.0h), (1.0w, 1.0h)), nothing, nothing, nothing, nothing, List([]), List([Compose.Form{Compose.TextPrimitive{Tuple{Measures.Length{:cx, Float64}, Measures.Length{:cy, Float64}}, Compose.Rotation{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}, Tuple{Measures.AbsoluteLength, Measures.AbsoluteLength}}}(Compose.TextPrimitive{Tuple{Measures.Length{:cx, Float64}, Measures.Length{:cy, Float64}}, Compose.Rotation{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}, Tuple{Measures.AbsoluteLength, Measures.AbsoluteLength}}[Compose.TextPrimitive{Tuple{Measures.Length{:cx, Float64}, Measures.Length{:cy, Float64}}, Compose.Rotation{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}, Tuple{Measures.AbsoluteLength, Measures.AbsoluteLength}}((-1.0cx, 0.696120623344691cy), \"1\", Compose.HCenter(), Compose.VCenter(), Compose.Rotation{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}(0.0, (0.5w, 0.5h)), (0.0mm, 0.0mm)), Compose.TextPrimitive{Tuple{Measures.Length{:cx, Float64}, Measures.Length{:cy, Float64}}, Compose.Rotation{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}, Tuple{Measures.AbsoluteLength, Measures.AbsoluteLength}}((-0.1963290353850643cx, 1.0cy), \"2\", Compose.HCenter(), Compose.VCenter(), Compose.Rotation{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}(0.0, (0.5w, 0.5h)), (0.0mm, 0.0mm)), Compose.TextPrimitive{Tuple{Measures.Length{:cx, Float64}, Measures.Length{:cy, Float64}}, Compose.Rotation{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}, Tuple{Measures.AbsoluteLength, Measures.AbsoluteLength}}((-0.4172776166342308cx, 0.09103174774981593cy), \"3\", Compose.HCenter(), Compose.VCenter(), Compose.Rotation{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}(0.0, (0.5w, 0.5h)), (0.0mm, 0.0mm)), Compose.TextPrimitive{Tuple{Measures.Length{:cx, Float64}, Measures.Length{:cy, Float64}}, Compose.Rotation{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}, Tuple{Measures.AbsoluteLength, Measures.AbsoluteLength}}((0.31123303997171714cx, 0.3684174182193414cy), \"4\", Compose.HCenter(), Compose.VCenter(), Compose.Rotation{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}(0.0, (0.5w, 0.5h)), (0.0mm, 0.0mm)), Compose.TextPrimitive{Tuple{Measures.Length{:cx, Float64}, Measures.Length{:cy, Float64}}, Compose.Rotation{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}, Tuple{Measures.AbsoluteLength, Measures.AbsoluteLength}}((0.4510963057182318cx, -0.3541252073396375cy), \"5\", Compose.HCenter(), Compose.VCenter(), Compose.Rotation{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}(0.0, (0.5w, 0.5h)), (0.0mm, 0.0mm)), Compose.TextPrimitive{Tuple{Measures.Length{:cx, Float64}, Measures.Length{:cy, Float64}}, Compose.Rotation{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}, Tuple{Measures.AbsoluteLength, Measures.AbsoluteLength}}((1.0cx, -1.0cy), \"6\", Compose.HCenter(), Compose.VCenter(), Compose.Rotation{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}(0.0, (0.5w, 0.5h)), (0.0mm, 0.0mm))], Symbol(\"\"))]), List([Compose.Property{Compose.FontSizePrimitive}(Compose.FontSizePrimitive[Compose.FontSizePrimitive(4.0mm)]), Compose.Property{Compose.StrokePrimitive}(Compose.StrokePrimitive[Compose.StrokePrimitive(RGBA{Float64}(0.0,0.0,0.0,0.0))]), Compose.Property{Compose.FillPrimitive}(Compose.FillPrimitive[Compose.FillPrimitive(RGBA{Float64}(0.0,0.0,0.0,1.0))])]), 0, false, false, false, false, nothing, nothing, 0.0, Symbol(\"\"))]), List([]), List([]), 0, false, false, false, false, nothing, nothing, 0.0, Symbol(\"\"))" ] }, "execution_count": 18, "metadata": {}, "output_type": "execute_result" } ], "source": [ "add_vertex!(G)\n", "add_edge!(G, 5, 6)\n", "\n", "gplot(G, nodelabel=1:nv(G), edgelabel=1:ne(G))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "However, removing a vertex is **not** a *label-preserving* operation. For performance reasons, a vertex `k` is removed from the graph by swaping `k` with the latest vertex `nv(G)`. This side-effect is particularly relevant if data is being stored externally for each vertex or edge of the graph:" ] }, { "cell_type": "code", "execution_count": 19, "metadata": {}, "outputs": [ { "data": { "image/svg+xml": [ "\n", "\n", "\n", " \n", " \n", " \n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "\n", "\n", "\n", "\n", " \n", " \n", " 1\n", " \n", " \n", " \n", " \n", " 2\n", " \n", " \n", " \n", " \n", " 3\n", " \n", " \n", " \n", " \n", " 4\n", " \n", " \n", " \n", " \n", " 5\n", " \n", " \n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "\n", "\n", " \n", " \n", " 1\n", " \n", " \n", " \n", " \n", " 2\n", " \n", " \n", " \n", " \n", " 3\n", " \n", " \n", " \n", " \n", " 4\n", " \n", " \n", " \n", " \n", " 5\n", " \n", " \n", "\n", "\n" ], "text/html": [ "\n", "\n", "\n", " \n", " \n", " \n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "\n", "\n", "\n", "\n", " \n", " \n", " 1\n", " \n", " \n", " \n", " \n", " 2\n", " \n", " \n", " \n", " \n", " 3\n", " \n", " \n", " \n", " \n", " 4\n", " \n", " \n", " \n", " \n", " 5\n", " \n", " \n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "\n", "\n", " \n", " \n", " 1\n", " \n", " \n", " \n", " \n", " 2\n", " \n", " \n", " \n", " \n", " 3\n", " \n", " \n", " \n", " \n", " 4\n", " \n", " \n", " \n", " \n", " 5\n", " \n", " \n", "\n", "\n", "\n" ], "text/plain": [ "Compose.Context(Measures.BoundingBox{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}, Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}((0.0w, 0.0h), (1.0w, 1.0h)), Compose.UnitBox{Float64, Float64, Float64, Float64}(-1.2, -1.2, 2.4, 2.4, 0.0mm, 0.0mm, 0.0mm, 0.0mm), nothing, nothing, nothing, List([Compose.Context(Measures.BoundingBox{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}, Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}((0.0w, 0.0h), (1.0w, 1.0h)), nothing, nothing, nothing, nothing, List([]), List([Compose.Form{Compose.LinePrimitive}(Compose.LinePrimitive[Compose.LinePrimitive{Tuple{Measures.Measure, Measures.Measure}}(Tuple{Measures.Measure, Measures.Measure}[(0.9363872405679943cx, -0.908057535178538cy), (0.4759719245705804cx, -0.24259797372684488cy)]), Compose.LinePrimitive{Tuple{Measures.Measure, Measures.Measure}}(Tuple{Measures.Measure, Measures.Measure}[(-0.8893919393659478cx, 0.44971563602506cy), (-0.40162585742786805cx, 0.3778123387301933cy)]), Compose.LinePrimitive{Tuple{Measures.Measure, Measures.Measure}}(Tuple{Measures.Measure, Measures.Measure}[(0.14613103568545394cx, 0.9124192202649926cy), (-0.22152242269590847cx, 0.44908799893868867cy)]), Compose.LinePrimitive{Tuple{Measures.Measure, Measures.Measure}}(Tuple{Measures.Measure, Measures.Measure}[(0.23446852523170159cx, 0.8897957592221089cy), (0.3935170496902345cx, -0.040451268127491724cy)]), Compose.LinePrimitive{Tuple{Measures.Measure, Measures.Measure}}(Tuple{Measures.Measure, Measures.Measure}[(-0.20063601090632932cx, 0.2956958768697907cy), (0.32197737925108816cx, -0.08484416657149242cy)])], Symbol(\"\"))]), List([Compose.Property{Compose.LineWidthPrimitive}(Compose.LineWidthPrimitive[Compose.LineWidthPrimitive(1.3416407864998738mm)]), Compose.Property{Compose.FillPrimitive}(Compose.FillPrimitive[Compose.FillPrimitive(RGBA{Float64}(0.0,0.0,0.0,0.0))]), Compose.Property{Compose.StrokePrimitive}(Compose.StrokePrimitive[Compose.StrokePrimitive(RGBA{Float64}(0.8274509803921568,0.8274509803921568,0.8274509803921568,1.0))])]), 0, false, false, false, false, nothing, nothing, 0.0, Symbol(\"\")), Compose.Context(Measures.BoundingBox{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}, Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}((0.0w, 0.0h), (1.0w, 1.0h)), nothing, nothing, nothing, nothing, List([]), List([]), List([Compose.Property{Compose.LineWidthPrimitive}(Compose.LineWidthPrimitive[Compose.LineWidthPrimitive(1.3416407864998738mm)]), Compose.Property{Compose.StrokePrimitive}(Compose.StrokePrimitive[Compose.StrokePrimitive(RGBA{Float64}(0.8274509803921568,0.8274509803921568,0.8274509803921568,1.0))])]), 0, false, false, false, false, nothing, nothing, 0.0, Symbol(\"\")), Compose.Context(Measures.BoundingBox{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}, Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}((0.0w, 0.0h), (1.0w, 1.0h)), nothing, nothing, nothing, nothing, List([]), List([Compose.Form{Compose.TextPrimitive{Tuple{Measures.Length{:cx, Float64}, Measures.Length{:cy, Float64}}, Compose.Rotation{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}, Tuple{Measures.AbsoluteLength, Measures.AbsoluteLength}}}(Compose.TextPrimitive{Tuple{Measures.Length{:cx, Float64}, Measures.Length{:cy, Float64}}, Compose.Rotation{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}, Tuple{Measures.AbsoluteLength, Measures.AbsoluteLength}}[Compose.TextPrimitive{Tuple{Measures.Length{:cx, Float64}, Measures.Length{:cy, Float64}}, Compose.Rotation{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}, Tuple{Measures.AbsoluteLength, Measures.AbsoluteLength}}((0.7061795825692874cx, -0.5753277544526915cy), \"1\", Compose.HCenter(), Compose.VCenter(), Compose.Rotation{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}(0.0, (0.5w, 0.5h)), (0.0mm, 0.0mm)), Compose.TextPrimitive{Tuple{Measures.Length{:cx, Float64}, Measures.Length{:cy, Float64}}, Compose.Rotation{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}, Tuple{Measures.AbsoluteLength, Measures.AbsoluteLength}}((-0.645508898396908cx, 0.41376398737762665cy), \"2\", Compose.HCenter(), Compose.VCenter(), Compose.Rotation{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}(0.0, (0.5w, 0.5h)), (0.0mm, 0.0mm)), Compose.TextPrimitive{Tuple{Measures.Length{:cx, Float64}, Measures.Length{:cy, Float64}}, Compose.Rotation{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}, Tuple{Measures.AbsoluteLength, Measures.AbsoluteLength}}((-0.03769569350522728cx, 0.6807536096018406cy), \"3\", Compose.HCenter(), Compose.VCenter(), Compose.Rotation{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}(0.0, (0.5w, 0.5h)), (0.0mm, 0.0mm)), Compose.TextPrimitive{Tuple{Measures.Length{:cx, Float64}, Measures.Length{:cy, Float64}}, Compose.Rotation{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}, Tuple{Measures.AbsoluteLength, Measures.AbsoluteLength}}((0.31399278746096804cx, 0.42467224554730854cy), \"4\", Compose.HCenter(), Compose.VCenter(), Compose.Rotation{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}(0.0, (0.5w, 0.5h)), (0.0mm, 0.0mm)), Compose.TextPrimitive{Tuple{Measures.Length{:cx, Float64}, Measures.Length{:cy, Float64}}, Compose.Rotation{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}, Tuple{Measures.AbsoluteLength, Measures.AbsoluteLength}}((0.06067068417237942cx, 0.10542585514914915cy), \"5\", Compose.HCenter(), Compose.VCenter(), Compose.Rotation{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}(0.0, (0.5w, 0.5h)), (0.0mm, 0.0mm))], Symbol(\"\"))]), List([Compose.Property{Compose.FontSizePrimitive}(Compose.FontSizePrimitive[Compose.FontSizePrimitive(4.0mm)]), Compose.Property{Compose.StrokePrimitive}(Compose.StrokePrimitive[Compose.StrokePrimitive(RGBA{Float64}(0.0,0.0,0.0,0.0))]), Compose.Property{Compose.FillPrimitive}(Compose.FillPrimitive[Compose.FillPrimitive(RGBA{Float64}(0.0,0.0,0.0,1.0))])]), 0, false, false, false, false, nothing, nothing, 0.0, Symbol(\"\")), Compose.Context(Measures.BoundingBox{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}, Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}((0.0w, 0.0h), (1.0w, 1.0h)), nothing, nothing, nothing, nothing, List([]), List([Compose.Form{Compose.CirclePrimitive{Tuple{Measures.Measure, Measures.Measure}, Measures.Measure}}(Compose.CirclePrimitive{Tuple{Measures.Measure, Measures.Measure}, Measures.Measure}[Compose.CirclePrimitive{Tuple{Measures.Measure, Measures.Measure}, Measures.Measure}((1.0cx, -1.0cy), 0.044721359549995794w), Compose.CirclePrimitive{Tuple{Measures.Measure, Measures.Measure}, Measures.Measure}((-1.0cx, 0.4660207555515721cy), 0.044721359549995794w), Compose.CirclePrimitive{Tuple{Measures.Measure, Measures.Measure}, Measures.Measure}((0.21562640978336134cx, 1.0cy), 0.044721359549995794w), Compose.CirclePrimitive{Tuple{Measures.Measure, Measures.Measure}, Measures.Measure}((-0.2910177967938159cx, 0.36150721920368123cy), 0.044721359549995794w), Compose.CirclePrimitive{Tuple{Measures.Measure, Measures.Measure}, Measures.Measure}((0.41235916513857473cx, -0.15065550890538293cy), 0.044721359549995794w)], Symbol(\"\"))]), List([Compose.Property{Compose.LineWidthPrimitive}(Compose.LineWidthPrimitive[Compose.LineWidthPrimitive(0.0mm)]), Compose.Property{Compose.StrokePrimitive}(Compose.StrokePrimitive[Compose.StrokePrimitive(RGBA{Float64}(0.0,0.0,0.0,0.0))]), Compose.Property{Compose.FillPrimitive}(Compose.FillPrimitive[Compose.FillPrimitive(RGBA{Float64}(0.25098039215686274,0.8784313725490196,0.8156862745098039,1.0))])]), 0, false, false, false, false, nothing, nothing, 0.0, Symbol(\"\")), Compose.Context(Measures.BoundingBox{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}, Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}((0.0w, 0.0h), (1.0w, 1.0h)), nothing, nothing, nothing, nothing, List([]), List([Compose.Form{Compose.TextPrimitive{Tuple{Measures.Length{:cx, Float64}, Measures.Length{:cy, Float64}}, Compose.Rotation{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}, Tuple{Measures.AbsoluteLength, Measures.AbsoluteLength}}}(Compose.TextPrimitive{Tuple{Measures.Length{:cx, Float64}, Measures.Length{:cy, Float64}}, Compose.Rotation{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}, Tuple{Measures.AbsoluteLength, Measures.AbsoluteLength}}[Compose.TextPrimitive{Tuple{Measures.Length{:cx, Float64}, Measures.Length{:cy, Float64}}, Compose.Rotation{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}, Tuple{Measures.AbsoluteLength, Measures.AbsoluteLength}}((1.0cx, -1.0cy), \"1\", Compose.HCenter(), Compose.VCenter(), Compose.Rotation{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}(0.0, (0.5w, 0.5h)), (0.0mm, 0.0mm)), Compose.TextPrimitive{Tuple{Measures.Length{:cx, Float64}, Measures.Length{:cy, Float64}}, Compose.Rotation{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}, Tuple{Measures.AbsoluteLength, Measures.AbsoluteLength}}((-1.0cx, 0.4660207555515721cy), \"2\", Compose.HCenter(), Compose.VCenter(), Compose.Rotation{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}(0.0, (0.5w, 0.5h)), (0.0mm, 0.0mm)), Compose.TextPrimitive{Tuple{Measures.Length{:cx, Float64}, Measures.Length{:cy, Float64}}, Compose.Rotation{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}, Tuple{Measures.AbsoluteLength, Measures.AbsoluteLength}}((0.21562640978336134cx, 1.0cy), \"3\", Compose.HCenter(), Compose.VCenter(), Compose.Rotation{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}(0.0, (0.5w, 0.5h)), (0.0mm, 0.0mm)), Compose.TextPrimitive{Tuple{Measures.Length{:cx, Float64}, Measures.Length{:cy, Float64}}, Compose.Rotation{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}, Tuple{Measures.AbsoluteLength, Measures.AbsoluteLength}}((-0.2910177967938159cx, 0.36150721920368123cy), \"4\", Compose.HCenter(), Compose.VCenter(), Compose.Rotation{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}(0.0, (0.5w, 0.5h)), (0.0mm, 0.0mm)), Compose.TextPrimitive{Tuple{Measures.Length{:cx, Float64}, Measures.Length{:cy, Float64}}, Compose.Rotation{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}, Tuple{Measures.AbsoluteLength, Measures.AbsoluteLength}}((0.41235916513857473cx, -0.15065550890538293cy), \"5\", Compose.HCenter(), Compose.VCenter(), Compose.Rotation{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}(0.0, (0.5w, 0.5h)), (0.0mm, 0.0mm))], Symbol(\"\"))]), List([Compose.Property{Compose.FontSizePrimitive}(Compose.FontSizePrimitive[Compose.FontSizePrimitive(4.0mm)]), Compose.Property{Compose.StrokePrimitive}(Compose.StrokePrimitive[Compose.StrokePrimitive(RGBA{Float64}(0.0,0.0,0.0,0.0))]), Compose.Property{Compose.FillPrimitive}(Compose.FillPrimitive[Compose.FillPrimitive(RGBA{Float64}(0.0,0.0,0.0,1.0))])]), 0, false, false, false, false, nothing, nothing, 0.0, Symbol(\"\"))]), List([]), List([]), 0, false, false, false, false, nothing, nothing, 0.0, Symbol(\"\"))" ] }, "execution_count": 19, "metadata": {}, "output_type": "execute_result" } ], "source": [ "rem_vertex!(G, 1)\n", "\n", "gplot(G, nodelabel=1:nv(G), edgelabel=1:ne(G))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Set interface\n", "\n", "Set-like operations are defined for graphs. For example, we can construct a very cool 3D airplane graph with the cartesian product between its framework (or skeleton) and squared metal plates:" ] }, { "cell_type": "code", "execution_count": 20, "metadata": {}, "outputs": [ { "data": { "image/svg+xml": [ "\n", "\n", "\n", " \n", " \n", " \n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "\n", "\n", "\n", "\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "\n", "\n", "\n", "\n" ], "text/html": [ "\n", "\n", "\n", " \n", " \n", " \n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "\n", "\n", "\n", "\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "\n", "\n", "\n", "\n", "\n" ], "text/plain": [ "Compose.Context(Measures.BoundingBox{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}, Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}((0.0w, 0.0h), (1.0w, 1.0h)), Compose.UnitBox{Float64, Float64, Float64, Float64}(-1.2, -1.2, 2.4, 2.4, 0.0mm, 0.0mm, 0.0mm, 0.0mm), nothing, nothing, nothing, List([Compose.Context(Measures.BoundingBox{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}, Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}((0.0w, 0.0h), (1.0w, 1.0h)), nothing, nothing, nothing, nothing, List([]), List([Compose.Form{Compose.LinePrimitive}(Compose.LinePrimitive[Compose.LinePrimitive{Tuple{Measures.Measure, Measures.Measure}}(Tuple{Measures.Measure, Measures.Measure}[(-0.9641197707884048cx, -0.4064371118123383cy), (-0.6441212005210923cx, -0.30355908587663216cy)]), Compose.LinePrimitive{Tuple{Measures.Measure, Measures.Measure}}(Tuple{Measures.Measure, Measures.Measure}[(-0.9996776324266448cx, -0.45565997508043893cy), (-0.997877447455423cx, -0.6661170669339044cy)]), Compose.LinePrimitive{Tuple{Measures.Measure, Measures.Measure}}(Tuple{Measures.Measure, Measures.Measure}[(-0.9742799337951797cx, -0.4455211696062545cy), (-0.8866252253875473cx, -0.5394080289315951cy)]), Compose.LinePrimitive{Tuple{Measures.Measure, Measures.Measure}}(Tuple{Measures.Measure, Measures.Measure}[(-0.5715911703762906cx, -0.2832347553898603cy), (-0.09848718148604563cx, -0.1697794575476159cy)]), Compose.LinePrimitive{Tuple{Measures.Measure, Measures.Measure}}(Tuple{Measures.Measure, Measures.Measure}[(-0.608027928619369cx, -0.32971207792795604cy), (-0.6068149846943504cx, -0.5442879163858753cy)]), Compose.LinePrimitive{Tuple{Measures.Measure, Measures.Measure}}(Tuple{Measures.Measure, Measures.Measure}[(-0.5809630158971141cx, -0.31803083206633853cy), (-0.47930943897560097cx, -0.4149483487415532cy)]), Compose.LinePrimitive{Tuple{Measures.Measure, Measures.Measure}}(Tuple{Measures.Measure, Measures.Measure}[(-0.024958691356289135cx, -0.168763277241978cy), (0.4342857384211142cx, -0.2655570423398826cy)]), Compose.LinePrimitive{Tuple{Measures.Measure, Measures.Measure}}(Tuple{Measures.Measure, Measures.Measure}[(-0.08819102683392772cx, -0.13404717955875806cy), (-0.3191031490199266cx, 0.102031270790298cy)]), Compose.LinePrimitive{Tuple{Measures.Measure, Measures.Measure}}(Tuple{Measures.Measure, Measures.Measure}[(-0.07476773969929609cx, -0.1963918684024885cy), (-0.20970516815903326cx, -0.5658306582344488cy)]), Compose.LinePrimitive{Tuple{Measures.Measure, Measures.Measure}}(Tuple{Measures.Measure, Measures.Measure}[(-0.04967615557642772cx, -0.19666339801600033cy), (0.08632288704771222cx, -0.5955941519705938cy)]) … Compose.LinePrimitive{Tuple{Measures.Measure, Measures.Measure}}(Tuple{Measures.Measure, Measures.Measure}[(-0.8124272923911959cx, -0.8442281933853302cy), (-0.4853939116511733cx, -0.7371626606038694cy)]), Compose.LinePrimitive{Tuple{Measures.Measure, Measures.Measure}}(Tuple{Measures.Measure, Measures.Measure}[(-0.41452525798098544cx, -0.7115826514361155cy), (0.05056426572656507cx, -0.527755860038094cy)]), Compose.LinePrimitive{Tuple{Measures.Measure, Measures.Measure}}(Tuple{Measures.Measure, Measures.Measure}[(0.1207579756980254cx, -0.5275184154649155cy), (0.5448357879939728cx, -0.6918268507225607cy)]), Compose.LinePrimitive{Tuple{Measures.Measure, Measures.Measure}}(Tuple{Measures.Measure, Measures.Measure}[(0.058453994716700514cx, -0.487772640507431cy), (-0.17430061852822362cx, -0.26385430313623454cy)]), Compose.LinePrimitive{Tuple{Measures.Measure, Measures.Measure}}(Tuple{Measures.Measure, Measures.Measure}[(0.0744124872145464cx, -0.5498878144964676cy), (-0.054503315240782765cx, -0.9640143655947cy)]), Compose.LinePrimitive{Tuple{Measures.Measure, Measures.Measure}}(Tuple{Measures.Measure, Measures.Measure}[(0.0976194002840945cx, -0.5496280914442299cy), (0.22868508323447503cx, -0.9396774077708674cy)]), Compose.LinePrimitive{Tuple{Measures.Measure, Measures.Measure}}(Tuple{Measures.Measure, Measures.Measure}[(0.09723813122411741cx, -0.4780504095847166cy), (0.3018122817461649cx, 0.1529439794867748cy)]), Compose.LinePrimitive{Tuple{Measures.Measure, Measures.Measure}}(Tuple{Measures.Measure, Measures.Measure}[(0.6162054331179634cx, -0.7158405687004551cy), (0.9191946398962036cx, -0.802802872304618cy)]), Compose.LinePrimitive{Tuple{Measures.Measure, Measures.Measure}}(Tuple{Measures.Measure, Measures.Measure}[(0.3086045673058232cx, 0.22617374064055562cy), (0.2507818611817532cx, 0.6735372772532348cy)]), Compose.LinePrimitive{Tuple{Measures.Measure, Measures.Measure}}(Tuple{Measures.Measure, Measures.Measure}[(0.3398752456762945cx, 0.21565478575565813cy), (0.6040570037402524cx, 0.48402859779467583cy)])], Symbol(\"\"))]), List([Compose.Property{Compose.LineWidthPrimitive}(Compose.LineWidthPrimitive[Compose.LineWidthPrimitive(0.45226701686664544mm)]), Compose.Property{Compose.FillPrimitive}(Compose.FillPrimitive[Compose.FillPrimitive(RGBA{Float64}(0.0,0.0,0.0,0.0))]), Compose.Property{Compose.StrokePrimitive}(Compose.StrokePrimitive[Compose.StrokePrimitive(RGBA{Float64}(0.8274509803921568,0.8274509803921568,0.8274509803921568,1.0))])]), 0, false, false, false, false, nothing, nothing, 0.0, Symbol(\"\")), Compose.Context(Measures.BoundingBox{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}, Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}((0.0w, 0.0h), (1.0w, 1.0h)), nothing, nothing, nothing, nothing, List([]), List([]), List([Compose.Property{Compose.LineWidthPrimitive}(Compose.LineWidthPrimitive[Compose.LineWidthPrimitive(0.45226701686664544mm)]), Compose.Property{Compose.StrokePrimitive}(Compose.StrokePrimitive[Compose.StrokePrimitive(RGBA{Float64}(0.8274509803921568,0.8274509803921568,0.8274509803921568,1.0))])]), 0, false, false, false, false, nothing, nothing, 0.0, Symbol(\"\")), Compose.Context(Measures.BoundingBox{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}, Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}((0.0w, 0.0h), (1.0w, 1.0h)), nothing, nothing, nothing, nothing, List([]), List([]), List([Compose.Property{Compose.FontSizePrimitive}(Compose.FontSizePrimitive[Compose.FontSizePrimitive(4.0mm)]), Compose.Property{Compose.StrokePrimitive}(Compose.StrokePrimitive[Compose.StrokePrimitive(RGBA{Float64}(0.0,0.0,0.0,0.0))]), Compose.Property{Compose.FillPrimitive}(Compose.FillPrimitive[Compose.FillPrimitive(RGBA{Float64}(0.0,0.0,0.0,1.0))])]), 0, false, false, false, false, nothing, nothing, 0.0, Symbol(\"\")), Compose.Context(Measures.BoundingBox{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}, Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}((0.0w, 0.0h), (1.0w, 1.0h)), nothing, nothing, nothing, nothing, List([]), List([Compose.Form{Compose.CirclePrimitive{Tuple{Measures.Measure, Measures.Measure}, Measures.Measure}}(Compose.CirclePrimitive{Tuple{Measures.Measure, Measures.Measure}, Measures.Measure}[Compose.CirclePrimitive{Tuple{Measures.Measure, Measures.Measure}, Measures.Measure}((-1.0cx, -0.41797243569933584cy), 0.015075567228888182w), Compose.CirclePrimitive{Tuple{Measures.Measure, Measures.Measure}, Measures.Measure}((-0.6082409713094972cx, -0.29202376198963464cy), 0.015075567228888182w), Compose.CirclePrimitive{Tuple{Measures.Measure, Measures.Measure}, Measures.Measure}((-0.06183738055283905cx, -0.1609904509478416cy), 0.015075567228888182w), Compose.CirclePrimitive{Tuple{Measures.Measure, Measures.Measure}, Measures.Measure}((0.4711644276176641cx, -0.273329868634019cy), 0.015075567228888182w), Compose.CirclePrimitive{Tuple{Measures.Measure, Measures.Measure}, Measures.Measure}((0.8763639919848425cx, -0.34290937208654537cy), 0.015075567228888182w), Compose.CirclePrimitive{Tuple{Measures.Measure, Measures.Measure}, Measures.Measure}((-0.34545679530101525cx, 0.12897454217938153cy), 0.015075567228888182w), Compose.CirclePrimitive{Tuple{Measures.Measure, Measures.Measure}, Measures.Measure}((-0.2226355273054903cx, -0.6012320756890956cy), 0.015075567228888182w), Compose.CirclePrimitive{Tuple{Measures.Measure, Measures.Measure}, Measures.Measure}((0.09848411202412355cx, -0.6312670990387526cy), 0.015075567228888182w), Compose.CirclePrimitive{Tuple{Measures.Measure, Measures.Measure}, Measures.Measure}((0.10695762341511195cx, 0.5245617534915703cy), 0.015075567228888182w), Compose.CirclePrimitive{Tuple{Measures.Measure, Measures.Measure}, Measures.Measure}((0.04656209627487207cx, 1.0cy), 0.015075567228888182w) … Compose.CirclePrimitive{Tuple{Measures.Measure, Measures.Measure}, Measures.Measure}((-0.44957565166468993cx, -0.725436331383042cy), 0.015075567228888182w), Compose.CirclePrimitive{Tuple{Measures.Measure, Measures.Measure}, Measures.Measure}((0.08561465941026958cx, -0.5139021800911676cy), 0.015075567228888182w), Compose.CirclePrimitive{Tuple{Measures.Measure, Measures.Measure}, Measures.Measure}((0.5799791042817286cx, -0.7054430860963086cy), 0.015075567228888182w), Compose.CirclePrimitive{Tuple{Measures.Measure, Measures.Measure}, Measures.Measure}((0.9554209687324384cx, -0.8132003549087645cy), 0.015075567228888182w), Compose.CirclePrimitive{Tuple{Measures.Measure, Measures.Measure}, Measures.Measure}((-0.2014612832217927cx, -0.23772476355249794cy), 0.015075567228888182w), Compose.CirclePrimitive{Tuple{Measures.Measure, Measures.Measure}, Measures.Measure}((-0.06570548743650595cx, -1.0cy), 0.015075567228888182w), Compose.CirclePrimitive{Tuple{Measures.Measure, Measures.Measure}, Measures.Measure}((0.24068982410829998cx, -0.9754033191239296cy), 0.015075567228888182w), Compose.CirclePrimitive{Tuple{Measures.Measure, Measures.Measure}, Measures.Measure}((0.31343575356001274cx, 0.1887957499932258cy), 0.015075567228888182w), Compose.CirclePrimitive{Tuple{Measures.Measure, Measures.Measure}, Measures.Measure}((0.24595067492756373cx, 0.7109152679005646cy), 0.015075567228888182w), Compose.CirclePrimitive{Tuple{Measures.Measure, Measures.Measure}, Measures.Measure}((0.6304964958565342cx, 0.5108876335571082cy), 0.015075567228888182w)], Symbol(\"\"))]), List([Compose.Property{Compose.LineWidthPrimitive}(Compose.LineWidthPrimitive[Compose.LineWidthPrimitive(0.0mm)]), Compose.Property{Compose.StrokePrimitive}(Compose.StrokePrimitive[Compose.StrokePrimitive(RGBA{Float64}(0.0,0.0,0.0,0.0))]), Compose.Property{Compose.FillPrimitive}(Compose.FillPrimitive[Compose.FillPrimitive(RGBA{Float64}(0.25098039215686274,0.8784313725490196,0.8156862745098039,1.0))])]), 0, false, false, false, false, nothing, nothing, 0.0, Symbol(\"\")), Compose.Context(Measures.BoundingBox{Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}, Tuple{Measures.Length{:w, Float64}, Measures.Length{:h, Float64}}}((0.0w, 0.0h), (1.0w, 1.0h)), nothing, nothing, nothing, nothing, List([]), List([]), List([Compose.Property{Compose.FontSizePrimitive}(Compose.FontSizePrimitive[Compose.FontSizePrimitive(4.0mm)]), Compose.Property{Compose.StrokePrimitive}(Compose.StrokePrimitive[Compose.StrokePrimitive(RGBA{Float64}(0.0,0.0,0.0,0.0))]), Compose.Property{Compose.FillPrimitive}(Compose.FillPrimitive[Compose.FillPrimitive(RGBA{Float64}(0.0,0.0,0.0,1.0))])]), 0, false, false, false, false, nothing, nothing, 0.0, Symbol(\"\"))]), List([]), List([]), 0, false, false, false, false, nothing, nothing, 0.0, Symbol(\"\"))" ] }, "execution_count": 20, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# metal plate\n", "□ = Graph(4)\n", "add_edge!(□, 1, 2)\n", "add_edge!(□, 1, 3)\n", "add_edge!(□, 2, 4)\n", "add_edge!(□, 3, 4)\n", "\n", "# airplane skeleton\n", "skeleton = Graph(11)\n", "add_edge!(skeleton, 1, 2)\n", "add_edge!(skeleton, 2, 3)\n", "add_edge!(skeleton, 3, 4)\n", "add_edge!(skeleton, 4, 5)\n", "add_edge!(skeleton, 3, 6)\n", "add_edge!(skeleton, 3, 7)\n", "add_edge!(skeleton, 3, 8)\n", "add_edge!(skeleton, 3, 9)\n", "add_edge!(skeleton, 9, 10)\n", "add_edge!(skeleton, 9, 11)\n", "\n", "gplot(cartesian_product(□, skeleton))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Many other operations, such as union, intersection, and complement are available and can be useful for manipulating graphs as first-class objects. Please check the documentation or the file `src/operators.jl` in the project for a complete list of operations.\n", "\n", "## Conclusions\n", "\n", "This basic tutorial covered the basic types defined in Graphs.jl and the various helper functions that the package provides for construction and manipulation of simple graphs. Please consult the other tutorials in this repository for more advanced features." ] } ], "metadata": { "kernelspec": { "display_name": "Julia 1.8.2", "language": "julia", "name": "julia-1.8" }, "language_info": { "file_extension": ".jl", "mimetype": "application/julia", "name": "julia", "version": "1.8.2" } }, "nbformat": 4, "nbformat_minor": 2 }