Toutes les classes pour l'algorithme de génération des personnes et de création des indices correspondant à une personne choisie

pull/51/head
Thomas Chazot 1 year ago
parent 1943236395
commit b03196d91a

@ -12,6 +12,7 @@
"@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^13.5.0",
"bootstrap": "^5.3.2",
"lodash": "^4.17.21",
"react": "^18.2.0",
"react-bootstrap": "^2.9.1",
"react-dom": "^18.2.0",

@ -5,7 +5,9 @@
"@testing-library/jest-dom": "^5.17.0",
"@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^13.5.0",
"@types/lodash": "^4.14.200",
"bootstrap": "^5.3.2",
"lodash": "^4.17.21",
"react": "^18.2.0",
"react-bootstrap": "^2.9.1",
"react-dom": "^18.2.0",

@ -7,6 +7,17 @@ import Color from '../source/Color';
import Sport from '../source/Sport';
import PersonNetwork from '../source/PersonsNetwork';
import AgeIndice from '../source/Indices/AgeIndice';
import IndiceTesterFactory from '../source/Factory/IndiceTesterFactory';
import NbEdgesIndice from '../source/Indices/NbEdgesIndice';
import ColorIndice from '../source/Indices/ColorIndice';
import EdgesCreator from '../source/EdgesCreator';
import ColorEdgesIndice from '../source/Indices/ColorEdgesIndice';
import IndiceChooser from '../source/IndiceChooser';
import Indice from '../source/Indices/Indice';
import SportIndice from '../source/Indices/SportIndice';
import Stub from '../source/Stub';
import NetworkGenerator from '../source/NetworkGenerator';
import GraphCreator from '../source/GraphCreator';
@ -15,10 +26,40 @@ import AgeIndice from '../source/Indices/AgeIndice';
function Home() {
/*
let person = new Person(0, "test", 23, Color.BLANC, [Sport.CURLING], []);
let p1 = new Person(1, "1", 51, Color.BLOND, [Sport.CURLING], [])
let p2 = new Person(2, "2", 20, Color.NOIR, [Sport.BASKET], [])
let p3 = new Person(3, "3", 25, Color.ROUX, [Sport.TENNIS], [])
let p4 = new Person(5, "5", 51, Color.BLOND, [Sport.FOOT], [])
let p5 = new Person(6, "6", 27, Color.CHATAIN, [Sport.RUGBY], [])
let p6 = new Person(7, "7", 40, Color.ROUX, [Sport.FOOT], [])
let p7 = new Person(8, "8", 51, Color.CHATAIN, [Sport.TENNIS], [])
let p8 = new Person(9, "9", 28, Color.BLANC, [Sport.BASKET], [])
let p9 = new Person(10, "10", 40, Color.ROUX, [Sport.RUGBY], [])
let network = new PersonNetwork([person, p1, p2, p3, p4, p5, p6, p7, p8, p9])
*/
const edgesCreator = new EdgesCreator()
const chooser = new IndiceChooser()
const indices = Stub.GenerateIndice()
const network = NetworkGenerator.GenerateNetwork(12)
const rand = Math.floor(Math.random() * 12)
const person = network.getPersons()[rand]
const choosenIndices = chooser.chooseIndice(network, person, indices, 3)
edgesCreator.CreateAllEdges(network, person, choosenIndices)
const graph = GraphCreator.CreateGraph(network)
console.log(network)
console.log(graph)
let person = new Person(1, "test", 12, Color.NOIR, [Sport.CURLING], []);
let network = new PersonNetwork([person, person])
let indice = new AgeIndice(1, 10, 20)
return (
<div className="home-container">

@ -1,9 +1,9 @@
enum Color {
BLANC,
NOIR,
JAUNE,
ROUGE,
BLEU,
BLOND,
ROUX,
CHATAIN,
}
export default Color

@ -0,0 +1,12 @@
class Edge{
public from: number
public to: number
constructor(from: number, to: number){
this.from = from
this.to = to
}
}
export default Edge

@ -0,0 +1,104 @@
import IndiceTesterFactory from "./Factory/IndiceTesterFactory";
import EdgesIndice from "./Indices/EdgesIndice";
import Indice from "./Indices/Indice";
import Person from "./Person";
import PersonNetwork from "./PersonsNetwork";
import cloneDeep from 'lodash/cloneDeep';
import IndiceEdgesFactory from "./Factory/IndiceEdgesCreatorFactory";
class EdgesCreator{
CreateWorkingEdge(personNetwork: PersonNetwork, choosenPerson: Person, indice: Indice, indices: Indice[]){
let creator = IndiceEdgesFactory.Create(indice)
const nbMaxEdge = Math.floor(Math.random() * 5) + 1
creator.createWorkingEdges(personNetwork, choosenPerson, indices)
if (choosenPerson.getFriends().length < nbMaxEdge){
for (const p of personNetwork.getPersons()){
if (choosenPerson.getFriends().length == nbMaxEdge){
return
}
if (p!=choosenPerson && !choosenPerson.getFriends().includes(p)){
let testEdgeWork = 0
const p1 = cloneDeep(p);
const personEdge = cloneDeep(choosenPerson);
p1.addFriend(personEdge)
personEdge.addFriend(p1)
indices.forEach((indice) => {
const tester = IndiceTesterFactory.Create(indice)
if (tester.Works(p1)){
testEdgeWork ++
}
});
if (testEdgeWork < indices.length){
p.addFriend(choosenPerson)
choosenPerson.addFriend(p)
}
}
}
}
}
CreateNotWorkingEdge(personNetwork: PersonNetwork, personToCreateEdge: Person, choosenPerson: Person, indices: Indice[], map: Map<number, number>){
const test = [...personNetwork.getPersons()]
shuffleArray(test)
test.forEach((p) => {
if (personToCreateEdge.getFriends().length == map.get(personToCreateEdge.getId())){
return
}
if (p != personToCreateEdge && p != choosenPerson && !personToCreateEdge.getFriends().includes(p)){
let testEdgeWork = 0
const p1 = cloneDeep(p);
const personEdge = cloneDeep(personToCreateEdge);
p1.addFriend(personEdge)
personEdge.addFriend(p1)
indices.forEach((indice) => {
const tester = IndiceTesterFactory.Create(indice)
if (tester.Works(p1) || tester.Works(personEdge) || map.get(p.getId()) === p.getFriends().length){
testEdgeWork ++
}
});
if (testEdgeWork < indices.length){
p.addFriend(personToCreateEdge)
personToCreateEdge.addFriend(p)
}
}
});
}
CreateAllEdges(personNetwork: PersonNetwork, choosenPerson: Person, indices: Indice[]){
const test = new Map<number, number>()
indices.forEach(indice => {
if (indice instanceof EdgesIndice){
this.CreateWorkingEdge(personNetwork, choosenPerson, indice, indices)
}
});
personNetwork.getPersons().forEach((p) => {
if (p != choosenPerson){
test.set(p.getId(), Math.floor(Math.random() * 5) + p.getFriends().length + 1)
}
});
personNetwork.getPersons().forEach((p) => {
if (p != choosenPerson){
this.CreateNotWorkingEdge(personNetwork, p, choosenPerson, indices, test)
}
});
}
}
function shuffleArray(array: Person[]) {
for (var i = array.length - 1; i > 0; i--) {
var j = Math.floor(Math.random() * (i + 1));
var temp = array[i];
array[i] = array[j];
array[j] = temp;
}
}
export default EdgesCreator

@ -0,0 +1,27 @@
import ColorIndiceEdgesCreator from "../IndiceEdgesCreator.ts/ColorIndiceEdgesCreator";
import IndiceEdgesCreator from "../IndiceEdgesCreator.ts/IndiceEdgesCreator";
import NbEdgesIndiceEdgesCreator from "../IndiceEdgesCreator.ts/NbEdgesIndiceEdgesCreator";
import AgeIndice from "../Indices/AgeIndice";
import ColorEdgesIndice from "../Indices/ColorEdgesIndice";
import ColorIndice from "../Indices/ColorIndice";
import Indice from "../Indices/Indice";
import NbEdgesIndice from "../Indices/NbEdgesIndice";
import ColorIndiceTester from "../IndiceTester/ColorIndiceTester";
import IndiceTester from "../IndiceTester/IndiceTester";
import IndiceTesterAge from "../IndiceTester/IndiceTesterAge";
import NbEdgesIndiceTester from "../IndiceTester/NbEdgesIndiceTester";
class IndiceEdgesFactory{
static Create(indice: Indice): IndiceEdgesCreator{
if (indice instanceof NbEdgesIndice){
return new NbEdgesIndiceEdgesCreator(indice)
}
if (indice instanceof ColorEdgesIndice){
return new ColorIndiceEdgesCreator(indice)
}
throw new Error("Method not finished.");
}
}
export default IndiceEdgesFactory

@ -1,7 +1,15 @@
import AgeIndice from "../Indices/AgeIndice";
import ColorEdgesIndice from "../Indices/ColorEdgesIndice";
import ColorIndice from "../Indices/ColorIndice";
import Indice from "../Indices/Indice";
import NbEdgesIndice from "../Indices/NbEdgesIndice";
import SportIndice from "../Indices/SportIndice";
import ColorEdgesIndiceTester from "../IndiceTester/ColorIndiceEdgesTester";
import ColorIndiceTester from "../IndiceTester/ColorIndiceTester";
import IndiceTester from "../IndiceTester/IndiceTester";
import IndiceTesterAge from "../IndiceTester/IndiceTesterAge";
import NbEdgesIndiceTester from "../IndiceTester/NbEdgesIndiceTester";
import SportIndiceTester from "../IndiceTester/SportIndiceTester";
class IndiceTesterFactory{
@ -9,6 +17,18 @@ class IndiceTesterFactory{
if (indice instanceof AgeIndice){
return new IndiceTesterAge(indice)
}
if (indice instanceof NbEdgesIndice){
return new NbEdgesIndiceTester(indice)
}
if (indice instanceof ColorIndice){
return new ColorIndiceTester(indice)
}
if (indice instanceof ColorEdgesIndice){
return new ColorEdgesIndiceTester(indice)
}
if (indice instanceof SportIndice){
return new SportIndiceTester(indice)
}
throw new Error("Method not finished.");
}
}

@ -0,0 +1,26 @@
import Edge from "./Edge";
import GraphPerson from "./GraphPerson";
import NodePerson from "./NodePerson";
import PersonNetwork from "./PersonsNetwork";
class GraphCreator{
static CreateGraph(network: PersonNetwork): GraphPerson{
const nodesPerson : NodePerson[] = []
const edges: Edge[] = []
network.getPersons().forEach((p) =>{
const nodePerson = new NodePerson(p.getId(), p.getName())
nodesPerson.push(nodePerson)
p.getFriends().forEach((f) =>{
if(edges.some(edge => (edge.from === f.getId() && edge.to === p.getId()) || (edge.from === p.getId() && edge.to === f.getId()))){
return;
}
edges.push(new Edge(p.getId(), f.getId()))
});
});
return new GraphPerson(edges, nodesPerson)
}
}
export default GraphCreator

@ -0,0 +1,17 @@
import Edge from "./Edge";
import NodePerson from "./NodePerson";
class GraphPerson{
private edges: Edge[]
private nodesPerson: NodePerson[]
constructor(edges: Edge[], nodesPerson: NodePerson[]){
this.edges = edges
this.nodesPerson = nodesPerson
}
}
export default GraphPerson

@ -0,0 +1,68 @@
import IndiceTesterFactory from "./Factory/IndiceTesterFactory";
import EdgesIndice from "./Indices/EdgesIndice";
import Indice from "./Indices/Indice";
import Person from "./Person";
import PersonNetwork from "./PersonsNetwork";
import cloneDeep from 'lodash/cloneDeep';
import IndiceEdgesFactory from "./Factory/IndiceEdgesCreatorFactory";
import AgeIndice from "./Indices/AgeIndice";
import ColorIndice from "./Indices/ColorIndice";
import SportIndice from "./Indices/SportIndice";
class IndiceChooser{
chooseIndice(personNetwork: PersonNetwork, choosenPerson: Person, indices: Indice[], nbPlayer: number): Indice[]{
const choosenIndices: Indice[] = []
const ageIndice : Indice[] = []
const sportIndice : Indice[] = []
const colorIndice : Indice[] = []
const edgeIndice : Indice[] = []
const tabIndice: Indice[][] = []
for (const indice of indices){
if (indice instanceof EdgesIndice){
edgeIndice.push(indice)
continue
}
const tester = IndiceTesterFactory.Create(indice)
if (tester.Works(choosenPerson)){
if (indice instanceof AgeIndice){
ageIndice.push(indice)
}
else if(indice instanceof ColorIndice){
colorIndice.push(indice)
}
else if(indice instanceof SportIndice){
sportIndice.push(indice)
}
}
}
let test = [...tabIndice]
if (ageIndice.length > 0) tabIndice.push(ageIndice)
if (colorIndice.length > 0) tabIndice.push(colorIndice)
if (sportIndice.length > 0) tabIndice.push(sportIndice)
for (let i = 0; i<nbPlayer-1; i++){
if (test.length == 0){
if (ageIndice.length > 0) test.push(ageIndice)
if (colorIndice.length > 0) test.push(colorIndice)
if (sportIndice.length > 0) test.push(sportIndice)
}
const rand = Math.floor(Math.random() * test.length)
const rand2 = Math.floor(Math.random() * test[rand].length)
choosenIndices.push(test[rand][rand2])
test[rand].splice(rand2, 1)
test.splice(rand, 1)
}
const rand = Math.floor(Math.random() * edgeIndice.length)
choosenIndices.push(edgeIndice[rand])
return choosenIndices
}
}
export default IndiceChooser

@ -0,0 +1,53 @@
import cloneDeep from "lodash/cloneDeep";
import IndiceTesterFactory from "../Factory/IndiceTesterFactory";
import ColorEdgesIndice from "../Indices/ColorEdgesIndice";
import ColorIndice from "../Indices/ColorIndice";
import EdgesIndice from "../Indices/EdgesIndice";
import Indice from "../Indices/Indice";
import NbEdgesIndice from "../Indices/NbEdgesIndice";
import ColorEdgesIndiceTester from "../IndiceTester/ColorIndiceEdgesTester";
import ColorIndiceTester from "../IndiceTester/ColorIndiceTester";
import NbEdgesIndiceTester from "../IndiceTester/NbEdgesIndiceTester";
import Person from "../Person";
import PersonNetwork from "../PersonsNetwork";
import IndiceEdgesCreator from "./IndiceEdgesCreator";
class ColorIndiceEdgesCreator implements IndiceEdgesCreator{
private indice: ColorEdgesIndice
constructor(indice: ColorEdgesIndice){
this.indice = indice
}
createWorkingEdges(personNetwork: PersonNetwork, person: Person, indices: Indice[]): number {
let indiceTest = new ColorEdgesIndiceTester(this.indice)
for (const p of personNetwork.getPersons()){
let a = false
if (p!=person){
let testEdgeWork = 0
const p1 = cloneDeep(p)
p1.addFriend(person)
const choosenOne = cloneDeep(person)
choosenOne.addFriend(p1)
if (indiceTest.Works(choosenOne)){
for (const indice of indices){
const tester = IndiceTesterFactory.Create(indice)
if (tester.Works(p1)){
testEdgeWork ++
}
}
if (testEdgeWork < indices.length){
p.addFriend(person)
person.addFriend(p)
return 1
}
}
}
}
return person.getFriends().length
}
}
export default ColorIndiceEdgesCreator

@ -0,0 +1,9 @@
import Indice from "../Indices/Indice";
import Person from "../Person";
import PersonNetwork from "../PersonsNetwork";
interface IndiceEdgesCreator{
createWorkingEdges(personNetwork: PersonNetwork, person: Person, indices: Indice[]): number
}
export default IndiceEdgesCreator

@ -0,0 +1,47 @@
import cloneDeep from "lodash/cloneDeep";
import IndiceTesterFactory from "../Factory/IndiceTesterFactory";
import EdgesIndice from "../Indices/EdgesIndice";
import Indice from "../Indices/Indice";
import NbEdgesIndice from "../Indices/NbEdgesIndice";
import NbEdgesIndiceTester from "../IndiceTester/NbEdgesIndiceTester";
import Person from "../Person";
import PersonNetwork from "../PersonsNetwork";
import IndiceEdgesCreator from "./IndiceEdgesCreator";
class NbEdgesIndiceEdgesCreator implements IndiceEdgesCreator{
private indice: NbEdgesIndice
constructor(indice: NbEdgesIndice){
this.indice = indice
}
createWorkingEdges(personNetwork: PersonNetwork, person: Person, indices: Indice[]): number {
let indiceTest = new NbEdgesIndiceTester(this.indice)
const nbEdges = this.indice.getNbEdges() + Math.floor(Math.random() * 2)
personNetwork.getPersons().forEach(p => {
if (person.getFriends().length == nbEdges){
return
}
if (p!=person){
let testEdgeWork = 0
const p1 = cloneDeep(p)
p1.addFriend(person)
indices.forEach((indice) => {
const tester = IndiceTesterFactory.Create(indice)
if (tester.Works(p1)){
testEdgeWork ++
}
});
if (testEdgeWork < indices.length){
p.addFriend(person)
person.addFriend(p)
}
}
});
return person.getFriends().length
}
}
export default NbEdgesIndiceEdgesCreator

@ -0,0 +1,36 @@
import AgeIndice from "../Indices/AgeIndice";
import ColorEdgesIndice from "../Indices/ColorEdgesIndice";
import ColorIndice from "../Indices/ColorIndice";
import Person from "../Person";
import IndiceTester from "./IndiceTester";
class ColorEdgesIndiceTester implements IndiceTester{
private colorEdgesIndice: ColorEdgesIndice
constructor(colorEdgesIndice: ColorEdgesIndice){
this.colorEdgesIndice = colorEdgesIndice;
}
Works(person: Person): boolean {
let res = false
person.getFriends().forEach(p => {
if(this.colorEdgesIndice.getColors().includes(p.getColor())){
res = true
return true
}
});
return res
}
TestWorks(person: Person): boolean {
person.getFriends().forEach(p => {
if(this.colorEdgesIndice.getColors().includes(p.getColor())){
return true
}
});
return false
}
}
export default ColorEdgesIndiceTester

@ -0,0 +1,23 @@
import AgeIndice from "../Indices/AgeIndice";
import ColorIndice from "../Indices/ColorIndice";
import Person from "../Person";
import IndiceTester from "./IndiceTester";
class ColorIndiceTester implements IndiceTester{
private colorIndice: ColorIndice
constructor(colorIndice: ColorIndice){
this.colorIndice = colorIndice;
}
Works(person: Person): boolean {
return this.colorIndice.getColors().includes(person.getColor())
}
TestWorks(person: Person): boolean {
return this.colorIndice.getColors().includes(person.getColor())
}
}
export default ColorIndiceTester

@ -11,7 +11,7 @@ class IndiceTesterAge implements IndiceTester{
}
Works(person: Person): boolean {
return person.getAge() >= this.ageIndice.getMinimum() && person.getAge()<this.ageIndice.getMaximum()
return person.getAge() >= this.ageIndice.getMinimum() && person.getAge()<= this.ageIndice.getMaximum()
}
TestWorks(person: Person): boolean {

@ -0,0 +1,23 @@
import AgeIndice from "../Indices/AgeIndice";
import NbEdgesIndice from "../Indices/NbEdgesIndice";
import Person from "../Person";
import IndiceTester from "./IndiceTester";
class NbEdgesIndiceTester implements IndiceTester{
private nbEdgesIndice: NbEdgesIndice
constructor(nbEdgesIndice: NbEdgesIndice){
this.nbEdgesIndice = nbEdgesIndice;
}
Works(person: Person): boolean {
return person.getFriends().length >= this.nbEdgesIndice.getNbEdges()
}
TestWorks(person: Person): boolean {
return true
}
}
export default NbEdgesIndiceTester

@ -0,0 +1,34 @@
import AgeIndice from "../Indices/AgeIndice";
import ColorIndice from "../Indices/ColorIndice";
import SportIndice from "../Indices/SportIndice";
import Person from "../Person";
import IndiceTester from "./IndiceTester";
class SportIndiceTester implements IndiceTester{
private sportIndice: SportIndice
constructor(sportIndice: SportIndice){
this.sportIndice = sportIndice;
}
Works(person: Person): boolean {
for (const sport of person.getSports()){
if (this.sportIndice.getSports().includes(sport)){
return true
}
}
return false
}
TestWorks(person: Person): boolean {
for (const sport of person.getSports()){
if (this.sportIndice.getSports().includes(sport)){
return true
}
}
return false
}
}
export default SportIndiceTester

@ -21,7 +21,7 @@ class AgeIndice extends Indice {
}
getMaximum(): number{
return this.minimum
return this.maximum
}
}

@ -0,0 +1,22 @@
import Color from "../Color";
import EdgesIndice from "./EdgesIndice";
class ColorEdgesIndice extends EdgesIndice {
private neighborsColors: Color[];
constructor(id: number, neighborsColors: Color[]) {
super(id);
this.neighborsColors = neighborsColors;
}
public getColors(): Color[]{
return this.neighborsColors
}
// Implémentation de la méthode abstraite
ToString(): string {
return "La personne a au moins " + this.neighborsColors + " amis";
}
}
export default ColorEdgesIndice

@ -0,0 +1,23 @@
import Color from "../Color";
import Indice from "./Indice";
class ColorIndice extends Indice {
private colors: Color[]
constructor(id: number, colors: Color[]) {
super(id);
this.colors = colors
}
// Implémentation de la méthode abstraite
ToString(): string {
return "La personne a entre "
}
getColors(): Color[]{
return this.colors
}
}
export default ColorIndice

@ -1,10 +1,6 @@
import Indice from "./Indice";
abstract class EdgesIndice extends Indice {
constructor(id: number) {
super(id);
}
}
export default EdgesIndice

@ -1,6 +1,6 @@
import EdgesIndice from "./EdgesIndice";
class NbEdgesIbndice extends EdgesIndice {
class NbEdgesIndice extends EdgesIndice {
private nbNeighbors: number;
constructor(id: number, nbNeighbors: number) {
@ -8,10 +8,14 @@ class NbEdgesIbndice extends EdgesIndice {
this.nbNeighbors = nbNeighbors;
}
public getNbEdges(): number{
return this.nbNeighbors
}
// Implémentation de la méthode abstraite
ToString(): string {
return "La personne a au moins " + this.nbNeighbors + " amis";
}
}
export default NbEdgesIbndice
export default NbEdgesIndice

@ -0,0 +1,23 @@
import Sport from "../Sport";
import Indice from "./Indice";
class SportIndice extends Indice {
private sports: Sport[]
constructor(id: number, sports: Sport[]) {
super(id);
this.sports = sports
}
// Implémentation de la méthode abstraite
ToString(): string {
return "La personne a entre "
}
getSports(): Sport[]{
return this.sports
}
}
export default SportIndice

@ -0,0 +1,71 @@
import Color from "./Color";
import Person from "./Person";
import PersonNetwork from "./PersonsNetwork";
import Sport from "./Sport";
class NetworkGenerator{
static GenerateNetwork(nbPerson: number): PersonNetwork{
const tabSports: Sport[] = [0, 1, 2, 3, 4, 5, 5, 5, 5]
const tabColor: Color[] = [0, 1, 2, 3, 4]
const tabJeune: number[] = []
const tabAdo: number[] = []
const tabAdulte: number[] = []
const tabVieux: number[] = []
const tabPerson: Person[] = []
let id = 0
for(let i = 0; i < nbPerson/4; i++){
const nombreAleatoire = Math.floor(Math.random() * 14) + 1;
tabJeune.push(nombreAleatoire)
}
for(let i = 0; i < nbPerson/4; i++){
const nombreAleatoire = Math.floor(Math.random() * 5) + 15;
tabAdo.push(nombreAleatoire)
}
for(let i = 0; i < nbPerson/4; i++){
const nombreAleatoire = Math.floor(Math.random() * 10) + 20;
tabAdulte.push(nombreAleatoire)
}
for(let i = 0; i < nbPerson/4; i++){
const nombreAleatoire = Math.floor(Math.random() * 31) + 30;
tabVieux.push(nombreAleatoire)
}
const tabAge: number[][] = [tabJeune, tabAdo, tabAdulte, tabVieux]
let tmpTabSport=[...tabSports]
let tmpTabColor = [...tabColor]
for (let i = 0; i<nbPerson; i++){
if (tmpTabColor.length == 0){
tmpTabColor = [...tabColor]
}
let sports = []
for (let j = 0; j < 3; j++){
if (tmpTabSport.length == 0) tmpTabSport = [...tabSports]
const rand = Math.floor(Math.random() * tmpTabSport.length)
if (tmpTabSport[rand] != Sport.AUCUN){
sports.push(tmpTabSport[rand])
}
tmpTabSport.splice(rand, 1)
}
const randCol = Math.floor(Math.random() * tmpTabColor.length)
const color = tmpTabColor[randCol]
tmpTabColor.splice(randCol, 1)
const randAge = Math.floor(Math.random() * tabAge.length)
const randAge2 = Math.floor(Math.random() * tabAge[randAge].length)
const age = tabAge[randAge][randAge2]
tabAge[randAge].splice(randAge2, 1)
if (tabAge[randAge].length == 0){
tabAge.splice(randAge, 1)
}
tabPerson.push(new Person(i, i.toString(), age, color, sports, []))
}
return new PersonNetwork(tabPerson)
}
}
export default NetworkGenerator

@ -0,0 +1,11 @@
class NodePerson{
public id: number
public label: string
constructor(id: number, label: string){
this.id=id
this.label=label
}
}
export default NodePerson

@ -4,6 +4,7 @@ enum Sport {
BASKET,
TENNIS,
CURLING,
AUCUN
}
export default Sport

@ -0,0 +1,51 @@
import Color from "./Color"
import AgeIndice from "./Indices/AgeIndice"
import ColorEdgesIndice from "./Indices/ColorEdgesIndice"
import ColorIndice from "./Indices/ColorIndice"
import Indice from "./Indices/Indice"
import NbEdgesIndice from "./Indices/NbEdgesIndice"
import SportIndice from "./Indices/SportIndice"
import Sport from "./Sport"
class Stub{
static GenerateIndice(): Indice[]{
let indice = new NbEdgesIndice(1, 3)
let indice1 = new NbEdgesIndice(2, 4)
let ageIndice = new AgeIndice(3, 0, 14)
let ageIndice1 = new AgeIndice(4, 15, 19)
let ageIndice2 = new AgeIndice(5, 20, 29)
let ageIndice3 = new AgeIndice(6, 30, 100000)
let indices: Indice[] = [indice, indice1, ageIndice, ageIndice1, ageIndice2, ageIndice3]
let test = 7
for (let i: Color=0; i<5; i++){
for (let j: Color=0; j<5; j++){
if (j==i){
continue
}
indices.push(new ColorIndice(test, [i, j]))
test++
}
}
for (let i: Sport=0; i<5; i++){
for (let j: Sport=0; j<5; j++){
if (j==i){
continue
}
indices.push(new SportIndice(test, [i, j]))
test++
}
}
for (let i: Color=0; i<5; i++){
indices.push(new ColorEdgesIndice(test, [i]))
test++
}
return indices
}
}
export default Stub

@ -8,7 +8,7 @@
"target": "es5",
"lib": ["dom", "es2015"],
"jsx": "react",
"strict": true
"strict": true,
},
// ...
}

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save