added evaluation of full graph

This commit is contained in:
2020-05-14 13:05:56 +02:00
parent 380a46c1ed
commit 952d9e8e3f
@@ -60,11 +60,180 @@ public class ResultHandler {
}
public static void addAdditionalEdges() {
// TODO Auto-generated method stub
if (newUploads.size() > 0) {
addnewUploads();
}
if (newDownloads.size() > 0) {
addnewDownloads();
}
}
private static void addnewDownloads() {
outer: for (int i = 0;;) {
List<Result> results = new ArrayList<>();
Result res = newDownloads.get(i);
results.add(res);
i++;
for (;;) {
if (i >= newDownloads.size()) {
addDownloadsToGraph(results);
break outer;
}
Result next = newDownloads.get(i);
if (next.getBefore() == res.getBefore() && next.getAfter() == res.getAfter()) {
results.add(next);
res = next;
i++;
} else {
break;
}
}
addDownloadsToGraph(results);
if (i >= newDownloads.size()) {
break;
}
}
}
/**
* @param results
*/
private static void addDownloadsToGraph(List<Result> results) {
Task before = results.get(0).getBefore();
Task after = results.get(0).getAfter();
List<Result> l = graph.nodes().stream().filter(res -> res.getTask() == before && res.getExecution() == TestExecution.GPU).collect(Collectors.toList());
if (l.size() != 1) {
throw new IllegalStateException();
}
Result nodeBefore = l.get(0);
l = graph.nodes().stream().filter(res -> res.getTask() == after && res.getExecution() == TestExecution.CPU).collect(Collectors.toList());
if (l.size() != 1) {
throw new IllegalStateException();
}
Result nodeAfter = l.get(0);
Result tmp = nodeBefore;
for (int i = 0; i < results.size(); i++) {
Result r = results.get(i);
graph.addNode(r);
graph.putEdge(tmp, r);
tmp = r;
}
if (tmp == nodeBefore) {
throw new IllegalStateException();
}
graph.putEdge(tmp, nodeAfter);
}
private static void addnewUploads() {
outer: for (int i = 0;;) {
List<Result> results = new ArrayList<>();
Result res = newUploads.get(i);
results.add(res);
i++;
for (;;) {
if (i >= newUploads.size()) {
addUploadsToGraph(results);
break outer;
}
Result next = newUploads.get(i);
if (next.getBefore() == res.getBefore() && next.getAfter() == res.getAfter()) {
results.add(next);
res = next;
i++;
} else {
break;
}
}
addUploadsToGraph(results);
if (i >= newUploads.size()) {
break;
}
}
}
private static void addUploadsToGraph(List<Result> results) {
Task before = results.get(0).getBefore();
Task after = results.get(0).getAfter();
List<Result> l = graph.nodes().stream().filter(res -> res.getTask() == before && res.getExecution() == TestExecution.CPU).collect(Collectors.toList());
if (l.size() != 1) {
throw new IllegalStateException();
}
Result nodeBefore = l.get(0);
l = graph.nodes().stream().filter(res -> res.getTask() == after && res.getExecution() == TestExecution.GPU).collect(Collectors.toList());
if (l.size() != 1) {
throw new IllegalStateException();
}
Result nodeAfter = l.get(0);
Result tmp = nodeBefore;
for (int i = 0; i < results.size(); i++) {
Result r = results.get(i);
graph.addNode(r);
graph.putEdge(tmp, r);
tmp = r;
}
if (tmp == nodeBefore) {
throw new IllegalStateException();
}
graph.putEdge(tmp, nodeAfter);
}
private static final List<Result> newUploads = new ArrayList<>();
private static final List<Result> newDownloads = new ArrayList<>();
public static void newResultCpuToGpu(Task cpuBefore, Task gpuTask, TimeDto time, boolean upload, Task task) {
if (!upload) {
throw new IllegalArgumentException();
}
newUploads.add(new Result(cpuBefore, gpuTask, time, task));
}
public static void newResultGpuToCpu(Task gpuBefore, Task cpuTask, TimeDto time, boolean upload, Task task) {
if (upload) {
throw new IllegalArgumentException();
}
newDownloads.add(new Result(gpuBefore, cpuTask, time, task));
}
private static void removeDuplicatePaths(List<List<Result>> paths) {
boolean modified = true;
while (modified) {
outer: for (int i = 0; i < paths.size(); i++) {
for (int j = 0; j < paths.size(); j++) {
if (i != j) {
modified = checkPathsEquality(paths.get(i), paths.get(j));
if (modified) {
break outer;
}
}
}
}
}
paths.removeIf(List::isEmpty);
}
private static boolean checkPathsEquality(List<Result> path1, List<Result> path2) {
if (path1.size() != path2.size()) {
return false;
}
if (path1.isEmpty()) {
return false;
}
for (int i = 0; i < path1.size(); i++) {
Result r1 = path1.get(i);
Result r2 = path2.get(i);
if (!r1.equals(r2)) {// TODO: improve equality check?
return false;
}
}
path2.clear();
return true;
}
private static void evaluatePaths(List<List<Result>> paths) {
// removeDuplicatePaths(paths); //Are duplicate paths even possible?
List<Result> fastest = Collections.emptyList();
double time = Double.POSITIVE_INFINITY;
for (int i = 0; i < paths.size(); i++) {
@@ -230,27 +399,4 @@ public class ResultHandler {
}
}
/**
* @param cpuBefore
* @param gpuTask
* @param time
* @param b
* @param task
*/
public static void newResultCpuToGpu(Task cpuBefore, Task gpuTask, TimeDto time, boolean b, Task task) {
System.out.println("AAAAA");
}
/**
* @param gpuBefore
* @param cpuTask
* @param time
* @param b
* @param task
*/
public static void newResultGpuToCpu(Task gpuBefore, Task cpuTask, TimeDto time, boolean b, Task task) {
System.out.println("BBBBB");
}
}