private Result ILS(SCP problem) { List <Tuple <double, SCPSolution> > history = new List <Tuple <double, SCPSolution> >(); bool validity = false; int iteratin = 0; TimeSpan elapsed = new TimeSpan(); double cost = 0; while (iteratin++ < 5) { IConstructiveHeuristic grasp = new SCPGRASP(0.9, 1e-9); cost = grasp.Execute(problem.Clone()); SmartLocalSearch scpLS = new SmartLocalSearch(); cost = scpLS.Execute(grasp.Problem); elapsed = scpLS.Elapsed; history.Add(new Tuple <double, SCPSolution>(cost, scpLS.OptimumSultion.Clone())); } ((SCP)scpParser.Problem).Solution = history.OrderBy(h => h.Item1).ToList().FirstOrDefault().Item2; validity = SolutionValidity(); Assert.AreEqual(validity, true); Result r = new UnitTest.Result(); r.Time = elapsed.Milliseconds; r.Cost = cost; return(r); }
public void GRASP() { IConstructiveHeuristic grasp = new SCPGRASP(0.9, 1e-9); double cost = grasp.Execute(scpParser.Problem); TimeSpan elapsed = grasp.Elapsed; bool validity = SolutionValidity(); Assert.AreEqual(validity, true); }
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 GLocalSearch() { IConstructiveHeuristic grasp = new SCPGRASP(0.9, 1e-9); double cost = grasp.Execute(scpParser.Problem); LocalSearch scpLS = new LocalSearch(); cost = scpLS.Execute(grasp.Problem.Clone()); ((SCP)scpParser.Problem).Solution = scpLS.OptimumSultion; TimeSpan elapsed = scpLS.Elapsed; bool validity = SolutionValidity(); Assert.AreEqual(validity, true); }
public void DCGRASP() { IConstructiveHeuristic grasp = new SCPGRASP(0.9, 1e-9); double cost = grasp.Execute(scpParser.Problem); DestructiveConstructive dc = new DestructiveConstructive(); cost = dc.Execute(grasp.Problem); ((SCP)scpParser.Problem).Solution = dc.OptimumSultion; TimeSpan elapsed = dc.Elapsed; bool validity = SolutionValidity(); Assert.AreEqual(validity, true); }
public void IterativeLocalSearch() { List <Tuple <double, SCPSolution> > history = new List <Tuple <double, SCPSolution> >(); bool validity = false; int iteratin = 0; while (iteratin++ < 5) { IConstructiveHeuristic grasp = new SCPGRASP(0.9, 1e-9); double cost = grasp.Execute((SCP)((SCP)scpParser.Problem).Clone()); LocalSearch scpLS = new LocalSearch(); cost = scpLS.Execute(grasp.Problem); TimeSpan elapsed = scpLS.Elapsed; history.Add(new Tuple <double, SCPSolution>(cost, scpLS.OptimumSultion.Clone())); } ((SCP)scpParser.Problem).Solution = history.OrderBy(h => h.Item1).ToList().FirstOrDefault().Item2; validity = SolutionValidity(); Assert.AreEqual(validity, true); }