-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMiner.java
More file actions
114 lines (104 loc) · 5.31 KB
/
Miner.java
File metadata and controls
114 lines (104 loc) · 5.31 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
package com.vincentderk.acircuitminer.miner;
import com.google.common.base.Stopwatch;
import com.vincentderk.acircuitminer.miner.enumerators.ExpandableEnumerator;
import com.vincentderk.acircuitminer.miner.enumerators.MultiBackTrackEnumerator;
import static com.vincentderk.acircuitminer.miner.util.OperationUtils.removeOverlap;
import com.vincentderk.acircuitminer.miner.util.Utils;
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenCustomHashMap;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
import java.util.Map;
import java.util.concurrent.TimeUnit;
/**
*
*
* Uses the {@link ExpandableEnumerator Enumerators} to find patterns and their
* occurrences in an arithmetic circuit ({@link Graph}).
* <p>
* Note: The current search implementations do not allow a node to be directly
* connected to another node twice. (This is caused by the EdgeCanonical
* choices).
*
* @author Vincent Derkinderen
* @version 2.0
*/
public class Miner {
/**
* Execute an enumeration algorithm to find patterns and their occurrences.
* The patterns found are induced connected subgraphs with one output and a
* maximum of {@code maxPorts-1} input ports.
* <p>
* First, a complete search is performed for patterns upto size
* {@code k[0]}. If {@code k} has more than one element, the search
* continues heuristically (incomplete) in the second step to bigger sizes
* {@code k[1],k[2],...}. Every iteration, the xBest expandable patterns are
* further expanded.
* <p>
* In the end, a first-come, first-served heuristic is used to remove
* overlapping occurrences within each pattern. The results are internally
* filtered so for each pattern there are no overlapping occurrences. After
* that, all results are printed from low to high according to
* {@link Utils#writeResults(java.util.Map.Entry<long[],it.unimi.dsi.fastutil.objects.ObjectArrayList<int[]>>[],
* boolean)}.
*
* @param g The graph to mine in.
* @param k The sizes to mine upto. Size of a pattern is determined by the
* amount of operations in it.
* @param verbose Prints more information.
* @param maxPorts The maximum amount of ports. Note, all found patterns
* only have 1 output port.
* @param xBest The x best patterns to select for the next iteration.
* @return An array of entries from pattern to its occurrences. An
* occurrence is in this case given by the nodes that represent an
* operation. The operation nodes are in order of appearance in the pattern
* code.
*/
public static Map.Entry<long[], ObjectArrayList<int[]>>[] execute(Graph g, int[] k, boolean verbose, int maxPorts, int xBest) {
ExpandableEnumerator enumerator = new MultiBackTrackEnumerator();
Object2ObjectOpenCustomHashMap<long[], ObjectArrayList<int[]>> patternsMap = enumerator.enumerate(g, k, maxPorts, xBest, verbose);
Stopwatch stopwatch = Stopwatch.createStarted();
Map.Entry<long[], ObjectArrayList<int[]>>[] subset = removeOverlap(patternsMap, null);
System.out.printf("Removed overlap in %s secs.\n", stopwatch.elapsed(TimeUnit.SECONDS));
System.out.println("");
System.out.println("Printing results...");
Utils.writeResults(subset, true);
return subset;
}
/**
* Execute an enumeration algorithm to find patterns and their occurrences.
* The patterns found are induced connected subgraphs with one output and a
* maximum of {@code maxPorts-1} input ports.
* <p>
* First, a complete search is performed for patterns upto size
* {@code k[0]}. If {@code k} has more than one element, the search
* continues heuristically (incomplete) in the second step to bigger sizes
* {@code k[1],k[2],...}. Every iteration, the xBest expandable patterns are
* further expanded.
* <p>
* In the end, all results are printed from low to high according to
* {@link Utils#writeResults(java.util.Map.Entry<long[],it.unimi.dsi.fastutil.objects.ObjectArrayList<int[]>>[],
* boolean)}.
* <p>
* The difference with {@link #execute(Graph, int[], boolean, int, int)} is
* that this method does not filter the overlap.
*
* @param g The graph to mine in.
* @param k The sizes to mine upto. Size of a pattern is determined by the
* amount of operations in it.
* @param verbose Prints more information.
* @param maxPorts The maximum amount of ports. Note, all found patterns
* only have 1 output port.
* @param xBest The x best patterns to select for the next iteration.
* @return An array of entries from pattern to its occurrences. An
* occurrence is in this case given by the nodes that represent an
* operation. The operation nodes are in order of appearance in the pattern
* code.
*/
public static Object2ObjectOpenCustomHashMap<long[], ObjectArrayList<int[]>> executeRaw(Graph g, int[] k, boolean verbose, int maxPorts, int xBest) {
ExpandableEnumerator enumerator = new MultiBackTrackEnumerator();
Object2ObjectOpenCustomHashMap<long[], ObjectArrayList<int[]>> patternsMap = enumerator.enumerate(g, k, maxPorts, xBest, verbose);
System.out.println("");
System.out.println("Printing results...");
Utils.writeResults(patternsMap, true);
return patternsMap;
}
}