Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[AMIEQueue] Add progress bar for each generation #45

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions mining/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,6 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>commons-cli</groupId>
<artifactId>commons-cli</artifactId>
Expand All @@ -31,6 +25,11 @@
<artifactId>rules</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>me.tongfei</groupId>
<artifactId>progressbar</artifactId>
<version>0.8.1</version>
</dependency>
</dependencies>

<build>
Expand Down
2 changes: 1 addition & 1 deletion mining/src/main/java/amie/mining/AMIE.java
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ public List<Rule> 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);
Expand Down
31 changes: 27 additions & 4 deletions mining/src/main/java/amie/mining/AMIEQueue.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -31,6 +32,10 @@ public final class AMIEQueue {

private LinkedHashSet<Rule> next;

private ProgressBar progressBar;

private boolean verbose;

private int generation;

private int maxThreads;
Expand All @@ -49,13 +54,15 @@ public void printStats() {
}
}

public AMIEQueue(Collection<Rule> seeds, int maxThreads) {
public AMIEQueue(Collection<Rule> 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;
Expand Down Expand Up @@ -139,6 +146,9 @@ public Rule dequeue() throws InterruptedException {
--waitingThreads;
} else {
if (next.isEmpty()) {
if (this.verbose) {
this.progressBar.close();
}
done = true;
} else {
nextGeneration();
Expand All @@ -160,14 +170,27 @@ public Rule dequeue() throws InterruptedException {
* @return
*/
private Rule poll() {
return current.next();
if (this.verbose) {
this.progressBar.step();
}
return current.next();
}


private void nextGeneration() {
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));
}

generation++;
this.queueCalls.put(this.generation, 0);
this.queueAdded.put(this.generation, 0);
this.queueCalls.put(this.generation, 0);
this.queueAdded.put(this.generation, 0);

current = next.iterator();
next = new LinkedHashSet<>();
}
Expand Down