getting closer

git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@846 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
Tom Copeland
2002-09-04 21:19:35 +00:00
parent 7a7287edc9
commit 80ea469d8c
5 changed files with 73 additions and 24 deletions

View File

@ -45,9 +45,9 @@ public class DCPD {
DGST dgst = new DGST(space, job, tokenSetWrapper.tokenSets, 50);
dgst.crunch(new CPDListenerImpl());
/*
System.out.println(render());
*/
} catch (Exception e) {
e.printStackTrace();

View File

@ -48,9 +48,12 @@ public class DCPDWorker {
tsw = (TokenSetsWrapper)space.read(new TokenSetsWrapper(null, job.id), null, 100);
System.out.println("Read a TokenSetsWrapper with " + tsw.tokenSets.size() + " token lists");
System.out.println("Starting expansion");
doExpansion();
System.out.println("Done");
while (true) {
System.out.println("Starting expansion");
doExpansion();
System.out.println("Done, sleeping");
Thread.currentThread().sleep(1000);
}
} catch (Exception e) {
e.printStackTrace();
@ -61,15 +64,23 @@ public class DCPDWorker {
Entry twQuery = space.snapshot(new TileWrapper(null, null, currentJob.id, TileWrapper.NOT_DONE, null, null, null));
TileWrapper tileWrapper = null;
while ((tileWrapper = (TileWrapper)space.take(twQuery, null, 100)) != null) {
while ((tileWrapper = (TileWrapper)space.take(twQuery, null, 10)) != null) {
System.out.println("got " + tileWrapper.tile.getImage());
Occurrences results = expand(tileWrapper);
int expansionIndex = 0;
for (Iterator i = results.getTiles();i.hasNext();) {
Tile tile = (Tile)i.next();
List theseOccurrences = marshal(results.getOccurrences(tile));
for (int j=0; j<=theseOccurrences.size(); j++) {
TileWrapper newTW = new TileWrapper(tile, theseOccurrences, currentJob.id, TileWrapper.DONE, tileWrapper.originalTilePosition, new Integer(j), new Integer(theseOccurrences.size()));
space.write(newTW, null, Lease.FOREVER);
}
TileWrapper newTW = new TileWrapper(tile,
theseOccurrences,
currentJob.id,
TileWrapper.DONE,
tileWrapper.originalTilePosition,
new Integer(expansionIndex),
new Integer(results.size()));
space.write(newTW, null, Lease.FOREVER);
System.out.println("Wrote " + newTW.getExpansionIndexPicture());
expansionIndex++;
}
}
}

View File

@ -52,11 +52,16 @@ public class DGST {
int tilesSoFar=0;
for (Iterator i = occ.getTiles(); i.hasNext();) {
Tile tile = (Tile)i.next();
TileWrapper tw = new TileWrapper(tile, marshal(occ.getOccurrences(tile)), job.id, TileWrapper.NOT_DONE, new Integer(tilesSoFar), null, null);
TileWrapper tw = new TileWrapper(tile,
marshal(occ.getOccurrences(tile)),
job.id,
TileWrapper.NOT_DONE,
new Integer(tilesSoFar),
null, null);
space.write(tw, null, Lease.FOREVER);
tilesSoFar++;
if (tilesSoFar % 10 == 0) {
System.out.println("tilesSoFar = " + tilesSoFar);
System.out.println("Written " + tilesSoFar + " tiles so far");
}
}
}
@ -66,21 +71,36 @@ public class DGST {
Occurrences occ = new Occurrences(new CPDNullListener());
for (int i=0;i<originalOccurrencesCount; i++) {
// this gets tile x:1 - i.e., (5:1/3)
TileWrapper tw = (TileWrapper)space.take(new TileWrapper(null, null, job.id, TileWrapper.DONE, new Integer(i), new Integer(1), null), null, Lease.FOREVER);
addTileWrapperToOccurrences(tw, occ);
// this gets tile (6:0/3:4:0/2:3)
TileWrapper tw = (TileWrapper)space.take(new TileWrapper(null,
null,
job.id,
TileWrapper.DONE,
new Integer(i), null, null), null, Lease.FOREVER);
System.out.println("Took " + tw.getExpansionIndexPicture());
// now get tiles x:2..n - i.e., (5:2/3 and 5:3/3)
for (int j = tw.expansionIndex.intValue()+1; j<tw.totalExpansions.intValue()+1; j++) {
TileWrapper tw2 = (TileWrapper)space.take(new TileWrapper(null, null, job.id, TileWrapper.DONE, new Integer(i), new Integer(j), null), null, 100);
addTileWrapperToOccurrences(tw2, occ);
}
addAllExpansions(i, tw, occ);
}
System.out.println("DONE GATHERING");
return occ;
}
private void addAllExpansions(int originalPosition, TileWrapper firstTileWrapper, Occurrences occ) throws RemoteException, UnusableEntryException, TransactionException, InterruptedException {
addTileWrapperToOccurrences(firstTileWrapper, occ);
for (int i=1; i<firstTileWrapper.expansionsTotal.intValue(); i++) {
TileWrapper nextExpansion = (TileWrapper)space.take(new TileWrapper(null,
null,
firstTileWrapper.jobID,
TileWrapper.DONE,
new Integer(originalPosition),
new Integer(i),
firstTileWrapper.expansionsTotal), null, Lease.FOREVER);
System.out.println("Took " + nextExpansion.getExpansionIndexPicture());
addTileWrapperToOccurrences(nextExpansion, occ);
}
}
private void addTileWrapperToOccurrences(TileWrapper tw, Occurrences occ) {
for (int i=0; i<tw.occurrences.size(); i++) {
if (!occ.containsAnyTokensIn(tw.tile)) {

View File

@ -19,19 +19,31 @@ public class TileWrapper implements Entry {
public Integer jobID;
public List occurrences;
public Integer isDone;
public Integer originalTilePosition;
public Integer expansionIndex;
public Integer totalExpansions;
public Integer expansionsTotal;
public TileWrapper() {}
public TileWrapper(Tile tile, List occurrences, Integer jobID, Integer isDone, Integer originalTilePosition, Integer expansionIndex, Integer totalExpansions) {
public TileWrapper(Tile tile, List occurrences, Integer jobID, Integer isDone, Integer originalTilePosition, Integer expansionIndex, Integer expansionsTotal) {
this.tile = tile;
this.jobID = jobID;
this.occurrences = occurrences;
this.isDone = isDone;
this.originalTilePosition = originalTilePosition;
this.expansionIndex = expansionIndex;
this.totalExpansions = totalExpansions;
this.expansionsTotal = expansionsTotal;
}
public String toString() {
return "TileWrapper " + tile.getImage() + ":" + jobID + ":" + occurrences.size() + ":" + isDone + ":" + getExpansionIndexPicture();
}
public String getExpansionIndexPicture() {
return "(" + originalTilePosition + "->" + expansionIndex + "/" + expansionsTotal + ")";
}
}

View File

@ -30,11 +30,17 @@ public class Util {
public static void main(String[] args) {
try {
int objectCount = 0;
if (args[0].equals("clear")) {
JavaSpace space = Util.findSpace(SPACE_SERVER);
Entry e = null;
while ( (e = space.take(null, null, 100)) != null) {
//System.out.println("took " + e);
objectCount++;
if (objectCount % 100 == 0) {
System.out.println(objectCount + " objects taken so far");
}
System.out.println("took " + e);
}
} else {
System.out.println("Usage: clear");