Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

10 update graph interfaces #11

Merged
merged 8 commits into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "JSMDInterfaces"
uuid = "6b30ee2f-618e-4a15-bf4e-7df7b496e609"
authors = ["JSMD Team"]
version = "1.4.0"
version = "1.4.1"

[deps]
Graphs = "86223c79-3864-5bf0-83f7-82e725a168b6"
Expand Down
13 changes: 6 additions & 7 deletions src/Frames.jl
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
module Frames

using Graphs: AbstractGraph
using JSMDInterfaces.Interface

export AbstractJSMDFrameGraph,
vector3, vector6, vector9, vector12,
rotation3, rotation6, rotation9, rotation12

using JSMDInterfaces.Interface

import JSMDInterfaces.Graph: AbstractJSMDGraph


"""
AbstractJSMDFrameGraph

Abstract type for frames graphs.
Subtype it to create a new frames graph compatible with the ecosystem.
"""
abstract type AbstractJSMDFrameGraph{T} <: AbstractGraph{T} end

# ----
# JSMD interface
abstract type AbstractJSMDFrameGraph{T} <: AbstractJSMDGraph{T} end

"""
vector3(model::F, from::Int, to::Int, axis::Int, time::Number)
Expand Down
98 changes: 56 additions & 42 deletions src/Graph.jl
Original file line number Diff line number Diff line change
@@ -1,85 +1,99 @@
module Graph

using JSMDInterfaces.Interface
using Graphs

using JSMDInterfaces.Interface: @interface

import Graphs: has_vertex,
has_edge,
edges,
edgetype,
inneighbors,
ne,
nv,
outneighbors,
vertices,
is_directed
import Graphs:
AbstractGraph,
has_vertex,
has_edge,
edges,
edgetype,
inneighbors,
ne,
nv,
outneighbors,
vertices,
is_directed,
add_vertex!,
add_edge!,
has_path

"""
AbstractJSMDGraph{T}

Abstract type for graphs.
Subtype it to create a graphs compatible with the ecosystem.

Graphs here could be compatible with both JSMD ecosystem and [`Graphs.jl`](https://github.com/JuliaGraphs/Graphs.jl).
Subtype it to create graphs compatible with the JSMD ecosystem.

For `JSMD` compatibility, see also: [`add_vertex!`](@ref) and [`add_edge!`](@ref).

For `Graphs.jl` compatibility, see also: [Graphs.jl interface](https://juliagraphs.org/Graphs.jl/dev/ecosystem/interface/)
Graphs here could be compatible with both JSMD ecosystem and [`Graphs.jl`](https://github.com/JuliaGraphs/Graphs.jl):
- For `JSMD` compatibility, see also: [`get_path`](@ref).
- For `Graphs.jl` compatibility, see also: [Graphs.jl interface](https://juliagraphs.org/Graphs.jl/dev/ecosystem/interface/)
"""
abstract type AbstractJSMDGraph{T} <: AbstractGraph{T} end


"""
AbstractJSMDGraphNode

Abstract type for graph nodes.
Subtype it to create a graph nodes compatible with the ecosystem.
Subtype it to create a node graph compatible with the JSMD ecosystem.
"""
abstract type AbstractJSMDGraphNode end

# Graphs interface

@interface function Graphs.has_vertex(::AbstractJSMDGraph, ::Int) end
# Graphs interfaces
# ==================

@interface function Graphs.has_edge(::AbstractJSMDGraph, ::Int, ::Int) end
@interface function has_vertex(::AbstractJSMDGraph, ::Int) end

@interface function Graphs.edges(::AbstractJSMDGraph) end
@interface function has_edge(::AbstractJSMDGraph, ::Int, ::Int) end

@interface function Graphs.edgetype(::AbstractJSMDGraph) end
@interface function edges(::AbstractJSMDGraph) end

@interface function Graphs.inneighbors(::AbstractJSMDGraph, ::Int) end
@interface function edgetype(::AbstractJSMDGraph) end

@interface function Graphs.ne(::AbstractJSMDGraph) end
@interface function inneighbors(::AbstractJSMDGraph, ::Int) end

@interface function Graphs.nv(::AbstractJSMDGraph) end
@interface function ne(::AbstractJSMDGraph) end

@interface function Graphs.outneighbors(::AbstractJSMDGraph, ::Int) end
@interface function nv(::AbstractJSMDGraph) end

@interface function Graphs.vertices(::AbstractJSMDGraph) end
@interface function outneighbors(::AbstractJSMDGraph, ::Int) end

@interface function Graphs.is_directed(::AbstractJSMDGraph) end
@interface function vertices(::AbstractJSMDGraph) end

# JSMD interface
@interface function is_directed(::AbstractJSMDGraph) end

"""
add_vertex!(::AbstractJSMDGraph, ::N)

This function serves as an interface for inserting a new vertex in a graph.
# JSMD interfaces
# ==================

!!! warning
Concrete implementations of `AbstractJSMDGraph` must provide this function!
"""
@interface function add_vertex!(::AbstractJSMDGraph, ::N) where {N<:AbstractJSMDGraphNode} end
add_node!(g::AbstractJSMDGraph, vertex::AbstractJSMDGraphNode)

This function adds `vertex` to the graph `g`.
"""
add_edge!(::AbstractJSMDGraph, ::Int, ::Int, ::Int)
@interface function add_vertex!(::AbstractJSMDGraph, ::N) where {N<:AbstractJSMDGraphNode} end

This function serves as an interface for inserting a new (weighted) edge in a graph.
"""
add_edge!(g::AbstractJSMDGraph, from::Int, to::Int, cost::Int)

!!! warning
Concrete implementations of `AbstractJSMDGraph` must provide this function!
This function add an edge between `from` and `to` with weight `cost`.
"""
@interface function add_edge!(::AbstractJSMDGraph, ::Int, ::Int, ::Int) end

"""
has_path(g::AbstractJSMDGraph, from::Int, to::Int)

Return true if there is a path between `from` and `to` in the graph `g`.
"""
@interface function has_path(::AbstractJSMDGraph, ::Int, ::Int) end

"""
get_path(g::AbstractJSMDGraph, from::Int, to::Int)

Get the nodes on hte path between and including `from' and `to`. Returns an empty array if
either `from` or `to` are not part of `g` or if there is no path between them.
"""
@interface function get_path(::AbstractJSMDGraph, ::Int, ::Int) end

end