Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
Dissiml
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Guyslain Naves
Dissiml
Commits
23da8475
Commit
23da8475
authored
1 year ago
by
Guyslain Naves
Browse files
Options
Downloads
Patches
Plain Diff
more tests on chain insertion
parent
0b846295
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
lib/pqtrees/pqTree.ml
+5
-15
5 additions, 15 deletions
lib/pqtrees/pqTree.ml
test/propertytest/chainInsertion.ml
+38
-3
38 additions, 3 deletions
test/propertytest/chainInsertion.ml
test/propertytest/pqtree.ml
+13
-1
13 additions, 1 deletion
test/propertytest/pqtree.ml
with
56 additions
and
19 deletions
lib/pqtrees/pqTree.ml
+
5
−
15
View file @
23da8475
...
@@ -192,23 +192,13 @@ module MakeEnumerate =
...
@@ -192,23 +192,13 @@ module MakeEnumerate =
PQTEnum
.
map
to_pqtree
enum_skeleton
PQTEnum
.
map
to_pqtree
enum_skeleton
let
extensions
list
=
let
rec
go
previous
=
function
|
[]
->
[]
|
this
::
next
->
(
this
,
List
.
rev_append
previous
next
)
::
go
(
this
::
previous
)
next
in
go
[]
list
let
rec
enum_permutations
=
let
rec
enum_permutations
=
let
open
PQTIFSeq
in
let
open
PQTIFSeq
in
function
function
|
[]
->
singleton
[]
|
0
->
singleton
[]
|
elements
->
|
n
->
exists
product
(
up
0
n
)
(
enum_permutations
(
n
-
1
))
(
extensions
elements
)
|>
map
(
fun
(
i
,
sigma
)
->
i
::
List
.
map
(
fun
j
->
if
i
=
j
then
(
n
-
1
)
else
j
)
sigma
)
(
fun
(
head
,
tail
)
->
map
(
List
.
cons
head
)
(
enum_permutations
tail
))
let
rec
big_product
=
let
rec
big_product
=
let
open
PQTIFSeq
in
let
open
PQTIFSeq
in
...
@@ -226,7 +216,7 @@ module MakeEnumerate =
...
@@ -226,7 +216,7 @@ module MakeEnumerate =
match
pqtree
with
match
pqtree
with
|
Leaf
x
->
singleton
[
x
]
|
Leaf
x
->
singleton
[
x
]
|
P
children
->
|
P
children
->
let
permutations
=
enum_permutations
(
List
.
mapi
(
fun
i
_
->
i
)
children
)
in
let
permutations
=
enum_permutations
(
List
.
length
children
)
in
let
orders
=
big_product
(
List
.
map
compatible_orders
children
)
in
let
orders
=
big_product
(
List
.
map
compatible_orders
children
)
in
product
permutations
orders
product
permutations
orders
|>
map
(
fun
(
permutation
,
orders
)
->
apply_permutation
permutation
orders
|>
List
.
concat
)
|>
map
(
fun
(
permutation
,
orders
)
->
apply_permutation
permutation
orders
|>
List
.
concat
)
...
...
This diff is collapsed.
Click to expand it.
test/propertytest/chainInsertion.ml
+
38
−
3
View file @
23da8475
...
@@ -45,6 +45,12 @@ let rec zip list1 list2 = match list1, list2 with
...
@@ -45,6 +45,12 @@ let rec zip list1 list2 = match list1, list2 with
let
function_from_list
assocs
=
let
map
=
List
.
fold_left
(
fun
map
(
arg
,
res
)
->
IntMap
.
add
arg
res
map
)
IntMap
.
empty
assocs
in
fun
arg
->
IntMap
.
find
arg
map
let
print_tree_and_chain
=
let
print_tree_and_chain
=
Print
.(
pair
to_string
(
pair
int
(
list
(
pair
int
int
))))
Print
.(
pair
to_string
(
pair
int
(
list
(
pair
int
int
))))
...
@@ -68,7 +74,7 @@ let gen_tree_and_chain =
...
@@ -68,7 +74,7 @@ let gen_tree_and_chain =
let
new_valid_permutation_is_old_valid_permutation
(
pqtree
,
(
source
,
distances
))
=
let
new_valid_permutation_is_old_valid_permutation
(
pqtree
,
(
source
,
distances
))
=
let
f
i
=
List
.
assoc
i
distances
in
let
f
=
function_from_list
distances
in
match
PqChainInsertion
.
refine_by_distances
source
f
pqtree
with
match
PqChainInsertion
.
refine_by_distances
source
f
pqtree
with
|
None
->
false
|
None
->
false
|
Some
new_pqtree
->
Ref
.
is_refinement
new_pqtree
pqtree
|
Some
new_pqtree
->
Ref
.
is_refinement
new_pqtree
pqtree
...
@@ -77,13 +83,41 @@ let test_new_valid_permutation_is_old_valid_permutation =
...
@@ -77,13 +83,41 @@ let test_new_valid_permutation_is_old_valid_permutation =
Test
.
make
Test
.
make
~
name
:
"Chain insertion returns a refinement of the original PQ-tree"
~
name
:
"Chain insertion returns a refinement of the original PQ-tree"
~
print
:
print_tree_and_chain
~
print
:
print_tree_and_chain
~
count
:
100
0
~
count
:
100
gen_tree_and_chain
gen_tree_and_chain
new_valid_permutation_is_old_valid_permutation
new_valid_permutation_is_old_valid_permutation
let
rec
is_increasing
=
function
|
[]
|
[
_
]
->
true
|
x
::
y
::
tail
->
x
<=
y
&&
is_increasing
(
y
::
tail
)
let
rec
is_bitonic
=
function
|
[]
|
[
_
]
->
true
|
x
::
y
::
tail
when
x
>=
y
->
is_bitonic
(
y
::
tail
)
|
_
::
y
::
tail
->
is_increasing
(
y
::
tail
)
let
permutations_are_bitonic
(
pqtree
,
(
source
,
distances
))
=
let
f
=
function_from_list
distances
in
match
PqChainInsertion
.
refine_by_distances
source
f
pqtree
with
|
None
->
false
|
Some
pqtree
->
Seq
.
repeat
()
|>
Seq
.
take
10
|>
Seq
.
map
(
fun
_
->
PqTree
.
sample_compatible_order
pqtree
)
|>
Seq
.
map
(
List
.
map
f
)
|>
Seq
.
for_all
is_bitonic
let
test_permutations_are_bitonic
=
Test
.
make
~
name
:
"Permutations of refined pqtree are bitonic relative to the distance to the source"
~
print
:
print_tree_and_chain
~
count
:
1000
gen_tree_and_chain
permutations_are_bitonic
...
@@ -91,4 +125,5 @@ let tests =
...
@@ -91,4 +125,5 @@ let tests =
[
[
test_interval_insertion_does_not_fail
;
test_interval_insertion_does_not_fail
;
test_new_valid_permutation_is_old_valid_permutation
;
test_new_valid_permutation_is_old_valid_permutation
;
test_permutations_are_bitonic
]
]
This diff is collapsed.
Click to expand it.
test/propertytest/pqtree.ml
+
13
−
1
View file @
23da8475
...
@@ -85,6 +85,17 @@ let test_shuffled_frontier_is_a_contained_permutation =
...
@@ -85,6 +85,17 @@ let test_shuffled_frontier_is_a_contained_permutation =
shuffled_frontier_is_a_contained_permutation
shuffled_frontier_is_a_contained_permutation
let
sampled_compatible_order_is_a_valid_permutation
(
permutation
,
pqtree
)
=
CheckPermutation
.
contains_permutation
pqtree
permutation
let
test_sampled_compatible_order_is_a_valid_permutation
=
QCheck2
.
Test
.
make
~
name
:
"Sampled compatible order are valid permutations"
~
print
:
QCheck2
.
Print
.(
pair
(
list
int
)
print
)
~
count
:
100
Gen
.(
pqtree_gen
>>=
fun
pqtree
->
return
(
PqTree
.
sample_compatible_order
pqtree
,
pqtree
))
sampled_compatible_order_is_a_valid_permutation
let
tests
=
let
tests
=
...
@@ -93,5 +104,6 @@ let tests =
...
@@ -93,5 +104,6 @@ let tests =
test_frontier_is_a_contained_permutation
;
test_frontier_is_a_contained_permutation
;
test_sampled_permutation_is_contained_in_pqtree
;
test_sampled_permutation_is_contained_in_pqtree
;
test_shuffled_is_equal_to_pqtree
;
test_shuffled_is_equal_to_pqtree
;
test_shuffled_frontier_is_a_contained_permutation
test_shuffled_frontier_is_a_contained_permutation
;
test_sampled_compatible_order_is_a_valid_permutation
]
]
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment