Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
R
Reusable Analysis
Manage
Activity
Members
Labels
Plan
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container registry
Model registry
Analyze
Value stream analytics
Contributor 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
JastAdd
Reusable Analysis
Commits
61b0c71d
Project 'hcp-xr/xr-starter' was moved to 'hyper/core'. Please update any links and bookmarks that may still have the old path.
Commit
61b0c71d
authored
5 years ago
by
Johannes Mey
Browse files
Options
Downloads
Patches
Plain Diff
sync submodule
parent
7e6217fc
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
dg/src/main/jastadd/DependencyGraphReachability.jrag
+68
-89
68 additions, 89 deletions
dg/src/main/jastadd/DependencyGraphReachability.jrag
extendj
+1
-1
1 addition, 1 deletion
extendj
with
69 additions
and
90 deletions
dg/src/main/jastadd/DependencyGraphReachability.jrag
+
68
−
89
View file @
61b0c71d
import java.util.Collections;
import java.util.*;
import java.util.Deque;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Collectors;
aspect Naviagation {
inh DependencyGraph Component.dg();
eq DependencyGraph.getComponent().dg() = this;
}
aspect Reachability {
aspect Reachability {
// syn Set<Component> Component.successors() circular [new HashSet<>()] {
// old, dependency-based algorithm for SCC
// Set<Component> result = new HashSet<>();
// for (Component c: getFromList()) {
// result.add(c);
// result.addAll(c.successors());
// }
// return result;
// }
// syn Set<Component> Component.predecessors() circular [new HashSet<>()] {
// coll Set<Component> Component.successors() circular [new HashSet<>()] with add root DependencyGraph;
// Set<Component> result = new HashSet<>();
// Component contributes this to Component.successors() for each getToList();
// for (Component c: getToList()) {
// Component contributes each this.successors() to Component.successors() for each getToList();
// result.add(c);
// result.addAll(c.predecessors());
// }
// return result;
// }
// inh DependencyGraph Component.dg();
// coll Set<Component> Component.predecessors() [new HashSet<>()] with add root DependencyGraph;
// eq DependencyGraph.getComponent().dg() = this;
// Component contributes this to Component.predecessors() for each successors();
//
// syn lazy Map<Component,Set<Component>> DependencyGraph.componentPredecessorMap() {
// Map<Component,Set<Component>> result = new HashMap<>();
// for (Component c: getComponentList()) {
// result.put(c, new HashSet<>());
// }
//
// for (Component from: getComponentList()) {
// for (Component to: from.successors()){
// result.get(to).add(from);
// }
// }
// return result;
// }
syn lazy Set<Component> Component.predecessors() = new HashSet<>();
// coll HashSet<Component> Component.SCC() with add root DependencyGraph;
syn lazy Set<Component> Component.successors() = new HashSet<>();
// Component contributes each predecessors() when (successors().contains(this)) to Component.SCC() for this;
syn lazy Set<Component> Component.SCC() = new HashSet<>();
// syn lazy Set<Component> Component.SCC() {
// Set<Component> result = new HashSet<>(successors());
// result.retainAll(predecessors());
// return result;
// }
// coll HashSet<Set<Component>> DependencyGraph.SCC() with add root DependencyGraph;
// coll HashSet<Set<Component>> DependencyGraph.SCC() with add root DependencyGraph;
// Component contributes SCC() when SCC().size() > 0 to DependencyGraph.SCC();
// Component contributes SCC() when SCC().size() > 0 to DependencyGraph.SCC();
syn Set<Set<Component>> DependencyGraph.SCC() { //Kosaraju's algorithm
System.out.println("Kosaraju's algorithm");
// stubs for tests that use old algorithm
syn lazy Set<Component> Component.predecessors() = new HashSet<>();
syn lazy Set<Component> Component.successors() = new HashSet<>();
syn lazy Set<Component> Component.SCC() = new HashSet<>();
/**
* Kosaraju's algorithm
*/
syn Set<Set<Component>> DependencyGraph.SCC() {
// System.out.println("Kosaraju's algorithm");
Map<Component, Integer> visited = new HashMap<>();
Map<Component, Integer> visited = new HashMap<>();
Deque<Component> locked = new LinkedList<>();
Deque<Component> locked = new LinkedList<>();
//Visit nodes forward
//Visit nodes forward
long startVisit = System.nanoTime();
//
long startVisit = System.nanoTime();
for (Component n : getComponentList())
for (Component n : getComponentList())
visit(n, visited, locked);
visit(n, visited, locked);
//Assign nodes to SCCs backward
//Assign nodes to SCCs backward
long startAssign = System.nanoTime();
//
long startAssign = System.nanoTime();
int scc = 0;
int scc = 0;
for (Component n : locked) {
for (Component n : locked) {
assign(n, visited, scc);
assign(n, visited, scc);
scc++;
scc++;
}
}
long stop = System.nanoTime();
//
long stop = System.nanoTime();
//Map visited Map[Node,int]-> result Map[int,Set[Node]]
//Map visited Map[Node,int]-> result Map[int,Set[Node]]
System.out.println("visit : "
+
(startAssign
-
startVisit));
//
System.out.println("visit : "
+
(startAssign
-
startVisit));
System.out.println("assign: "
+
(stop
-
startAssign));
//
System.out.println("assign: "
+
(stop
-
startAssign));
System.out.println("sum: "
+
(stop
-
startVisit));
//
System.out.println("sum: "
+
(stop
-
startVisit));
Map<Integer,Set<Component>> result=visited.entrySet().stream()
Map<Integer, Set<Component>> result = visited.entrySet().stream().collect(
.collect(Collectors.groupingBy(e->e.getValue(),
Collectors.groupingBy(
Collectors.mapping(e->e.getKey(),
e -> e.getValue(),
Collectors.toSet())));
Collectors.mapping(e -> e.getKey(), Collectors.toSet())
)
);
return result.values().stream().collect(Collectors.toSet());
return result.values().stream().collect(Collectors.toSet());
}
}
p
ublic
void DependencyGraph.visit(Component n, Map<Component, Integer> visited, Deque<Component> locked){
p
rivate
void DependencyGraph.visit(Component n, Map<Component, Integer> visited, Deque<Component> locked)
{
if (visited.containsKey(n)) return;
if (visited.containsKey(n)) return;
visited.put(n, -1);
visited.put(n, -1);
for (Component s : n.getFromList())
for (Component s : n.getFromList())
...
@@ -92,7 +71,7 @@ aspect Reachability {
...
@@ -92,7 +71,7 @@ aspect Reachability {
locked.addFirst(n);
locked.addFirst(n);
}
}
p
ublic
void DependencyGraph.assign(Component n, Map<Component, Integer> visited, int root) {
p
rivate
void DependencyGraph.assign(Component n, Map<Component, Integer> visited, int root) {
if (visited.get(n) > -1) return;
if (visited.get(n) > -1) return;
visited.put(n, root);
visited.put(n, root);
for (Component p : n.getToList())
for (Component p : n.getToList())
...
...
This diff is collapsed.
Click to expand it.
extendj
@
bab01c7e
Compare
1b26decc
...
bab01c7e
Subproject commit
1b26decca78b3cdbfa3a9ba9666fbd75e2bdd436
Subproject commit
bab01c7e6df0d3e6aa2a0bc0ba7dc9f6f2ee3184
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