예제 #1
0
        public object Clone()
        {
            SCPDataSet copy = new SCPDataSet();

            copy.Size = Size;
            Sets.ForEach(s => copy.Sets.Add((SCPSet)s.Copy()));
            Attributes.ForEach(a => copy.Attributes.Add(a.Copy()));

            Sets.ForEach(s1 =>
            {
                SCPSet set = copy.Sets.Find(s2 => s2.Tag == s1.Tag);
                s1.Attributes.ForEach(a1 =>
                {
                    SCPAttribute attribute = copy.Attributes.Find(a2 => a2.Tag == a1.Tag);
                    set.Attributes.Add(attribute);
                });
            });

            Attributes.ForEach(a1 =>
            {
                SCPAttribute attribute = copy.Attributes.Find(a2 => a2.Tag == a1.Tag);
                a1.UsedIn.ForEach(s1 => attribute.UsedIn.Add(copy.Sets.Find(s2 => s2.Tag == s1.Tag)));
            });

            return(copy);
        }
예제 #2
0
        public SCPSolution Clone()
        {
            List <SCPAttribute> attributes = new List <SCPAttribute>();

            Sets.ForEach(s => s.Attributes.ForEach(a1 =>
            {
                if (attributes.Exists(a2 => a2.Tag == a1.Tag) == false)
                {
                    attributes.Add(a1.Copy());
                }
            }));

            SCPSolution clone = new SCPSolution();

            Sets.ForEach(s =>
            {
                SCPSet set = s.Copy();
                clone.Sets.Add(set);
                s.Attributes.ForEach(a1 =>
                {
                    SCPAttribute attribute = attributes.Find(a2 => a2.Tag == a1.Tag);
                    attribute.UsedIn.Add(set);
                    set.Attributes.Add(attribute);
                });
            });

            clone.CriticalList = new List <SCPSet>(CriticalList);

            return(clone);
        }
예제 #3
0
        public bool IsSubset(SCPSet set)
        {
            HashSet <int> me  = new HashSet <int>();
            HashSet <int> sub = new HashSet <int>();

            Attributes.ForEach(a => me.Add(a.Tag));
            set.Attributes.ForEach(a => sub.Add(a.Tag));
            return(me.IsSubsetOf(sub));
        }
예제 #4
0
        public List <SCPSet> GetNeighbors(SCPSet set)
        {
            List <SCPSet> subsets = new List <SCPSet>();

            foreach (var s in Sets)
            {
                bool subest = set.IsSubset(s);
                if (subest)
                {
                    subsets.Add(s);
                }
            }
            return(subsets);
        }
예제 #5
0
        public object Clone()
        {
            SCPSet clone = new SCPSet();

            Attributes.ForEach(a => clone.Attributes.Add((SCPAttribute)a.Copy()));
            clone.Tag         = Tag;
            clone.Cost        = Cost;
            clone.Overhead    = Overhead;
            clone.Frequency   = Frequency;
            clone.Confilict   = Confilict;
            clone.Weight      = Weight;
            clone.Probibility = Probibility;
            return(clone);
        }
예제 #6
0
        public SCPSet Copy()
        {
            SCPSet copy = new SCPSet();

            copy.Attributes  = new List <SCPAttribute>();
            copy.Tag         = Tag;
            copy.Overhead    = Overhead;
            copy.Confilict   = Confilict;
            copy.Cost        = Cost;
            copy.Frequency   = Frequency;
            copy.Weight      = Weight;
            copy.Probibility = Probibility;
            return(copy);
        }
예제 #7
0
 public void RemoveSet(SCPSet set)
 {
     set.Attributes.ForEach(a =>
     {
         int frequency = USet.Count(i => i == a.Tag);
         if (frequency - 1 == 0)
         {
             a.Visit = false;
         }
     });
     if (set.Attributes.Where(a => a.Visit == false).Count() > 0)
     {
         CriticalList.Add(set);
     }
     Sets.Remove(Sets.Find(s => s.Tag.ToString() == set.Tag.ToString()));
 }
예제 #8
0
        public bool IsSubset(SCPSet set)
        {
            if (USet == null)
            {
                return(false);
            }

            HashSet <int> universal = new HashSet <int>();

            USet.ForEach(u => universal.Add(u));
            HashSet <int> subset = new HashSet <int>();

            set.Attributes.ForEach(a => subset.Add(a.Tag));
            bool r = subset.IsSubsetOf(universal);

            return(r);
        }
예제 #9
0
        public void Adapt(SCPSet set)
        {
            double gain  = 0;
            double price = 0;

            Dictionary <int, int> suFreq = SUFrequency;

            int[,] catalog = Catalog;
            List <int> targets = new List <int>();

            price += set.Cost;
            foreach (var attribute in set.Attributes)
            {
                for (int i = 0; i < catalog.Length / 2; i++)
                {
                    if (catalog[1, i] == attribute.Tag)
                    {
                        targets.Add(catalog[0, i]);
                    }
                }
            }

            foreach (var t in targets)
            {
                suFreq[t]--;
            }

            foreach (var item in suFreq)
            {
                if (item.Value <= 0)
                {
                    gain += Sets.Find(s => s.Tag == item.Key).Cost;
                }
            }

            if (set.Cost - gain < 0)
            {
                Sets.Add(set);
                suFreq.Where(s1 => s1.Value == 0).ToList().ForEach(s => Sets.Remove(Sets.Find(s2 => s.Key == s2.Tag)));
            }
        }
예제 #10
0
 public void ComputeAttributeRedundancyPrice()
 {
     Sets.ForEach(set =>
     {
         set.Attributes.ForEach(a =>
         {
             if (USet.Exists(u => u == a.Tag))
             {
                 a.Cost = 0;
                 USet.Where(u => u == a.Tag).ToList().ForEach(i =>
                 {
                     double price = 0;
                     SCPSet ts    = Sets.Find(s => s.Tag == i);
                     if (ts != null)
                     {
                         price = ts.Cost / ts.Attributes.Count;
                     }
                     a.Cost += price;
                 });
             }
         });
     });
 }
예제 #11
0
        public double Delta(SCPSet set)
        {
            double gain  = 0;
            double price = 0;

            Dictionary <int, int> suFreq = SUFrequency;

            int[,] catalog = Catalog;
            List <int> targets = new List <int>();

            price += set.Cost;
            foreach (var attribute in set.Attributes)
            {
                for (int i = 0; i < catalog.Length / 2; i++)
                {
                    if (catalog[1, i] == attribute.Tag)
                    {
                        targets.Add(catalog[0, i]);
                    }
                }
            }

            foreach (var t in targets)
            {
                suFreq[t]--;
            }

            foreach (var item in suFreq)
            {
                if (item.Value <= 0)
                {
                    gain += Sets.Find(s => s.Tag == item.Key).Cost;
                }
            }

            return(set.Cost - gain);
        }