Toutes les classes pour l'algorithme de génération des personnes et de création des indices correspondant à une personne choisie
parent
1943236395
commit
b03196d91a
@ -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
|
@ -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
|
@ -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
|
@ -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
|
@ -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
|
@ -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
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in new issue