diff --git a/src/Node.txt b/src/Node.txt new file mode 100644 index 0000000..a81b409 --- /dev/null +++ b/src/Node.txt @@ -0,0 +1,187 @@ +//IMPORTS +import java.util.LinkedList; +import java.util.*; + +public class Node{ + //ATTRIBUTS + /*----------------------------------------------------------------------------------*/ + private String value; + private LinkedList successors = new LinkedList(); + private int successors_len = 0; + private int depth = 0; + + //ASSOCIATIONS DIRECTES + private LinkedList directedfrom = new LinkedList(); + private LinkedList directedto = new LinkedList(); + + private int directedfrom_len = 0; + private int directedto_len = 0; + + //PARAMETRES CUSTOMISES + /*le dictionnaire de paramètres customisés n'est pas ordonné. A prenre en compte + lors de la conception ou de la modification de fonctionnalités.*/ + private Map custom_parameters = new HashMap(); + private Set> cstprms_entry = custom_parameters.entrySet(); + private Set keys; + /*----------------------------------------------------------------------------------*/ + //FIN ATTRIBUTS + + + //METHODES + /*----------------------------------------------------------------------------------*/ + /*methodes params customs*/ + private void updateKeysForCustParams(){ + this.keys = this.custom_parameters.keySet(); + } + + public boolean newCustomParameter(String name, String value){ + if(this.custom_parameters.containsKey(name)){ + System.out.println("FAILED:UNIQUE NAME CONSTRAINT VIOLATED"); + return false; + } + this.custom_parameters.put(name, value); + this.updateKeysForCustParams(); + return true; + } + + public boolean editCustomParameter(String name, String value){ + if(this.custom_parameters.containsKey(name)){ + this.custom_parameters.remove(name); + this.custom_parameters.put(name, value); + this.updateKeysForCustParams(); + return true; + } else { + System.out.println("FAILED:PARAMETER NOT REGISTERED IN MAP"); + return false; + } + } + + public boolean removeCustomParameter(String name, String value){ + if(!this.custom_parameters.containsKey(name)){ + System.out.println("FAILED:PARAMETER NOT REGISTERED IN MAP"); + return false; + } + this.custom_parameters.remove(name); + this.updateKeysForCustParams(); + return true; + } + + public String getCustomParam(String name){ + if(!this.custom_parameters.containsKey(name)){ + System.out.println("FAILED:PARAMETER NOT REGISTERED IN MAP"); + return ""; + } + return this.custom_parameters.get(name); + } + + /*----------------------------------------------------------------------------------*/ + /*methodes associations dirigées*/ + + public void addDirectedAssociationFrom(Node n){ + this.directedfrom.add(n); + this.directedfrom_len++; + } + + public void addDirectedAssociationTo(Node n){ + this.directedto.add(n); + n.addDirectedAssociationFrom(this); + this.directedto_len++; + } + + public LinkedList getDirectedAssociationsTo(){ + return this.directedto; + } + + public boolean hasDirectedAssociationTo(Node n){ + for(int i=0; i"); + return; + } + if (Integer.parseInt(args[0])<2) { + System.out.println("FAILSAFE: MUST BE GREATER OR EQUAL TO 2"); + } + + //fin tests + + //variables + LinkedList pool = new LinkedList(); + LinkedList popular_kids = new LinkedList(); + Random randgen = new Random(); + int r1, r2; + double pertmax; + int scoremax; + Node x, y; + int targetScore; + int added_links = 0; + int no_link=0; + int last = -1; + boolean exit = false; + //fin variables + + + //prog + for(int i=0; ipertmax){ + pertmax = Double.parseDouble(x.getDirectedAssociationsTo().get(i).getCustomParam("pertinence")); + } + } + + if(Double.parseDouble(y.getCustomParam("pertinence"))>=pertmax){ + x.addDirectedAssociationTo(y); + targetScore = Integer.parseInt(y.getCustomParam("score")); + y.editCustomParameter("score", Integer.toString(targetScore+1)); + added_links++; + no_link=0; + } else { + no_link++; + } + last = r1; + if(x.getLenDirectedAssociationsTo()==(Integer.parseInt(args[0])-1)) { + popular_kids.add(r1); + } + + } + + try { + popular_kids.get(0); + if (added_links>=((Integer.parseInt(args[0])*(Integer.parseInt(args[0])+1)/2)-Integer.parseInt(args[0]))) { + exit=true; + } + /* rien */ + } catch (IndexOutOfBoundsException e) { + + /* rien */ + } finally { + if(no_link >= 10000){ + exit=true; + } + } + } + + + /* affichage (dans la console) */ + System.out.println("les sites sont classés dans l'ordre du plus haut score au plus bas:"); + for(int i=0; iscoremax){ + scoremax=Integer.parseInt(pool.get(j).getCustomParam("score")); + pertmax=Double.parseDouble(pool.get(j).getCustomParam("pertinence")); + targetScore = j; + } + } + System.out.println(" "+Integer.toString(i+1)+") "+pool.get(targetScore).getVal()+" - score:"+pool.get(targetScore).getCustomParam("score")+" - pertinence:"+pool.get(targetScore).getCustomParam("pertinence")); + pool.remove(targetScore); + } + + System.out.println("\nfin programme"); + + } +} + + +/*NOTES: +La classe Node.java est une classe que j'avais codé anciennement; +je l'ai reprise et adapté à l'exercice. +Les segments du code pertinents par rapport à l'exercice sont +codés dans les sections suivantes de la classe Node : + -PARAMETRES CUSTOMISES + -methodes associations dirigées + -methodes params customs + -CONSTRUCTEUR(s) +J'avais, pour des raisons que j'ignore, des problèmes avec la division des pertinences par 100 pour une représentation correcte. +La représentation est donc en pourcentage. +*/ \ No newline at end of file