diff --git a/src/jcl/Classification.java b/src/jcl/Classification.java index 453241b9c7a6a4b22a4513a5d2492c3d90f303cf..d09a43795fddff5fb04d25fd224bc267dba6230e 100644 --- a/src/jcl/Classification.java +++ b/src/jcl/Classification.java @@ -4,6 +4,7 @@ import java.awt.Color; import java.io.IOException; import java.io.Serializable; import java.text.NumberFormat; +import java.util.ArrayList; import java.util.Arrays; import java.util.Observable; import java.util.Vector; @@ -19,6 +20,8 @@ import jcl.jcld.RmiServer; import jcl.jcld.database.SSHParameters; import jcl.learning.LearningMethod; import jcl.learning.methods.ClassifierUtils; +import jcl.utils.ProgressMonitor; +import jcl.utils.Progressable; import jcl.utils.exceptions.JCLFormatException; import jcl.utils.exceptions.MethodNotImplementedException; @@ -32,10 +35,12 @@ import jcl.utils.exceptions.MethodNotImplementedException; *
* * @author WEMMERT Cedric + * + * Implementation progressable avec liste de sous-processus progressable à suivre par Jean-Noël Balanche */ public abstract class Classification extends Observable implements - Serializable, Cloneable { + Progressable, Serializable, Cloneable { /** */ private static final long serialVersionUID = 1L; @@ -49,7 +54,7 @@ public abstract class Classification extends Observable implements /** paramtre de la connection ssh si besoin */ public SSHParameters sshParameters = null; - /** panel ou il faut afficher la non disponibiliter du server rmi */ + /** panel ou il faut afficher la non disponibilite du server rmi */ transient public JPanel container_; /** titre de la classid pour le tabedpane en hybridclassification */ @@ -68,7 +73,24 @@ public abstract class Classification extends Observable implements /** Le nom de la classification */ private String name = ""; + /** + * Parametre de progression pour l'affichage eventuel d'une barre de + * progression + */ + protected int progress = 0; + + /** Valeur maximale de la progression */ + protected int progressM = 100; + + /** Name of the current step of learning */ + protected String statusName = "Loading"; + + /** + * The list of all the progressable to monitor + */ + protected ArrayList* Methode utilisee pour le debuggage. Affiche le contenu de la memoire. @@ -767,5 +789,113 @@ public abstract class Classification extends Observable implements * @return the Classification generated */ public abstract Classification ImportResult(String model, int classifIndex) throws MethodNotImplementedException, JCLFormatException; + + /** + *
+ * Fin de la progression. + *
+ */ + @Override + public void endProgress() { + this.progress = this.progressM; + } + + /** + *+ * Incrementation du niveau de progression. + *
+ */ + @Override + public void incProgress() { + this.progress++; + } + + /** + *+ * Remise e zero du niveau de progression. + *
+ */ + @Override + public void resetProgress() { + this.progress = 0; + } + + @Override + public void setProgress(final int value) { + this.progress = value; + } + + @Override + public void setStatus(String status) + { + this.statusName = status; + + } + + @Override + public String getStatus() + { + String status = "Preparing ... "; + boolean allEnded = true; //boolean for the stop condition + + if(!this.progressableList.isEmpty()) { + for (int i = 0 ; i < this.progressableList.size(); i++) { + if (this.progressableList.get(i) != null) { + if (this.progressableList.get(i).getProgress() != 100) { + status = "Step "+ (i+1) + "/" + (this.progressableList.size()+1) + " : " + this.progressableList.get(i).getStatus(); + allEnded = false; + } + } + } + } + if(allEnded) {//return the usual value (this.status) when all progressables are done (to monitor the final step which is displaying the result) + status = this.statusName; + } + return status; + } + + @Override + public int getProgress() + { + int progress = 0; + boolean allEnded = true; //boolean for the stop condition + + if(!this.progressableList.isEmpty()) { + for (Progressable p : this.progressableList) { + if(p!=null) { + if (p.getProgress() != 100) { + progress=p.getProgress(); + allEnded=false; + } + } + } + } + if(allEnded) {//return the usual value (this.progress) when all progressables are done (to monitor the final step which is displaying the result) + progress = this.progress; + //System.out.println("all progressable ended"); + } + return progress; + } + + /** + * Add a progressable to monitor + * @param p the progressable to add + */ + public void addProgressable(Progressable p) { + this.progressableList.add(p); + } + + /** + * Get the list of all the progressables to monitor in this classification + * @return the progressable list + */ + public ArrayList* Constructeur a partir d'un ensemble de parametres et de ponderations. @@ -204,4 +218,72 @@ public abstract class LearningResult extends Object implements Serializable { * @return the LearningResult generated */ protected abstract LearningResult ImportResult(String model) throws MethodNotImplementedException, JCLFormatException; + + /** + *
+ * Fin de la progression. + *
+ */ + @Override + public void endProgress() { + this.progress = this.progressM; + } + + /** + *+ * Accesseur au niveau de progression des calculs. + *
+ * + * @return le compteur de progression + */ + @Override + public int getProgress() { + return (int) (((double) this.progress / (double) this.progressM) * 100.0); + } + + /** + *+ * Incrementation du niveau de progression. + *
+ */ + @Override + public void incProgress() { + this.progress++; + } + + /** + *+ * Remise e zero du niveau de progression. + *
+ */ + @Override + public void resetProgress() { + this.progress = 0; + } + + /** + *+ * Modification du niveau de progression des calculs. + *
+ * + * @param value + * la nouvelle valeur du compteur de progression + */ + @Override + public void setProgress(final int value) { + this.progress = value; + } + + @Override + public void setStatus(String status) + { + statusName = status; + + } + + @Override + public String getStatus() + { + return statusName; + } } diff --git a/src/jcl/learning/methods/monostrategy/SingleClassification.java b/src/jcl/learning/methods/monostrategy/SingleClassification.java index 06d901d89dc8d3026453d9868e940d44c47e7cb3..0f0aca8d18cb1a45c0f51aa52863ae89289ddc25 100644 --- a/src/jcl/learning/methods/monostrategy/SingleClassification.java +++ b/src/jcl/learning/methods/monostrategy/SingleClassification.java @@ -7,6 +7,7 @@ import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.util.ArrayList; +import java.util.Date; import java.util.Vector; import javax.naming.Context; @@ -26,6 +27,7 @@ import jcl.learning.methods.ClassifierUtils; import jcl.learning.methods.monostrategy.ahc.LearningResultAHC; import jcl.learning.methods.monostrategy.ahc.ParametersAHC; import jcl.learning.methods.monostrategy.kmeans.LearningResultKmeans; +import jcl.utils.Progressable; import jcl.utils.exceptions.JCLFormatException; import jcl.utils.exceptions.MethodNotImplementedException; import jcl.weights.ClassificationWeights; @@ -322,6 +324,12 @@ public class SingleClassification extends Classification { @Override public void classify() { + /* + * Add all the processes to monitor in the list (they have to implement progressable) + */ + this.addProgressable(this.learningMethod); + this.addProgressable(null);// had null because this.learningResult is not defined yet + if (this.useRmi() && !this.isMaclaw()) { if (this.sshParameters == null) { this.rmiClassify(); @@ -330,16 +338,19 @@ public class SingleClassification extends Classification { } } else { if (this.learningResult == null) { - // System.out.println("debut learn"); +// System.out.println("debut learn "+new Date().toString()); this.learn(); - // System.out.println("fin learn"); +// System.out.println("fin learn "+new Date().toString()); } - + + this.progressableList.set(1, this.learningResult);// now this.learningResult isn't null anymore so we can add him + +// System.out.println("debut classify "+new Date().toString()); this.clusteringResult = this.learningResult .classify(this.classificationData, false); - +// System.out.println("fin classify "+new Date().toString()); + this.clusteringResult.setMethode(this.learningMethod.getType()); - /* * si l'utilisateur souhaite une classification hierarchique, il * faut encore appliquer l'algorithme de classification hierarchique @@ -459,7 +470,7 @@ public class SingleClassification extends Classification { this.learningMethod.sshparameters = this.sshParameters; this.learningMethod.container_ = this.container_; } - // System.out.println(this.learningMethod.getName()+" starts to learn"); +// System.out.println(this.learningMethod.getName()+" starts to learn"); this.learningResult = this.learningMethod .learn(this.classificationData); } @@ -610,4 +621,8 @@ public class SingleClassification extends Classification { return result; } + + + + } diff --git a/src/jcl/learning/methods/monostrategy/kmeans/ClassifierKmeans.java b/src/jcl/learning/methods/monostrategy/kmeans/ClassifierKmeans.java index 97da418d567579810573c26e626ca413d2c8f847..6a38a2ba1d99fa416f84ecd8975dbdf61f358d06 100644 --- a/src/jcl/learning/methods/monostrategy/kmeans/ClassifierKmeans.java +++ b/src/jcl/learning/methods/monostrategy/kmeans/ClassifierKmeans.java @@ -281,6 +281,7 @@ public class ClassifierKmeans extends LearningMethod { @Override public LearningResult learn(Data data) { this.progressM = this.getNbIters(); + LearningResultKmeans result = new LearningResultKmeans(data, (ParametersKmeans) this.parameters, this.samples); this.initViewers(result); diff --git a/src/jcl/learning/methods/monostrategy/kmeans/LearningResultKmeans.java b/src/jcl/learning/methods/monostrategy/kmeans/LearningResultKmeans.java index 356e26baaafaf33688ae5ce738ea5c535531e3b6..dbe24991778755cbe4c0b64a8b72d00c4ca36688 100644 --- a/src/jcl/learning/methods/monostrategy/kmeans/LearningResultKmeans.java +++ b/src/jcl/learning/methods/monostrategy/kmeans/LearningResultKmeans.java @@ -139,7 +139,6 @@ public class LearningResultKmeans extends LearningResult { @Override public ClusteringResult classify(Data data, boolean fromSample) { - for (int i = 0 ; i < this.seeds.size() ; i++) { if (this.seeds.get(i) instanceof LightHardSeed) { ((LightHardSeed) this.seeds.get(i)).setId(i); @@ -147,10 +146,9 @@ public class LearningResultKmeans extends LearningResult { } // long startT = System.nanoTime(); // System.out.println("start at "+startT); - int clusterMap[] = this.clusterAffectation(data,fromSample); + int clusterMap[] = this.clusterAffectation(data,fromSample);// !!! // long endT = System.nanoTime(); // System.out.println("endat "+ endT + " total of "+ (endT - startT)/1000000000l); - ClusteringResult result = null; if (((ParametersKmeans) this.params).fuzzy) { @@ -163,7 +161,6 @@ public class LearningResultKmeans extends LearningResult { result = ClusteringResult.gerenerateDefaultClusteringResult(this, clusterMap, null, this.weights, this.seeds.size(), null, data, this.qualityIndices, getColors()); } - return result; } @@ -257,8 +254,11 @@ public class LearningResultKmeans extends LearningResult { } else { nbObjects = data.getWholeDataNbObjects(); } - int clusterMap[] = new int[nbObjects]; + + this.progressM=nbObjects; + this.resetProgress(); + int clusterMap[] = new int[nbObjects]; int nbThreads = ((ParametersKmeans) this.params).nbThreads; nbThreads = 1; if (((ParametersKmeans) this.params).fuzzy) { @@ -347,7 +347,7 @@ public class LearningResultKmeans extends LearningResult { this.weights, this.seeds); } tabThreads[nbThreads - 1].start(); - + for (int th = 0; th < nbThreads; th++) { try { tabThreads[th].join(); @@ -899,6 +899,7 @@ public class LearningResultKmeans extends LearningResult { threadGlobalDistance += distMin; //((HardSeed) seeds.get(clusterMap[i])).addObject(obj); + incProgress(); i++; } // writer.close(); diff --git a/src/jcl/utils/ProgressMonitor.java b/src/jcl/utils/ProgressMonitor.java new file mode 100644 index 0000000000000000000000000000000000000000..9d17cd6e5c4878e0647b98d9904bf1fa9f47c096 --- /dev/null +++ b/src/jcl/utils/ProgressMonitor.java @@ -0,0 +1,75 @@ +package jcl.utils; + +/** + * ?? + * @author Jean-Noël Balanche + * + */ + + +public interface ProgressMonitor { + /** + * ?? + * @param id ?? + */ + public void incProgress(int id); + + /** + *+ * Methode de decrementation de l'indice de progression. + *
+ * + */ + public void endMonitorProgress(); + + /** + *+ * Methode d'acces au pourcentage en cours de la progression. + *
+ * + * @return le pourcentage (entre 0 et 100) de la progression + */ + public int getMonitorProgress(); + + /** + *+ * Methode d'incrementation de l'indice de progression. + *
+ */ + public void incMonitorProgress(); + + /** + *+ * Methode de remise a zero de l'indice de progression. + *
+ */ + public void resetMonitorProgress(); + + /** + *+ * Methode de modification du pourcentage de progression. + *
+ * + * @param value + * la nouvelle valeur + */ + public void setMonitorProgress(int value); + + /** + *+ * Methode de modification du status. + *
+ * + * @param status + */ + public void setMonitorStatus(String status); + + /** + *+ * Methode d'acces au status. + *
+ * + * @param status + */ + public String getMonitorStatus(); +} \ No newline at end of file