//CTOR public BusTrip(BusLine l, int stt) { //nicht threadsafe ;-) id = counter; counter++; Line = l; StartTime = stt; _stationsOfLine = new List <Station>(); }
private List <BusLine> generateBusLines() { List <BusLine> result = new List <BusLine>(); if (_stations == null || _stations.Count < 5) { return(result); } for (int i = 0; i < _numOfLines; i++) { //random frequency int rnd_freq = _rnd.Next(5, 15); //random number of trips int rnd_numOfTrips = _rnd.Next(5, 20); //get a new BusLine: var visitedStations = newRandomLine(); //calculate time for each bustrip of line int rnd_tripDuration = calcLineTime(visitedStations); //latest starting time of line given trip duration, number of trips and frequency (infeasibility possible) int latest_starting_point = calcLatestStartTime(288, rnd_numOfTrips, rnd_tripDuration, rnd_freq); int h = 0; //reduce number of trips or frequency if infeasible starting time for line occurs while (latest_starting_point < 1) { //20% chance to reduce freqency, 80% chance to reduce number of trips if (_rnd.NextDouble() > 0.8) { if (rnd_freq > 5) { rnd_freq--; } } else { if (rnd_numOfTrips > 3) { rnd_numOfTrips--; } } //recalc latest_starting_point = calcLatestStartTime(288, rnd_numOfTrips, rnd_tripDuration, rnd_freq); //change BusLine if needed if (h > 100) { visitedStations = newRandomLine(); rnd_tripDuration = calcLineTime(visitedStations); rnd_numOfTrips = _rnd.Next(5, 20); rnd_freq = _rnd.Next(5, 15); } h++; } int rnd_firstStart = _rnd.Next(0, latest_starting_point); BusLine newBusLine = new BusLine( visitedStations[0], visitedStations[visitedStations.Count() - 1], rnd_freq, rnd_firstStart, rnd_numOfTrips, rnd_tripDuration, visitedStations); result.Add(newBusLine); } return(result); }