Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
sasa
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
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
verimag
synchrone
sasa
Commits
a1c76eca
Commit
a1c76eca
authored
3 years ago
by
erwan
Browse files
Options
Downloads
Patches
Plain Diff
refactor: compute if a graph is a rooted tree instead of relying on a graph attribute
parent
ac38cbc6
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
lib/sasacore/register.ml
+5
-4
5 additions, 4 deletions
lib/sasacore/register.ml
lib/sasacore/topology.ml
+21
-7
21 additions, 7 deletions
lib/sasacore/topology.ml
lib/sasacore/topology.mli
+2
-1
2 additions, 1 deletion
lib/sasacore/topology.mli
with
28 additions
and
12 deletions
lib/sasacore/register.ml
+
5
−
4
View file @
a1c76eca
(* Time-stamp: <modified the 27/0
7
/2021 (at 1
0:36
) by Erwan Jahier> *)
(* Time-stamp: <modified the 27/0
8
/2021 (at 1
4:21
) by Erwan Jahier> *)
type
'
s
neighbor
=
{
state
:
'
s
;
...
...
@@ -303,11 +303,14 @@ let sub_tree_size : (string -> int) =
let
parent
:
(
string
->
int
option
)
=
fun
pid
->
if
is_tree
()
then
(
match
tbls
.
parent
with
|
Some
p
->
p
pid
|
None
->
let
p
=
Topology
.
get_parent
(
get_topology
()
)
in
tbls
.
parent
<-
Some
p
;
p
pid
)
else
not_a_tree
()
let
(
links_number
:
unit
->
int
)
=
...
...
@@ -351,6 +354,4 @@ let (graph_attribute_list: unit -> (string * string) list) =
Hashtbl
.
fold
(
fun
n
v
acc
->
(
n
,
v
)
::
acc
)
tbls
.
graph_attributes
[]
let
(
is_rooted_tree
:
unit
->
bool
)
=
fun
()
->
match
get_graph_attribute_opt
"is_rooted"
with
|
None
->
false
|
Some
str
->
bool_of_string
str
Topology
.
is_rooted_tree
(
get_topology
()
)
This diff is collapsed.
Click to expand it.
lib/sasacore/topology.ml
+
21
−
7
View file @
a1c76eca
(* Time-stamp: <modified the
09
/0
4
/2021 (at 1
0:58
) by Erwan Jahier> *)
(* Time-stamp: <modified the
27
/0
8
/2021 (at 1
4:30
) by Erwan Jahier> *)
open
Graph
open
Graph
.
Dot_ast
...
...
@@ -281,15 +281,21 @@ let is_cyclic : t -> bool =
fun
g
->
if
g
.
directed
then
directed_is_cyclic
g
else
non_directed_is_cyclic
g
let
is_tree
:
t
->
bool
=
fun
g
->
(
not
(
is_cyclic
g
))
&&
(
is_connected
g
)
let
is_root_pid
pid
=
Str
.
string_match
(
Str
.
regexp
".*root.*"
)
pid
0
let
is_root_node
n
=
is_root_pid
n
.
id
(* cf algo.mli for the spec *)
let
is_rooted_tree
:
t
->
bool
=
fun
g
->
is_tree
g
&&
List
.
length
(
List
.
filter
is_root_node
g
.
nodes
)
=
1
(** Returns the channel number that let [p_neighbor] access to the
content of [p], if [p] is a neighbor of [p_neighbor]. Returns -1 if
[p] is not a neig
b
hbor of [p_neigbor], which can happen in directed
[p] is not a neighbor of [p_neig
h
bor], which can happen in directed
graphs. *)
let
(
reply
:
t
->
string
->
string
->
int
)
=
fun
g
p
p_neighbor
->
...
...
@@ -307,16 +313,24 @@ let (reply_pred: t -> string -> string -> int) =
in
f
0
(
g
.
pred
p_neighbor
)
(* count the occurrences of x in l *)
let
_count
x
l
=
let
rec
f
acc
=
function
|
[]
->
acc
|
y
::
t
->
f
(
if
x
=
y
then
acc
+
1
else
acc
)
t
in
f
0
l
let
is_in_tree
g
=
g
.
directed
&&
(* redundant, but more efficient *)
(
is_tree
g
)
&&
(
List
.
for_all
(
fun
n
->
List
.
length
(
g
.
pred
n
.
id
)
<=
1
)
g
.
nodes
)
let
is_out_tree
g
=
g
.
directed
&&
(* redundant, but more efficient *)
(
is_tree
g
)
&&
(
List
.
for_all
(
fun
n
->
List
.
length
(
g
.
succ
n
.
id
)
<=
1
)
g
.
nodes
)
let
is_root_node
_
pid
=
pid
=
"root"
(* Donne les enfants d'un noeud dans un in-tree (liens partent de la racine) *)
let
children_in
g
pid
=
...
...
@@ -329,7 +343,7 @@ let children_out g pid =
(* Donne les enfants d'un noeud dans un in-out-tree *)
let
children_in_out
g
pid
=
let
succ
=
List
.
map
snd
(
g
.
succ
pid
)
in
if
is_root_
node
g
pid
then
succ
if
is_root_
pid
pid
then
succ
else
List
.
tl
succ
(* pour tous les noeuds sauf la racine, le parent est la tête de succ
ici on veut juste les enfants donc on enlève le premier *)
...
...
@@ -345,7 +359,7 @@ let parent_out g pid =
|
(
_
,
id
)
::_
->
Some
(
id
)
let
parent_in_out
g
pid
=
if
is_root_
node
g
pid
then
None
if
is_root_
pid
pid
then
None
else
Some
(
snd
(
List
.
hd
(
g
.
succ
pid
)))
(* Le parent est le premier dans la liste succ pour un in-out-tree ou un rooted-tree *)
...
...
This diff is collapsed.
Click to expand it.
lib/sasacore/topology.mli
+
2
−
1
View file @
a1c76eca
(* Time-stamp: <modified the 2
1
/0
4
/2021 (at
15:56
) by Erwan Jahier> *)
(* Time-stamp: <modified the 2
7
/0
8
/2021 (at
09:25
) by Erwan Jahier> *)
(** {1 Topology: internal representation of Graphs } *)
...
...
@@ -29,6 +29,7 @@ val get_nb_link: t -> int
val
get_mean_degree
:
t
->
float
val
is_connected
:
t
->
bool
val
is_cyclic
:
t
->
bool
val
is_rooted_tree
:
t
->
bool
val
is_tree
:
t
->
bool
val
is_in_tree
:
t
->
bool
val
is_out_tree
:
t
->
bool
...
...
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