/* Dla każdej osoby w każdy dzień losować czy uda się do hotelu. Jeśli tak, to do jakiego. Optymalizacja: Jak odnotować kolizję: np. słownik (para osób, liczba) */ const numPeople = 1000; const matchProbability = 1; const numHotels = 100; const numDays = 100; const numPeopleInHotel = []; const people = []; const hotels = []; const meetings = {}; let currentSimulationDay = 0; class Person { constructor(personID) { this.ID = personID; this.currentHotel = null; } selectHotel() { this.currentHotel = Math.floor(Math.random()*numHotels); console.log(`[${currentSimulationDay}] ${this.ID} -> ${this.currentHotel}`) return this.currentHotel; }; } class Hotel { constructor(hotelID) { this.ID = hotelID; this.currentNumPeople = 0; this.peopleInside = []; } visitHotel(personID) { this.currentNumPeople++; this.peopleInside.push(personID); } newDay() { this.currentNumPeople = 0; this.peopleInside = []; } } for (let i=0; i { if (Math.random() < matchProbability) { // if the person goes to the hotel, select a random hotel he goes to const selectedHotel = person.selectHotel(); hotels[selectedHotel].visitHotel(person.ID); } }); // console.log('~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~'); // console.log('Podsumowanie dnia ' + currentSimulationDay); hotels.forEach(hotel => { // console.log(`${hotel.ID} -> ${hotel.currentNumPeople}.`); hotel.peopleInside.forEach(personA => { hotel.peopleInside.forEach(personB => { if (personA !== personB) { if (!meetings[[personA, personB]]) { meetings[[personA, personB]] = 0; }; meetings[[personA, personB]]++; } }); }); hotel.newDay(); }); } console.log(meetings);