/****************************************/ // TrainConnections' related methods /****************************************/ /// <summary> /// Funtion creates trainConnecion off path of (optimalized) edges. /// </summary> /// <param name="edges"></param> /// <returns></returns> public static TrainConnection createTrainConnection(List <Edge> edges) { // if there is path with length 0 or list of edges doesn't exist if (edges.Count.Equals(0) || edges.Equals(null)) { return(null); } // determine start and destination station TrainStation from = edges[0].FromStation; TrainStation to = edges[edges.Count - 1].ToStation; // createConstraintSet new connection with start and destination stattion, and path of edges TrainConnection connection = new TrainConnection(from, to, edges); // randomizeTimetable changing station and set them in connection connection.setChangingStation(TrainConnection.generateChangingStation(edges)); // randomizeTimetable variableLines of connection and set them in connection connection.setLinesOfConnection(TrainConnection.generateLinesOfConnection(edges)); // calculate other variabiles connection.calculateDistance(); connection.calculatePassengers(); connection.calculateTime(); return(connection); }
private void detailsOfConnectionOpen() { // if nothing selected if (listViewListOfConnections.SelectedItems.Count.Equals(0)) { MessageBox.Show("Please, select the connection.", "No connection selected"); } // if selected else { TrainConnection connection = ShortestPathAlgoritm.getInstance().getTrainConnectionOnFromTo( listViewListOfConnections.SelectedItems[0].Text, listViewListOfConnections.SelectedItems[0].SubItems[1].Text); FormDetailsOfConnection formDetailsOfConnection = new FormDetailsOfConnection(connection); // before calling subform - remember listView focus int selectedIndex = listViewListOfConnections.SelectedIndices[0]; DialogResult dr = formDetailsOfConnection.ShowDialog(); if (dr.Equals(DialogResult.OK)) { // update list view prepareListViewListOfConnections(); // refresh selection and focus on selected item FormUtil.listView_SelecdAndFocus(listViewListOfConnections, selectedIndex); } } }
//----------------------------------------------------- // Methods generating STAGES based on CONNECTION //----------------------------------------------------- /// <summary> /// Function generates and returns all stages existed at trainConnection. /// </summary> /// <param name="connection"></param> /// <returns></returns> public static List <Stage> generateStages(TrainConnection connection) { List <Stage> stages = new List <Stage>(); TrainStation from = connection.FromStation; // randomizeTimetable changing station according edges List <TrainStation> changingStation = TrainConnection.generateChangingStation(connection.getEdges()); // loop over all changing station at connection foreach (TrainStation station in changingStation) { // randomizeTimetable connection Stage stage = generateStage(connection.getEdges(), from, station); // if exists, then addConstraint if (stage != null) { stages.Add(stage); } // set up actual toStation as a fromStation for next loop from = station; } // randomizeTimetable last stage Stage lastStage = generateStage(connection.getEdges(), from, connection.ToStation); // if exists, then addConstraint last stage if (lastStage != null) { stages.Add(lastStage); } return(stages); }
/// <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> /// Initializes a new instance of the <see cref="Stage"/> class. /// </summary> /// <param name="edges_">The list of edges.</param> public Stage(List <Edge> edges_) { edges = edges_; line = TrainLineCache.getInstance().getCacheContentOnNumber(edges[0].Line); fromStation = edges[0].FromStation; toStation = edges[edges.Count - 1].ToStation; time = TrainConnection.calculateTime(edges); distance = TrainConnection.calculateDistance(edges); }
/// <summary> /// Method addConstraint new connection to cache. /// </summary> /// <param name="connection"></param> public void addTrainConnection(TrainConnection connection) { // test if connection off to already exits if (!doesConnectionExist(connection.FromStation, connection.ToStation)) { // if no, then addConstraint trainConnections.Add(connection); } }
/// <summary> /// Function finds connection between station names off and to. /// </summary> /// <param name="off"></param> /// <param name="to"></param> /// <returns></returns> private TrainConnection findConnection(String from, String to) { TrainConnection connection = null; foreach (TrainConnection c in trainConnections) { if (c.FromStation.Name.Equals(from) && c.ToStation.Name.Equals(to)) { connection = c; break; } } return(connection); }
private void editPathConnectionOpen() { // if nothing selected if (listViewListOfConnections.SelectedItems.Count.Equals(0)) { MessageBox.Show("Please, select the connection", "No connection selected"); } // if selected else { TrainConnection connection = ShortestPathAlgoritm.getInstance().getTrainConnectionOnFromTo( listViewListOfConnections.SelectedItems[0].Text, listViewListOfConnections.SelectedItems[0].SubItems[1].Text); FormEditPathOfConnection editPathConnection = new FormEditPathOfConnection(connection); // before calling subform - remember listView focus int selectedIndex = listViewListOfConnections.SelectedIndices[0]; // open subform as a dialog DialogResult dr = editPathConnection.ShowDialog(); // if the dialog was closed by button OK if (dr.Equals(DialogResult.OK)) { // and if there are new valid stages List <Stage> newStages = editPathConnection.NewStages; if (newStages != null) { // set new stages connection.setStages(newStages); connection.updateGeneratedValues(); // refresh ListView prepareListViewListOfConnections(); // refresh selection and focus on selected item FormUtil.listView_SelecdAndFocus(listViewListOfConnections, selectedIndex); } } } }
/// <summary> /// Generates all train connections. /// </summary> public void generateAllTrainConnections() { // clearStableLines train connection off previous run trainConnections.Clear(); // retreive all paths off field stationXstation List <List <Edge> > allPaths = floydWarshalAlgorithm.getAllPaths(); printToFile(allPaths, "path.tmp"); List <Edge> otpimizedPath; // loop over all path foreach (List <Edge> path in allPaths) { //TrainConnection fictive = new TrainConnection(path); //Console.Out.WriteLine("---------------------------------"); //Console.Out.WriteLine("before: "+ fictive.LinesOfConnection); // town to town optimization, starts end ends in the same town if (path[0].FromStation.Town != null && path[path.Count - 1].ToStation.Town != null && path[0].FromStation.Town.Equals(path[path.Count - 1].ToStation.Town)) { // dont consider this connection continue; } // optimse path otpimizedPath = optimisePath(path, floydWarshalAlgorithm.getEdgesCache()); // createConstraintSet train connection TrainConnection connection = new TrainConnection(otpimizedPath); //Console.Out.WriteLine("after: " +connection.LinesOfConnection); trainConnections.Add(connection); } }
public static int generatePassengers(TrainConnection connection) { return(evaluateNewtonFormula(connection.FromStation.Inhabitation, connection.ToStation.Inhabitation, connection.Time)); }
public void addTrainConnection(TrainConnection connection) { throw new System.NotImplementedException(); }
public static List <Stage> generateStages(TrainConnection connection) { return(StageUtil.generateStages(connection)); }