Ejemplo n.º 1
0
 public static void DeaktiverBy(by by)
 {
     by.Active = false;
     using (var context = new OADbContext())
     {
          context.by.AddOrUpdate(by);
          context.SaveChanges();
     }
 }
Ejemplo n.º 2
0
 public IEnumerable<Route> GetRoutes(by by, pakke pakke)
 {
     var result = new List<Route>();
     foreach (var externalServicesApi in _externalApis)
     {
         result.AddRange(externalServicesApi.GetRoute(by, pakke));
     }
     return result;
 }
Ejemplo n.º 3
0
        public Node CalculateRouteTime(by source, by target, IList<IExternalServicesApi> externalServicesApis, pakke sendtPakke, float multiplier)
        {
            _externalServicesApis = externalServicesApis;
            _byliste = DataManager.HentAktiveredeByer().ToList();
            foreach (var externalServicesApi in externalServicesApis)
            {
                _byliste.AddRange(externalServicesApi.GetCities().Select(e => _byliste.FirstOrDefault(p => p != null && p.CityId == e.CityId) == null ? e : null));
            }

            _byliste.RemoveAll(p => p == null);

            var result = Dijstra(source, target, Politik.Tid, sendtPakke, multiplier);
            return result;
        }
Ejemplo n.º 4
0
        public Tuple<CalculationManager.Node, long> CalculateRouteWeight(by fra, by til, int height, int depth, int width, int weight, List<long> pakkeTypeId)
        {
            var pakke = new pakke
            {
                SizeDepth = depth,
                SizeHight = height,
                SizeWidth = width,
                Weight = weight
            };

            var result = _calculationManager.CalculateRouteWeight(fra, til, _externalApis, pakke, DataManager.HentPakkeType(pakkeTypeId));
            long forsendelsesId = SaveRoute(result, new forsendelse(), pakke);
            return new Tuple<CalculationManager.Node, long> (result, forsendelsesId);
        }
Ejemplo n.º 5
0
        public override IEnumerable<Route> GetRoute(by by, pakke pakke)
        {
            var result = new List<Route>()
            {
                new Route()
                {
                    Pris = 20,
                    Rute = new rute()
                    {
                        EndCity = 1,
                        StartCity = 3,
                        Id = 5,
                        Time = 5000
                    },
                    TransportType = TransportType.TELSTAR
                },
                new Route()
                {
                    Pris = 20,
                    Rute = new rute()
                    {
                        EndCity = 2,
                        StartCity = 5,
                        Id = 6,
                        Time = 12000
                    },
                    TransportType = TransportType.EIC
                },
                new Route()
                {
                    Pris = 20,
                    Rute = new rute()
                    {
                        EndCity = 2,
                        StartCity = 8,
                        Id = 9,
                        Time = 12000
                    },
                    TransportType = TransportType.Oceanic
                },

            };
            return result;
        }
Ejemplo n.º 6
0
        public virtual IEnumerable<Route> GetRoute(by by, pakke pakke)
        {
            var routes = new List<Route>();

            var queryString = HttpUtility.ParseQueryString(string.Empty);
            queryString["date"] = DateTime.Now.AddDays(1).ToString("o");
            queryString["measurements"] = string.Format("{0}x{1}x{2}", pakke.SizeDepth, pakke.SizeHight, pakke.SizeWidth);
            queryString["weight"] = (pakke.Weight * 0.001).ToString(CultureInfo.InvariantCulture);
            queryString["requirements"] = GetRequirements(pakke.forsendelse);
            var queryParams = queryString.ToString();

            //var result = HttpClient.GetAsync(uriBuilder.ToString()).Result;
            var url = string.Format("api/cities/{0}/routes?{1}", by.CityId, queryParams);
            var result = HttpClient.GetAsync(url).Result;
            if (result.IsSuccessStatusCode)
            {
                var jsonResponse = result.Content.ReadAsStringAsync().Result;
                var convertedResponse = JsonConvert.DeserializeObject<RouteResponseContract>(jsonResponse);
                routes =
                    convertedResponse.routes.Select(
                        route =>
                            new Route()
                            {
                                TransportType = GetTransportType(),
                                Pris = (route.price / 100),
                                Rute =
                                    new rute()
                                    {
                                        Time = route.duration,
                                        EndCity = route.destination,
                                        StartCity = by.CityId
                                    }
                            }).ToList();

            }
            //            else
            //            {
            //                throw new WebException(string.Format("GetRoutes from {0} failed", HttpClient.BaseAddress));
            //            }
            return routes;
        }
Ejemplo n.º 7
0
 public virtual IEnumerable<Route> GetRoute(by by, pakke pakke)
 {
     return new[] { new Route { TransportType = TransportType.EIC, Pris = 11, Rute = new rute { Time = 8, StartCity = 1, EndCity = 2 } } };
 }
Ejemplo n.º 8
0
        private Node Dijstra(by source, by target, Politik politik, pakke sendtPakke, float multiplier)
        {
            var queue = new HeapPriorityQueue<Node>(_byliste.Count * 2);
            _nodes = new List<Node>();
            Node targetBy = null;
            foreach (var by in _byliste)
            {
                var node = new Node
                {
                    By = by
                };

                if (by.CityId == target.CityId)
                {
                    targetBy = node;
                }

                node.Distance = by.CityId == source.CityId ? 0 : double.MaxValue;
                _nodes.Add(node);
                queue.Enqueue(node, node.Distance);
            }

            while (queue.Any())
            {
                var node = queue.Dequeue();

                if (node == targetBy && node.Distance != double.MaxValue)
                    return node;

                GetRoutes(node, politik, sendtPakke, multiplier);

                foreach (var neighbour in getNeighbourghNodes(node, queue))
                {
                    if (neighbour == null || !queue.Contains(neighbour))
                        continue;

                    var dist = node.Distance + DistanceBetween(node, neighbour, politik);
                    if (dist < neighbour.Distance)
                    {
                        neighbour.Distance = dist;
                        neighbour.Previous = node;
                        queue.UpdatePriority(neighbour, dist);
                    }
                }
            }
            return null;
        }
Ejemplo n.º 9
0
 public static IList<Route> HentRuter(by _by)
 {
     using (var context = new OADbContext())
     {
         var res = (from ruteObjekt in context.rute
             where ruteObjekt.StartCity == _by.CityId
             select ruteObjekt).Select(r => new Route {Rute = r, TransportType = TransportType.Oceanic}).ToList();
         res.ForEach(q => q.Rute.Time = q.Rute.Time*60);
         return res;
     }
 }
Ejemplo n.º 10
0
 public void DeaktiverBy(by by)
 {
     DataManager.DeaktiverBy(by);
 }
Ejemplo n.º 11
0
 public void AktiverBy(by by)
 {
     DataManager.AktiverBy(by);
 }