private void HorizantalSelection() { sp.Restart(); SCPDataSet source = (SCPDataSet)_problem.Source.Clone(); // source.Attributes = AttributeProbability(source.Attributes,source.Sets.Count); //source.Sets = Weighting(source.Sets); //List<SCPSet> candidates = GetCandidates(source.Sets); Stack <SCPSet> starts = new Stack <SCPSet>(source.Sets); List <SCPSolution> solutions = new List <SCPSolution>(); while (starts.Count > 0) { starts.Peek().Visit = true; List <SCPSet> best = Fitness(new List <SCPSet>() { starts.Pop() }, ((SCPDataSet)source.Clone()).Sets); SCPSolution solution = new SCPSolution(); solution.Sets = best; solutions.Add(RemoveRedundantSet(solution)); } FSolution = solutions.OrderBy(s => s.Cost).First(); sp.Stop(); }
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); }
public void Test() { SCP problem = (SCP)scpParser.Problem; SCPDataSet source = (SCPDataSet)problem.Source.Clone(); List <Tuple <SCPAttribute, SCPSet> > panel = new List <Tuple <SCPAttribute, SCPSet> >(); source.Attributes.ForEach(a => { a.Cost = a.GetCheapestCost(); panel.Add(new Tuple <SCPAttribute, SCPSet>(a, a.GetCheapestSet())); }); int covered = 0; SCPSolution solution2 = new SCPSolution(); while (covered < source.Attributes.Count) { source.Attributes = source.Attributes.OrderByDescending(a => a.Cost).ToList(); source.Attributes.ForEach(a1 => { a1.Visit = false; a1.UsedIn.ForEach(s => { s.Weight = s.Cost / s.Frequency; }); a1.UsedIn = a1.UsedIn.OrderBy(ui => ui.Weight).ToList(); }); SCPSet set = source.Attributes.Where(at => at.Visit == false).First().UsedIn.First(); set.Attributes.ForEach(a => { if (a.Visit == false) { a.Visit = true; covered++; a.UsedIn.ForEach(s => s.Frequency--); } }); if (set.Visit == false) { solution2.Sets.Add(set); } set.Visit = true; } RemoveRedundantSet(solution2); bool result = IsFeasible(solution2, problem); }