private void addConnectedLine()
        {
            FormAddLinesDialog formAddLinesDialog = new FormAddLinesDialog(trainLine, listViewListOfConnectedLines.Items);
            DialogResult       dr = formAddLinesDialog.ShowDialog();

            // if the dialog was closed by Button OK
            if (dr.Equals(DialogResult.OK))
            {
                // prevent off method draw
                listViewListOfConnectedLines.BeginUpdate();

                // if something was selected
                if (!formAddLinesDialog.AddedLines.Count.Equals(0))
                {
                    // addConstraint new connected lines
                    foreach (ListViewItem lvi in formAddLinesDialog.AddedLines)
                    {
                        ListViewItem lviClone = (ListViewItem)lvi.Clone();
                        listViewListOfConnectedLines.Items.Add(lviClone);

                        // The line that is already in the list can not be selected, so we can not store the same line twice.
                        connectedLinesLocal.Add(TrainLineCache.getInstance().getCacheContentOnNumber(Convert.ToInt32(lviClone.Tag)));
                    }
                }
                listViewListOfConnectedLines.EndUpdate();
            }
        }
        private void prepareListViewListOfStations(int lineNumber)
        {
            // get trainLine1 on lineNumber
            TrainLine trainLine = TrainLineCache.getInstance().getCacheContentOnNumber(lineNumber);
            // get trainStop of line_
            List <TrainStop> stops = trainLine.getTrainStops();

            // starting update list, protected before method Draw
            listViewListOfStations.BeginUpdate();
            // clearStableLines previous list's items
            listViewListOfStations.Items.Clear();
            // and prepare new list view accordind trainStops of line_
            foreach (TrainStop stop in stops)
            {
                // get station of stop
                TrainStation station = stop.TrainStation;

                ListViewItem lvi = new ListViewItem();
                // fill item with throughStation's information
                lvi.Text = station.Id.ToString();
                lvi.Tag  = station.Id.ToString();

                lvi.SubItems.Add(station.Name);
                lvi.SubItems.Add(station.TownCategory.ToString());
                lvi.SubItems.Add(station.Inhabitation.ToString());
                lvi.SubItems.Add(station.Town);

                // addConstraint item into the list
                listViewListOfStations.Items.Add(lvi);
            }
            // release list view
            listViewListOfStations.EndUpdate();
        }
        private void detailsLineOpen()
        {
            // if nothing selected
            if (listViewListOfLines.SelectedItems.Count.Equals(0))
            {
                MessageBox.Show("Please, select the line_.", "No line_ selected");
            }
            // if selected
            else
            {
                Form formLineDetails = new FormDetailsOfLine(
                    TrainLineCache.getInstance().getCacheContentOnNumber(
                        Convert.ToInt32(
                            listViewListOfLines
                            .SelectedItems[0]
                            .Text
                            )
                        )
                    );

                // before calling subform - remember listView focus
                int selectedIndex = listViewListOfLines.SelectedIndices[0];

                DialogResult dr = formLineDetails.ShowDialog();
                if (dr.Equals(DialogResult.OK))
                {
                    // update list view
                    prepareListViewListOfLines();
                    // refresh selection and focus on selected item
                    FormUtil.listView_SelecdAndFocus(listViewListOfLines, selectedIndex);
                }
            }
        }
        private void prepareListViewListOfLines()
        {
            // load line_'s cache
            List <TrainLine> listLines = TrainLineCache.getInstance().getCacheContent();


            // starting update list, protected before draw method
            listViewListOfLines.BeginUpdate();
            // clearStableLines previous list of items
            listViewListOfLines.Items.Clear();

            // and prepare new list view according line_'s cahe
            foreach (TrainLine line in listLines)
            {
                ListViewItem lvi = new ListViewItem();
                // fill item with line_'s information
                lvi.Text = line.LineNumber.ToString();
                lvi.Tag  = line.LineNumber.ToString();

                //ListViewItem.ListViewSubItem lvsi = new ListViewItem.ListViewSubItem();
                //lvsi.Text = line_.TypeTrain.ToString();
                lvi.SubItems.Add(line.TypeTrain.ToString());
                lvi.SubItems.Add(line.Period.ToString());
                lvi.SubItems.Add(line.getFirstTrainStop().TrainStation.Name);
                lvi.SubItems.Add(line.getLastTrainStop().TrainStation.Name);

                listViewListOfLines.Items.Add(lvi);
            }
            // release list of items
            listViewListOfLines.EndUpdate();
        }
        /// <summary>
        /// Creates the train line variables independent on solution.
        /// </summary>
        /// <param name="solution">The solution.</param>
        /// <param name="trainLineMap">The train line map.</param>
        /// <returns>Train line variables.</returns>
        private static List <TrainLineVariable> createTrainLineVariablesIndependentOnSolution(Solution solution, List <TrainLine> trainLineMap)
        {
            // retreive all lines from train line cache
            List <TrainLine> allLines = TrainLineCache.getInstance().getCacheContent();
            // new train lines variable
            List <TrainLineVariable> trainLineVariables = new List <TrainLineVariable>();

            // if not all lines already contained, otherwise return
            if (allLines.Count != trainLineMap.Count)
            {
                foreach (TrainLine line in allLines)
                {
                    // if line is not contained in trian line map
                    if (!containsTrainLine(trainLineMap, line))
                    {
                        // create new line of timetable
                        TrainLineVariable tlv = new TrainLineVariable(line);
                        // set independent start time
                        tlv.StartTime = Time.MinValue;
                        // add
                        trainLineVariables.Add(tlv);
                    }
                }
            }

            return(trainLineVariables);
        }
Пример #6
0
        /// <summary>
        /// Function generates variableLines of connetcion according of edges of path.
        /// New line_ is added, when previous edge has different line_ number.
        ///
        /// Static funtion may be called don't change instance of TrainConnection.
        /// </summary>
        /// <param name="edges"></param>
        /// <returns></returns>
        public static List <TrainLine> generateLinesOfConnection(List <Edge> edges)
        {
            List <TrainLine> lines = new List <TrainLine>();
            TrainLine        line  = null;
            // variable for remembering previous edge
            Edge previousEdge = null;

            // loop over all edges in path
            foreach (Edge edge in edges)
            {
                // if no previous edge exists then addConstraint first line_ and continue
                if (previousEdge == null)
                {
                    line = TrainLineCache.getInstance().getCacheContentOnNumber(edge.Line);
                    lines.Add(line);
                    previousEdge = edge;
                    continue;
                }
                // if previous edge of path has a different line_ number,
                if (!previousEdge.Line.Equals(edge.Line))
                {
                    line = TrainLineCache.getInstance().getCacheContentOnNumber(edge.Line);
                    lines.Add(line);
                    previousEdge = edge;
                }
            }
            // if path has no variableLines return null
            // if (variableLines.Count.Equals(0)) variableLines = null;

            return(lines);
        }
        private void buttonEvaluateOriginalTimetable_Click(object sender, EventArgs e)
        {
            Timetable      tt   = TimetableUtil.constructOriginalTimetable(TrainLineCache.getInstance().getCacheContent());
            FormTimetables form = new FormTimetables(new DummyAlgorithm(tt));

            form.generateTimetables();
            form.Show();
        }
Пример #8
0
 /// <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);
 }
Пример #9
0
        /// <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);
        }
        //--------------------------------------------
        // create TrainLines
        //--------------------------------------------

        private void createTrainLinesFromFiles()
        {
            // clearStableLines variableLines off previous run
            TrainLineCache.getInstance().clearContent();
            // clearStableLines station off previous run
            TrainStationCache.getInstance().clearContent();

            TrainLineCache lineCache = TrainLineCache.getInstance();

            foreach (ListViewItem lvi in listViewLoadFiles.Items)
            {
                TrainLine line = IOUtil.readTrainLineFromFile(lvi.Tag.ToString());
                // test if already exists
                if (TrainLineCache.getInstance().doesLineExist(line.LineNumber))
                {
                }
                else
                {
                    lineCache.addTrainLine(line);
                }
            }
        }
Пример #11
0
        /// <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);
        }
        /// <summary>
        /// Creates the components.
        /// </summary>
        /// <param name="listOfStrings">The list of strings.</param>
        /// <returns>The components</returns>
        private static List <HashSet <TrainLine> > createComponents(List <String[]> listOfStrings)
        {
            // create list of components
            List <HashSet <TrainLine> > components = new List <HashSet <TrainLine> >();


            // loop over all pair
            foreach (String[] strings in listOfStrings)
            {
                // if is not pair, continue
                if (!strings.Length.Equals(2))
                {
                    continue;
                }

                TrainLine item1 = TrainLineCache.getInstance().getCacheContentOnNumber(Convert.ToInt32(strings[0]));
                TrainLine item2 = TrainLineCache.getInstance().getCacheContentOnNumber(Convert.ToInt32(strings[1]));

                // both lines must exist
                if (item1 == null || item2 == null)
                {
                    continue;
                }

                // set single components
                HashSet <TrainLine> component1 = new HashSet <TrainLine>();
                component1.Add(item1);
                HashSet <TrainLine> component2 = new HashSet <TrainLine>();
                component2.Add(item2);

                int foundBoth = 0;
                // find components
                foreach (HashSet <TrainLine> component in components)
                {
                    // find first component
                    if (component.Contains(item1))
                    {
                        component1 = component;
                        foundBoth++;
                    }
                    // find second component
                    if (component.Contains(item2))
                    {
                        component2 = component;
                        foundBoth++;
                    }
                    if (foundBoth == 2)
                    {
                        break;
                    }
                }

                // no compomenets exist, add first as the only one
                if (foundBoth == 0)
                {
                    components.Add(component1);
                }

                // if different, mergde them
                if (component1 != component2)
                {
                    // remove 2nd
                    components.Remove(component2);
                    component1.UnionWith(component2);
                }
            }
            return(components);
        }
 /// <summary>
 /// Sets the default values for fields.
 /// </summary>
 private void setDefaultValues()
 {
     this.Timetables    = new List <Timetable>();
     this.TrainLines    = TrainLineCache.getInstance().getCacheContent();
     this.TrainStations = TrainStationCache.getInstance().getCacheContent();
 }