Ejemplo n.º 1
0
        void RefreshRoutes()
        {
            _routesDTO = _routeController.GetAllRoutes();
            listRoute.Items.Clear();

            int ordin = 1;

            foreach (var route in _routesDTO.Routes)
            {
                string name = string.Format("{0} {1}, {2} {3} - {4} {5} ({6})",
                                            route.CreationDateTime.ToShortDateString(),
                                            route.CreationDateTime.ToShortTimeString(),
                                            route.Employee.Name,
                                            route.Employee.Surname,
                                            route.Vehicle.Brand,
                                            route.Vehicle.Model,
                                            route.Vehicle.Registration
                                            );
                ListViewItem item = new ListViewItem(new string[] { (ordin++).ToString(), name });
                item.Tag = route.Id;
                listRoute.Items.Add(item);
            }

            labelRouteCounter.Text = (ordin - 1).ToString();
        }
Ejemplo n.º 2
0
        private RoutesDTO AfterCalculateShortestPath(NodeGraphDTO nodeCon)
        {
            if (nodeCon == null)
            {
                return(null);
            }

            NodeGraphDTO node = nodeCon;
            LinkedList <NodeLocationDTO> nodeRoute = new LinkedList <NodeLocationDTO>();

            while (node != null)
            {
                nodeRoute.AddLast(new NodeLocationDTO()
                {
                    Lat = node.Node.Lat,
                    Lon = node.Node.Lon
                });
                node = node.PreviousNode;
            }

            RouteDTO route = new RouteDTO()
            {
                PocetHranCesty            = nodeRoute.Count - 1,
                PocetSpracovanychVrcholov = Utils.PocetSpracovanychVrcholov,
                DlzkaCesty = Math.Round(nodeCon.CurrentDistance, 5),
                CasVypoctu = Math.Round(time.TotalMilliseconds, 5),
                Nodes      = nodeRoute
            };

            RoutesDTO routes = new RoutesDTO();

            routes.Route.AddLast(route);
            return(routes);
        }
Ejemplo n.º 3
0
        private void btnApply_Click(object sender, EventArgs e)
        {
            RoutesDTO           route           = new RoutesDTO();
            ScheduleManagersDTO scheduleManager = new ScheduleManagersDTO();
            string order;

            route.ArrivalAirportID   = cbbFrom.SelectedValue.ToString();
            route.DepartureAirportID = cbbTo.SelectedValue.ToString();
            if (cbbSortBy.SelectedItem.ToString() == "Price")
            {
                order = "EconomyPrice";
            }
            else if (cbbSortBy.SelectedItem.ToString() == "Confirmed")
            {
                order = "Confirmed";
            }
            else
            {
                order = "DateFlight";
            }
            dtpOutbound.CustomFormat     = "dd/MM/yyyy";
            scheduleManager.Date         = dtpOutbound.Value;
            scheduleManager.FlightNumber = txtFlightNumber.Text;

            if (cbbFrom.SelectedValue.Equals(cbbTo.SelectedValue))
            {
                MessageBox.Show("Sân bay đi và Sân bay đến không được trùng nhau");
            }
            else
            {
                schedules = schedulesBUL.search(scheduleManager, route, order);
                this.loadData();
            }
        }
Ejemplo n.º 4
0
        private void buttonShowRoute_Click(object sender, EventArgs e)
        {
            if (listRoute.SelectedIndices.Count == 0)
            {
                return;
            }

            int       routeId  = (int)listRoute.Items[listRoute.SelectedIndices[0]].Tag;
            RoutesDTO routeDto = _routeController.GetRouteById(routeId);;

            _routeView.route = routeDto.Routes.First();
            _routeView.ShowDialog();
        }
Ejemplo n.º 5
0
        public RoutesDTO DuplexDijksterDisabled(string startLatLon, string endLatLon)
        {
            KeyValuePair <NodeGraphDTO, NodeGraphDTO> nodes = BeforeCalculateDisabledShortestPath(startLatLon, endLatLon);

            PrepareData.PutStartEnd(nodes.Key, nodes.Value);
            var          watch = Stopwatch.StartNew();
            NodeGraphDTO node  = duplexDijkster.CalculateShortestPath(nodes.Key, nodes.Value);

            watch.Stop();
            time = watch.Elapsed;
            RoutesDTO routes = AfterCalculateShortestPathDuplex(node);

            PrepareData.RemoveStartEnd(nodes.Key, nodes.Value);
            return(routes);
        }
Ejemplo n.º 6
0
        public RoutesDTO MultiLabelDIsabled(string startLatLon, string endLatLon, string k)
        {
            KeyValuePair <NodeGraphDTO, NodeGraphDTO> nodes = BeforeCalculateDisabledShortestPath(startLatLon, endLatLon);

            PrepareData.PutStartEnd(nodes.Key, nodes.Value);
            multiLabel.K = Int32.Parse(k);
            var          watch = Stopwatch.StartNew();
            NodeGraphDTO node  = multiLabel.CalculateShortestPath(nodes.Key, nodes.Value);

            watch.Stop();
            time = watch.Elapsed;
            RoutesDTO routes = AfterCalculateShortestPathMultiLabel(node);

            PrepareData.RemoveStartEnd(nodes.Key, nodes.Value);
            return(routes);
        }
Ejemplo n.º 7
0
        private void btnUpdate_Click(object sender, EventArgs e)
        {
            string from = cbbFrom.Text;
            string to   = cbbTo.Text;

            if (from == to)
            {
                MessageBox.Show("Sân bay đi và Sân bay đên không được trùng nhau, mời bạn chọn lại");
                return;
            }

            AircraftDTO aircraft = new AircraftDTO();

            aircraft.AircraftName = txtAircraft.Text;
            aircraft.AircraftID   = scheduleManager.AircraftID;

            RoutesDTO route = new RoutesDTO();

            route.ArrivalAirportID   = airportsFrom.ElementAt(cbbFrom.SelectedIndex).AirportID;
            route.DepartureAirportID = airportsTo.ElementAt(cbbTo.SelectedIndex).AirportID;
            route.RouteID            = scheduleManager.RoutesID;

            SchedulesDTO schedule = new SchedulesDTO();

            schedule.Date         = dtpDate.Value.ToString();
            schedule.Time         = dtpTime.Value.ToString();
            schedule.EconomyPrice = float.Parse(txtEconomyPrice.Text);
            schedule.ScheduleID   = scheduleManager.SchedulesID;

            try
            {
                aircraftsBUL.update(aircraft);
                routesBUL.update(route);
                schedulesBUL.update(schedule);
                MessageBox.Show("Cập nhật thành công");
            } catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }

            this.Close();
            frmMain frm = new frmMain();

            frm.Show();
        }
Ejemplo n.º 8
0
 public void update(RoutesDTO route)
 {
     try
     {
         conn.Open();
         string     sql = "update Routes set DepartureAirportID = @from, ArrivalAirportID = @to where RouteID = @id ";
         SqlCommand cmd = new SqlCommand(sql, conn);
         cmd.Parameters.AddWithValue("from", route.DepartureAirportID);
         cmd.Parameters.AddWithValue("to", route.ArrivalAirportID);
         cmd.Parameters.AddWithValue("id", route.RouteID);
         cmd.ExecuteNonQuery();
         conn.Close();
     }
     catch (Exception e)
     {
         MessageBox.Show(e.ToString());
         conn.Close();
     }
 }
Ejemplo n.º 9
0
        private RoutesDTO AfterCalculateShortestPathMultiLabel(NodeGraphDTO nodeCon)
        {
            if (nodeCon == null)
            {
                return(null);
            }

            RoutesDTO routes = new RoutesDTO();

            foreach (MultiLabelMark n in nodeCon.MultiLabelMark)
            {
                int          k     = n.K;
                int          xk    = k;
                NodeGraphDTO node  = nodeCon;
                RouteDTO     route = null;
                LinkedList <NodeLocationDTO> nodeRoute = new LinkedList <NodeLocationDTO>();
                while (xk != 0)
                {
                    nodeRoute.AddLast(new NodeLocationDTO()
                    {
                        Lat = node.Node.Lat,
                        Lon = node.Node.Lon
                    });
                    xk   = node.MultiLabelMark[k - 1].Xk;
                    node = node.MultiLabelMark[k - 1].X;
                    k    = xk;
                }

                route = new RouteDTO()
                {
                    PocetHranCesty            = nodeRoute.Count - 1,
                    PocetSpracovanychVrcholov = Utils.PocetSpracovanychVrcholov,
                    DlzkaCesty = Math.Round(nodeCon.MultiLabelMark[n.K - 1].T, 5),
                    CasVypoctu = Math.Round(time.TotalMilliseconds, 5),
                    Nodes      = nodeRoute
                };
                routes.Route.AddLast(route);
            }
            return(routes);
        }
Ejemplo n.º 10
0
        public RoutesDTO GetRouteById(int id)
        {
            RoutesDTO dto;

            try
            {
                var route = _routeService.GetRouteByID(id);
                dto = new RoutesDTO
                {
                    Routes = new [] { route },
                    Status = route == default(Route) ? Enums.CollectionGetStatus.Empty : Enums.CollectionGetStatus.Success
                };
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);

                dto = new RoutesDTO
                {
                    Status = Enums.CollectionGetStatus.Failure
                };
            }
            return(dto);
        }
Ejemplo n.º 11
0
        public RoutesDTO GetAllRoutes()
        {
            RoutesDTO dto;

            try
            {
                var routes = _routeService.GetAllRoutes();
                dto = new RoutesDTO
                {
                    Routes = routes,
                    Status = routes.Length == 0 ? Enums.CollectionGetStatus.Empty : Enums.CollectionGetStatus.Success
                };
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);

                dto = new RoutesDTO
                {
                    Status = Enums.CollectionGetStatus.Failure
                };
            }
            return(dto);
        }
Ejemplo n.º 12
0
        public List <List <int> > importSchedule(String[][] data)
        {
            // tạo ra các danh sách status khi import.
            // mỗi ds status bao gồm: phần tử đầu tiên là status, các phần tử còn lại là dòng trong excel ứng vs mỗi status
            List <int> success = new List <int> {
                1
            };
            List <int> duplicate = new List <int> {
                0
            };
            List <int> recordMissing = new List <int> {
                -1
            };
            List <int> aircraftInvalid = new List <int> {
                -2
            };
            List <int> routesInvalid = new List <int> {
                -3
            };
            List <int> recordNotFound = new List <int> {
                -4
            };
            List <List <int> > statusImport = new List <List <int> >();   // trả về 1 danh sách bao gồm các danh sách status

            for (int i = 0; i < data.Length; i++)
            {
                bool isContinue = false;
                for (int j = 0; j < data[i].Length; j++)
                {
                    if (data[i][j] == null)       // check thiếu dữ liệu
                    {
                        recordMissing.Add(i + 2); // thêm dòng excel bị lỗi. dữ liệu tính từ dòng thứ 2 trong excel => (+2)
                        isContinue = true;
                    }
                }
                if (isContinue)
                {
                    continue;
                }

                String operation    = data[i][0];
                String date         = data[i][1];
                String time         = data[i][2];
                String from         = data[i][3];
                String to           = data[i][4];
                String flightNumber = data[i][5];
                String aircraft     = data[i][6];
                float  economyPrice;
                try { economyPrice = float.Parse(data[i][7]); } catch { economyPrice = 0; };
                int confirmed = data[i][8].Equals("OK") ? 1 : 0;

                SchedulesDTO schedule   = schedulesDAL.getSchedule(flightNumber, date);
                String       aircraftID = aircraftDAL.getAircraftID(aircraft);
                String       routesID   = routesDAL.getRoutesID(from, to);

                if (operation.Equals("ADD"))
                {
                    if (schedule.ScheduleID != null)  // check trùng bản ghi dựa vào flightNumber & date
                    {
                        duplicate.Add(i + 2);
                        continue;
                    }
                    else
                    {
                        if (aircraftID == null)  // check tồn tại Aircraft
                        {
                            aircraftInvalid.Add(i + 2);
                            continue;
                        }
                        else
                        {
                            if (routesID == null) // check tồn tại Routes
                            {
                                routesInvalid.Add(i + 2);
                                continue;
                            }
                            else // thêm thành công
                            {
                                String lastScheduleID = schedulesDAL.getLastID(); // lấy id của bản ghi cuối cùng
                                String id             = "S01";
                                if (lastScheduleID != null)
                                {
                                    id = (int.Parse(lastScheduleID.Substring(1)) + 1).ToString(); // tăng id lên 1
                                    id = "S" + id.PadLeft(2, '0');
                                }
                                schedule.ScheduleID   = id;
                                schedule.Date         = DateTime.Parse(date);
                                schedule.Time         = time;
                                schedule.RoutesID     = routesID;
                                schedule.AircraftID   = aircraftID;
                                schedule.FlightNumber = flightNumber;
                                schedule.EconomyPrice = economyPrice;
                                schedule.Confirmed    = confirmed;

                                schedulesDAL.create(schedule);
                                success.Add(i + 2);
                            }
                        }
                    }
                }
                if (operation.Equals("EDIT"))
                {
                    if (schedule.ScheduleID == null)  // check tồn tại ghi dựa vào flightNumber & date
                    {
                        recordNotFound.Add(i + 2);
                        continue;
                    }
                    else
                    {
                        if (aircraftID == null)  // check tồn tại Aircraft
                        {
                            aircraftInvalid.Add(i + 2);
                            continue;
                        }
                        else
                        {
                            String fromAirportID = airportsDAL.getByIATAcode(from);
                            String toAirportID   = airportsDAL.getByIATAcode(to);
                            if (fromAirportID == null || toAirportID == null)
                            {
                                routesInvalid.Add(i + 2);
                                continue;
                            }
                            else
                            {
                                schedule.ScheduleID   = schedule.ScheduleID;
                                schedule.Date         = DateTime.Parse(date);
                                schedule.Time         = time;
                                schedule.RoutesID     = routesID;
                                schedule.AircraftID   = aircraftID;
                                schedule.FlightNumber = flightNumber;
                                schedule.EconomyPrice = economyPrice;
                                schedule.Confirmed    = confirmed;
                                schedulesDAL.updateWhenImport(schedule);

                                RoutesDTO routes = new RoutesDTO();
                                routes.RoutesID           = schedule.RoutesID;
                                routes.DepartureAirportID = fromAirportID;
                                routes.ArrivalAirportID   = toAirportID;
                                routesDAL.update(routes);

                                success.Add(i + 2);
                            }
                        }
                    }
                }
            }
            statusImport.Add(success);
            statusImport.Add(duplicate);
            statusImport.Add(recordMissing);
            statusImport.Add(aircraftInvalid);
            statusImport.Add(routesInvalid);

            return(statusImport);
        }
Ejemplo n.º 13
0
 public List <ScheduleManagersDTO> search(ScheduleManagersDTO scheduleManager,
                                          RoutesDTO route, string order)
 {
     return(schedulesDAL.search(scheduleManager, route, order));
 }
Ejemplo n.º 14
0
        private void LogisticsNewRouteForm_Shown(object sender, EventArgs e)
        {
            comboBoxDriver.Items.Clear();
            comboBoxVehicle.Items.Clear();

            listViewWarehouseParcels.Items.Clear();
            listViewVehicleParcels.Items.Clear();

            // TODO: show error message when no vehicles etc. to not crash app

            Position courierPosition = _positionController.GetPositionByName("Kurier");

            currentWarehouse = _storePlaceController.GetAllWarehouses().StorePlaces[0];
            RoutesDTO       routes       = _routeController.GetAllRoutes();
            List <Vehicle>  vehiclesTemp = new List <Vehicle>();
            List <Employee> couriersTemp = new List <Employee>();

            vehicles = _vehicleController.GetAllVehicles();
            couriers = _employeeController.GetEmployeesByPositionId(courierPosition.Id);

            if (routes.Routes.Count() == 0)
            {
                foreach (var vehicle in vehicles.Vehicles)
                {
                    comboBoxVehicle.Items.Add(string.Format(
                                                  "{0} {1} ({2})", vehicle.Brand, vehicle.Model, vehicle.Registration
                                                  ));
                }

                foreach (var courier in couriers.Employees)
                {
                    comboBoxDriver.Items.Add(string.Format(
                                                 "{0} {1}", courier.Name, courier.Surname
                                                 ));
                }
            }

            else
            {
                foreach (var vehicle in vehicles.Vehicles)
                {
                    bool isFree = true;
                    foreach (var route in routes.Routes)
                    {
                        if (isFree && route.VehicleId == vehicle.Id)
                        {
                            foreach (var point in route.RoutePoints)
                            {
                                if (point.Parcel.ParcelStatus == Model.Enums.ParcelStatus.OnWayToTheCustomer)
                                {
                                    isFree = false;
                                    break;
                                }
                            }
                        }
                    }
                    if (isFree)
                    {
                        vehiclesTemp.Add(vehicle);
                    }
                }

                /*
                 * foreach (var item in routes.Routes)
                 * {
                 *
                 *  foreach (var vehicle in vehicles.Vehicles)
                 *  {
                 *      if (vehicle.Id != item.VehicleId)
                 *          vehiclesTemp.Add(vehicle);
                 *  }
                 * }
                 */

                if (vehiclesTemp.Count() == 0)
                {
                    MessageBox.Show("Za mała ilość danych w bazie. Brak pojazdów w danym magazynie.", "Błąd bazy danych", 0, MessageBoxIcon.Error);
                    this.Close();
                }
                else
                {
                    foreach (var vehicle in vehiclesTemp)
                    {
                        comboBoxVehicle.Items.Add(string.Format(
                                                      "{0} {1} ({2})", vehicle.Brand, vehicle.Model, vehicle.Registration
                                                      ));
                    }
                }


                foreach (var courier in couriers.Employees)
                {
                    bool isFree = true;
                    foreach (var route in routes.Routes)
                    {
                        if (isFree && route.EmployeeId == courier.Id)
                        {
                            foreach (var point in route.RoutePoints)
                            {
                                if (point.Parcel.ParcelStatus == Model.Enums.ParcelStatus.OnWayToTheCustomer)
                                {
                                    isFree = false;
                                    break;
                                }
                            }
                        }
                    }
                    if (isFree)
                    {
                        couriersTemp.Add(courier);
                    }
                }

                /*
                 * foreach (var item in routes.Routes)
                 * {
                 *  foreach (var courier in couriers.Employees)
                 *  {
                 *      if (courier.Id != item.EmployeeId)
                 *          couriersTemp.Add(courier);
                 *  }
                 * }
                 */
                if (couriersTemp.Count() == 0)
                {
                    MessageBox.Show("Za mała ilość danych w bazie. Brak pracowników na stanowisku kurier", "Błąd bazy danych", 0, MessageBoxIcon.Error);
                    this.Close();
                }
                else
                {
                    foreach (var courier in couriersTemp)
                    {
                        comboBoxDriver.Items.Add(string.Format(
                                                     "{0} {1}", courier.Name, courier.Surname
                                                     ));
                    }
                }
            }

            parcels = _parcelController.GetParcelsFromStorePlaceByStatus(currentWarehouse, Model.Enums.ParcelStatus.InWarehouse);
            if (parcels.Length == 0)
            {
                MessageBox.Show("Za mała ilość danych w bazie. Brak paczek do doręczenia", "Błąd bazy danych", 0, MessageBoxIcon.Error);
                this.Close();
            }
            else
            {
                foreach (var parcel in parcels)
                {
                    Address      addr        = parcel.ReceiverData.PersonalAddress;
                    string       addressText = string.Format("{0} {1}/{2}, {3}, {4}", addr.Street, addr.HomeNumber, addr.ApartmentNumber, addr.PostCode, addr.City);
                    int          weight      = (int)parcel.ParcelWeight;
                    int          volume      = (int)(parcel.ParcelLength * parcel.ParcelHeight * parcel.ParcelWidth);
                    ListViewItem item        = new ListViewItem(new string[] { "", addressText, weight.ToString(), volume.ToString() });
                    item.Tag = parcel.Id;
                    if (parcel.Priority > 0)
                    {
                        item.BackColor = Color.LightGoldenrodYellow;
                    }
                    listViewWarehouseParcels.Items.Add(item);
                }
            }

            ReordereOrdinNumbers(listViewWarehouseParcels);
            UpdateWeightVolumeInfo();
        }
Ejemplo n.º 15
0
        public List <ScheduleManagersDTO> search(ScheduleManagersDTO scheduleManager,
                                                 RoutesDTO route, string order)
        {
            // Tạo 1 biến danh sách ScheduleManagers để lưu trữ
            List <ScheduleManagersDTO> schedules = new List <ScheduleManagersDTO>();

            try
            {
                conn.Open();
                string sql = "select DateFlight, TimeFlight, fromAirport.IATAcode as frmAirIATACode, " +
                             "toAirport.IATAcode as toAirIATACode, FlightNumber, Aircrafts.AircraftID, " +
                             "EconomyPrice, Confirmed, Routes.RouteID, AircraftName, SchedulesID from Schedules " +
                             "join Routes on Schedules.RouteID=Routes.RouteID " +
                             "join Airports as fromAirport on Routes.ArrivalAirportID=fromAirport.AirportID " +
                             "join Airports as toAirport on Routes.DepartureAirportID=toAirport.AirportID " +
                             "join Aircrafts on Schedules.AircraftID=Aircrafts.AircraftID " +
                             "where Routes.ArrivalAirportID = @arrivalID " +
                             "OR Routes.DepartureAirportID = @departureID " +
                             "OR DateFlight = @outbound " +
                             "OR FlightNumber = @flightNumber " +
                             "ORDER BY " + order + " DESC";

                SqlCommand cmd = new SqlCommand(sql, conn);
                cmd.Parameters.AddWithValue("arrivalID", route.ArrivalAirportID);
                cmd.Parameters.AddWithValue("departureID", route.DepartureAirportID);
                cmd.Parameters.AddWithValue("outbound", scheduleManager.Date.ToString("yyyy-MM-dd"));
                cmd.Parameters.AddWithValue("flightNumber", scheduleManager.FlightNumber);


                SqlDataReader dr = cmd.ExecuteReader();

                while (dr.Read())
                {
                    float economyPrice    = float.Parse(dr["EconomyPrice"].ToString().Trim());
                    float bussinessPrice  = economyPrice * 35 / 100 + economyPrice;
                    float firstClassPrice = bussinessPrice * 30 / 100 + bussinessPrice;

                    ScheduleManagersDTO schedule = new ScheduleManagersDTO();
                    schedule.Date            = DateTime.Parse(dr["DateFlight"].ToString().Trim());
                    schedule.Time            = DateTime.Parse(dr["TimeFlight"].ToString().Trim());
                    schedule.From            = dr["frmAirIATACode"].ToString().Trim();
                    schedule.To              = dr["toAirIATACode"].ToString().Trim();
                    schedule.FlightNumber    = dr["FlightNumber"].ToString().Trim();
                    schedule.AircraftID      = dr["AircraftID"].ToString().Trim();
                    schedule.EconomyPrice    = economyPrice;
                    schedule.BusinessPrice   = bussinessPrice;
                    schedule.FirstClassPrice = firstClassPrice;
                    schedule.Confirmed       = int.Parse(dr["Confirmed"].ToString().Trim());
                    schedule.RoutesID        = dr["RouteID"].ToString().Trim();
                    schedule.AircraftName    = dr["AircraftName"].ToString().Trim();
                    schedule.SchedulesID     = dr["SchedulesID"].ToString().Trim();

                    schedules.Add(schedule);
                }
                conn.Close();
            }
            catch (Exception ex)
            {
                conn.Close();
                MessageBox.Show(ex.Message);
                return(null);
            }

            return(schedules);
        }
Ejemplo n.º 16
0
 public void update(RoutesDTO route)
 {
     routesDAL.update(route);
 }
Ejemplo n.º 17
0
        public void RouteUpdate(RoutesDTO routesDTO)
        {
            var updateRoutes = routes.GetAll().SingleOrDefault(c => c.Id == routesDTO.Id);

            routes.Update((mapper.Map <RoutesDTO, Routes>(routesDTO, updateRoutes)));
        }
Ejemplo n.º 18
0
        public int RouteCreate(RoutesDTO routesDTO)
        {
            var createRoute = routes.Create(mapper.Map <Routes>(routesDTO));

            return((int)createRoute.Id);
        }
Ejemplo n.º 19
0
        public ActionResult Statistics()
        {
            var statistic = new
            {
                GraphMemory         = Utils.GraphMemory,
                DisabledGraphMemory = Utils.DisabledGraphMemory,
                GraphTime           = Utils.GraphTime,
                DisabledGraphTime   = Utils.DisabledGraphTime,
                PocetVrcholov       = Utils.PocetVrcholov
            };
            int            opakovani  = 10;
            int            algoritmus = 0;
            TimeSpan       time;
            Zakladny       zakladny       = new Zakladny();
            Dijkster       dijkster       = new Dijkster();
            AStar          astar          = new AStar();
            LabelCorrect   labelCorrect   = new LabelCorrect();
            LabelSet       labelSet       = new LabelSet();
            DuplexDijkster duplexDijkster = new DuplexDijkster();
            var            watch          = Stopwatch.StartNew();
            Random         random         = new Random();

            NodeGraphDTO[]   startNodes = new NodeGraphDTO[opakovani];
            NodeGraphDTO[]   endNodes   = new NodeGraphDTO[opakovani];
            List <RoutesDTO> routesAll  = new List <RoutesDTO>(6);

            for (int i = 0; i < opakovani; i++)
            {
                startNodes[i] = PrepareData.NodesGraph.Values.ElementAt(random.Next(PrepareData.NodesGraph.Count));
                endNodes[i]   = PrepareData.NodesGraph.Values.ElementAt(random.Next(PrepareData.NodesGraph.Count));
            }

            for (int j = 0; j < 6; j++)
            {
                RoutesDTO routes = new RoutesDTO();
                for (int i = 0; i < opakovani; i++)
                {
                    PrepareData.PrepareNodesGraph();
                    switch (j)
                    {
                    case 0:
                        PrepareData.PutStartEnd(startNodes[i], endNodes[i]);
                        watch.Restart();
                        var n = zakladny.CalculateShortestPath(startNodes[i], endNodes[i], PrepareData.DisabledMovementGraph);
                        watch.Stop();
                        time = watch.Elapsed;
                        AfterCalculateShortestPath(n, time, routes);
                        PrepareData.RemoveStartEnd(startNodes[i], endNodes[i]);
                        break;

                    case 1:
                        PrepareData.PutStartEnd(startNodes[i], endNodes[i]);
                        watch.Restart();
                        n = dijkster.CalculateShortestPath(startNodes[i], endNodes[i]);
                        watch.Stop();
                        time = watch.Elapsed;
                        AfterCalculateShortestPath(n, time, routes);
                        PrepareData.RemoveStartEnd(startNodes[i], endNodes[i]);
                        break;

                    case 2:
                        PrepareData.PutStartEnd(startNodes[i], endNodes[i]);
                        watch.Restart();
                        n = astar.CalculateShortestPath(startNodes[i], endNodes[i]);
                        watch.Stop();
                        time = watch.Elapsed;
                        var a = routes.Route.Last;
                        AfterCalculateShortestPath(n, time, routes);
                        PrepareData.RemoveStartEnd(startNodes[i], endNodes[i]);
                        break;

                    case 3:
                        PrepareData.PutStartEnd(startNodes[i], endNodes[i]);
                        watch.Restart();
                        n = labelSet.CalculateShortestPath(startNodes[i], endNodes[i]);
                        watch.Stop();
                        time = watch.Elapsed;
                        AfterCalculateShortestPath(n, time, routes);
                        PrepareData.RemoveStartEnd(startNodes[i], endNodes[i]);
                        break;

                    case 4:
                        PrepareData.PutStartEnd(startNodes[i], endNodes[i]);
                        watch.Restart();
                        n = labelCorrect.CalculateShortestPath(startNodes[i], endNodes[i]);
                        watch.Stop();
                        time = watch.Elapsed;
                        AfterCalculateShortestPath(n, time, routes);
                        PrepareData.RemoveStartEnd(startNodes[i], endNodes[i]);
                        break;

                    case 5:
                        PrepareData.PutStartEnd(startNodes[i], endNodes[i]);
                        watch.Restart();
                        n = duplexDijkster.CalculateShortestPath(startNodes[i], endNodes[i]);
                        watch.Stop();
                        time = watch.Elapsed;
                        AfterCalculateShortestPathDuplex(n, time, routes);
                        PrepareData.RemoveStartEnd(startNodes[i], endNodes[i]);
                        break;
                    }
                }
                routesAll.Add(routes);
            }

            double[] PocetHranCesty            = new double[6];
            double[] PocetSpracovanychVrcholov = new double[6];
            double[] DlzkaCesty = new double[6];
            double[] CasVypoctu = new double[6];
            algoritmus = 0;
            foreach (RoutesDTO r in routesAll)
            {
                opakovani = r.Route.Count == 0 ? opakovani : r.Route.Count;
                long   PocetHranCestyA            = 0;
                long   PocetSpracovanychVrcholovA = 0;
                double DlzkaCestyA = 0;
                double CasVypoctuA = 0;
                foreach (RouteDTO route in r.Route)
                {
                    PocetHranCestyA            += route.PocetHranCesty;
                    PocetSpracovanychVrcholovA += route.PocetSpracovanychVrcholov;
                    DlzkaCestyA += route.DlzkaCesty;
                    CasVypoctuA += route.CasVypoctu;
                }
                PocetHranCesty[algoritmus]            = (double)PocetHranCestyA / opakovani;
                PocetSpracovanychVrcholov[algoritmus] = (double)PocetSpracovanychVrcholovA / opakovani;
                DlzkaCesty[algoritmus] = DlzkaCestyA / opakovani;
                CasVypoctu[algoritmus] = CasVypoctuA / opakovani;
                algoritmus++;
            }
            return(Json(statistic));
        }
Ejemplo n.º 20
0
        private void AfterCalculateShortestPathDuplex(NodeGraphDTO nodeCon, TimeSpan time, RoutesDTO routes)
        {
            if (nodeCon == null)
            {
                return;
            }

            NodeGraphDTO node = nodeCon;
            LinkedList <NodeLocationDTO> nodeRoute = new LinkedList <NodeLocationDTO>();

            while (node != null)
            {
                nodeRoute.AddLast(new NodeLocationDTO()
                {
                    Lat = node.Node.Lat,
                    Lon = node.Node.Lon
                });
                node = node.PreviousNode;
            }

            node = nodeCon != null ? nodeCon.PreviousNodeR : null;
            while (node != null)
            {
                nodeRoute.AddFirst(new NodeLocationDTO()
                {
                    Lat = node.Node.Lat,
                    Lon = node.Node.Lon
                });
                node = node.PreviousNodeR;
            }

            RouteDTO route = new RouteDTO()
            {
                PocetHranCesty            = nodeRoute.Count - 1,
                PocetSpracovanychVrcholov = Utils.PocetSpracovanychVrcholov,
                DlzkaCesty = nodeCon.CurrentDistance / 1000,
                CasVypoctu = time.TotalMilliseconds
            };

            routes.Route.AddLast(route);
        }