save
This commit is contained in:
BIN
src/Node.class
Normal file
BIN
src/Node.class
Normal file
Binary file not shown.
152
src/Node.java
Normal file
152
src/Node.java
Normal file
@@ -0,0 +1,152 @@
|
|||||||
|
//IMPORTS
|
||||||
|
import java.util.LinkedList;
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
public class Node{
|
||||||
|
//ATTRIBUTS
|
||||||
|
/*----------------------------------------------------------------------------------*/
|
||||||
|
private String value;
|
||||||
|
private LinkedList<Node> successors = new LinkedList<Node>();
|
||||||
|
private int successors_len = 0;
|
||||||
|
private int depth = 0;
|
||||||
|
|
||||||
|
//ASSOCIATIONS DIRECTES
|
||||||
|
private LinkedList<Node> directedfrom = new LinkedList<Node>();
|
||||||
|
private LinkedList<Node> directedto = new LinkedList<Node>();
|
||||||
|
|
||||||
|
//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<String, String> custom_parameters = new HashMap<String, String>();
|
||||||
|
private Set<Map.Entry<String, String>> cstprms_entry = custom_parameters.entrySet();
|
||||||
|
private Set<String> 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 addDirectedAssociation(Node n){
|
||||||
|
this.directedto.add(n);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addDirectedAssociationParent(Node n){
|
||||||
|
this.directedfrom.add(n);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*----------------------------------------------------------------------------------*/
|
||||||
|
/*methodes generales*/
|
||||||
|
public String getVal(){
|
||||||
|
return this.value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getDepth(){
|
||||||
|
return this.depth;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateDepth(int val){
|
||||||
|
this.depth = val;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Node getSuccessorAt(int index){
|
||||||
|
return this.successors.get(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addSuccessor(Node n){
|
||||||
|
n.updateDepth(this.depth+1);
|
||||||
|
this.successors.add(n);
|
||||||
|
this.successors_len++;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addSuccessors(Node[] ns){
|
||||||
|
for(int i=0; i<ns.length; i++){
|
||||||
|
ns[i].updateDepth(this.depth+1);
|
||||||
|
this.successors.add(ns[i]);
|
||||||
|
}
|
||||||
|
this.successors_len+=ns.length;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SortSuccessorsByIntVal(){
|
||||||
|
//tests
|
||||||
|
if(this.successors_len == 0){
|
||||||
|
System.out.println("FAILED:no successors");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//variables
|
||||||
|
Node tmp;
|
||||||
|
|
||||||
|
//prog
|
||||||
|
for(int i=1; i<this.successors_len-1; i++){
|
||||||
|
for(int j=i; j<this.successors_len; j++){
|
||||||
|
if(Integer.parseInt(this.successors.get(j).getVal())<Integer.parseInt(this.successors.get(i).getVal())){
|
||||||
|
tmp = this.successors.get(i);
|
||||||
|
this.successors.set(i, this.successors.get(j));
|
||||||
|
this.successors.set(j, tmp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*----------------------------------------------------------------------------------*/
|
||||||
|
/*----------------------------------------------------------------------------------*/
|
||||||
|
//FIN METHODES
|
||||||
|
|
||||||
|
|
||||||
|
//CONSTRUCTEUR(s)
|
||||||
|
/*----------------------------------------------------------------------------------*/
|
||||||
|
public Node(String value){
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
/*----------------------------------------------------------------------------------*/
|
||||||
|
//FIN CONSTRUCTEURS(s)
|
||||||
|
}
|
BIN
src/Simulation.class
Normal file
BIN
src/Simulation.class
Normal file
Binary file not shown.
49
src/Simulation.java
Normal file
49
src/Simulation.java
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
import java.util.LinkedList;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
public class Simulation {
|
||||||
|
public static void main(String[] args){
|
||||||
|
//tests
|
||||||
|
if(args.length<1){
|
||||||
|
System.out.println("USAGEERROR:java Simulation <int:nbr de sites>");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//fin tests
|
||||||
|
|
||||||
|
//variables
|
||||||
|
LinkedList<Node> pool = new LinkedList<Node>();
|
||||||
|
Random randgen = new Random();
|
||||||
|
int added_links = 0;
|
||||||
|
int r1, r2;
|
||||||
|
|
||||||
|
//fin variables
|
||||||
|
|
||||||
|
|
||||||
|
//prog
|
||||||
|
for(int i=0; i<Integer.parseInt(args[0]); i++){
|
||||||
|
pool.add(new Node("pas_important"));
|
||||||
|
}
|
||||||
|
for(int i=0; i<Integer.parseInt(args[0]); i++){
|
||||||
|
pool.get(i).newCustomParameter("pertinence", Double.toString((double) (randgen.nextInt(100)/100)));
|
||||||
|
pool.get(i).newCustomParameter("score", "0");
|
||||||
|
}
|
||||||
|
|
||||||
|
while(added_links < Integer.parseInt(args[0])*Integer.parseInt(args[0])-2){
|
||||||
|
r1 = randgen.nextInt(Integer.parseInt(args[0]));
|
||||||
|
r2 = randgen.nextInt(Integer.parseInt(args[0]));
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*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 de nommage suivantes :
|
||||||
|
-PARAMETRES CUSTOMISES
|
||||||
|
-methodes params customs
|
||||||
|
-CONSTRUCTEUR(s)
|
||||||
|
*/
|
Reference in New Issue
Block a user