Ejemplo n.º 1
0
        /// <summary>
        /// Estimates the time it takes to travel from one waypoint to another.
        /// </summary>
        /// <param name="from">The start node.</param>
        /// <param name="to">The destination node.</param>
        /// <returns>The estimated time it takes to travel between the nodes.</returns>
        private double EstimateTravelTime(TimeWaypoint from, Waypoint to)
        {
            // Init, if not done yet
            if (_timeGraph == null)
            {
                _timeGraph = new TimeGraph(_instance);
            }
            // --> Calculate time needed for driving the given distance
            double travelTime = Distances.CalculateEuclid(from.OriginalWaypoint, to, _instance.WrongTierPenaltyDistance) / _timeGraph.Speed;

            // Check whether we reached the goal already, thus, eliminating the need for turning
            if (from.OriginalWaypoint == to)
            {
                // No turning necessary - only consider time for driving
                return(travelTime);
            }
            else
            {
                // In addition to the drive time also consider the effort for turning
                return
                    // --> Calculate time needed for turning towards new orientation
                    (Math.Abs(Circle.GetOrientationDifference(from.Orientation,
                                                              Circle.GetOrientation(from.OriginalWaypoint.X, from.OriginalWaypoint.Y, to.X, to.Y))) / TimeGraph.PI2 * _timeGraph.TurnSpeed +
                     // --> Add time for driving
                     travelTime);
            }
        }
Ejemplo n.º 2
0
        private static IEnumerable<TextLine> GetLines(List<Word> words, double maxDist, AngleBounds withinLine, int maxDegreeOfParallelism)
        {
            TextDirection textDirection = words[0].TextDirection;
            var groupedIndexes = ClusteringAlgorithms.ClusterNearestNeighbours(words, 2, Distances.Euclidean,
                    (pivot, candidate) => maxDist,
                    pivot => pivot.BoundingBox.BottomRight, candidate => candidate.BoundingBox.BottomLeft,
                    pivot => true,
                    (pivot, candidate) => withinLine.Contains(Distances.Angle(pivot.BoundingBox.BottomRight, candidate.BoundingBox.BottomLeft)),
                    maxDegreeOfParallelism).ToList();

            Func<IEnumerable<Word>, IReadOnlyList<Word>> orderFunc = l => l.OrderBy(x => x.BoundingBox.Left).ToList();
            if (textDirection == TextDirection.Rotate180)
            {
                orderFunc = l => l.OrderByDescending(x => x.BoundingBox.Right).ToList();
            }
            else if (textDirection == TextDirection.Rotate90)
            {
                orderFunc = l => l.OrderByDescending(x => x.BoundingBox.Top).ToList();
            }
            else if (textDirection == TextDirection.Rotate270)
            {
                orderFunc = l => l.OrderBy(x => x.BoundingBox.Bottom).ToList();
            }

            for (var a = 0; a < groupedIndexes.Count; a++)
            {
                yield return new TextLine(orderFunc(groupedIndexes[a].Select(i => words[i])));
            }
        }
Ejemplo n.º 3
0
        public static WarehouseResult Optimize(WarehouseParameters warehouseParameters, CancellationToken ct, Random random)
        {
            WarehouseManager warehouseManager = new WarehouseManager();

            double[][] distancesMatrix = warehouseManager.CreateWarehouseDistancesMatrix(warehouseParameters.WarehousePath);
            Distances.Create(distancesMatrix);
            Orders orders = new Orders(warehouseParameters.OrdersPath, warehouseManager.WarehouseSize);

            GeneticWarehouse geneticWarehouse = new GeneticWarehouse(warehouseParameters.WarehouseGeneticAlgorithmParameters,
                                                                     warehouseManager.WarehouseSize,
                                                                     (population) =>
            {
                double[] fitness = new double[population.Length];
                warehouseParameters.FitnessGeneticAlgorithmParameters.WriteCsv = false;
                Parallel.For(0, population.Length, i =>
                {
                    var results = Fitness.CalculateAllOrdersFitness(orders, population[i],
                                                                    warehouseParameters.FitnessGeneticAlgorithmParameters, random);
                    fitness[i] = results.Sum(x => x.Fitness);
                });

                return(fitness);
            }, ct, random);

            var z      = geneticWarehouse.Run();
            var result = Fitness.CalculateAllOrdersFitness(orders, z.BestChromosome, warehouseParameters.FitnessGeneticAlgorithmParameters, random);

            z.FinalFitness    = result.Sum(x => x.Fitness);
            z.FinalOrderPaths = result.Select(x => x.Path).ToArray();
            return(z);
        }
Ejemplo n.º 4
0
        private static IEnumerable<TextBlock> GetLinesGroups(TextLine[] lines, double maxDist, int maxDegreeOfParallelism)
        {
            /**************************************************************************************************
             * We want to measure the distance between two lines using the following method:
             *  We check if two lines are overlapping horizontally.
             *  If they are overlapping, we compute the middle point (new X coordinate) of the overlapping area.
             *  We finally compute the Euclidean distance between these two middle points.
             *  If the two lines are not overlapping, the distance is set to the max distance.
             **************************************************************************************************/

            double euclidianOverlappingMiddleDistance(PdfLine l1, PdfLine l2)
            {
                var left = Math.Max(l1.Point1.X, l2.Point1.X);
                var d = (Math.Min(l1.Point2.X, l2.Point2.X) - left);

                if (d < 0) return double.MaxValue; // not overlapping -> max distance

                return Distances.Euclidean(
                    new PdfPoint(left + d / 2, l1.Point1.Y),
                    new PdfPoint(left + d / 2, l2.Point1.Y));
            }

            var groupedIndexes = ClusteringAlgorithms.ClusterNearestNeighbours(lines,
                euclidianOverlappingMiddleDistance,
                (pivot, candidate) => maxDist,
                pivot => new PdfLine(pivot.BoundingBox.BottomLeft, pivot.BoundingBox.BottomRight),
                candidate => new PdfLine(candidate.BoundingBox.TopLeft, candidate.BoundingBox.TopRight),
                pivot => true, (pivot, candidate) => true,
                maxDegreeOfParallelism).ToList();

            for (int a = 0; a < groupedIndexes.Count; a++)
            {
                yield return new TextBlock(groupedIndexes[a].Select(i => lines[i]).ToList());
            }
        }
Ejemplo n.º 5
0
        public Distances GetClosestOffice(double longitude, double latitude)
        {
            List <Distances> distances = new List <Distances> ();
            List <Office>    offices   = new List <Office> ();
            bool             checky    = _cxt.Offices.Any();
            DataSeed         seed      = new DataSeed(_cxt);

            if (!checky)
            {
                if (seed.CreateOffices())
                {
                    offices = _cxt.Offices.ToList();
                }
            }
            else
            {
                offices = _cxt.Offices.ToList();
            }

            foreach (Office office in offices)
            {
                double    dist     = DistanceBetweenPlaces(longitude, latitude, office.longitude, office.latitude);
                Distances distance = new Distances {
                    OfficeId    = office.OfficeId,
                    distance    = dist,
                    description = office.Description
                };
                distances.Add(distance);
            }

            List <Distances> distos = distances.OrderBy(disto => disto.distance).ToList();

            return(distos.First());
        }
Ejemplo n.º 6
0
        public RegressionModel Train(BaseVector[] x, float[] y, Parameters param, int ntheads)
        {
            int       k        = param.GetParam <int>("Number of neighbours").Value;
            IDistance distance = Distances.GetDistanceFunction(param);

            return(new KnnRegressionModel(x, y, k, distance));
        }
        /// <summary>
        /// Returns true if MatrixResponse instances are equal
        /// </summary>
        /// <param name="input">Instance of MatrixResponse to be compared</param>
        /// <returns>Boolean</returns>
        public bool Equals(MatrixResponse input)
        {
            if (input == null)
            {
                return(false);
            }

            return
                ((
                     Distances == input.Distances ||
                     Distances != null &&
                     Distances.SequenceEqual(input.Distances)
                     ) &&
                 (
                     Times == input.Times ||
                     Times != null &&
                     Times.SequenceEqual(input.Times)
                 ) &&
                 (
                     Weights == input.Weights ||
                     Weights != null &&
                     Weights.SequenceEqual(input.Weights)
                 ) &&
                 (
                     Info == input.Info ||
                     (Info != null &&
                      Info.Equals(input.Info))
                 ));
        }
        /// <summary>
        /// Find the cities that are closest to this one.
        /// </summary>
        /// <param name="numberOfCloseCities">When creating the initial population of tours, this is a greater chance
        /// that a nearby city will be chosen for a link. This is the number of nearby cities that will be considered close.</param>
        public void FindClosestCities(int numberOfCloseCities)
        {
            double shortestDistance;
            int    shortestCity = 0;

            double[] dist = new double[Distances.Count];
            Distances.CopyTo(dist);

            if (numberOfCloseCities > Distances.Count - 1)
            {
                numberOfCloseCities = Distances.Count - 1;
            }

            closeCities.Clear();

            for (int i = 0; i < numberOfCloseCities; i++)
            {
                shortestDistance = Double.MaxValue;
                for (int cityNum = 0; cityNum < Distances.Count; cityNum++)
                {
                    if (dist[cityNum] < shortestDistance)
                    {
                        shortestDistance = dist[cityNum];
                        shortestCity     = cityNum;
                    }
                }
                closeCities.Add(shortestCity);
                dist[shortestCity] = Double.MaxValue;
            }
        }
Ejemplo n.º 9
0
        public void EuclideanDistanceTest()
        {
            var pR = new Bounds[, ]
            {
                { B(0.6f, 0.8f), B(0.6f, 0.6f), B(0.2f, 0.2f), B(0.6f, 0.8f), B(0.1f, 0.2f) },
                { B(0.0f, 0.3f), B(0.3f, 0.4f), B(0.6f, 0.6f), B(0.0f, 0.3f), B(0.1f, 0.2f) },
                { B(0.2f, 0.8f), B(0.4f, 0.8f), B(0.0f, 0.2f), B(0.2f, 0.8f), B(0.0f, 0.2f) },
                { B(0.6f, 0.7f), B(0.5f, 0.5f), B(0.3f, 0.3f), B(0.6f, 0.7f), B(0.3f, 0.3f) }
            };

            var cQ = new Bounds[, ]
            {
                { B(0.4f, 0.4f), B(0.3f, 0.4f), B(0.1f, 0.2f), B(0.4f, 0.4f), B(0.1f, 0.2f) },
                { B(0.7f, 0.7f), B(0.1f, 0.4f), B(0.0f, 0.2f), B(0.7f, 0.7f), B(0.1f, 0.2f) },
                { B(0.3f, 0.3f), B(0.6f, 0.6f), B(0.2f, 0.2f), B(0.2f, 0.3f), B(0.1f, 0.2f) },
                { B(0.1f, 0.3f), B(0.2f, 0.4f), B(0.8f, 0.8f), B(0.2f, 0.3f), B(0.2f, 0.2f) },
                { B(0.1f, 0.3f), B(0.0f, 0.4f), B(0.2f, 0.2f), B(0.2f, 0.3f), B(0.8f, 0.8f) },
            };

            var exp = new float[, ]
            {
                { 0.23f, 0.19f, 0.27f, 0.43f, 0.46f },
                { 0.27f, 0.43f, 0.24f, 0.12f, 0.36f },
                { 0.24f, 0.28f, 0.25f, 0.42f, 0.43f },
                { 0.20f, 0.18f, 0.26f, 0.37f, 0.39f }
            };

            var result = Distances.EuclideanSetDistance(pR, cQ);

            AssertSetsEqual(exp, result);
        }
Ejemplo n.º 10
0
    /// <summary>
    /// Lida com a movimentação do baiacu
    /// </summary>
    void Update()
    {
        // Se a parede não for nula
        if (wall != null)
        {
            distances = wall.GetDistances(player.transform);

            // Verifica se ele já está longe o suficiente dos corais para fazer os cálculos para os próximos corais
            if (distances.horizontalDistance > maxDist)
            {
                GetNextWall();
            }

            // Verifica se é necessário inflar o baiacu para ele não cair nos corais
            if (distances.lowerWallDistance < minDist)
            {
                player.Inflate();
            }
        }
        // Caso a parede seja nula, pega referência da próxima parede
        else
        {
            GetNextWall();
        }
    }
Ejemplo n.º 11
0
    //Dijkstra algorithm - go backwards - from goal cell to root cell
    public Distances DijkstraShortestPathTo(MazeCell goal)
    {
        MazeCell currentCell = goal;
        // навигационная цепочка
        Distances breadcrumbTrail = new Distances(this.startingCell);

        breadcrumbTrail[currentCell] = this[currentCell];

        // starightforward algo -  For each cell along the path, the neighboring cell with the lowest distance will be the next step of the solution
        while (currentCell != startingCell)
        {
            foreach (MazeCell neighbourCell in currentCell.Links())  //get all linked cells of current cell
            {
                if (this[neighbourCell] < this[currentCell])         //find linked cell with min distance (closest to the startingCell)
                {
                    if (!breadcrumbTrail.ContainsKey(neighbourCell)) // add to dictionary if not exists in dictionary
                    {
                        breadcrumbTrail.Add(neighbourCell, this[neighbourCell]);
                    }
                    else
                    {
                        breadcrumbTrail[neighbourCell] = this[neighbourCell]; // replace distance if less distance value found
                    }

                    currentCell = neighbourCell;                    // switch current cell to the neighbour
                    break;
                }
            }
        }
        return(breadcrumbTrail);
    }
Ejemplo n.º 12
0
        public void HammingDistanceTest()
        {
            var pR = new Bounds[, ]
            {
                { B(0.6f, 0.8f), B(0.6f, 0.6f), B(0.2f, 0.2f), B(0.6f, 0.8f), B(0.1f, 0.2f) },
                { B(0.0f, 0.3f), B(0.3f, 0.4f), B(0.6f, 0.6f), B(0.0f, 0.3f), B(0.1f, 0.2f) },
                { B(0.2f, 0.8f), B(0.4f, 0.8f), B(0.0f, 0.2f), B(0.2f, 0.8f), B(0.0f, 0.2f) },
                { B(0.6f, 0.7f), B(0.5f, 0.5f), B(0.3f, 0.3f), B(0.6f, 0.7f), B(0.3f, 0.3f) }
            };

            var cQ = new Bounds[, ]
            {
                { B(0.4f, 0.4f), B(0.3f, 0.4f), B(0.1f, 0.2f), B(0.4f, 0.4f), B(0.1f, 0.2f) },
                { B(0.7f, 0.7f), B(0.1f, 0.4f), B(0.0f, 0.2f), B(0.7f, 0.7f), B(0.1f, 0.2f) },
                { B(0.3f, 0.3f), B(0.6f, 0.6f), B(0.2f, 0.2f), B(0.2f, 0.3f), B(0.1f, 0.2f) },
                { B(0.1f, 0.3f), B(0.2f, 0.4f), B(0.8f, 0.8f), B(0.2f, 0.3f), B(0.2f, 0.2f) },
                { B(0.1f, 0.3f), B(0.0f, 0.4f), B(0.2f, 0.2f), B(0.2f, 0.3f), B(0.8f, 0.8f) },
            };

            var exp = new float[, ]
            {
                { 0.18f, 0.13f, 0.17f, 0.38f, 0.40f },
                { 0.19f, 0.34f, 0.18f, 0.09f, 0.27f },
                { 0.19f, 0.20f, 0.18f, 0.33f, 0.35f },
                { 0.19f, 0.14f, 0.22f, 0.33f, 0.35f }
            };

            var result = Distances.HammingSetDistance(pR, cQ);

            AssertSetsEqual(exp, result);
        }
        //Метод для нахождения ближайшего города
        public void NearestTownDistance(int nearTownCount)
        {
            double closestDistance;
            int    nearestTown = 0;

            double[] way = new double[Distances.Count];
            Distances.CopyTo(way);
            if (nearTownCount > Distances.Count - 1)
            {
                nearTownCount = Distances.Count - 1;
            }
            nearTown.Clear();
            for (int i = 0; i < nearTownCount; i++)
            {
                closestDistance = Double.MaxValue;
                for (int townNum = 0; townNum < Distances.Count; townNum++)
                {
                    if (way[townNum] < nearestTown)
                    {
                        closestDistance = way[townNum];
                        nearestTown     = townNum;
                    }
                    nearTown.Add(nearestTown);
                    way[nearestTown] = Double.MaxValue;
                }
            }
        }
Ejemplo n.º 14
0
 public void Disconnect(int cell_id)
 {
     foreach (var pair in Distances.Where(pair => (pair.Key.Id1 == cell_id || pair.Key.Id2 == cell_id)).ToList())
     {
         Distances.Remove(pair.Key);
     }
 }
Ejemplo n.º 15
0
        public float GetDistance(int cell_id_1, int cell_id_2)
        {
            float dist = -1;

            Distances.TryGetValue(new CellIdPair(cell_id_1, cell_id_2), out dist);
            return(dist);
        }
Ejemplo n.º 16
0
        private static void Normalize()
        {
            var    prevCity      = City.SaoPaulo;
            double totalDistance = 0;

            foreach (var d in WorldCupChronogram.Days)
            {
                var currentDistance = double.MaxValue;
                var localCity       = City.SaoPaulo;
                foreach (var m in d.Matches)
                {
                    var localDistance = Distances.GetDistance(prevCity, m.City);
                    if (localDistance < currentDistance)
                    {
                        currentDistance = localDistance;
                        localCity       = m.City;
                    }
                }

                prevCity       = localCity;
                totalDistance += currentDistance;

                Console.WriteLine(Convert.ToString(localCity) + " - " + totalDistance);
            }
            Console.ReadLine();
        }
Ejemplo n.º 17
0
        /// <summary>
        /// Sets the footer line count.
        /// </summary>
        /// <param name="value">The value.</param>
        protected override void SetFooterLineCount(int value)
        {
            if (value == 0)
            {
                footerExtent = 0;
            }
            else
            {
                if (Distances.Count <= value)
                {
                    footerExtent = 0;
                    return;
                }

                int n = Distances.Count - value;
                // The Total distance must be reduced by the padding size of the Distance total size. Then it should be calculated. This issue is occured in Nested Grid. SD 9312.
                // this will give the exact size of the footer Extent when padding distance is reduced from total distance.

                if (!(Distances is DistanceCounterSubset)) // Nested Grid cells in GridControl is not DistanceRangeCounterCollection type.
                {
                    footerExtent = Distances.TotalDistance - ((DistanceRangeCounterCollection)(Distances)).paddingDistance - Distances.GetCumulatedDistanceAt(n);
                }
                else
                {
                    footerExtent = Distances.TotalDistance - Distances.GetCumulatedDistanceAt(n);
                }
                //footerExtent = Distances.GetCumulatedDistanceAt(Math.Min(value, Distances.Count));
            }
        }
Ejemplo n.º 18
0
    // Wave algo - fill all nearby cells with distance from first cell to the last cell on grid
    public virtual Distances FindDistanceForAllReachableLinkedCells()
    {
        Distances       distances = new Distances(this);
        List <MazeCell> frontier  = new List <MazeCell>()
        {
            this
        };

        // Will expands until last connected cell found
        while (frontier.Count > 0)
        {
            var newFrontier = new List <MazeCell>();

            foreach (var frontierCell in frontier)
            {
                foreach (var linkedCell in frontierCell.Links())
                {
                    if (distances.ContainsKey(linkedCell)) // if cell is visited then skip
                    {
                        continue;
                    }
                    distances.Add(linkedCell, distances[frontierCell] + 1);
                    newFrontier.Add(linkedCell);
                }
            }

            frontier = newFrontier;
        }

        return(distances);
    }
Ejemplo n.º 19
0
        /// <summary>
        /// 这个方法有很多用途
        /// 【1】寻找路径
        /// 【2】寻找最优出入口
        /// 【3】给迷宫上色(依据距离某一个点的距离)
        /// </summary>
        /// <param name="start"></param>
        /// <returns></returns>
        Distances FloodMaze(IDijkstraNode start)
        {
            Distances diss = new Distances(start);

            List <IDijkstraNode> frontiers = new List <IDijkstraNode>();

            frontiers.Add(start);

            //Algorithm from the book Mazes for programmers.
            while (frontiers.Count > 0)
            {
                List <IDijkstraNode> new_frontiers = new List <IDijkstraNode>();

                foreach (var front in frontiers)
                {
                    foreach (var conn in front.connections)
                    {
                        if (diss.Visited(conn) == false)
                        {
                            diss.SetDistanceReferenceTo(conn, front);
                            new_frontiers.Add(conn);
                        }
                    }
                }

                frontiers = new_frontiers;
            }

            return(diss);
        }
Ejemplo n.º 20
0
        /// <summary>
        /// This is called to decide about potentially pending orders.
        /// This method is being timed for statistical purposes and is also ONLY called when <code>SituationInvestigated</code> is <code>false</code>.
        /// Hence, set the field accordingly to react on events not tracked by this outer skeleton.
        /// </summary>
        protected override void DecideAboutPendingOrders()
        {
            foreach (var order in _pendingOrders.Where(o => o.Positions.All(p => Instance.StockInfo.GetActualStock(p.Key) >= p.Value)).ToArray())
            {
                // Check all pods for the maximum number of picks that can be done with them
                List <Pod> bestPods     = new List <Pod>();
                int        bestPodPicks = -1;
                foreach (var pod in Instance.Pods.Where(p => !p.InUse))
                {
                    // Calculate picks that can potentially be done with the pod
                    int picks = order.Positions.Sum(pos => Math.Min(pod.CountAvailable(pos.Key), pos.Value));
                    // Check whether we found even more possible picks with this pod
                    if (bestPodPicks < picks)
                    {
                        bestPods.Clear();
                        bestPods.Add(pod);
                        bestPodPicks = picks;
                    }
                    else
                    {
                        // Check whether the current pod belongs into the winner group
                        if (bestPodPicks == picks)
                        {
                            bestPods.Add(pod);
                        }
                    }
                }
                // Choose station nearest to one of the best pods
                OutputStation chosenStation    = null;
                double        shortestDistance = double.PositiveInfinity;
                foreach (var station in Instance.OutputStations.Where(s => s.Active && s.FitsForReservation(order)))
                {
                    foreach (var pod in bestPods)
                    {
                        double distance;
                        switch (_config.DistanceRule)
                        {
                        case NearBestPodOrderBatchingDistanceRule.Euclid: distance = Distances.CalculateEuclid(pod, station, Instance.WrongTierPenaltyDistance); break;

                        case NearBestPodOrderBatchingDistanceRule.Manhattan: distance = Distances.CalculateManhattan(pod, station, Instance.WrongTierPenaltyDistance); break;

                        case NearBestPodOrderBatchingDistanceRule.ShortestPath: distance = Distances.CalculateShortestPathPodSafe(pod.Waypoint, station.Waypoint, Instance); break;

                        default: throw new ArgumentException("Unknown distance rule: " + _config.DistanceRule);
                        }
                        if (distance < shortestDistance)
                        {
                            shortestDistance = distance;
                            chosenStation    = station;
                        }
                    }
                }
                // If we found a station, assign the bundle to it
                if (chosenStation != null)
                {
                    AllocateOrder(order, chosenStation);
                }
            }
        }
Ejemplo n.º 21
0
        /// <summary>
        /// Дополняет текущий отель по данным из отеля извне
        /// </summary>
        /// <returns>Успешность объединения</returns>
        public bool TryMerge(Hotel other)
        {
            if (other == null || other.Id != Id || other.Supplier != Supplier)
            {
                return(false);
            }

            if (!other.Name.IsNullOrEmpty())
            {
                Name ??= new Dictionary <Language, string>();
                Name.AddRangeWithNonrecurringKey(other.Name);
            }

            if (!other.Info.IsNullOrEmpty())
            {
                Info ??= new Dictionary <Language, string>();
                Info.AddRangeWithNonrecurringKey(other.Info);
            }

            if (!other.Address.IsNullOrEmpty())
            {
                Address ??= new Dictionary <Language, List <string> >();
                Address.AddRangeWithNonrecurringKey(other.Address);
            }

            if (!other.Features.IsNullOrEmpty())
            {
                Features ??= new Dictionary <Language, List <Feature> >();
                Features.AddRangeWithNonrecurringKey(other.Features);
            }

            if (!other.Description.IsNullOrEmpty())
            {
                Description ??= new Dictionary <Language, string>();
                Description.AddRangeWithNonrecurringKey(other.Description);
            }

            if (!other.Distances.IsNullOrEmpty())
            {
                Distances ??= new Dictionary <Language, List <Distance> >();
                Distances.AddRangeWithNonrecurringKey(other.Distances);
            }

            CheckInTime    = string.IsNullOrEmpty(CheckInTime) ? other.CheckInTime : CheckInTime;
            CheckOutTime   = string.IsNullOrEmpty(CheckOutTime) ? other.CheckOutTime : CheckOutTime;
            CityId         = string.IsNullOrEmpty(CityId) ? other.CityId : CityId;
            ResortId       = string.IsNullOrEmpty(ResortId) ? other.ResortId : ResortId;
            HotelChainName = string.IsNullOrEmpty(HotelChainName) ? other.HotelChainName : HotelChainName;

            Photos = Photos.IsNullOrEmpty() ? other.Photos : Photos;
            Phones = Phones.IsNullOrEmpty() ? other.Phones : Phones;

            StarRating ??= other.StarRating;
            PosLatitude ??= other.PosLatitude;
            PosLongitude ??= other.PosLongitude;
            CustomerRating ??= other.CustomerRating;

            return(true);
        }
Ejemplo n.º 22
0
 /// <summary>
 /// Calculates the time to move from one time-waypoint to another.
 /// </summary>
 /// <param name="from">The start node.</param>
 /// <param name="to">The destination node.</param>
 /// <returns>The time for traveling from one node to the other.</returns>
 public double GetTimeNeededToTravel(TimeWaypoint from, TimeWaypoint to)
 {
     return
         // --> Calculate time needed for turning towards new orientation
         (Math.Abs(Circle.GetOrientationDifference(from.Orientation, to.Orientation)) / PI2 * TurnSpeed +
          // --> Calculate time needed for driving the given distance
          Distances.CalculateEuclid(from.OriginalWaypoint, to.OriginalWaypoint, Instance.WrongTierPenaltyDistance) / Speed);
 }
Ejemplo n.º 23
0
 private void DrawDistances(Distances d, double hCellSize, double vCellSize) =>
 d.Cells.ForEach(cellDistance => {
     TextBlock tb = new TextBlock {
         Text   = cellDistance.Distance.ToString(),
         Margin = new Thickness(cellDistance.Cell.Col * hCellSize + 10, cellDistance.Cell.Row * vCellSize + 10, 0, 0)
     };
     MazeCanvas.Children.Add(tb);
 });
Ejemplo n.º 24
0
        public override ClassificationModel Train(BaseVector[] x, int[][] y, int ngroups, Parameters param, int nthreads,
                                                  Action <double> reportProgress)
        {
            int       k        = param.GetParam <int>("Number of neighbours").Value;
            IDistance distance = Distances.GetDistanceFunction(param);

            return(new KnnClassificationModel(x, y, ngroups, k, distance));
        }
Ejemplo n.º 25
0
 public float GetDistance(int cell_id_1, int cell_id_2)
 {
     if (Distances.TryGetValue(cell_id_1, out var distance_table) && distance_table.TryGetValue(cell_id_2, out var dist))
     {
         return(dist);
     }
     return(0);
 }
Ejemplo n.º 26
0
 public void find_dist_to_all_rovers(List <Rover> fidos)
 {
     Distances.Clear();
     for (int i = 0; i < num_rovers; i++)
     {
         Distances.Add(find_dist_to_rover(i, fidos));
     }
 }
Ejemplo n.º 27
0
        public override RegressionModel Train(BaseVector[] x, int[] nominal, double[] y, Parameters param, int ntheads, Action <double> reportProgress)
        {
            x = ClassificationMethod.ToOneHotEncoding(x, nominal);
            int       k        = param.GetParam <int>("Number of neighbours").Value;
            IDistance distance = Distances.GetDistanceFunction(param);

            return(new KnnRegressionModel(x, y, k, distance));
        }
Ejemplo n.º 28
0
        public WarehousePairwiseProductFrequencyResolver(Random random, double probability, int participantsCount) : base(random, probability)
        {
            _participantsCount = participantsCount;

            _distancesMatrix           = Distances.GetInstance().DistancesMatrix;
            _warehousePointsByLocation = Enumerable.Range(0, _distancesMatrix.Length)
                                         .OrderBy(x => _distancesMatrix[0][x]).ToArray();
        }
Ejemplo n.º 29
0
 public Ship(int id, List <Link> links)
 {
     Id = id;
     foreach (var link in links.Where(l => l.HasFactory(Id)))
     {
         Distances.Add(link.GetOtherId(Id), link.Distance);
     }
 }
Ejemplo n.º 30
0
        public IActionResult locate()
        {
            OrderServices orderservice = new OrderServices(_cxt);
            // 9.081999<br>Longitude: 8.675277
            Distances dist = orderservice.GetClosestOffice(8.675277, 9.081999);

            return(Json(dist));
        }
Ejemplo n.º 31
0
        public Distances CellDistances()
        {
            var distances = new Distances(this);
            var frontier = new List<Cell>() { this };

            while (frontier.Count > 0)
            {
                var newFrontier = new List<Cell>();
                foreach (var cell in frontier)
                {
                    foreach (var linked in cell.Links)
                    {
                        if (!distances.ContainsKey(linked))
                        {
                            distances.Add(linked, distances[cell] + 1);
                            newFrontier.Add(linked);
                        }
                    }
                }
                frontier = newFrontier;
            }
            return distances;
        }
Ejemplo n.º 32
0
	public int compareTo(Distances o){
		if ((this.distanceValue - o.distanceValue)>0)
			return 1;
		else if ((this.distanceValue - o.distanceValue)==0)
			return 0;
		else return -1;
	}