/// <summary> /// Returns departures from specified station with in this line. /// </summary> /// <param name="station">The station.</param> /// <returns>The arrival time.</returns> public Time departureFromStation(TrainStation station) { TrainStop stop = trainLine.getTrainStopOnStation(station.Name); Time time; // if departure is not equal 00:00 if (!stop.TimeDeparture.Equals(Time.MinValue)) { time = stop.TimeDeparture; } else { // if stop is a first one, there it is a legal time, use it if (stop.OrderInTrainLine.Equals(0)) { time = stop.TimeDeparture; } // otherwise (time is 00:00 but the stop is not first) else { // it has to be last stop, which has no departure (not continue) time = Time.EmptyValue; } } return(time); }
/// <summary> /// Gets the train stop ordered at. /// </summary> /// <param name="order">The ordinal number.</param> /// <returns>The train stop.</returns> public TrainStop getTrainStopOrderedAt(int order) { TrainStop newStop = null; // not initialized if (trainStops == null) { return(null); } // if empty if (trainStops.Count.Equals(0)) { return(null); } foreach (TrainStop stop in trainStops) { if (stop.OrderInTrainLine.Equals(order)) { newStop = stop; break; } } return(newStop); }
/// <summary> /// Returns arrival on specified station within this line. /// </summary> /// <param name="station">The station.</param> /// <returns></returns> public Time arrivalOnStation(TrainStation station) { TrainStop stop = trainLine.getTrainStopOnStation(station.Name); Time time; // if arrival is not equal 00:00 if (!stop.TimeArrival.Equals(Time.MinValue)) { time = stop.TimeArrival; } else { // if stop is the first, there no arrival exists if (stop.OrderInTrainLine.Equals(0)) { time = Time.EmptyValue; } // otherwise (time is 00:00 but the stop is not first) use departure else { time = stop.TimeDeparture; } } return(time); }
public static List <Edge> createEdges(TrainLine line) { List <Edge> edges = new List <Edge>(); Boolean first = true; List <TrainStop> stops; TrainStop previousStop = null; stops = line.getTrainStops(); // loop over stops foreach (TrainStop stop in stops) { // first run = first stop if (first) { previousStop = stop; first = false; } // other stops else { // createConstraintSet new edge according line_ and stop information Edge edge = new Edge(previousStop.TrainStation, stop.TrainStation, stop.TimeFromPreviousStop, stop.KmFromPreviousStop, line.LineNumber); // addConstraint edge into edges edges.Add(edge); // save stop as a previous stop for next loop previousStop = stop; } } return(edges); }
public static List <Edge> createEdges(TrainLine line, int from, int to) { List <Edge> edges = new List <Edge>(); Boolean first = true; Boolean perform = false; List <TrainStop> stops; TrainStop previousStop = null; stops = line.getTrainStops(); // loop over stops foreach (TrainStop stop in stops) { // first find a stop with FROM station if (stop.TrainStation.Id.Equals(from)) { perform = true; } // perform creating a path if (perform) { // first run = first stop if (first) { previousStop = stop; first = false; } // other stops else { // createConstraintSet new edge according line_ and stop information Edge edge = new Edge(previousStop.TrainStation, stop.TrainStation, stop.TimeFromPreviousStop, stop.KmFromPreviousStop, line.LineNumber); // addConstraint edge into edges edges.Add(edge); // save stop as a previous stop for next loop previousStop = stop; } } // last stop find, stop perform creating if (perform && stop.TrainStation.Id.Equals(to)) { perform = false; break; } } return(edges); }
private void saveStopsInformation() { foreach (ListViewItem lvi in listViewListOfStops.Items) { // if there where changes of the train stop, save it if (lvi.Tag.Equals(CHANGED)) { // train stop at order int order = Convert.ToInt32(lvi.SubItems[1].Text); TrainStop stop = trainLine.getTrainStopOrderedAt(order); stop.TimeStayingAtStation = Time.ToTime(lvi.SubItems[4].Text); stop.TimeFromPreviousStop = Time.ToTime(lvi.SubItems[5].Text); stop.KmFromPreviousStop = Convert.ToInt32(lvi.SubItems[6].Text); } } this.trainLine.updateRelativeTrainStopInformation(); }
/// <summary> /// Gets the train stop on station. /// </summary> /// <param name="stationName">Name of the station.</param> /// <returns>The train stop.</returns> public TrainStop getTrainStopOnStation(TrainStation station) { TrainStop newStop = null; // not initialized if (trainStops == null) { return(null); } foreach (TrainStop stop in trainStops) { if (stop.TrainStation == station) { newStop = stop; break; } } return(newStop); }
/// <summary> /// Gets the train stop on station. /// </summary> /// <param name="stationName">Name of the station.</param> /// <returns>The train stop.</returns> public TrainStop getTrainStopOnStation(String stationName) { TrainStop newStop = null; // not initialized if (trainStops == null) { return(null); } foreach (TrainStop stop in trainStops) { if (stop.TrainStation.Name.Equals(stationName)) { newStop = stop; break; } } return(newStop); }
/// <summary> /// Creates the train stops. /// </summary> /// <param name="data">The data.</param> /// <param name="line">The line.</param> /// <returns>The train stops.</returns> private static List <TrainStop> createTrainStops(List <String[]> data, TrainLine line, out Time originalDepartureTime) { List <TrainStop> trainStops = new List <TrainStop>(); TrainStationCache stationCache = TrainStationCache.getInstance(); Int16 orderInLine = 0; String nameStation; Time departure; Time arrival; int kmFromStart; Time timeStart = Time.ToTime(data[0][2]);//Time.MinValue; // set original departure time originalDepartureTime = new Time(timeStart); Time timePrev = Time.MinValue; int kmPrev = 0; // foreach string[] createConstraintSet specific trainStop foreach (String[] str in data) { // if not correct number of stop details, take next stop if (str.Length != NUMBER_OF_STOP_DETAILS) { continue; } // createConstraintSet new stop TrainStop stop = new TrainStop(); // extract information about stop nameStation = str[0]; arrival = Time.ToTime(str[1]); departure = Time.ToTime(str[2]); kmFromStart = Convert.ToInt32(str[3]); // try toStation find out if throughStation already exists, if not, createConstraintSet appropriate throughStation if (!stationCache.doesStationExist(nameStation)) { // calculate new ID for new throughStation int id = stationCache.getCacheContent().Count; stationCache.addTrainStation(new TrainStation(id, nameStation)); // download new throughStation //stationCache = } // find appropriate throughStation TrainStation trainStation = stationCache.getCacheContentOnName(nameStation); // addConstraint linked line_ toStation throughStation trainStation.addTrainLine(line); stop.KmFromPreviousStop = kmFromStart - kmPrev; stop.KmFromStart = kmFromStart; stop.OrderInTrainLine = orderInLine; stop.TrainStation = trainStation; stop.TimeArrival = arrival - timeStart; stop.TimeDeparture = departure - timeStart; // if no arrival time_, count with departure if (arrival.Equals(Time.MinValue)) { stop.TimeFromPreviousStop = stop.TimeDeparture - timePrev; } //if arrival time_, use it else { stop.TimeFromPreviousStop = stop.TimeArrival - timePrev; } // set time_ and km for next stop timePrev = stop.TimeDeparture; kmPrev = stop.KmFromStart; orderInLine++; // addConstraint into final stops trainStops.Add(stop); } return(trainStops); }
/// <summary> /// Adds the train stop. /// </summary> /// <param name="trainStop">The train stop.</param> public void addTrainStop(TrainStop trainStop) { trainStops.Add(trainStop); }