fini
This commit is contained in:
BIN
src/Node.class
BIN
src/Node.class
Binary file not shown.
@@ -1,7 +1,6 @@
|
||||
//IMPORTS
|
||||
import java.util.LinkedList;
|
||||
import java.util.*;
|
||||
import java.util.Arrays;
|
||||
|
||||
public class Node{
|
||||
//ATTRIBUTS
|
||||
@@ -15,6 +14,9 @@ public class Node{
|
||||
private LinkedList<Node> directedfrom = new LinkedList<Node>();
|
||||
private LinkedList<Node> directedto = new LinkedList<Node>();
|
||||
|
||||
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.*/
|
||||
@@ -75,12 +77,45 @@ public class Node{
|
||||
/*----------------------------------------------------------------------------------*/
|
||||
/*methodes associations dirigées*/
|
||||
|
||||
public void addDirectedAssociation(Node n){
|
||||
this.directedto.add(n);
|
||||
public void addDirectedAssociationFrom(Node n){
|
||||
this.directedfrom.add(n);
|
||||
this.directedfrom_len++;
|
||||
}
|
||||
|
||||
public void addDirectedAssociationParent(Node n){
|
||||
this.directedfrom.add(n);
|
||||
public void addDirectedAssociationTo(Node n){
|
||||
this.directedto.add(n);
|
||||
n.addDirectedAssociationFrom(this);
|
||||
this.directedto_len++;
|
||||
}
|
||||
|
||||
public LinkedList<Node> getDirectedAssociationsTo(){
|
||||
return this.directedto;
|
||||
}
|
||||
|
||||
public boolean hasDirectedAssociationTo(Node n){
|
||||
for(int i=0; i<this.directedto_len; i++){
|
||||
if(n == this.directedto.get(i)){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean hasDirectedAssociationFrom(Node n){
|
||||
for(int i=0; i<this.directedfrom_len; i++){
|
||||
if(n == this.directedfrom.get(i)){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public int getLenDirectedAssociationsTo(){
|
||||
return this.directedto_len;
|
||||
}
|
||||
|
||||
public int getLenDirectedAssociationsFrom(){
|
||||
return this.directedfrom_len;
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------------*/
|
||||
|
Binary file not shown.
@@ -8,32 +8,121 @@ public class Simulation {
|
||||
System.out.println("USAGEERROR:java Simulation <int:nbr de sites>");
|
||||
return;
|
||||
}
|
||||
if (Integer.parseInt(args[0])<2) {
|
||||
System.out.println("FAILSAFE:<int:nbr de sites> MUST BE GREATER OR EQUAL TO 2");
|
||||
}
|
||||
|
||||
//fin tests
|
||||
|
||||
//variables
|
||||
LinkedList<Node> pool = new LinkedList<Node>();
|
||||
LinkedList<Integer> popular_kids = new LinkedList<Integer>();
|
||||
Random randgen = new Random();
|
||||
int added_links = 0;
|
||||
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; i<Integer.parseInt(args[0]); i++){
|
||||
pool.add(new Node("pas_important"));
|
||||
pool.add(new Node("site"+Integer.toString(i+1)));
|
||||
}
|
||||
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("pertinence", Double.toString((double) (randgen.nextInt(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]));
|
||||
/*
|
||||
for(int i=0; i<Integer.parseInt(args[0]); i++){
|
||||
System.out.println(pool.get(i).getVal());
|
||||
System.out.println(pool.get(i).getCustomParam("score"));
|
||||
System.out.println(pool.get(i).getCustomParam("pertinence"));
|
||||
System.out.println("-----------------------");
|
||||
}*/
|
||||
|
||||
while((!exit)){
|
||||
do{
|
||||
r1 = randgen.nextInt(Integer.parseInt(args[0]));
|
||||
}while((popular_kids.contains(r1))||(r1==last));
|
||||
|
||||
r2 = randgen.nextInt(Integer.parseInt(args[0]));
|
||||
pertmax = -1;
|
||||
|
||||
if(r2!=r1){
|
||||
x = pool.get(r1);
|
||||
y = pool.get(r2);
|
||||
|
||||
while(x.hasDirectedAssociationTo(y)){
|
||||
r2 = (r2+1)%Integer.parseInt(args[0]);
|
||||
if(r2!=r1){
|
||||
y = pool.get(r2);
|
||||
}
|
||||
}
|
||||
|
||||
for(int i=0; i<x.getLenDirectedAssociationsTo(); i++){
|
||||
if(Double.parseDouble(x.getDirectedAssociationsTo().get(i).getCustomParam("pertinence"))>pertmax){
|
||||
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; i<Integer.parseInt(args[0]); i++){
|
||||
scoremax=-1;
|
||||
targetScore=0;
|
||||
for(int j=0; j<Integer.parseInt(args[0])-i; j++){
|
||||
if(Integer.parseInt(pool.get(j).getCustomParam("score"))>scoremax){
|
||||
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");
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,8 +131,11 @@ public class Simulation {
|
||||
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 :
|
||||
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.
|
||||
*/
|
Reference in New Issue
Block a user