Sport
This commit is contained in:
@@ -50,25 +50,19 @@ document.getElementById("generateGraph")!.addEventListener("click", () => {
|
||||
// coordonnees
|
||||
const x = cx + Math.cos(angle) * (radius + (Math.random() - 0.5) * jitter);
|
||||
const y = cy + Math.sin(angle) * (radius + (Math.random() - 0.5) * jitter);
|
||||
ind.edges = 0;
|
||||
|
||||
graph.addNode(String(i), {
|
||||
label: `${ind.prenom} (${ind.age} ans)`,
|
||||
x, // position initiale X
|
||||
y, // position initiale Y
|
||||
size: 2,
|
||||
size: 1,
|
||||
color: ind.sexe === "F" ? "#ff99aa" : "#6699ff",
|
||||
age: ind.age,
|
||||
sexe: ind.sexe,
|
||||
richesse: ind.richesse,
|
||||
etudes: ind.etudes,
|
||||
lecture: ind.lecture,
|
||||
musique: ind.musique,
|
||||
sport: ind.sport,
|
||||
});
|
||||
});
|
||||
|
||||
// maintenant on peut créer Sigma en lui passant le conteneur
|
||||
sigma = new Sigma(graph, container, { renderLabels: true });
|
||||
sigma = new Sigma(graph, container, { renderLabels: false });
|
||||
// rafraîchir pour que Sigma prenne en compte les positions initiales
|
||||
sigma.refresh();
|
||||
|
||||
@@ -92,30 +86,40 @@ function updateSizes() {
|
||||
}
|
||||
|
||||
async function animateLinks() {
|
||||
const pairs: [number, number][] = [];
|
||||
|
||||
// Liste de toutes les paires (i,j)
|
||||
for (let i = 0; i < individus.length; i++) {
|
||||
for (let j = i + 1; j < individus.length; j++) {
|
||||
pairs.push([i, j]);
|
||||
}
|
||||
}
|
||||
const N = individus.length;
|
||||
|
||||
// Mélanger un peu les paires pour éviter les patterns trop linéaires
|
||||
pairs.sort(() => Math.random() - 0.5);
|
||||
|
||||
for (const [i, j] of pairs) {
|
||||
for (let k = 0 ; k < N * 10 ; k++) {
|
||||
if (!running) break;
|
||||
|
||||
const i = Math.floor(Math.random() * N);
|
||||
const j = Math.floor(Math.random() * N);
|
||||
|
||||
console.log(`${i} ? ${j}`);
|
||||
|
||||
if (i === j) {
|
||||
console.log(`${i} == ${j}`);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (graph.hasEdge(String(i), String(j))) {
|
||||
console.log(`${i} hasEdge ${j}`);
|
||||
continue;
|
||||
}
|
||||
|
||||
const a = individus[i];
|
||||
const b = individus[j];
|
||||
|
||||
// Homophilie
|
||||
const diffSexe = +(a.sexe == b.sexe);
|
||||
const diffAge = Math.abs(a.age - b.age) / 60;
|
||||
const diffLecture = Math.abs(a.lecture - b.lecture);
|
||||
const diffMusique = Math.abs(a.musique - b.musique);
|
||||
const diffSport = Math.abs(a.sport - b.sport);
|
||||
const similitude = 1 - (diffAge * 2 + diffLecture + diffMusique + diffSport) / 5;
|
||||
const diffSport = (1 - Math.abs(a.sport - b.sport)) * Math.pow((a.sport + b.sport) / 2, 2);
|
||||
|
||||
const diffEtudes = Math.abs(a.etudes - b.etudes) / 3;
|
||||
const diffRichesse = Math.abs(a.richesse - b.richesse) / 3;
|
||||
const similitude = 1 - (diffSexe * 2 + diffAge * 2 + diffLecture + diffMusique + diffSport + diffEtudes + diffRichesse) / 9;
|
||||
|
||||
// Attachement préférentiel
|
||||
const degreeA = graph.degree(String(i)) + 1;
|
||||
@@ -130,8 +134,13 @@ async function animateLinks() {
|
||||
|
||||
// Probabilité globale
|
||||
const p = 0.15 * similitude + 0.45 * pref + 0.4 * triadic;
|
||||
const r = Math.random();
|
||||
|
||||
if (Math.random() < p) {
|
||||
console.log(`${similitude} ${pref} ${triadic} ${p} (>${r})`);
|
||||
|
||||
if (r < p) {
|
||||
individus[i].edges++;
|
||||
individus[j].edges++;
|
||||
graph.addEdge(String(i), String(j));
|
||||
updateSizes();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user