示例#1
0
 /// <summary>
 /// If neighbour has line of sight to currents parent and skipping current is cheaper, skips current node and sets neighbour cost / parent depending on whether current is used
 /// </summary>
 /// <param name="current"></param>
 /// <param name="neighbour"></param>
 /// <param name="settings"></param>
 /// <param name="openNodes"></param>
 private static void UpdateNode(Node current, Node neighbour, PathfindingSettings settings, BucketList <Node> openNodes)
 {
     if (LineOfSight(current.parent, neighbour))
     {
         var costSkippingCurrent = current.parent.cost + settings.CostIncrease(current.parent.pos, neighbour.pos);
         if (costSkippingCurrent < neighbour.cost)
         {
             if (openNodes.Contains(neighbour))
             {
                 openNodes.Remove(neighbour);
             }
             neighbour.cost   = costSkippingCurrent;
             neighbour.parent = current.parent;
             openNodes.Add(neighbour);
         }
     }
     else
     {
         var costUsingCurrent = current.cost + settings.CostIncrease(current.pos, neighbour.pos);
         if (costUsingCurrent < neighbour.cost)
         {
             if (openNodes.Contains(neighbour))
             {
                 openNodes.Remove(neighbour);
             }
             neighbour.cost   = costUsingCurrent;
             neighbour.parent = current;
             openNodes.Add(neighbour);
         }
     }
 }
示例#2
0
        private void InitializeImageType()
        {
            ImageType = new BucketList <string>();

            ImageType.Add(96, "ORIGINAL\\PRIMARY\\AXIAL");
            ImageType.Add(1, "ORIGINAL\\PRIMARY\\LOCALIZER");
            ImageType.Add(3, "DERIVED\\SECONDARY");
        }
示例#3
0
        private void InitializeModalityFrequency(Random r)
        {
            using (DataTable dt = new DataTable())
            {
                dt.Columns.Add("Frequency", typeof(int));
                dt.Columns.Add("AverageSeriesPerStudy", typeof(double));
                dt.Columns.Add("StandardDeviationSeriesPerStudy", typeof(double));
                dt.Columns.Add("AverageImagesPerSeries", typeof(double));
                dt.Columns.Add("StandardDeviationImagesPerSeries", typeof(double));

                DataGenerator.EmbeddedCsvToDataTable(typeof(DicomDataGenerator), "DicomDataGeneratorModalities.csv", dt);

                ModalityFrequency = new BucketList <ModalityStats>();

                int idx = 0;
                foreach (DataRow dr in dt.Rows)
                {
                    string modality = (string)dr["Modality"];
                    ModalityFrequency.Add((int)dr["Frequency"],
                                          new ModalityStats(
                                              modality,
                                              (double)dr["AverageSeriesPerStudy"],
                                              (double)dr["StandardDeviationSeriesPerStudy"],
                                              (double)dr["AverageImagesPerSeries"],
                                              (double)dr["StandardDeviationImagesPerSeries"],
                                              r
                                              ));

                    ModalityIndexes.Add(modality, idx++);
                }
            }
        }
        public static void Main()
        {
            var normalList = new NormalList <int>();
            var bucketList = new BucketList <int>();

            for (int i = 0; i < 1000000; i++)
            {
                normalList.Add(i);
                bucketList.Add(i);
            }

            MeasureTime(() =>
            {
                for (int i = 0; i < 400000; i++)
                {
                    normalList.Remove(0);
                }
            }, "normal list removing");

            MeasureTime(() =>
            {
                for (int i = 0; i < 400000; i++)
                {
                    bucketList.Remove(0);
                }
            }, "bucket list removing");
        }
示例#5
0
        public override BucketList Run()
        {
            var result = new BucketList();
            var generalizedBucketList = base.Run();

            foreach (var bucket in generalizedBucketList)
            {
                var privateBucket = new Bucket();
                foreach (var tuple in bucket)
                {
                    if (Int32.Parse(tuple.GetValue(tuple.GetNumberOfAttributes() - 1)) == 1)
                    {
                        tuple.RemoveAttribute(tuple.GetNumberOfAttributes() - 1);
                        privateBucket.Add(tuple);
                    }
                    if (privateBucket.Count > 0)
                    {
                        privateBucket.node = bucket.node;
                    }
                }
                if (privateBucket.Count > 0)
                {
                    result.Add(privateBucket);
                }
            }
            return(result);
        }
        /*
         * It returns a delta present BucketList with as less generalization as possible.
         */
        public BucketList GetBestPermutedTable(BucketList bucketList)
        {
            BucketList bestTable = new BucketList();
            for (int i = 0; i < bucketList.Count(); i++)
            {
                List<Node> nodeList = MakeNodeList(bucketList[i].node);
                var anonymizedBucket = GeneralizeAndPermute(min, max, bucketList[i], qid, nodeList, hierarchies);
                bestTable.Add(anonymizedBucket);
            }

            return bestTable;
        }
        /*
         * It returns a delta present BucketList with as less generalization as possible.
         */
        public BucketList GetBestPermutedTable(BucketList bucketList)
        {
            BucketList bestTable = new BucketList();

            for (int i = 0; i < bucketList.Count(); i++)
            {
                List <Node> nodeList         = MakeNodeList(bucketList[i].node);
                var         anonymizedBucket = GeneralizeAndPermute(min, max, bucketList[i], qid, nodeList, hierarchies);
                bestTable.Add(anonymizedBucket);
            }

            return(bestTable);
        }
        /// <summary>
        /// Tuple partitioning is dane by K-Mondrian. 
        /// This method doesn't generalize the tuples, but permutes the sensitive values 
        /// within each QI column inside every bucket. 
        /// </summary>
        /// <returns>a one-attribute-per-column-sliced BucketList</returns>
        public override BucketList Run()
        {
            var result = new BucketList();
            var generalizedBucketList = base.Run();

            foreach (var bucket in generalizedBucketList)
            {
                //undo all of the generalizations
                for (int i = 0; i < bucket.node.generalizations.Count; i++)
                {
                    bucket.node.generalizations[i] = 0;
                }
                var permutedBucket = GeneralizeBucket(bucket, hierarchies);

                foreach (int i in qid)
                    permutedBucket.PermuteValues(i);

                result.Add(permutedBucket);
            }
            return result;
        }
        public override BucketList Run()
        {
            var result = new BucketList();
            var generalizedBucketList = base.Run();
            var genPerm = GetBestPermutedTable(generalizedBucketList);


            foreach (var bucket in genPerm)
            {
                //if any of the bucket is null, it means that it is not delta-present, k has to be increased
                if (bucket == null)
                {
                    return(null);
                }
                var privateBucket = new Bucket();
                foreach (var tuple in bucket)
                {
                    if (Int32.Parse(tuple.GetValue(tuple.GetNumberOfAttributes() - 1)) == 1)
                    {
                        tuple.RemoveAttribute(tuple.GetNumberOfAttributes() - 1);
                        privateBucket.Add(tuple);
                    }
                    if (privateBucket.Count > 0)
                    {
                        privateBucket.node = bucket.node;
                    }
                }
                if (privateBucket.Count > 0)
                {
                    foreach (int i in qid)
                    {
                        privateBucket.PermuteValues(i);
                    }
                    result.Add(privateBucket);
                }
            }

            return(result);
        }
示例#10
0
 private void ActionEvent(Goods goods)
 {
     if (goods.ButtonContent == ButtonAction.Buy)
     {
         var bucketGoods = new Goods
         {
             Id            = goods.Id,
             Name          = goods.Name,
             Cost          = goods.Cost,
             Description   = goods.Description,
             Image         = goods.Image,
             ButtonContent = ButtonAction.Remove
         };
         bucketGoods.ActionEvent += () => ActionEvent(bucketGoods);
         BucketList.Add(bucketGoods);
     }
     else if (goods.ButtonContent == ButtonAction.Remove)
     {
         // ReSharper disable once EventUnsubscriptionViaAnonymousDelegate
         goods.ActionEvent -= () => ActionEvent(goods);
         BucketList.Remove(goods);
     }
 }
示例#11
0
        /// <summary>
        /// Tuple partitioning is dane by K-Mondrian.
        /// This method doesn't generalize the tuples, but permutes the sensitive values
        /// within each QI column inside every bucket.
        /// </summary>
        /// <returns>a one-attribute-per-column-sliced BucketList</returns>
        public override BucketList Run()
        {
            var result = new BucketList();
            var generalizedBucketList = base.Run();

            foreach (var bucket in generalizedBucketList)
            {
                //undo all of the generalizations
                for (int i = 0; i < bucket.node.generalizations.Count; i++)
                {
                    bucket.node.generalizations[i] = 0;
                }
                var permutedBucket = GeneralizeBucket(bucket, hierarchies);

                foreach (int i in qid)
                {
                    permutedBucket.PermuteValues(i);
                }

                result.Add(permutedBucket);
            }
            return(result);
        }
        public override BucketList Run()
        {
            var result = new BucketList();
            var generalizedBucketList = base.Run();

            foreach (var bucket in generalizedBucketList)
            {
                var privateBucket = new Bucket();
                foreach (var tuple in bucket)
                {
                    if (Int32.Parse(tuple.GetValue(tuple.GetNumberOfAttributes() - 1)) == 1)
                    {
                        tuple.RemoveAttribute(tuple.GetNumberOfAttributes() - 1);
                        privateBucket.Add(tuple);
                    }
                    if (privateBucket.Count > 0)
                        privateBucket.node = bucket.node;
                }
                if (privateBucket.Count > 0)
                    result.Add(privateBucket);
            }
            return result;
        }
示例#13
0
        /// <summary>
        /// Tries to find a path from start to goal node using settings
        /// </summary>
        /// <param name="start">Start node</param>
        /// <param name="goal">Goal node</param>
        /// <param name="settings">PathfindingSettings (which heuristics to use etc)</param>
        /// <param name="isoLevel">Determines which nodes are considered walkable (iso value > this)</param>
        /// <param name="openNodes">Nodes that were still open after algorithm finished</param>
        /// <param name="closedNodes">Nodes that were fully explored after algorithm finished</param>
        /// <param name="maxIterations">Max number of loop iterations, prevents infinite loops</param>
        /// <param name="nodeCount">Approximate total node count, determines start capacity of path stack</param>
        /// <returns></returns>
        public static Stack <Vector3> FindPath(Node start, Node goal, PathfindingSettings settings, float isoLevel, out BucketList <Node> openNodes, out HashSet <Node> closedNodes, int maxIterations = 50000, int nodeCount = 1000)
        {
            NodesGenerator.CostHeuristicBalance = settings.greediness;
            int neighbourChecks = 0;

            int numIterations = 0;

            //euclidean distance from start to end
            float distance = Vector3.Distance(start.pos, goal.pos);

            //full length of path
            float pathLength = 0;

            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();

            if (settings.benchmark)
            {
                sw.Start();
            }

            var             startCapacity = nodeCount / 100;
            Stack <Vector3> path          = new Stack <Vector3>(startCapacity);

            openNodes = new BucketList <Node>(distance / 100, Mathf.Min(settings.Heuristic(start.pos, goal.pos) * settings.greediness, settings.CostIncrease(start.pos, goal.pos) * (1 - settings.greediness)));
            //openNodes = new MinHeap<Node>(startCapacity * 10);

            closedNodes = new HashSet <Node>();

            Node current = null;

            start.cost      = 0;
            start.parent    = start;
            start.heuristic = settings.Heuristic(start.pos, goal.pos);
            openNodes.Add(start);
            while (openNodes.Count != 0 && !closedNodes.Contains(goal))
            {
                if (++numIterations == maxIterations)
                {
                    break;
                }

                current = openNodes.ExtractMin();

                closedNodes.Add(current);

                foreach (var neighbour in current.neighbours)
                {
                    neighbourChecks++;
                    if (neighbour.isoValue <= isoLevel)
                    {
                        continue;
                    }
                    if (closedNodes.Contains(neighbour))
                    {
                        continue;
                    }
                    var newCost = current.cost + settings.CostIncrease(current.pos, neighbour.pos);
                    if (openNodes.Contains(neighbour))
                    {
                        if (newCost >= neighbour.cost)
                        {
                            continue;
                        }
                        openNodes.Remove(neighbour);
                    }
                    neighbour.parent    = current;
                    neighbour.heuristic = settings.Heuristic(neighbour.pos, goal.pos);
                    neighbour.cost      = newCost;

                    openNodes.Add(neighbour);
                }
            }

            if (!closedNodes.Contains(goal))
            {
                Debug.Log("no goal, " + numIterations + " iterations, closed: " + closedNodes.Count + ", opened: " + openNodes.Count);
                return(path);
            }

            path.Push(goal.pos);
            Node temp = goal.parent;

            while (temp != null)
            {
                pathLength += Vector3.Distance(path.Peek(), temp.pos);
                path.Push(temp.pos);
                if (temp == start)
                {
                    break;
                }
                temp = temp.parent;
            }

            if (settings.benchmark)
            {
                sw.Stop();
                Debug.Log("A*, Heuristic: " + settings.heuristic + ", Cost increase: " + settings.costIncrease + ", Path length: " + pathLength * 100 / distance + "%, ms: " + sw.Elapsed.TotalMilliseconds + ", closed: " + closedNodes.Count + ", opened: " + openNodes.Count + ", Neighbour checks: " + neighbourChecks);
            }

            return(path);
        }
示例#14
0
        private void InitializeHourOfDay(Random r)
        {
            //Provenance:
            //select DATEPART(HOUR,StudyTime),work.dbo.get_aggregate_value(count(*)) from CT_Godarts_StudyTable group by DATEPART(HOUR,StudyTime)

            HourOfDay = new BucketList <int>();

            HourOfDay.Add(1, 1);
            HourOfDay.Add(4, 1);
            HourOfDay.Add(5, 1);
            HourOfDay.Add(6, 1);
            HourOfDay.Add(8, 15);
            HourOfDay.Add(9, 57);
            HourOfDay.Add(10, 36);
            HourOfDay.Add(11, 41);
            HourOfDay.Add(12, 51);
            HourOfDay.Add(13, 55);
            HourOfDay.Add(14, 54);
            HourOfDay.Add(15, 42);
            HourOfDay.Add(16, 44);
            HourOfDay.Add(17, 42);
            HourOfDay.Add(18, 33);
            HourOfDay.Add(19, 1);
            HourOfDay.Add(20, 7);
            HourOfDay.Add(21, 5);
            HourOfDay.Add(22, 8);
        }
        public override BucketList Run()
        {
            var result = new BucketList();
            var generalizedBucketList = base.Run();
            var genPerm = GetBestPermutedTable(generalizedBucketList);

            foreach (var bucket in genPerm)
            {
                //if any of the bucket is null, it means that it is not delta-present, k has to be increased
                if (bucket == null) return null;
                var privateBucket = new Bucket();
                foreach (var tuple in bucket)
                {
                    if (Int32.Parse(tuple.GetValue(tuple.GetNumberOfAttributes() - 1)) == 1)
                    {
                        tuple.RemoveAttribute(tuple.GetNumberOfAttributes() - 1);
                        privateBucket.Add(tuple);
                    }
                    if (privateBucket.Count > 0)
                        privateBucket.node = bucket.node;
                }
                if (privateBucket.Count > 0)
                {
                    foreach (int i in qid)
                        privateBucket.PermuteValues(i);
                    result.Add(privateBucket);
                }
            }

            return result;
        }