Skip to content

Commit

Permalink
Dependence on NestedGraphsIO.jl
Browse files Browse the repository at this point in the history
  • Loading branch information
filchristou committed Jan 11, 2023
1 parent e71c7f6 commit a00d25b
Show file tree
Hide file tree
Showing 18 changed files with 258 additions and 147 deletions.
4 changes: 1 addition & 3 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,14 @@ version = "0.1.0"

[deps]
AbstractTrees = "1520ce14-60c1-5f80-bbc7-55ef81b5835c"
Colors = "5ae59095-9a9b-59fe-a467-6f913c188581"
Distances = "b4f34e82-e78d-54a5-968a-f98e89d6e8f7"
DocStringExtensions = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae"
Graphs = "86223c79-3864-5bf0-83f7-82e725a168b6"
IterTools = "c8e1da08-722c-5040-9ed9-7db0dc04731e"
JET = "c3a54625-cd67-489e-a8e7-0a5a0ff4e31b"
MetaGraphs = "626554b9-1ddb-594c-aa3c-2596fe9399a5"
MetaGraphsNext = "fa8bd995-216d-47f1-8a91-f3b68fbeb377"
NestedGraphs = "03c36417-ddab-428a-818d-5359aee292ef"
Parameters = "d96e819e-fc66-5662-9728-84c9c7592b0a"
Reexport = "189a3867-3050-52da-a836-e630ba90ab69"
Term = "22787eb5-b846-44ae-b979-8e399b8463ab"
UUIDs = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"
Unitful = "1986cc42-f94f-5a68-af5c-568840ba703d"
Expand Down
20 changes: 16 additions & 4 deletions docs/Manifest.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This file is machine-generated - editing it directly is not advised

julia_version = "1.8.1"
julia_version = "1.8.4"
manifest_format = "2.0"
project_hash = "01d4ac2b982857f32a790991403aebed06ffe6b2"

Expand Down Expand Up @@ -57,7 +57,7 @@ version = "4.4.0"
[[deps.CompilerSupportLibraries_jll]]
deps = ["Artifacts", "Libdl"]
uuid = "e66e0078-7015-5450-92f7-15fbd957f2ae"
version = "0.5.2+0"
version = "1.0.1+0"

[[deps.ConstructionBase]]
deps = ["LinearAlgebra"]
Expand Down Expand Up @@ -85,6 +85,12 @@ version = "1.0.0"
deps = ["Printf"]
uuid = "ade2ca70-3891-5945-98fb-dc099432e06a"

[[deps.Distances]]
deps = ["LinearAlgebra", "SparseArrays", "Statistics", "StatsAPI"]
git-tree-sha1 = "3258d0659f812acde79e8a74b11f17ac06d0ca04"
uuid = "b4f34e82-e78d-54a5-968a-f98e89d6e8f7"
version = "0.10.7"

[[deps.Distributed]]
deps = ["Random", "Serialization", "Sockets"]
uuid = "8ba89e20-285c-5b6f-9357-94700520ee1b"
Expand Down Expand Up @@ -218,7 +224,7 @@ uuid = "6f1432cf-f94c-5a45-995e-cdbf5db27b0b"
version = "2.2.2"

[[deps.MINDFul]]
deps = ["AbstractTrees", "Colors", "DocStringExtensions", "Graphs", "IterTools", "JET", "MetaGraphs", "MetaGraphsNext", "NestedGraphs", "Parameters", "Reexport", "Term", "UUIDs", "Unitful"]
deps = ["AbstractTrees", "Colors", "Distances", "DocStringExtensions", "Graphs", "IterTools", "JET", "MetaGraphs", "MetaGraphsNext", "NestedGraphs", "Parameters", "Reexport", "Term", "UUIDs", "Unitful"]
path = ".."
uuid = "437ce7a4-cd80-4539-9a29-b274cfe157d6"
version = "0.1.0"
Expand Down Expand Up @@ -378,6 +384,12 @@ version = "1.4.0"
deps = ["LinearAlgebra", "SparseArrays"]
uuid = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"

[[deps.StatsAPI]]
deps = ["LinearAlgebra"]
git-tree-sha1 = "f9af7f195fb13589dd2e2d57fdb401717d2eb1f6"
uuid = "82ae8749-77ed-4fe6-ae5f-f523153014b0"
version = "1.5.0"

[[deps.TOML]]
deps = ["Dates"]
uuid = "fa267f1f-6049-4f14-aa54-33bafae1ed76"
Expand All @@ -398,7 +410,7 @@ version = "1.10.0"
[[deps.Tar]]
deps = ["ArgTools", "SHA"]
uuid = "a4e569a6-e804-4fa4-b0f3-eef7a1d5b13e"
version = "1.10.0"
version = "1.10.1"

[[deps.Term]]
deps = ["CodeTracking", "Dates", "Highlights", "InteractiveUtils", "Logging", "Markdown", "MyterialColors", "OrderedCollections", "Parameters", "ProgressLogging", "SnoopPrecompile", "Tables", "UUIDs", "UnicodeFun"]
Expand Down
2 changes: 2 additions & 0 deletions docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ using Documenter, MINDFul
makedocs(sitename="MINDFul.jl",
pages = [
"Introduction" => "index.md",
"Usage and Examples" => "usage.md",
"Roadmap" => "roadmap.md",
"API" => "API.md"
])

Expand Down
9 changes: 9 additions & 0 deletions docs/src/roadmap.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Roadmap

`MINDFul.jl` is an effort meant to help parties interested in the reasearch of intent-driven network coordination.
Future additions are going to be determined by our research directions.
However the following consitute a list of plans that are irrelevant to research purposes
- complete substitution of `MetaGraphs` by `MetaGraphsNext`
- complete integration of `Term.jl`
- definition of line rate units with `Unitful.jl`
- companion package `MINDFulCompanion.jl` for better demonstration
4 changes: 4 additions & 0 deletions docs/src/usage.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Usage and Examples

This page demonstrates a basic usage of the package.
To see all functionalities head to the [API](@ref) documentation
4 changes: 2 additions & 2 deletions src/IBN/algorithms.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
function compile!(ibn::IBN, dag::IntentDAG, idagn::IntentDAGNode{R}, algmethod::F; algargs...) where {R<:Union{ConnectivityIntent},F<:Function}
iam(ibn, neibn) = getid(ibn) == getid(neibn)
firstforeignibnnode(ibn::IBN) = getfirst(x -> ibn.controllers[NestedGraphs.domain(ibn.ngr,x)] isa IBN, [v for v in vertices(ibn.ngr)])
firstnode(ibn::IBN, neibn::IBN) = getfirst(x -> ibn.controllers[NestedGraphs.domain(ibn.ngr,x)] == neibn, [v for v in vertices(ibn.ngr)])
firstforeignibnnode(ibn::IBN) = getfirst(x -> ibn.controllers[NestedGraphs.subgraph(ibn.ngr,x)] isa IBN, [v for v in vertices(ibn.ngr)])
firstnode(ibn::IBN, neibn::IBN) = getfirst(x -> ibn.controllers[NestedGraphs.subgraph(ibn.ngr,x)] == neibn, [v for v in vertices(ibn.ngr)])

conint = idagn.intent
if getsrc(conint) == getdst(conint)
Expand Down
8 changes: 4 additions & 4 deletions src/IBN/ibncore.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ getid(ibn::IBN) = ibn.id
getindex(ibn::IBN, c::R) where {R<:Union{IBN,SDN}} = findfirst(==(c), ibn.controllers)
getindex(ibn::IBN, c::R) where {R<:Intent} = findfirst(==(c), getfield.(ibn.intents, :data))
getindex(ibn::IBN, c::R) where {R<:IntentDAG} = findfirst(==(c), ibn.intents)
controllerofnode(ibn::IBN, node::Int) = ibn.controllers[domain(ibn.ngr, node)]
controllerofnode(ibn::IBN, node::Int) = ibn.controllers[NestedGraphs.subgraph(ibn.ngr, node)]
nodesofcontroller(ibn::IBN, ci::Int) = [i for (i,nd) in enumerate(ibn.ngr.vmap) if nd[1] == ci]
getibns(ibn::IBN) = Iterators.filter(x -> isa(x, IBN),ibn.controllers)
getsdns(ibn::IBN) = Iterators.filter(x -> isa(x, SDN),ibn.controllers)
Expand Down Expand Up @@ -111,11 +111,11 @@ function connectIBNs!(ibn1::IBN, ibn2::IBN, cedges::Vector{NestedEdge{T}}, dprop
#add controllers

# build graph as prrovided from the other ibn
gr2, vmap2 = subgraph(ibn2, ibn1)
gr2, vmap2 = subgraphibn(ibn2, ibn1)
v2add = [vp for vp in v2list if !has_vertex(gr2, vp)]
add_vertices!(gr2, ibn2.ngr, v2add)

gr1, vmap1 = subgraph(ibn1, ibn2)
gr1, vmap1 = subgraphibn(ibn1, ibn2)
v1add = [vp for vp in v1list if !has_vertex(gr1, vp)]
add_vertices!(gr1, ibn1.ngr, v1add)

Expand Down Expand Up @@ -172,7 +172,7 @@ function remintent!(ibnc::IBNIssuer, ibns::IBN, intentid::Int)
end

"ibn-customer asks for the graph of ibn-provider"
function subgraph(ibnp::IBN, ibnc::IBN)
function subgraphibn(ibnp::IBN, ibnc::IBN)
#check permissions
return (MetaDiGraph(), Vector{Int}())
end
Expand Down
2 changes: 1 addition & 1 deletion src/IBN/ibninterface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ function breakdown(ibn::IBN, e::Edge)
controllerofnodedst = controllerofnode(ibn, e.dst)
if controllerofnodesrc == controllerofnodedst
#intradomain
return (;sdn1=controllerofnodesrc, sdn2=nothing, ce=domainedge(ibn.ngr, e), ceintra=nothing)
return (;sdn1=controllerofnodesrc, sdn2=nothing, ce=subgraphedge(ibn.ngr, e), ceintra=nothing)
else
#interdomain
if controllerofnodesrc isa IBN || controllerofnodedst isa IBN
Expand Down
6 changes: 2 additions & 4 deletions src/MINDFul.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
module MINDFul

using Reexport
using Parameters
using Graphs, MetaGraphs
using DocStringExtensions
Expand All @@ -11,12 +10,11 @@ import MetaGraphsNext as MGN
import MetaGraphsNext: MetaGraph as MG
import MetaGraphsNext: MetaDiGraph as MDG
import IterTools: partition
import Distances: haversine
const EARTH_RADIUS = 6371

import Term

@reexport using AbstractTrees
@reexport import AbstractTrees:isroot

export Counter
export SDN, SDNdummy, IBNEnv, updatetime!, resettime!
export IBN, addintent!, deploy!, transnodes, issatisfied
Expand Down
3 changes: 2 additions & 1 deletion src/NetRes/simnetcore.jl
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,10 @@ function simgraph(mgr::MetaDiGraph; distance_method=euclidean_dist)
return simgr
end
euclidean_dist(possrc, posdst) = sqrt(sum((possrc .- posdst) .^ 2))
geodesic_dist(possrc, posdst) = haversine(possrc, posdst, EARTH_RADIUS)

function simgraph(ng::G; distance_method=euclidean_dist) where G<:NestedMetaGraph
cgnew = G()
cgnew = G(;extrasubgraph=false)
for gr in ng.grv
add_vertex!(cgnew, simgraph(gr; distance_method=distance_method))
end
Expand Down
14 changes: 7 additions & 7 deletions src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ function resetIBNF!()
end

"Converts a node path to a sequence of edges"
edgeify(p::Vector{Int}) = map(Edge , zip(p, p[2:end]));
edgeify(p) = map(Edge , zip(p, p[2:end]));
edgeify(p::Vector{Tuple{Int, Int}}) = map(NestedEdge , zip(p, p[2:end]));

"$(TYPEDSIGNATURES) Get first element or `nothing`"
Expand Down Expand Up @@ -67,12 +67,12 @@ function nestedGraph2IBNs!(globalnet::NestedGraph)
add_vertex!(ibn1.ngr, MetaDiGraph())
push!(ibn1.controllers, ibn2)
#add node
add_vertex!(ibn1.ngr, filter(x -> first(x) in [:xcoord, :ycoord] , props(globalnet, ed.dst)), domains=length(ibn1.ngr.grv), targetnode=node2)
add_vertex!(ibn1.ngr, filter(x -> first(x) in [:xcoord, :ycoord] , props(globalnet, ed.dst)), subgraphs=length(ibn1.ngr.grv), targetnode=node2)
idx = length(ibn1.ngr.grv)
else
add_vertex!(ibn1.ngr, filter(x -> first(x) in [:xcoord, :ycoord] , props(globalnet, ed.dst)), domains=idx, targetnode=node2)
add_vertex!(ibn1.ngr, filter(x -> first(x) in [:xcoord, :ycoord] , props(globalnet, ed.dst)), subgraphs=idx, targetnode=node2)
end
con1idx = NestedGraphs.domain(ibn1.ngr, node1)
con1idx = NestedGraphs.subgraph(ibn1.ngr, node1)
domainnode1 = ibn1.ngr.vmap[node1][2]
con2idx = idx
domainnode2 = node2
Expand All @@ -88,14 +88,14 @@ function nestedGraph2IBNs!(globalnet::NestedGraph)
add_vertex!(ibn2.ngr, MetaDiGraph())
push!(ibn2.controllers, ibn1)
#add node
add_vertex!(ibn2.ngr, filter(x -> first(x) in [:xcoord, :ycoord] , props(globalnet, ed.src)), domains=length(ibn2.ngr.grv), targetnode=node1)
add_vertex!(ibn2.ngr, filter(x -> first(x) in [:xcoord, :ycoord] , props(globalnet, ed.src)), subgraphs=length(ibn2.ngr.grv), targetnode=node1)
idx = length(ibn2.ngr.grv)
else
add_vertex!(ibn2.ngr, filter(x -> first(x) in [:xcoord, :ycoord] , props(globalnet, ed.src)), domains=idx, targetnode=node1)
add_vertex!(ibn2.ngr, filter(x -> first(x) in [:xcoord, :ycoord] , props(globalnet, ed.src)), subgraphs=idx, targetnode=node1)
end
con1idx = idx
domainnode1 = node1
con2idx = NestedGraphs.domain(ibn2.ngr, node2)
con2idx = NestedGraphs.subgraph(ibn2.ngr, node2)
domainnode2 = ibn2.ngr.vmap[node2][2]
interibnedge = NestedEdge(con1idx, domainnode1, con2idx, domainnode2)
connect!(ibn2.controllers[con2idx], interibnedge, props(globalnet, ed))
Expand Down
Loading

0 comments on commit a00d25b

Please sign in to comment.