From bb5df49aa33362b99473f2632f22f52e8bd46080 Mon Sep 17 00:00:00 2001 From: Antonio Carlos Date: Sun, 13 Sep 2020 08:41:49 -0300 Subject: [PATCH 1/2] [AMIEQueue] Add progress bar for each generation --- mining/pom.xml | 11 ++++---- mining/src/main/java/amie/mining/AMIE.java | 2 +- .../src/main/java/amie/mining/AMIEQueue.java | 27 +++++++++++++++++-- 3 files changed, 31 insertions(+), 9 deletions(-) diff --git a/mining/pom.xml b/mining/pom.xml index 2315c11..8c59112 100644 --- a/mining/pom.xml +++ b/mining/pom.xml @@ -15,12 +15,6 @@ UTF-8 - - junit - junit - 3.8.1 - test - commons-cli commons-cli @@ -31,6 +25,11 @@ rules 1.0 + + me.tongfei + progressbar + 0.8.1 + diff --git a/mining/src/main/java/amie/mining/AMIE.java b/mining/src/main/java/amie/mining/AMIE.java index 13bab9f..2e61fd1 100644 --- a/mining/src/main/java/amie/mining/AMIE.java +++ b/mining/src/main/java/amie/mining/AMIE.java @@ -230,7 +230,7 @@ public List mine() throws Exception { seedRules = assistant.getInitialAtomsFromSeeds(seeds, minInitialSupport); } - AMIEQueue queue = new AMIEQueue(seedRules, nThreads); + AMIEQueue queue = new AMIEQueue(seedRules, nThreads, isVerbose()); if (realTime) { consumerObj = new RuleConsumer(result, resultsLock, resultsCondVar); diff --git a/mining/src/main/java/amie/mining/AMIEQueue.java b/mining/src/main/java/amie/mining/AMIEQueue.java index 8017af6..3a63ec3 100644 --- a/mining/src/main/java/amie/mining/AMIEQueue.java +++ b/mining/src/main/java/amie/mining/AMIEQueue.java @@ -11,6 +11,7 @@ import amie.rules.Rule; import it.unimi.dsi.fastutil.ints.Int2IntMap; import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap; +import me.tongfei.progressbar.ProgressBar; /** * A queue implementation with barriers tailored for the AMIE mining system. @@ -31,6 +32,10 @@ public final class AMIEQueue { private LinkedHashSet next; + private ProgressBar progressBar; + + private boolean verbose; + private int generation; private int maxThreads; @@ -49,13 +54,15 @@ public void printStats() { } } - public AMIEQueue(Collection seeds, int maxThreads) { + public AMIEQueue(Collection seeds, int maxThreads, boolean verbose) { this.generation = 1; this.queueCalls.put(this.generation, 0); this.queueAdded.put(this.generation, 0); this.maxThreads = maxThreads; this.waitingThreads = 0; this.next = new LinkedHashSet<>(); + this.progressBar = null; + this.verbose = verbose; this.queueAll(seeds); this.nextGeneration(); this.done = false; @@ -139,6 +146,9 @@ public Rule dequeue() throws InterruptedException { --waitingThreads; } else { if (next.isEmpty()) { + if (this.verbose) { + this.progressBar.close(); + } done = true; } else { nextGeneration(); @@ -160,7 +170,10 @@ public Rule dequeue() throws InterruptedException { * @return */ private Rule poll() { - return current.next(); + if (this.verbose) { + this.progressBar.step(); + } + return current.next(); } @@ -168,6 +181,16 @@ private void nextGeneration() { generation++; this.queueCalls.put(this.generation, 0); this.queueAdded.put(this.generation, 0); + + if (this.progressBar != null) { + this.progressBar.close(); + } + + if (this.verbose) { + // Heuristic for calculating updateIntervalMillis considering the queue's size and the number of consumers. + this.progressBar = new ProgressBar("Generation " + generation + ":", next.size(), Math.min(1000, next.size() * 1000 / 1000 / maxThreads)); + } + current = next.iterator(); next = new LinkedHashSet<>(); } From 9a7be82cb5e150b1409472c02ec2431f151e5a22 Mon Sep 17 00:00:00 2001 From: Antonio Carlos Date: Mon, 14 Sep 2020 08:48:19 -0300 Subject: [PATCH 2/2] [AMIEQueue] Fix generation counter on progress bar --- mining/src/main/java/amie/mining/AMIEQueue.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/mining/src/main/java/amie/mining/AMIEQueue.java b/mining/src/main/java/amie/mining/AMIEQueue.java index 3a63ec3..0eb0e9d 100644 --- a/mining/src/main/java/amie/mining/AMIEQueue.java +++ b/mining/src/main/java/amie/mining/AMIEQueue.java @@ -178,10 +178,6 @@ private Rule poll() { private void nextGeneration() { - generation++; - this.queueCalls.put(this.generation, 0); - this.queueAdded.put(this.generation, 0); - if (this.progressBar != null) { this.progressBar.close(); } @@ -191,6 +187,10 @@ private void nextGeneration() { this.progressBar = new ProgressBar("Generation " + generation + ":", next.size(), Math.min(1000, next.size() * 1000 / 1000 / maxThreads)); } + generation++; + this.queueCalls.put(this.generation, 0); + this.queueAdded.put(this.generation, 0); + current = next.iterator(); next = new LinkedHashSet<>(); }