Skip to content

Commit fbf403e

Browse files
committed
AbstractTrees
1 parent 822bad6 commit fbf403e

File tree

2 files changed

+85
-94
lines changed

2 files changed

+85
-94
lines changed

src/SoleModels.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ export MixedModel
6464
export solemodel
6565

6666
include("types/model.jl")
67+
include("types/AbstractTrees.jl")
6768
include("types/api.jl")
6869

6970
include("utils/models/leaf.jl")

src/types/model.jl

Lines changed: 84 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ and enclose a *tree* of `AbstractModel`s (with `LeafModel`s at the leaves).
3636
- `info(m::AbstractModel, [key, [defaultval]])`
3737
- `info!(m::AbstractModel, key, value)`
3838
- `hasinfo(m::AbstractModel, key)`
39-
- `AbstractTrees.children(m::AbstractModel)`
4039
4140
# Utility functions
4241
- `apply(m::AbstractModel, i::AbstractInterpretationSet; kwargs...)`
@@ -111,95 +110,6 @@ function outputtype(m::AbstractModel)
111110
iscomplete(m) ? outcometype(m) : Union{Nothing,outcometype(m)}
112111
end
113112

114-
115-
"""
116-
immediatesubmodels(m::AbstractModel)
117-
118-
Return the list of immediate child models.
119-
120-
!!! note
121-
If the model is a leaf model, then the returned list will be empty.
122-
123-
# Examples
124-
```julia-repl
125-
julia> using SoleLogics
126-
127-
julia> branch = Branch(SoleLogics.parseformula("p∧q∨r"), "YES", "NO");
128-
129-
julia> immediatesubmodels(branch)
130-
2-element Vector{SoleModels.ConstantModel{String}}:
131-
SoleModels.ConstantModel{String}
132-
YES
133-
134-
SoleModels.ConstantModel{String}
135-
NO
136-
137-
julia> branch2 = Branch(SoleLogics.parseformula("s→p"), branch, 42);
138-
139-
140-
julia> printmodel.(immediatesubmodels(branch2));
141-
Branch
142-
┐ p ∧ (q ∨ r)
143-
├ ✔ YES
144-
└ ✘ NO
145-
146-
ConstantModel
147-
42
148-
```
149-
150-
See also [`AbstractModel`](@ref), [`LeafModel`](@ref), [`submodels`](@ref).
151-
"""
152-
function immediatesubmodels(
153-
m::AbstractModel{O}
154-
)::Vector{<:{AbstractModel{<:O}}} where {O}
155-
return error("Please, provide method immediatesubmodels(::$(typeof(m))).")
156-
end
157-
158-
"""
159-
nimmediatesubmodels(m::AbstractModel)
160-
161-
Return the number of models returned by [`immediatesubmodels`](@ref).
162-
163-
See also [`AbstractModel`](@ref), [`immediatesubmodels`](@ref).
164-
"""
165-
function nimmediatesubmodels(m::AbstractModel)
166-
return error("Please, provide method nimmediatesubmodels(::$(typeof(m))).")
167-
end
168-
169-
"""
170-
listimmediaterules(m::AbstractModel{O} where {O})::Rule{<:O}
171-
172-
List the immediate rules equivalent to a symbolic model.
173-
174-
# Examples
175-
```julia-repl
176-
julia> using SoleLogics
177-
178-
julia> branch = Branch(SoleLogics.parseformula("p"), Branch(SoleLogics.parseformula("q"), "YES", "NO"), "NO")
179-
p
180-
├✔ q
181-
│├✔ YES
182-
│└✘ NO
183-
└✘ NO
184-
185-
186-
julia> printmodel.(listimmediaterules(branch); tree_mode = true);
187-
▣ p
188-
└✔ q
189-
├✔ YES
190-
└✘ NO
191-
192-
▣ ¬(p)
193-
└✔ NO
194-
```
195-
196-
See also [`AbstractModel`](@ref), [`listrules`](@ref).
197-
"""
198-
listimmediaterules(m::AbstractModel{O} where {O})::Rule{<:O} =
199-
error("Please, provide method listimmediaterules(::$(typeof(m))) " *
200-
"($(typeof(m)) is a symbolic model).")
201-
202-
203113
"""
204114
apply(m::AbstractModel, i::AbstractInterpretation; kwargs...)::outputtype(m)
205115
@@ -357,13 +267,93 @@ wrap(o::Any, FM::Type{<:AbstractModel}) = convert(FM, wrap(o))
357267
wrap(m::AbstractModel) = m
358268
# wrap(o::Any)::AbstractModel = error("Please, provide method wrap($(typeof(o))).")
359269

270+
"""
271+
immediatesubmodels(m::AbstractModel)
272+
273+
Return the list of immediate child models.
274+
275+
!!! note
276+
If the model is a leaf model, then the returned list will be empty.
277+
278+
# Examples
279+
```julia-repl
280+
julia> using SoleLogics
281+
282+
julia> branch = Branch(SoleLogics.parseformula("p∧q∨r"), "YES", "NO");
283+
284+
julia> immediatesubmodels(branch)
285+
2-element Vector{SoleModels.ConstantModel{String}}:
286+
SoleModels.ConstantModel{String}
287+
YES
288+
289+
SoleModels.ConstantModel{String}
290+
NO
291+
292+
julia> branch2 = Branch(SoleLogics.parseformula("s→p"), branch, 42);
293+
294+
295+
julia> printmodel.(immediatesubmodels(branch2));
296+
Branch
297+
┐ p ∧ (q ∨ r)
298+
├ ✔ YES
299+
└ ✘ NO
300+
301+
ConstantModel
302+
42
303+
```
304+
305+
See also [`AbstractModel`](@ref), [`LeafModel`](@ref), [`submodels`](@ref).
306+
"""
307+
function immediatesubmodels(
308+
m::AbstractModel{O}
309+
)::Vector{<:{AbstractModel{<:O}}} where {O}
310+
return error("Please, provide method immediatesubmodels(::$(typeof(m))).")
311+
end
312+
313+
"""
314+
nimmediatesubmodels(m::AbstractModel)
315+
316+
Return the number of models returned by [`immediatesubmodels`](@ref).
317+
318+
See also [`AbstractModel`](@ref), [`immediatesubmodels`](@ref).
319+
"""
320+
function nimmediatesubmodels(m::AbstractModel)
321+
return error("Please, provide method nimmediatesubmodels(::$(typeof(m))).")
322+
end
323+
324+
"""
325+
listimmediaterules(m::AbstractModel{O} where {O})::Rule{<:O}
360326
327+
List the immediate rules equivalent to a symbolic model.
361328
362-
# AbstracTrees interface
363-
using AbstractTrees
364-
import AbstractTrees: children
329+
# Examples
330+
```julia-repl
331+
julia> using SoleLogics
332+
333+
julia> branch = Branch(SoleLogics.parseformula("p"), Branch(SoleLogics.parseformula("q"), "YES", "NO"), "NO")
334+
p
335+
├✔ q
336+
│├✔ YES
337+
│└✘ NO
338+
└✘ NO
339+
340+
341+
julia> printmodel.(listimmediaterules(branch); tree_mode = true);
342+
▣ p
343+
└✔ q
344+
├✔ YES
345+
└✘ NO
346+
347+
▣ ¬(p)
348+
└✔ NO
349+
```
350+
351+
See also [`AbstractModel`](@ref), [`listrules`](@ref).
352+
"""
353+
listimmediaterules(m::AbstractModel{O} where {O})::Rule{<:O} =
354+
error("Please, provide method listimmediaterules(::$(typeof(m))) " *
355+
"($(typeof(m)) is a symbolic model).")
365356

366-
AbstractTrees.children(m::AbstractModel) = immediatesubmodels(m)
367357

368358
############################################################################################
369359
##################################### LeafModel ############################################

0 commit comments

Comments
 (0)