Skip to content

Commit 627c0f7

Browse files
authored
Merge pull request #57 from Herb-AI/duplicate-constraints
Duplicate constraints
2 parents 01315ec + 1b90b42 commit 627c0f7

File tree

5 files changed

+82
-12
lines changed

5 files changed

+82
-12
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "HerbCore"
22
uuid = "2b23ba43-8213-43cb-b5ea-38c12b45bd45"
33
authors = ["Jaap de Jong <jaapdejong15@gmail.com>", "Nicolae Filat <N.Filat@student.tudelft.nl>", "Tilman Hinnerichs <t.r.hinnerichs@tudelft.nl>", "Sebastijan Dumancic <s.dumancic@tudelft.nl>"]
4-
version = "0.3.11"
4+
version = "0.3.12"
55

66
[deps]
77
AbstractTrees = "1520ce14-60c1-5f80-bbc7-55ef81b5835c"

src/HerbCore.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ export
3636
AbstractGrammar,
3737
print_tree,
3838
update_rule_indices!,
39-
is_domain_valid
39+
is_domain_valid,
40+
issame
4041

4142
end # module HerbCore

src/indexing.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,13 @@ grammar or number of rules.
1616
If [`isfilled`](@ref)`(x)` and `x` has children, it checks if all children are valid.
1717
"""
1818
function is_domain_valid end
19+
20+
"""
21+
issame(a, b)
22+
23+
Returns whether the two given objects `a` and `b` (ex: [`RuleNode`](@ref),
24+
[`Hole`](@ref) or [`AbstractConstraint`](@ref)) are the same.
25+
"""
26+
function issame(a, b)
27+
false
28+
end

src/rulenode.jl

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,7 @@ function update_rule_indices!(
9090
end
9191
end
9292

93-
"""
94-
is_domain_valid(node::RuleNode, n_rules::Integer)
95-
96-
Check whether the `node`'s rule index exceeds the number of rules `n_rules.`
97-
"""
93+
# Check whether the `node`'s rule index exceeds the number of rules `n_rules.`
9894
function is_domain_valid(node::RuleNode, n_rules::Integer)
9995
if get_rule(node) > n_rules
10096
return false
@@ -132,11 +128,7 @@ end
132128

133129
UniformHole(domain) = UniformHole(domain, AbstractRuleNode[])
134130

135-
"""
136-
is_domain_valid(hole::AbstractHole, n_rules::Integer)
137-
138-
Check if `hole`'s domain length matches `n_rules`.
139-
"""
131+
# Check if `hole`'s domain length matches `n_rules`.
140132
function is_domain_valid(hole::AbstractHole, n_rules::Integer)
141133
if length(hole.domain) != n_rules
142134
return false
@@ -770,3 +762,15 @@ function have_same_shape(node1, node2)
770762
end
771763
return true
772764
end
765+
766+
function issame(a::RuleNode, b::RuleNode)
767+
(a.ind == b.ind) && length(a.children) == length(b.children) &&
768+
all(issame(a, b) for (a, b) in zip(a.children, b.children))
769+
end
770+
771+
function issame(a::UniformHole, b::UniformHole)
772+
a.domain == b.domain && length(a.children) == length(b.children) &&
773+
all(issame(a, b) for (a, b) in zip(a.children, b.children))
774+
end
775+
776+
issame(a::Hole, b::Hole) = a.domain == b.domain

test/test_rulenode.jl

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -513,4 +513,59 @@
513513
@test is_domain_valid(hole, 9) == false
514514
@test is_domain_valid(hole, 4) == true
515515
end
516+
517+
@testset "issame" begin
518+
# RuleNode
519+
node1 = @rulenode 1{4{5, 6}, 1{2, 3}}
520+
node2 = @rulenode 1{4{5, 6}, 1{2, 3}}
521+
node3 = @rulenode 1{4{5, 5}, 1{2, 3}}
522+
@test issame(node1, node2) == true
523+
@test issame(node1, node3) == false
524+
# Hole
525+
hole1 = Hole([1, 1, 0, 1])
526+
hole2 = Hole([1, 1, 0, 1])
527+
hole3 = Hole([1, 0, 0, 1])
528+
@test issame(hole1, hole2) == true
529+
@test issame(hole2, hole3) == false
530+
531+
# UniformHole
532+
uhole1 = UniformHole([0, 0, 1],
533+
[
534+
RuleNode(14),
535+
RuleNode(2, [
536+
RuleNode(4, [
537+
RuleNode(6)
538+
])
539+
])
540+
]
541+
)
542+
uhole2 = UniformHole([0, 0, 1],
543+
[
544+
RuleNode(14),
545+
RuleNode(2, [
546+
RuleNode(4, [
547+
RuleNode(6)
548+
])
549+
])
550+
]
551+
)
552+
uhole3 = UniformHole([0, 0, 1],
553+
[
554+
RuleNode(14),
555+
RuleNode(2, [
556+
RuleNode(4, [
557+
RuleNode(66)
558+
])
559+
])
560+
]
561+
)
562+
uhole4 = UniformHole([0, 0, 1], [RuleNode(14)])
563+
uhole5 = UniformHole([1, 0, 1], [RuleNode(14)])
564+
@test issame(uhole1, uhole2) == true
565+
@test issame(uhole1, uhole3) == false
566+
@test issame(uhole4, uhole5) == false
567+
# compare different types
568+
@test issame(node1, uhole2) == false
569+
@test issame(hole3, uhole5) == false
570+
end
516571
end

0 commit comments

Comments
 (0)