/*
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<numPeople; i++) {
people[i] = new Person(i);
}
for (let i=0; i<numHotels; i++) {
hotels[i] = new Hotel(i);
}
while (currentSimulationDay++ < numDays) {
// all people decide to go to hotel or not
people.forEach(person => {
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);
{"html5":"htmlmixed","css":"css","javascript":"javascript","php":"php","python":"python","ruby":"ruby","lua":"text\/x-lua","bash":"text\/x-sh","go":"go","c":"text\/x-csrc","cpp":"text\/x-c++src","diff":"diff","latex":"stex","sql":"sql","xml":"xml","apl":"apl","asterisk":"asterisk","c_loadrunner":"text\/x-csrc","c_mac":"text\/x-csrc","coffeescript":"text\/x-coffeescript","csharp":"text\/x-csharp","d":"d","ecmascript":"javascript","erlang":"erlang","groovy":"text\/x-groovy","haskell":"text\/x-haskell","haxe":"text\/x-haxe","html4strict":"htmlmixed","java":"text\/x-java","java5":"text\/x-java","jquery":"javascript","mirc":"mirc","mysql":"sql","ocaml":"text\/x-ocaml","pascal":"text\/x-pascal","perl":"perl","perl6":"perl","plsql":"sql","properties":"text\/x-properties","q":"text\/x-q","scala":"scala","scheme":"text\/x-scheme","tcl":"text\/x-tcl","vb":"text\/x-vb","verilog":"text\/x-verilog","yaml":"text\/x-yaml","z80":"text\/x-z80"}