Skip to content

Commit 3a9b621

Browse files
authored
Merge pull request #73 from leerosenthalj/graphcompat
Swapped out ItemGraphs -> Graphs for compatibility updates
2 parents 10d5eb1 + df70d60 commit 3a9b621

File tree

3 files changed

+53
-22
lines changed

3 files changed

+53
-22
lines changed

.github/workflows/CI.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,8 @@ jobs:
1313
fail-fast: false
1414
matrix:
1515
version:
16-
- '1.3' # Replace this with the minimum Julia version that your package supports. E.g. if your package requires Julia 1.5 or higher, change this to '1.5'.
16+
- 'min' # Minimum supported version according to the Project.toml file.
1717
- '1' # Leave this line unchanged. '1' will automatically expand to the latest stable 1.x release of Julia.
18-
- 'lts'
1918
- 'nightly'
2019
os:
2120
- ubuntu-latest

Project.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ version = "0.7.1"
55
[deps]
66
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
77
EarthOrientation = "732a3c5d-d6c0-58bc-adb1-1b51709a25e2"
8-
ItemGraphs = "d5eda45b-7e79-5788-9687-2c6ab7b96158"
8+
Graphs = "86223c79-3864-5bf0-83f7-82e725a168b6"
99
LeapSeconds = "2f5f767c-a11e-5269-a972-637d4b97c32d"
1010
MacroTools = "1914dd2f-81c6-5fcd-8719-6d5c9610ff09"
1111
MuladdMacro = "46d2c3a1-f734-5fdb-9937-b9b9aeba4221"
@@ -14,13 +14,13 @@ Reexport = "189a3867-3050-52da-a836-e630ba90ab69"
1414
[compat]
1515
ERFA = "0.5, 0.6, 1.0"
1616
EarthOrientation = "0.7"
17-
ItemGraphs = "0.4"
17+
Graphs = "1.12.0"
1818
LeapSeconds = "1.1"
1919
MacroTools = "0.5"
2020
Measurements = "2"
2121
MuladdMacro = "0.2"
2222
Reexport = "0.2, 1"
23-
julia = "1.3"
23+
julia = "1.10"
2424

2525
[extras]
2626
ERFA = "17511681-8477-586a-8d98-4cfd5a1f2ec3"

src/TimeScales.jl

Lines changed: 49 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
module TimeScales
22

3-
using ItemGraphs: ItemGraph, add_edge!, add_vertex!, items
4-
3+
using Graphs
54
import Dates
65

76
export
@@ -77,24 +76,51 @@ for (acronym, name) in zip(ACRONYMS, NAMES)
7776
end
7877
end
7978

80-
const SCALES = ItemGraph{TimeScale}()
81-
82-
function register_scale!(s)
83-
add_vertex!(SCALES, s)
79+
# Create a DiGraph to store the time scales
80+
const SCALES = SimpleDiGraph{Int}()
81+
const SCALE_VERTICES = Dict{TimeScale, Int}()
82+
const VERTEX_SCALES = Dict{Int, TimeScale}()
83+
84+
function register_scale!(s::TimeScale)
85+
if !haskey(SCALE_VERTICES, s)
86+
add_vertex!(SCALES)
87+
v = nv(SCALES)
88+
SCALE_VERTICES[s] = v
89+
VERTEX_SCALES[v] = s
90+
end
8491
end
8592

86-
function link_scales!(s1, s2; oneway=false)
87-
add_edge!(SCALES, s1, s2)
88-
oneway || add_edge!(SCALES, s2, s1)
93+
function link_scales!(s1::TimeScale, s2::TimeScale; oneway=false)
94+
# Ensure both scales are registered
95+
register_scale!(s1)
96+
register_scale!(s2)
97+
98+
# Add the edge
99+
add_edge!(SCALES, SCALE_VERTICES[s1], SCALE_VERTICES[s2])
100+
oneway || add_edge!(SCALES, SCALE_VERTICES[s2], SCALE_VERTICES[s1])
89101
end
90102

91-
link_scales!(TAI, TT)
92-
link_scales!(TAI, UT1)
93-
link_scales!(TT, TCG)
94-
link_scales!(TT, TDB)
95-
link_scales!(TCB, TDB)
96-
97-
find_path(from, to) = items(SCALES, from, to)
103+
function find_path(from::TimeScale, to::TimeScale)
104+
# Get vertex indices
105+
v_from = SCALE_VERTICES[from]
106+
v_to = SCALE_VERTICES[to]
107+
108+
# Find shortest path
109+
path = dijkstra_shortest_paths(SCALES, v_from)
110+
111+
# Extract path vertices
112+
path_vertices = Int[]
113+
current = v_to
114+
while current != v_from
115+
pushfirst!(path_vertices, current)
116+
current = path.parents[current]
117+
current == 0 && return TimeScale[] # No path exists
118+
end
119+
pushfirst!(path_vertices, v_from)
120+
121+
# Convert vertices back to TimeScales
122+
return [VERTEX_SCALES[v] for v in path_vertices]
123+
end
98124

99125
struct NotATimeScale <: TimeScale end
100126

@@ -110,5 +136,11 @@ tryparse(::Any) = nothing
110136
return val, i
111137
end
112138

113-
end
139+
# Initialize the graph with the time scale relationships
140+
link_scales!(TAI, TT)
141+
link_scales!(TAI, UT1)
142+
link_scales!(TT, TCG)
143+
link_scales!(TT, TDB)
144+
link_scales!(TCB, TDB)
114145

146+
end

0 commit comments

Comments
 (0)