static Hamming()
        {
            SortedSet <long> visited = new SortedSet <long>()
            {
                1
            };
            SortedQueue queue = new SortedQueue();

            queue.Push(1);

            int  counted = 1;
            long next;

            for (int i = 0; i < N; i++)
            {
                Precalc[i] = queue.Pop();

                for (int j = 0; j < Multipliers.Length; j++)
                {
                    next = Precalc[i] * Multipliers[j];

                    if (!visited.Contains(next) && counted < N)
                    {
                        visited.Add(next);
                        queue.Push(next);
                        counted++;
                    }
                }
            }
        }
Beispiel #2
0
        public SortedQueue GetSortedQueue(List <Models.TransactionQueue> pendingTransactions, string sortedColumnName, int sortedDirection, int page, int pageSize)
        {
            //instance to hold values of anonymous type
            var sortedQueue = new SortedQueue();

            //fetch data of priority rules
            var priorityRules = _priorityRules.GetPriorityRules();

            //fetch values of smartsort Columns dynamically by priority rules, it can be more than 1 column
            //if smart sort columns are not defined set values of default column as TransactionPriorityOrder
            var listofSmartCol = SortColumns.GetSmartColumn(priorityRules.Result);

            //fetch data after making join pending transaction and priority rules
            var result = (from pt in pendingTransactions
                          join pr in priorityRules.Result
                          on pt.TranPriorityId equals pr.TransactionPriorityId
                          //orderby
                          //pt.Status descending,
                          //pt.Type descending,
                          //pr.TransactionPriorityOrder ascending,
                          ////listofSmartCol,
                          //pt.ReceivedDt ascending,
                          //pt.ComponentNumber ascending

                          select new TransactionQueueItems()
            {
                Id = pt.Id,
                PriorityName = pr.TransactionPriorityCode,
                TransactionPriorityOrder = pr.TransactionPriorityOrder,
                Quantity = pt.Quantity,
                Item = pt.Description,
                Location = pt.Location,
                Destination = pt.Destination,
                PatientName = pt.PatientName,
                Description = pt.Description,
                Color = pr.Color,
                Status = pt.Status,
                Type = pt.Type,
                ReceivedDT = pt.ReceivedDt,
                ComponentNumber = pt.ComponentNumber,
                Rack = StorageSpace.GetStorageSpace(pt.Devices, Models.StorageSpaceItemType.Rack),
                Shelf = StorageSpace.GetStorageSpace(pt.Devices, Models.StorageSpaceItemType.Shelf),
                Bin = StorageSpace.GetStorageSpace(pt.Devices, Models.StorageSpaceItemType.Bin),
                Slot = StorageSpace.GetStorageSpace(pt.Devices, Models.StorageSpaceItemType.Slot)
            }
                          )
                         .ToList();

            DoSmartSort smartSort  = new DoSmartSort();
            var         sortedList = smartSort.OrderBySmartSort(result, listofSmartCol);

            if (page >= 1 && pageSize >= 1)
            {
                sortedList = sortedList.Skip((page - 1) * pageSize).Take(pageSize).ToList();
            }
            sortedQueue.QueueList = sortedList;
            return(sortedQueue);
        }
    public static IEnumerator FindPathAsync(SNode start, SNode goal, List <SNode> asyncPath)
    {
        openList = new SortedQueue <SNode>();
        openList.Push(start);
        start.initialCost   = 0.0f;
        start.estimatedCost = GetHeuristicEstimateCost(start, goal);
        start.nodeTotalCost = start.initialCost + start.estimatedCost;

        closedList = new HashSet <SNode>();
        SNode sNode = null;

        while (openList.Length != 0)
        {
            sNode = openList.First;
            if (sNode.position == goal.position)
            {
                asyncPath = CalculatePath(sNode);
            }


            List <SNode> neighbors = new List <SNode>();
            GridHandler.S.GetNeighbors(sNode, neighbors);

            for (int i = 0; i < neighbors.Count; i++)
            {
                SNode neighborNode = neighbors[i];
                if (!closedList.Contains(neighborNode))
                {
                    neighborNode.estimatedCost = GetHeuristicEstimateCost(neighborNode, goal);
                    neighborNode.initialCost   = sNode.initialCost + 1;
                    neighborNode.nodeTotalCost = neighborNode.estimatedCost + neighborNode.initialCost;

                    neighborNode.parent = sNode;
                    if (!openList.Contains(neighborNode))
                    {
                        openList.Push(neighborNode);
                    }
                }
            }

            closedList.Add(sNode);
            openList.Remove(sNode);
            //Debug.Log("iteration");
        }
        yield return(null);

        //If finished looping and cannot find the goal then return null
        if (sNode.position != goal.position)
        {
            Debug.LogError("Goal Not Found");
            asyncPath = null;
        }
        else
        {
            //Calculate the path based on the final node
            asyncPath = CalculatePath(sNode);
        }
    }
Beispiel #4
0
 public TaskQueue(int workerCount)
 {
     taskQ = new SortedQueue<TaskItem>(TaskItemComparision);
     if (workerCount <= 0)
         throw new ArgumentException("workerCount mast greater than zero", "workerCount");
     workers = new Thread[workerCount];
     for (int i = 0; i < workerCount; i++)
         (workers[i] = new Thread(Consume)).Start();
 }
        public void Peek()
        {
            SortedQueue <int> q = new SortedQueue <int>();

            q._list.AddRange(new int[] { 1, 1, 2 });

            Assert.AreEqual(1, q.Peek());
            CollectionAssert.AreEqual(new int[] { 1, 1, 2 }, q._list);
        }
        public void Enqueue_NotNull()
        {
            SortedQueue <string> q = new SortedQueue <string>();

            q.Enqueue("");

            var q1 = new SortedQueue <int>();

            q1.Enqueue(0);
        }
Beispiel #7
0
    public void OnPMCompilerStopped(HelloCompiler.StopStatus status)
    {
        if (status == HelloCompiler.StopStatus.Finished)
        {
            if (CorrectSorting())
            {
                PMWrapper.SetCaseCompleted();
            }
        }

        SortedQueue.ResetQueues();
    }
Beispiel #8
0
 public TaskQueue(int workerCount)
 {
     taskQ = new SortedQueue <TaskItem>(TaskItemComparision);
     if (workerCount <= 0)
     {
         throw new ArgumentException("workerCount mast greater than zero", "workerCount");
     }
     workers = new Thread[workerCount];
     for (int i = 0; i < workerCount; i++)
     {
         (workers[i] = new Thread(Consume)).Start();
     }
 }
        public void ForEach()
        {
            SortedQueue <int> q = new SortedQueue <int>();

            q._list.AddRange(new int[] { 0, 1, 1, 2 });

            List <int> result = new List <int>();

            foreach (var item in q)
            {
                result.Add(item);
            }

            CollectionAssert.AreEqual(new int[] { 0, 1, 1, 2 }, result);
        }
        public void Enqueue()
        {
            SortedQueue <int> q = new SortedQueue <int>();

            q.Enqueue(1);
            q.Enqueue(3);
            q.Enqueue(2);


            CollectionAssert.AreEqual(new int[] { 1, 2, 3 }, q._list);

            q = new SortedQueue <int>();
            q.Enqueue(new int[] { 1, 2, 2, 3, 0, -1 });

            CollectionAssert.AreEqual(new int[] { -1, 0, 1, 2, 2, 3 }, q._list);
        }
Beispiel #11
0
    public void OnPMCompilerStopped(HelloCompiler.StopStatus status)
    {
        if (status == HelloCompiler.StopStatus.Finished)
        {
            if (CarsSorted < carsToSort)
            {
                PMWrapper.RaiseTaskError("Alla varor sorterades inte.");
            }
            else if (CorrectSorting())
            {
                PMWrapper.SetCaseCompleted();
            }
        }

        SortedQueue.ResetQueues();
    }
Beispiel #12
0
        //Summary StoryId <> Default Sort Functionality by ReceivedDT
        public void Test_DefaultSorting_OrderByReceivedDT(DateTime ReceivedDT1, DateTime ReceivedDT2, DateTime ReceivedDT3)
        {
            var tq   = new Mock <ITransactionQueueRepository>();
            var tp   = new Mock <IPriorityRules>();
            var mock = new Mock <ISortStrategy>();
            //var ISA = new Mock<List<int?>>();
            string sortedColumnName = "PatientName";
            int    sortedDirection  = 1;
            int    page             = 1;
            int    pageSize         = 10;
            TestDataGeneratorSortStrategy testDataGenerator = new TestDataGeneratorSortStrategy();
            var transactionQueueEntities = testDataGenerator.GetTransactionQueueEntitybyReceivedDT();
            var transactionPriorities    = testDataGenerator.GetTransactionPriorityEntity();

            //tq.Setup(x => x.GetTransactionsByISAId(ISA.Object)).Returns(transactionQueueEntities);
            tp.Setup(x => x.GetPriorityRules()).Returns(transactionPriorities);

            ISortStrategy tranQueueData = new ColumnSorting(tp.Object, tq.Object);
            SortedQueue   sortedqueue   = tranQueueData.GetSortedQueue(transactionQueueEntities, sortedColumnName, sortedDirection, page, pageSize);

            Assert.Equal(ReceivedDT1, sortedqueue.QueueList[0].ReceivedDT);
            Assert.Equal(ReceivedDT2, sortedqueue.QueueList[1].ReceivedDT);
            Assert.Equal(ReceivedDT3, sortedqueue.QueueList[2].ReceivedDT);
        }
Beispiel #13
0
        //Summary StoryId <> Default Sort Functionality by Status and Type
        public void Test_DefaultSorting_OrderBySmartColLocation(string PatientName1, string PatientName2, string PatientName3)
        {
            var tq   = new Mock <ITransactionQueueRepository>();
            var tp   = new Mock <IPriorityRules>();
            var mock = new Mock <ISortStrategy>();
            //var ISA = new Mock<List<int?>>();
            string sortedColumnName = string.Empty;
            int    sortedDirection  = 1;
            int    page             = 1;
            int    pageSize         = 10;
            TestDataGeneratorQueueFilter testDataGenerator = new TestDataGeneratorQueueFilter();
            var transactionQueueEntities = testDataGenerator.GetTransactionQueueEntityByColumn();
            var transactionPriorities    = testDataGenerator.GetTransactionPriorityEntity();

            //tq.Setup(x => x.GetTransactionsByISAId(ISA.Object)).Returns(transactionQueueEntities);
            tp.Setup(x => x.GetPriorityRules()).Returns(transactionPriorities);

            IQueueFilter queueFilter = new QueueFilter(tp.Object, tq.Object);
            SortedQueue  sortedqueue = queueFilter.GetAllSortedTransaction(transactionQueueEntities, sortedColumnName, sortedDirection, page, pageSize);

            Assert.Equal(PatientName1, sortedqueue.QueueList[0].Location);
            Assert.Equal(PatientName2, sortedqueue.QueueList[1].Location);
            Assert.Equal(PatientName3, sortedqueue.QueueList[2].Location);
        }
Beispiel #14
0
        //Summary StoryId <> Default Sort Functionality by PatientName
        public void Test_SmartSorting_OrderByPatientName(string patient1, string patient2, string patient3)
        {
            var tq   = new Mock <ITransactionQueueRepository>();
            var tp   = new Mock <IPriorityRules>();
            var mock = new Mock <ISortStrategy>();
            //var ISA = new Mock<List<int?>>();
            string sortedColumnName = null;
            int    sortedDirection  = 1;
            int    page             = 1;
            int    pageSize         = 10;
            TestDataGeneratorSortStrategy testDataGenerator = new TestDataGeneratorSortStrategy();
            var transactionQueueEntities = testDataGenerator.GetTransactionQueueEntityBySmartColumn();
            var transactionPriorities    = testDataGenerator.GetTransactionPriorityEntityByPatientName();

            //tq.Setup(x => x.GetTransactionsByISAId(ISA.Object)).Returns(transactionQueueEntities);
            tp.Setup(x => x.GetPriorityRules()).Returns(transactionPriorities);

            SmartSorting tranQueueData = new SmartSorting(tp.Object, tq.Object);
            SortedQueue  sortedqueue   = tranQueueData.GetSortedQueue(transactionQueueEntities, sortedColumnName, sortedDirection, page, pageSize);

            Assert.Equal(patient1, sortedqueue.QueueList[0].PatientName);
            Assert.Equal(patient2, sortedqueue.QueueList[1].PatientName);
            Assert.Equal(patient3, sortedqueue.QueueList[2].PatientName);
        }
Beispiel #15
0
 public void Init()
 {
     _queue = new SortedQueue <CreatedTimeTagedObject <EmptyTestClass> >();
 }
        public void Enqueue_Null()
        {
            SortedQueue <string> q = new SortedQueue <string>();

            q.Enqueue((string)null);
        }
Beispiel #17
0
 // Use this for initialization
 public void Awake()
 {
     Instance = this;
     tasks    = new SortedQueue <float, Task>(false);
 }
Beispiel #18
0
 public void Cleanup()
 {
     _queue.Clear();
     _queue = null;
 }
Beispiel #19
0
 private Planing(SortedQueue <double, StateAction> priorityQueue, Planing other)
 {
     this.priorityQueue = priorityQueue;
     updateValues       = other.updateValues;
     getPriority        = other.getPriority;
 }
    public static List <SNode> FindPath(SNode start, SNode goal)
    {
        if (goal.bObstacle)
        {
            return(null);
        }
        IsCalculating = true;
        openList      = new SortedQueue <SNode>();
        openList.Push(start);
        start.initialCost   = 0.0f;
        start.estimatedCost = GetHeuristicEstimateCost(start, goal);
        start.nodeTotalCost = start.initialCost + start.estimatedCost;

        closedList = new HashSet <SNode>();
        SNode sNode = null;

        while (openList.Length != 0)
        {
            sNode = openList.First;
            if (sNode == null)
            {
                IsCalculating = false;
                return(null);
            }

            if (sNode.position == goal.position)
            {
                List <SNode> newPath = CalculatePath(sNode);
                IsCalculating = false;
                return(newPath);
            }


            List <SNode> neighbors = new List <SNode>();
            GridHandler.S.GetNeighbors(sNode, neighbors);

            for (int i = 0; i < neighbors.Count; i++)
            {
                SNode neighborNode = neighbors[i];
                if (!closedList.Contains(neighborNode))
                {
                    neighborNode.estimatedCost = GetHeuristicEstimateCost(neighborNode, goal);
                    neighborNode.initialCost   = sNode.initialCost + 1;
                    neighborNode.nodeTotalCost = neighborNode.estimatedCost + neighborNode.initialCost;

                    neighborNode.parent = sNode;
                    if (!openList.Contains(neighborNode))
                    {
                        openList.Push(neighborNode);
                    }
                }
            }
            if (sNode == null)
            {
                return(null);
            }
            closedList.Add(sNode);
            openList.Remove(sNode);
        }

        //If finished looping and cannot find the goal then return null
        if (sNode.position != goal.position)
        {
            Debug.LogError("Goal Not Found");
            IsCalculating = false;
            return(null);
        }

        //Calculate the path based on the final node
        List <SNode> Path = CalculatePath(sNode);

        IsCalculating = false;
        return(Path);
    }
Beispiel #21
0
        public SortedQueue GetSortedQueue(List <Models.TransactionQueue> pendingTransactions, string sortedColumnName, int sortedDirection, int page, int pageSize)
        {
            //fetch column name dynamically
            var ColumnName = typeof(TransactionQueueItems).GetProperty(sortedColumnName);
            //var ColumnNameBySortDir = SortColumns.GetDefaultColumn(sortedColumnName, sortedDirection);

            //instance to hold values of anonymous type
            var sortedQueue = new SortedQueue();

            //fetch data of priority rules
            var priorityRules = _priorityRules.GetPriorityRules();

            //fetch data by doing join
            var sortedList = (from pt in pendingTransactions
                              join pr in priorityRules.Result
                              on pt.TranPriorityId equals pr.TransactionPriorityId
                              //orderby
                              //pt.Status descending,
                              //pt.Type descending,
                              ////ColumnNameBySortDir,
                              //pt.ReceivedDT ascending

                              select new TransactionQueueItems()
            {
                Id = pt.Id,
                PriorityName = pr.TransactionPriorityCode,
                TransactionPriorityOrder = pr.TransactionPriorityOrder,
                Quantity = pt.Quantity,
                Item = pt.Description,
                Location = pt.Location,
                Destination = pt.Destination,
                PatientName = pt.PatientName,
                Description = pt.Description,
                Color = pr.Color,
                Status = pt.Status,
                Type = pt.Type,
                ReceivedDT = pt.ReceivedDt,
                ComponentNumber = pt.ComponentNumber,
                Rack = StorageSpace.GetStorageSpace(pt.Devices, Models.StorageSpaceItemType.Rack),
                Shelf = StorageSpace.GetStorageSpace(pt.Devices, Models.StorageSpaceItemType.Shelf),
                Bin = StorageSpace.GetStorageSpace(pt.Devices, Models.StorageSpaceItemType.Bin),
                Slot = StorageSpace.GetStorageSpace(pt.Devices, Models.StorageSpaceItemType.Slot)
            }
                              )
                             .ToList();

            if (sortedDirection == 1)
            {
                sortedList = sortedList.OrderByDescending(pt => pt.Status)
                             .ThenByDescending(pt => pt.Type)
                             .ThenByDescending(col => ColumnName.GetValue(col, null))
                             .ThenBy(pr => pr.ReceivedDT)
                             .ToList();
            }
            else
            {
                sortedList = sortedList.OrderByDescending(pt => pt.Status)
                             .ThenByDescending(pt => pt.Type)
                             .ThenBy(col => ColumnName.GetValue(col, null))
                             .ThenBy(pr => pr.ReceivedDT)
                             .ToList();
            }

            if (page >= 1 && pageSize >= 1)
            {
                sortedList = sortedList.Skip((page - 1) * pageSize).Take(pageSize).ToList();
            }
            sortedQueue.QueueList = sortedList;
            return(sortedQueue);
        }
Beispiel #22
0
 static Scheduler()
 {
     ScheduleTimer = new Timer(Callback, null, Timeout.Infinite, Timeout.Infinite);
     Tasks         = new SortedQueue <Task>();
 }
 public void Init()
 {
     _queue = new SortedQueue <int>();
 }