Example #1
0
        private double BudgetPlanning()
        {
            List <SCPSet>         sets       = new List <SCPSet>();
            List <SCPAttribute>   attributes = new List <SCPAttribute>();
            List <HashSet <int> > subsets    = new List <HashSet <int> >();

            subsets = SubsetMatrix();

            foreach (var set in subsets)
            {
                List <SCPSet> neighbors = _problem.Source.GetNeighbors(set.ToArray());
                if (neighbors.Count > 0)
                {
                    neighbors.ForEach(s =>
                    {
                        sets.Add(s);
                    });
                }
            }

            FindCardinalityInSet(sets);


            sets.ForEach(s => s.Attributes.ForEach(a1 =>
            {
                if (_losted.Exists(l => l.Item3 == a1.Tag))
                {
                    if (attributes.Exists(a2 => a1.Tag == a2.Tag) == false)
                    {
                        attributes.Add(a1);
                    }
                }
            }));

            SCPDataSet source = new SCPDataSet()
            {
                Sets = sets, Attributes = attributes
            };

            source.Resetset();
            SCP subproblem = new SCP(new MatrixSize()
            {
                X = attributes.Count, Y = sets.Count
            })
            {
                Source = source
            };

            IConstructiveHeuristic fog = new SCPGRASP(0.9, 1e-9);
            double cost = fog.Execute(subproblem);

            _cadidate = subproblem.Solution.Sets;
            return(cost);
        }