-
Notifications
You must be signed in to change notification settings - Fork 90
BSc thesis "Coloring Data Race Interference Graphs" #2061
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
sim642
wants to merge
17
commits into
master
Choose a base branch
from
race-coloring
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
357beca
Add graph coloring algorithms
vaartnou eb9e9d8
Add race graph coloring
vaartnou d48f2c2
Make race coloring per component
vaartnou 2ca1b6d
Add ocamlgraph to locked dependencies
sim642 7706507
Inline Access.InterferenceGraph.Vertex
sim642 6d33962
Extract goblint.ocamlgraph library
sim642 bd6dc3d
Remove now-unused Access.InterferenceGraph.of_warn_accs
sim642 901a7d2
Simplify warn.race-coloring option handling
sim642 35e8e53
Simplify Access.InterferenceGraph
sim642 73ba8f4
Move Access.InterferenceGraph down
sim642 7abfd0e
Simplify graph coloring module usage in Access
sim642 7c005af
Add interface to Goblint_ocamlgraph.Coloring
sim642 68c02ad
Extract ColorSet.find_unused in Coloring
sim642 7870d4b
Simplify ColorSet.find_unused calls in Coloring
sim642 fdc0086
Remove Hashtbl.add uses in Coloring
sim642 033caf9
Refactor Coloring.Optimal
sim642 b45d751
Simplify ColorMap in Access
sim642 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,209 @@ | ||
| module Color = Int | ||
|
|
||
| module ColorSet = | ||
| struct | ||
| include Set.Make (Color) | ||
|
|
||
| let find_unused used = | ||
| let rec loop c = | ||
| if mem c used then | ||
| loop (c + 1) | ||
| else | ||
| c | ||
| in | ||
| loop 1 | ||
| end | ||
|
|
||
| module Make (G: Graph.Coloring.G) = | ||
| struct | ||
| module H = Hashtbl.Make (G.V) | ||
| type coloring = Color.t H.t | ||
|
|
||
| module type Algorithm = | ||
| sig | ||
| val color: G.t -> coloring | ||
| end | ||
|
|
||
| module Greedy: Algorithm = | ||
| struct | ||
| let color g = | ||
| let n = G.nb_vertex g in | ||
| let coloring = H.create n in | ||
| let vertices = | ||
| G.fold_vertex (fun v acc -> (G.out_degree g v, v) :: acc) g [] | ||
| |> List.sort (fun (d1, _) (d2, _) -> compare d2 d1) | ||
| |> List.map snd | ||
| in | ||
| let next_color v = | ||
| (* TODO: use saturation hashtbl like in Dsatur? *) | ||
| let used = G.fold_succ (fun u used -> | ||
| match H.find_opt coloring u with | ||
| | None -> used | ||
| | Some c -> ColorSet.add c used | ||
| ) g v ColorSet.empty | ||
| in | ||
| ColorSet.find_unused used | ||
| in | ||
| List.iter (fun v -> H.replace coloring v (next_color v)) vertices; | ||
| coloring | ||
| end | ||
|
|
||
| module Optimal: Algorithm = | ||
| struct | ||
| module C = Graph.Coloring.Make (G) | ||
|
|
||
| let color g = | ||
| let n = G.nb_vertex g in | ||
| let rec loop k = | ||
| assert (k <= n); | ||
| try C.coloring g k | ||
| with Graph.Coloring.NoColoring -> loop (k + 1) | ||
| in | ||
| loop 1 | ||
| end | ||
|
|
||
| module Dsatur: Algorithm = | ||
| struct | ||
| let color g = | ||
| let n = G.nb_vertex g in | ||
| let coloring = H.create n in | ||
| let saturation = H.create n in | ||
| let degree = H.create n in | ||
| G.iter_vertex (fun v -> | ||
| H.replace saturation v ColorSet.empty; | ||
| H.replace degree v (G.out_degree g v) | ||
| ) g; | ||
| let is_colored v = H.mem coloring v in | ||
| let sat_count v = | ||
| ColorSet.cardinal (H.find saturation v) | ||
| in | ||
| let choose_vertex () = | ||
| let pick v best_opt = | ||
| if is_colored v then | ||
| best_opt | ||
| else | ||
| match best_opt with | ||
| | None -> Some v | ||
| | Some best -> | ||
| let sv = sat_count v in | ||
| let sb = sat_count best in | ||
| if sv > sb then | ||
| Some v | ||
| else if sv < sb then | ||
| Some best | ||
| else ( | ||
| let dv = H.find degree v in | ||
| let db = H.find degree best in | ||
| if dv > db then Some v else Some best | ||
| ) | ||
| in | ||
| (* TODO: uncolored set like in Rlf? *) | ||
| G.fold_vertex pick g None | ||
| in | ||
| let pick_color v = | ||
| let used = H.find saturation v in | ||
| ColorSet.find_unused used | ||
| in | ||
| let rec loop () = | ||
| match choose_vertex () with | ||
| | None -> () | ||
| | Some v -> | ||
| let c = pick_color v in | ||
| H.replace coloring v c; | ||
| G.iter_succ (fun u -> | ||
| if not (is_colored u) then | ||
| let s = H.find saturation u in | ||
| H.replace saturation u (ColorSet.add c s) | ||
| ) g v; | ||
| loop () | ||
| in | ||
| loop (); | ||
| coloring | ||
| end | ||
|
|
||
| module Rlf: Algorithm = | ||
| struct | ||
| module VSet = | ||
| struct | ||
| let create n = H.create n | ||
| let mem s v = H.mem s v | ||
| let add s v = H.replace s v () | ||
| let remove s v = H.remove s v | ||
| end | ||
|
|
||
| let color g = | ||
| let n = G.nb_vertex g in | ||
| let coloring = H.create n in | ||
| let uncolored = VSet.create n in | ||
| G.iter_vertex (fun v -> VSet.add uncolored v) g; | ||
| let degree v = G.out_degree g v in | ||
| let pick_start () = | ||
| G.fold_vertex (fun v best -> | ||
| if not (VSet.mem uncolored v) then | ||
| best | ||
| else | ||
| match best with | ||
| | None -> Some v | ||
| | Some b -> | ||
| if degree v > degree b then Some v else Some b | ||
| ) g None | ||
| in | ||
| let add_forbidden forbidden v = | ||
| G.iter_succ (fun u -> | ||
| if VSet.mem uncolored u then | ||
| VSet.add forbidden u | ||
| ) g v | ||
| in | ||
| let candidate_score forbidden v = | ||
| let count = ref 0 in | ||
| G.iter_succ (fun u -> | ||
| if VSet.mem forbidden u then | ||
| incr count | ||
| ) g v; | ||
| !count | ||
| in | ||
| let pick_candidate forbidden = | ||
| G.fold_vertex (fun v best -> | ||
| if not (VSet.mem uncolored v) || VSet.mem forbidden v then | ||
| best | ||
| else | ||
| match best with | ||
| | None -> Some v | ||
| | Some b -> | ||
| let sv = candidate_score forbidden v in | ||
| let sb = candidate_score forbidden b in | ||
| if sv > sb then | ||
| Some v | ||
| else if sv < sb then | ||
| Some b | ||
| else if degree v > degree b then | ||
| Some v | ||
| else | ||
| Some b | ||
| ) g None | ||
| in | ||
| let rec color_class color = | ||
| match pick_start () with | ||
| | None -> () | ||
| | Some v0 -> | ||
| let forbidden = VSet.create n in | ||
| let add_vertex v = | ||
| H.replace coloring v color; | ||
| VSet.remove uncolored v; | ||
| add_forbidden forbidden v | ||
| in | ||
| add_vertex v0; | ||
| let rec fill () = | ||
| match pick_candidate forbidden with | ||
| | None -> () | ||
| | Some v -> | ||
| add_vertex v; | ||
| fill () | ||
| in | ||
| fill (); | ||
| color_class (color + 1) | ||
| in | ||
| color_class 1; | ||
| coloring | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| (** Graph coloring. | ||
|
|
||
| See also {!Graph.Coloring}. *) | ||
|
|
||
| module Color = Int | ||
| (** Colors are {e positive} integers. *) | ||
|
|
||
| module ColorSet: Set.S with type elt = Color.t | ||
|
|
||
| module Make (G: Graph.Coloring.G): | ||
| sig | ||
| module H: Hashtbl.S with type key = G.V.t | ||
| type coloring = Color.t H.t | ||
|
|
||
| module type Algorithm = | ||
| sig | ||
| val color: G.t -> coloring | ||
| end | ||
|
|
||
| module Greedy: Algorithm | ||
| module Optimal: Algorithm | ||
| module Dsatur: Algorithm | ||
| module Rlf: Algorithm | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| (include_subdirs no) | ||
|
|
||
| (library | ||
| (name goblint_ocamlgraph) | ||
| (public_name goblint.ocamlgraph) | ||
| (libraries | ||
| ocamlgraph) | ||
| (instrumentation (backend bisect_ppx))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| (** OCamlgraph library extensions which are completely independent of Goblint. *) | ||
|
|
||
| module Coloring = Coloring |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There should be some explanation of what this would achieve from a user-level perspective.