Skip to content

Commit 3429581

Browse files
available_problems dans OptimalControlProbleme.jl et exporté
1 parent 6e8c5e3 commit 3429581

File tree

2 files changed

+28
-22
lines changed

2 files changed

+28
-22
lines changed

src/OptimalControlProblems.jl

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,33 @@ for i in 1:number_of_problems
7979
end
8080
end
8181

82-
export JuMPBackend, OptimalControlBackend
82+
# ------- Available Problems Function -------
83+
"""
84+
available_problems()
85+
86+
Returns the list of problems that are currently working based on the last test execution.
87+
The list is read from a cache file that gets updated every time tests are run.
88+
If no cache exists, returns an empty list with a warning to run tests first.
89+
"""
90+
function available_problems()
91+
cache_file = joinpath(dirname(@__FILE__), "..", "available_problems_cache.txt")
92+
if isfile(cache_file)
93+
try
94+
content = read(cache_file, String)
95+
if !isempty(strip(content))
96+
# Parse symbols from the file
97+
lines = split(strip(content), '\n')
98+
return [Symbol(strip(line)) for line in lines if !isempty(strip(line))]
99+
end
100+
catch e
101+
@warn "Error reading the cache: $e"
102+
end
103+
end
104+
# Default list if the cache does not exist or is empty
105+
@warn "Available problems cache not found. Run the tests to update the list."
106+
return Symbol[]
107+
end
108+
109+
export JuMPBackend, OptimalControlBackend, available_problems
83110

84111
end

test/utils.jl

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -44,25 +44,4 @@ function norm_Lp(u, p, dt)
4444
s += 0.5 * (sum(abs.(u[i]) .^ p) + sum(abs.(u[i+1]) .^ p))
4545
end
4646
return (s * dt)^(1 / p)
47-
end
48-
49-
function available_problems()
50-
cache_file = joinpath(@__DIR__, "..", "available_problems_cache.txt")
51-
52-
if isfile(cache_file)
53-
try
54-
content = read(cache_file, String)
55-
if !isempty(strip(content))
56-
# Parse symbols from the file
57-
lines = split(strip(content), '\n')
58-
return [Symbol(strip(line)) for line in lines if !isempty(strip(line))]
59-
end
60-
catch e
61-
@warn "Error reading the cache: $e"
62-
end
63-
end
64-
65-
# Default list if the cache does not exist or is empty
66-
@warn "Available problems cache not found. Run the tests to update the list."
67-
return Symbol[]
6847
end

0 commit comments

Comments
 (0)