/// <summary> /// Function randomizeTimetable stage off a train line, only between stations off and to. /// </summary> /// <param name="line"></param> /// <param name="off"></param> /// <param name="to"></param> /// <returns></returns> public static Stage generateStage(TrainLine line, TrainStation from, TrainStation to) { List <Edge> edges = FloydWarshallUtil.createEdges(line); return(generateStage(edges, from, to)); // with null checking //return generateStage(edges); }
/// <summary> /// Initializes a new instance of the <see cref="Stage"/> class. /// </summary> /// <param name="from">From station.</param> /// <param name="to">To station.</param> /// <param name="line_">By the line.</param> public Stage(TrainStation from, TrainStation to, TrainLine line_) { edges = FloydWarshallUtil.createEdges(line_, from, to); line = line_; fromStation = from; toStation = to; time = TrainConnection.calculateTime(edges); distance = TrainConnection.calculateDistance(edges); }
/// <summary> /// Optimizations by function with respect to same line. /// </summary> /// <param name="edges">The edges.</param> /// <param name="edgeCache">The edge cache.</param> /// <returns></returns> private static List <Edge> optimizationFunctionSameLine(List <Edge> edges, List <Edge> edgeCache) { // retreive all lines List <TrainLine> allLines = TrainLineCache.getInstance().getCacheContent(); List <Edge> newPath = edges; // loop over all lines foreach (TrainLine line in allLines) { // find if one line contains first and last stop on path if (containsTrainStations(line, edges[0].From, edges[edges.Count - 1].To)) { // prepare new path newPath = FloydWarshallUtil.createEdges(line, edges[0].From, edges[edges.Count - 1].To); } } // return the same or new return(newPath); }
private void createFloydWarshall(List <TrainLine> lines, List <TrainStation> stations) { // createConstraintSet node array, assign stationId toStation index of node nodes = FloydWarshallUtil.createArrayOfNode(stations); // initialize size n if (stations.Count == nodes.Length) { n = nodes.Length; } // createConstraintSet multidimensional arrays of size n time = FloydWarshallUtil.crateArrayOfTimeNxN(n); distance = FloydWarshallUtil.createArrayOfNxN(n); //line_ = FloydWarshallUtil.createArrayOfNxN(n); throughStation = FloydWarshallUtil.createArrayOfNxN(n); // createConstraintSet list of edges according the stops of trainlines edges = FloydWarshallUtil.createEdges(lines); // initialize all useful arrays by edges initializeArrays(edges); }
/// <summary> /// Optimizations by function - zig zag by stages. /// </summary> /// <param name="edges">The edges.</param> /// <param name="edgesCache">The edges cache.</param> /// <returns></returns> private static List <Edge> optimizationFunctionZigZagByStages(List <Edge> edges, List <Edge> edgesCache) { List <Edge> newEdges = new List <Edge>(); // loop over all edges with index for (int i = 0; i < edges.Count; i++) { // define last index int last = edges.Count - 1; // find last edges where the line is the same while (i < last) { // if edges on the last current index has the same line if (edges[last].Line.Equals(edges[i].Line)) { break; } last--; } // if there is path > 1 if ((last - i) > 1) { // between thouse indices replace edges for List <Edge> alternative = FloydWarshallUtil.createEdges(TrainLineCache.getInstance().getCacheContentOnNumber(edges[i].Line), edges[i].From, edges[last].To); // add alternative path instead newEdges.AddRange(alternative); // index += path i = last; } else { // add original edge newEdges.Add(edges[i]); // index ++, in for loop } } return(newEdges); }