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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
JastAdd
Reusable Analysis
Commits
272295a4
Commit
272295a4
authored
6 years ago
by
Thomas
Browse files
Options
Downloads
Patches
Plain Diff
added import java.util.Collections;
parent
85460556
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
dg/src/main/jastadd/DependencyGraphReachability.jrag
+77
-58
77 additions, 58 deletions
dg/src/main/jastadd/DependencyGraphReachability.jrag
with
77 additions
and
58 deletions
dg/src/main/jastadd/DependencyGraphReachability.jrag
+
77
−
58
View file @
272295a4
import java.util.Collections;
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;
aspect Reachability {
aspect Reachability {
syn Set<Component> Component.successors() circular [new HashSet<>()] {
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<>()] {
// syn Set<Component> Component.successors() circular [new HashSet<>()] {
Set<Component> result = new HashSet<>();
// Set<Component> result = new HashSet<>();
for (Component c: getToList()) {
// for (Component c: getFromList()) {
result.add(c);
// result.add(c);
result.addAll(c.predecessors());
// result.addAll(c.successors());
}
// }
return result;
// return result;
}
// }
// syn Set<Component> Component.predecessors() circular [new HashSet<>()] {
// Set<Component> result = new HashSet<>();
// for (Component c: getToList()) {
// result.add(c);
// result.addAll(c.predecessors());
// }
// return result;
// }
// inh DependencyGraph Component.dg();
// inh DependencyGraph Component.dg();
// eq DependencyGraph.getComponent().dg() = this;
// eq DependencyGraph.getComponent().dg() = this;
...
@@ -34,50 +43,60 @@ aspect Reachability {
...
@@ -34,50 +43,60 @@ aspect Reachability {
// return result;
// return result;
// }
// }
syn lazy Set<Component> Component.predecessors() = new HashSet<>();
syn lazy Set<Component> Component.successors() = new HashSet<>();
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;
// Component contributes SCC() when SCC().size() > 0 to DependencyGraph.SCC();
syn lazy Set<Component> Component.SCC() {
syn Set<Set<Component>> DependencyGraph.SCC() { //Kosaraju's algorithm
Set<Component> result = new HashSet<>(successors());
System.out.println("Kosaraju's algorithm");
result.retainAll(predecessors());
Map<Component,Integer> visited=new HashMap<>();
return result;
Deque<Component> locked=new LinkedList<>();
//Visit nodes forward
long startVisit = System.nanoTime();
for (Component n:getComponentList())
visit(n,visited,locked);
//Assign nodes to SCCs backward
long startAssign = System.nanoTime();
int scc=0;
for (Component n:locked) {
assign(n,visited,scc);
scc++;
}
}
long stop = System.nanoTime();
//Map visited Map[Node,int]-> result Map[int,Set[Node]]
coll HashSet<Set<Component>> DependencyGraph.SCC() with add root DependencyGraph;
System.out.println("visit : "+(startAssign-startVisit));
Component contributes SCC() when SCC().size() > 0 to DependencyGraph.SCC();
System.out.println("assign: "+(stop-startAssign));
System.out.println("sum: "+(stop-startVisit));
// syn Set<Set<Component>> DependencyGraph.SCC() { //Kosaraju's algorithm
Map<Integer,Set<Component>> result=visited.entrySet().stream()
// Map<Component,Integer> visited=new HashMap<>();
.collect(Collectors.groupingBy(e->e.getValue(),
// Deque<Component> locked=new LinkedList<>();
Collectors.mapping(e->e.getKey(),
// //Visit nodes forward
Collectors.toSet())));
// for (Component n:getComponentList())
return result.values().stream().collect(Collectors.toSet());
// n.visit(visited,locked);
}
// //Assign nodes to SCCs backward
// int scc=0;
public void DependencyGraph.visit(Component n, Map<Component, Integer> visited, Deque<Component> locked){
// for (Node n:locked) {
if (visited.containsKey(n)) return;
// n.assign(visited,scc);
visited.put(n,-1);
// scc++;
for (Component s:n.getFromList())
// }
visit(s,visited,locked);
// //Map visited Map[Node,int]-> result Map[int,Set[Node]]
locked.addFirst(n);
// Map<Integer,Set<Component>> result=visited.entrySet().stream()
}
// .collect(Collectors.groupingBy(e->e.getValue(),
// Collectors.mapping(e->e.getKey(),
public void DependencyGraph.assign(Component n, Map<Component, Integer> visited, int root) {
// Collectors.toSet())));
if (visited.get(n)>-1) return;
// return result.values().stream().collect(Collectors.toSet());
visited.put(n,root);
//
for (Component p:n.getToList())
// }
assign(p,visited,root);
//
}
// private void visit(Component n, Map<Component, Integer> visited, Deque<Component> locked){
// if (visited.containsKey(n)) return;
// visited.put(n,-1);
// for (Component s:n.getFromList())
// visit(s,visited,locked);
// locked.addFirst(n);
// }
//
// private void assign(Component n, Map<Node, Integer> visited, int root) {
// if (visited.get(n)>-1) return;
// visited.put(n,root);
// for (Component p:n.getToList())
// assign(p,visited,root);
// }
}
}
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