-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAlgorithmRunner.java
More file actions
69 lines (53 loc) · 2.87 KB
/
AlgorithmRunner.java
File metadata and controls
69 lines (53 loc) · 2.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package algorithmRunner;
import algorithm.LabelledSubgraphCountingAlgorithm;
import algorithm.ParameterValueOptimiser;
import graph.Graph;
import graph.Vertex;
import java.util.List;
import graph.VertexLists;
public class AlgorithmRunner {
public static void runAlgorithm(RunResult result, Graph hostGraph, Graph patternGraph,boolean labelled) {
if (labelled) {
// If labelled, run the labelled subgraph counting algorithm
LabelledSubgraphCountingAlgorithm lSa = new LabelledSubgraphCountingAlgorithm(hostGraph, patternGraph, hostGraph.getHighestDegVertices(0));
int count = lSa.run();
result.setCount(count);
} else {
// If unlabelled, run both algorithms and compute the unlabelled result
LabelledSubgraphCountingAlgorithm labelledSubgraphCountingAlgorithm = new LabelledSubgraphCountingAlgorithm(hostGraph, patternGraph, hostGraph.getHighestDegVertices(0));
int A = labelledSubgraphCountingAlgorithm.run();
int B = BruteForceLabelledSubgraphCountingAlgorithm.countLabelledCopiesWithLists(patternGraph,hostGraph);
int unlabelledCount = A / B;
System.out.println("Number of unlabelled copies of the subgraph: " + unlabelledCount);
result.setCount(unlabelledCount);
}
long startTime = System.currentTimeMillis();
Runtime.getRuntime().addShutdownHook(
new Thread(() -> {
long endTime = System.currentTimeMillis();
result.setStatus(RunStatus.INTERRUPTED);
result.setTotalRuntimeInMilliseconds(endTime - startTime);
System.out.println(result);
})
);
ParameterValueOptimiser parameterValueOptimiser = new ParameterValueOptimiser(patternGraph, hostGraph);
int numHighDegVertices = parameterValueOptimiser.getNumHighDegVertices();
long timeAfterParameterOptimisation = System.currentTimeMillis();
result.setParameterOptimisationRuntimeInMilliseconds(timeAfterParameterOptimisation - startTime);
result.setNumberOfHighDegreeVertices(numHighDegVertices);
result.setMaximumDegreeOfRemainingVertices(parameterValueOptimiser.getMaxDegRemainingVertices());
List<Vertex> highDegVerticesHost = hostGraph.getHighestDegVertices(numHighDegVertices);
LabelledSubgraphCountingAlgorithm labelledSubgraphCountingAlgorithm = new LabelledSubgraphCountingAlgorithm(hostGraph, patternGraph, highDegVerticesHost);
int count = labelledSubgraphCountingAlgorithm.run();
result.setCount(count);
long endTime = System.currentTimeMillis();
result.setAlgorithmRuntimeInMilliseconds(endTime - timeAfterParameterOptimisation);
result.setTotalRuntimeInMilliseconds(endTime - startTime);
if (count > 0) {
result.setStatus(RunStatus.PASS);
} else {
result.setStatus(RunStatus.FAIL);
}
System.out.println(result);
}
}