Générations des individus

This commit is contained in:
2025-10-17 19:45:26 +02:00
parent 02abde44a2
commit 0d1ebd1020
7 changed files with 243 additions and 26 deletions

View File

@@ -1,7 +1,7 @@
import './style.css'
import Graph from "https://esm.sh/graphology";
import Sigma from "https://esm.sh/sigma";
import forceAtlas2 from "graphology-layout-forceatlas2";
import Graph from "graphology";
import Sigma from "sigma";
import forceAtlas2 from "graphology-layout-forceatlas2";
// --- Génération de données de base ---
const graph = new Graph();
@@ -24,14 +24,8 @@ for (let i = 0; i < N; i++) {
});
}
// --- Ajout de quelques liens initiaux ---
for (let i = 0; i < N * 1.5; i++) {
const a = `n${Math.floor(Math.random() * N)}`;
const b = `n${Math.floor(Math.random() * N)}`;
if (a !== b && !graph.hasEdge(a, b)) {
graph.addEdge(a, b, { color: "#da1515ff", size: 1 });
}
}
let total = N * 1.5
// --- Calcul du layout ForceAtlas2 ---
/*
@@ -48,11 +42,13 @@ const container = document.getElementById("app");
const renderer = new Sigma(graph, container, { renderLabels: true });
// --- Fonctions dynamiques ---
function addLink(source, target) {
if (!graph.hasEdge(source, target)) {
graph.addEdge(source, target, { color: "#666" });
renderer.refresh();
function addLink() {
const a = `n${Math.floor(Math.random() * N)}`;
const b = `n${Math.floor(Math.random() * N)}`;
if (a !== b && !graph.hasEdge(a, b)) {
graph.addEdge(a, b, { color: "#da1515ff", size: 1 });
}
if (total-- > 0) setTimeout(() => addLink(), 1000); else running = false;
}
function removeLink(source, target) {
@@ -63,11 +59,8 @@ function removeLink(source, target) {
}
// --- Exemple dévolution dynamique ---
//setTimeout(() => addLink("n0", "n5"), 3000);
//setTimeout(() => removeLink("n1", "n2"), 6000);
//console.log("Graph loaded:", graph.order, "nodes,", graph.size, "edges");
setTimeout(() => addLink(), 1000);
setTimeout(() => removeLink("n1", "n2"), 8000);
// --- Animation du layout ---
// On crée une "simulation" ForceAtlas2 en incrémentant les positions à chaque frame.
@@ -86,11 +79,6 @@ function stepLayout() {
// Lancement
stepLayout();
// Arrêt automatique après 5 secondes
setTimeout(() => {
running = false;
console.log("Layout stabilisé");
}, 5000);
/*
const layout = new ForceAtlas2Layout(graph, {