private void RemoveRedundantSet(SCPSolution solution) { SCPSolution improved = solution.Clone(); List <int> blacklist = new List <int>(); solution.ComputeAttributeRedundancies(); foreach (var set in solution.Sets) { bool useless = true; foreach (var a in set.Attributes) { if (a.Redundancy <= 1) { useless = false; break; } } if (useless) { set.Attributes.ForEach(a => a.Redundancy--); blacklist.Add(set.Tag); } } blacklist.ForEach(b => improved.Sets.Remove(improved.Sets.Find(s => s.Tag.ToString() == b.ToString()))); if (improved.Cost < solution.Cost) { solution = improved; } }
public double Execute(IProblem problem) { _sp.Restart(); Initializer(problem); _currSolution.ComputeAttributeRedundancies(); List <double> cost_history = new List <double>(); while (true) { if (cost_history.Count > 2) { if (cost_history[cost_history.Count - 1] == cost_history[cost_history.Count - 2]) { break; } } //STEP#1 _currSolution = RemoveRedundantSet(_currSolution); if (_currSolution.Cost < _opSolution.Cost) { _opSolution = _currSolution.Clone(); } //STEP#2 ImproveByNeighborhood(); if (_currSolution.Cost < _opSolution.Cost) { _opSolution = _currSolution.Clone(); } ////STEP#3 ImproveBySecondNeighborhood(); if (_currSolution.Cost < _opSolution.Cost) { _opSolution = _currSolution.Clone(); } cost_history.Add(_opSolution.Cost); } _sp.Stop(); return(OptimumSultion.Cost); }
private SCPSolution RemoveRedundantSet(SCPSolution solution) { if (solution.Sets.Count == 1) { return(solution); } SCPSolution improved = solution.Clone(); List <int> blacklist = new List <int>(); solution.ComputeAttributeRedundancies(); solution.Sets = solution.Sets.OrderByDescending(s => s.Cost).ToList(); foreach (var set in solution.Sets) { bool useless = true; foreach (var a in set.Attributes) { if (a.Redundancy <= 1) { useless = false; break; } } if (useless) { set.Attributes.ForEach(a => { a.Redundancy--; }); blacklist.Add(set.Tag); } } blacklist.ForEach(b => improved.Sets.Remove(improved.Sets.Find(s => s.Tag.ToString() == b.ToString()))); if (improved.Cost < solution.Cost) { return(improved); } else { return(solution); } }