Changeset 16076 for branches/1614_GeneralizedQAP/GQAPSolver
- Timestamp:
- 08/14/18 10:46:59 (6 years ago)
- Location:
- branches/1614_GeneralizedQAP/GQAPSolver
- Files:
-
- 3 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/1614_GeneralizedQAP/GQAPSolver/GQAPSolver.csproj
r15890 r16076 35 35 <HintPath>..\packages\CommandLineParser.2.2.1\lib\net45\CommandLine.dll</HintPath> 36 36 </Reference> 37 <Reference Include="HeuristicLab.Algorithms.ALPS-3.3"> 38 <HintPath>..\..\..\trunk\bin\HeuristicLab.Algorithms.ALPS-3.3.dll</HintPath> 39 </Reference> 37 40 <Reference Include="HeuristicLab.Collections-3.3"> 38 41 <HintPath>..\..\..\trunk\bin\HeuristicLab.Collections-3.3.dll</HintPath> … … 44 47 <HintPath>..\..\..\trunk\bin\HeuristicLab.Core-3.3.dll</HintPath> 45 48 </Reference> 49 <Reference Include="HeuristicLab.Cplex-12.7.0"> 50 <HintPath>..\..\..\trunk\bin\HeuristicLab.Cplex-12.7.0.dll</HintPath> 51 </Reference> 46 52 <Reference Include="HeuristicLab.Data-3.3"> 47 53 <HintPath>..\..\..\trunk\bin\HeuristicLab.Data-3.3.dll</HintPath> 54 </Reference> 55 <Reference Include="HeuristicLab.LocalSolver-7.5"> 56 <HintPath>..\..\..\trunk\bin\HeuristicLab.LocalSolver-7.5.dll</HintPath> 57 </Reference> 58 <Reference Include="HeuristicLab.Operators-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL"> 59 <SpecificVersion>False</SpecificVersion> 60 <HintPath>..\..\..\trunk\bin\HeuristicLab.Operators-3.3.dll</HintPath> 61 </Reference> 62 <Reference Include="HeuristicLab.Operators.Views.GraphVisualization-3.3"> 63 <HintPath>..\..\..\trunk\bin\HeuristicLab.Operators.Views.GraphVisualization-3.3.dll</HintPath> 64 </Reference> 65 <Reference Include="HeuristicLab.Persistence-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL"> 66 <SpecificVersion>False</SpecificVersion> 67 <HintPath>..\..\..\trunk\bin\HeuristicLab.Persistence-3.3.dll</HintPath> 48 68 </Reference> 49 69 <Reference Include="HeuristicLab.Problems.Instances-3.3"> … … 52 72 <Reference Include="HeuristicLab.Problems.Instances.CordeauGQAP-3.3"> 53 73 <HintPath>..\..\..\trunk\bin\HeuristicLab.Problems.Instances.CordeauGQAP-3.3.dll</HintPath> 74 </Reference> 75 <Reference Include="HeuristicLab.Selection-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL"> 76 <SpecificVersion>False</SpecificVersion> 77 <HintPath>..\..\..\trunk\bin\HeuristicLab.Selection-3.3.dll</HintPath> 78 </Reference> 79 <Reference Include="HeuristicLab.SequentialEngine-3.3"> 80 <HintPath>..\..\..\trunk\bin\HeuristicLab.SequentialEngine-3.3.dll</HintPath> 81 </Reference> 82 <Reference Include="localsolvernet, Version=7.5.0.0, Culture=neutral, processorArchitecture=AMD64"> 83 <SpecificVersion>False</SpecificVersion> 84 <HintPath>..\..\..\trunk\bin\localsolvernet.dll</HintPath> 85 </Reference> 86 <Reference Include="oplall, Version=12.7.0.0, Culture=neutral, PublicKeyToken=7906592bc7cc7340, processorArchitecture=MSIL"> 87 <SpecificVersion>False</SpecificVersion> 88 <HintPath>..\..\..\trunk\bin\oplall.dll</HintPath> 54 89 </Reference> 55 90 <Reference Include="System" /> … … 65 100 <Compile Include="Program.cs" /> 66 101 <Compile Include="Properties\AssemblyInfo.cs" /> 102 <Compile Include="Properties\Resources.Designer.cs"> 103 <AutoGen>True</AutoGen> 104 <DesignTime>True</DesignTime> 105 <DependentUpon>Resources.resx</DependentUpon> 106 </Compile> 67 107 </ItemGroup> 68 108 <ItemGroup> 109 <None Include="ALPS Instance.hl" /> 110 <EmbeddedResource Include="Properties\Resources.resx"> 111 <Generator>ResXFileCodeGenerator</Generator> 112 <LastGenOutput>Resources.Designer.cs</LastGenOutput> 113 </EmbeddedResource> 69 114 <None Include="App.config" /> 70 115 <None Include="packages.config" /> -
branches/1614_GeneralizedQAP/GQAPSolver/Program.cs
r15904 r16076 1 1 using System; 2 using System.IO; 2 3 using System.Linq; 3 4 using CommandLine; 5 using HeuristicLab.Algorithms.ALPS; 4 6 using HeuristicLab.Data; 7 using HeuristicLab.Optimization; 8 using HeuristicLab.Persistence.Default.Xml; 5 9 using HeuristicLab.Problems.GeneralizedQuadraticAssignment; 10 using HeuristicLab.Problems.GeneralizedQuadraticAssignment.Algorithms.CPLEX; 6 11 using HeuristicLab.Problems.GeneralizedQuadraticAssignment.Algorithms.Evolutionary; 7 12 using HeuristicLab.Problems.GeneralizedQuadraticAssignment.Algorithms.GRASP; 13 using HeuristicLab.Problems.GeneralizedQuadraticAssignment.Algorithms.LAHC; 8 14 using HeuristicLab.Problems.GeneralizedQuadraticAssignment.Algorithms.LocalSearch; 15 using HeuristicLab.Problems.GeneralizedQuadraticAssignment.Algorithms.LocalSolverNet; 9 16 using HeuristicLab.Problems.Instances.CordeauGQAP; 17 using HeuristicLab.Selection; 10 18 11 19 namespace GQAPSolver { 12 public enum AlgorithmType { OSGA = 1, ILS = 2, ES = 3, GRASP = 4}20 public enum AlgorithmType { ALPS = 0, OSGA = 1, ES = 2, ILS = 3, MLS = 4, GRASP = 5, PLAHCS = 6, CPLEX_FY = 7, CPLEX_KB = 8, LOSOL_01 = 9, LOSOL_N = 10 } 13 21 14 22 class CLOptions { … … 23 31 public string ProblemInstance { get; set; } 24 32 25 [Option('a', "alg", Default = AlgorithmType.OSGA, HelpText = "Either: OSGA, ILS, ES, GRASP")]33 [Option('a', "alg", Required = true, HelpText = "Algorithm: ALPS, OSGA, ES, ILS, MLS, GRASP, PLAHCS, CPLEX_FY, CPLEX_KB, LOSOL_01, LOSOL_N")] 26 34 public AlgorithmType Algorithm { get; set; } 27 35 … … 39 47 public int MaxEvaluations { get; set; } 40 48 41 [Option("popsize", Default = 500, HelpText = "Population size (OSGA)")] 49 [Option("agegap", Default = 20, HelpText = "Age gap (ALPS)")] 50 public int AgeGap { get; set; } 51 [Option("agescheme", Default = AgingScheme.Polynomial, HelpText = "Aging Scheme: Linear, Polynomial, Fibonacci, Exponentional (ALPS)")] 52 public AgingScheme AgingScheme { get; set; } 53 [Option("elites", Default = 1, HelpText = "Elite solutions (ALPS)")] 54 public int Elites { get; set; } 55 [Option("layers", Default = 10, HelpText = "Number of layers (ALPS)")] 56 public int NumberOfLayers { get; set; } 57 [Option("selpress", Default = 4, HelpText = "Selection pressure (ALPS)")] 58 public double SelectionPressure { get; set; } 59 60 [Option("popsize", Default = 500, HelpText = "Population size (OSGA, ALPS)")] 42 61 public int PopulationSize { get; set; } 43 [Option("mutprob", Default = 0.05, HelpText = "Mutation probability (OSGA )")]62 [Option("mutprob", Default = 0.05, HelpText = "Mutation probability (OSGA, ALPS)")] 44 63 public double MutationProbability { get; set; } 45 46 [Option("pertstr", Default = 0.5, HelpText = "Perturbation strength (ILS)")]47 public double PerturbationStrength { get; set; }48 64 49 65 [Option("mu", Default = 10, HelpText = "Parent population size (ES)")] … … 51 67 [Option("lambda", Default = 10, HelpText = "Offspring population size (ES)")] 52 68 public int Lambda { get; set; } 53 [Option("evosel", Default = ESSelection.Plus, HelpText = "Selection strategy + or , (ES )")]69 [Option("evosel", Default = ESSelection.Plus, HelpText = "Selection strategy + or , (ES, ALPS)")] 54 70 public ESSelection Selection { get; set; } 55 71 [Option("recomb", Default = 0, HelpText = "Use recombination 0 or 1 (ES)")] 56 72 public int Recombination { get; set; } 73 74 [Option("pertstr", Default = 0.5, HelpText = "Perturbation strength (ILS)")] 75 public double PerturbationStrength { get; set; } 57 76 58 77 [Option("eliteset", Default = 10, HelpText = "Size of the elite set (GRASP)")] … … 82 101 var descriptors = provider.GetDataDescriptors().ToList(); 83 102 var avgBest = 0.0; 103 var gqapInstance = provider.LoadData(descriptors.Single(x => x.Name == opts.ProblemInstance)); 104 84 105 for (var t = 0; t < opts.Tries; t++) { 85 HeuristicLab.Optimization.IAlgorithm alg = null;106 IAlgorithm alg = null; 86 107 switch (opts.Algorithm) { 108 case AlgorithmType.ALPS: 109 using (var stream = new MemoryStream(Properties.Resources.ALPS)) { 110 var alps = (AlpsGeneticAlgorithm)XmlParser.Deserialize(stream, CompressionType.Zip); 111 alps.Seed.Value = (int)opts.Seed; 112 alps.SetSeedRandomly.Value = true; 113 #region Termination 114 var execTimeTerm = alps.Terminators.Operators.OfType<ExecutionTimeTerminator>().SingleOrDefault(); 115 if (execTimeTerm != null) { 116 alps.Terminators.Operators.SetItemCheckedState(execTimeTerm, opts.MaxRuntime > 0); 117 execTimeTerm.Threshold.Value = TimeSpan.FromSeconds(opts.MaxRuntime); 118 } 119 var compTerm = alps.Terminators.Operators.OfType<ComparisonTerminator<IntValue>>().SingleOrDefault(x => x.Name == "Generations"); 120 if (compTerm != null) { 121 alps.Terminators.Operators.SetItemCheckedState(compTerm, opts.MaxIterations > 0); 122 compTerm.Threshold.Value = opts.MaxIterations; 123 } 124 compTerm = alps.Terminators.Operators.OfType<ComparisonTerminator<IntValue>>().SingleOrDefault(x => x.Name == "Evaluations"); 125 if (compTerm != null) { 126 alps.Terminators.Operators.SetItemCheckedState(compTerm, opts.MaxEvaluations > 0); 127 compTerm.Threshold.Value = opts.MaxEvaluations; 128 } 129 var fitTerm = alps.Terminators.Operators.OfType<SingleObjectiveQualityTerminator>().SingleOrDefault(); 130 if (fitTerm != null) { 131 alps.Terminators.Operators.SetItemCheckedState(fitTerm, gqapInstance.BestKnownQuality.HasValue); 132 fitTerm.Threshold.Value = gqapInstance.BestKnownQuality.GetValueOrDefault(); 133 } 134 if (alps.Terminators.Operators.CheckedItems.Count() == 0) throw new InvalidOperationException("No termination criteria defined for ALPS"); 135 #endregion 136 alps.AgeGap.Value = opts.AgeGap; 137 alps.AgingScheme.Value = opts.AgingScheme; 138 alps.Elites.Value = opts.Elites; 139 alps.NumberOfLayers.Value = opts.NumberOfLayers; 140 if (!(alps.Selector is GeneralizedRankSelector)) 141 alps.Selector = alps.SelectorParameter.ValidValues.OfType<GeneralizedRankSelector>().Single(); 142 var sel = alps.Selector as GeneralizedRankSelector; 143 sel.PressureParameter.Value.Value = opts.SelectionPressure; 144 alps.PopulationSize.Value = opts.PopulationSize; 145 alps.MutationProbability.Value = opts.MutationProbability; 146 alps.PlusSelection = opts.Selection == ESSelection.Plus; 147 alg = alps; 148 } 149 break; 87 150 case AlgorithmType.OSGA: 88 151 alg = new OSGA() { … … 92 155 PopulationSize = opts.PopulationSize, 93 156 MutationProbability = opts.MutationProbability, 94 StopAtBestKnownQuality = true,95 Seed = (int)opts.Seed,96 SetSeedRandomly = false97 };98 break;99 case AlgorithmType.ILS:100 alg = new IteratedLS() {101 MaximumEvaluations = opts.MaxEvaluations,102 MaximumIterations = opts.MaxIterations,103 MaximumRuntime = TimeSpan.FromSeconds(opts.MaxRuntime),104 PerturbationStrength = opts.PerturbationStrength,105 157 StopAtBestKnownQuality = true, 106 158 Seed = (int)opts.Seed, … … 117 169 Selection = opts.Selection, 118 170 UseRecombination = opts.Recombination > 0, 171 StopAtBestKnownQuality = true, 172 Seed = (int)opts.Seed, 173 SetSeedRandomly = false 174 }; 175 break; 176 case AlgorithmType.ILS: 177 alg = new IteratedLS() { 178 MaximumEvaluations = opts.MaxEvaluations, 179 MaximumIterations = opts.MaxIterations, 180 MaximumRuntime = TimeSpan.FromSeconds(opts.MaxRuntime), 181 PerturbationStrength = opts.PerturbationStrength, 182 StopAtBestKnownQuality = true, 183 Seed = (int)opts.Seed, 184 SetSeedRandomly = false 185 }; 186 break; 187 case AlgorithmType.MLS: 188 alg = new MultistartLS() { 189 MaximumEvaluations = opts.MaxEvaluations, 190 MaximumIterations = opts.MaxIterations, 191 MaximumRuntime = TimeSpan.FromSeconds(opts.MaxRuntime), 119 192 StopAtBestKnownQuality = true, 120 193 Seed = (int)opts.Seed, … … 139 212 }; 140 213 break; 214 case AlgorithmType.PLAHCS: 215 alg = new PLAHCS() { 216 MaximumEvaluations = opts.MaxEvaluations, 217 MaximumIterations = opts.MaxIterations, 218 MaximumRuntime = TimeSpan.FromSeconds(opts.MaxRuntime), 219 MaximumExponent = 20, 220 StopAtBestKnownQuality = true, 221 Seed = (int)opts.Seed, 222 SetSeedRandomly = false 223 }; 224 break; 225 case AlgorithmType.CPLEX_FY: 226 alg = new GQAP_FY() { 227 MaximumEvaluations = opts.MaxEvaluations, 228 MaximumIterations = opts.MaxIterations, 229 MaximumRuntime = TimeSpan.FromSeconds(opts.MaxRuntime), 230 StopAtBestKnownQuality = true 231 }; 232 break; 233 case AlgorithmType.CPLEX_KB: 234 alg = new GQAP_KB() { 235 MaximumEvaluations = opts.MaxEvaluations, 236 MaximumIterations = opts.MaxIterations, 237 MaximumRuntime = TimeSpan.FromSeconds(opts.MaxRuntime), 238 StopAtBestKnownQuality = true 239 }; 240 break; 241 case AlgorithmType.LOSOL_01: 242 alg = new GQAPBinarySolver() { 243 MaximumEvaluations = opts.MaxEvaluations, 244 MaximumIterations = opts.MaxIterations, 245 MaximumRuntime = TimeSpan.FromSeconds(opts.MaxRuntime), 246 StopAtBestKnownQuality = true 247 }; 248 break; 249 case AlgorithmType.LOSOL_N: 250 alg = new GQAPIntegerSolver() { 251 MaximumEvaluations = opts.MaxEvaluations, 252 MaximumIterations = opts.MaxIterations, 253 MaximumRuntime = TimeSpan.FromSeconds(opts.MaxRuntime), 254 StopAtBestKnownQuality = true 255 }; 256 break; 141 257 } 142 if (alg == null) throw new InvalidOperationException("Unknown algorithm .");258 if (alg == null) throw new InvalidOperationException("Unknown algorithm " + opts.Algorithm + "."); 143 259 var prob = alg.Problem as GQAP; 144 260 if (prob == null) alg.Problem = prob = new GQAP(); 145 prob.Load( provider.LoadData(descriptors.Single(x => x.Name == opts.ProblemInstance)));261 prob.Load(gqapInstance); 146 262 alg.Start(); 147 263 avgBest += ((DoubleValue)alg.Results["BestQuality"].Value).Value;
Note: See TracChangeset
for help on using the changeset viewer.