Free cookie consent management tool by TermsFeed Policy Generator

Changeset 16076


Ignore:
Timestamp:
08/14/18 10:46:59 (6 years ago)
Author:
abeham
Message:

#1614: pending updates

Location:
branches/1614_GeneralizedQAP/GQAPSolver
Files:
3 added
2 edited

Legend:

Unmodified
Added
Removed
  • branches/1614_GeneralizedQAP/GQAPSolver/GQAPSolver.csproj

    r15890 r16076  
    3535      <HintPath>..\packages\CommandLineParser.2.2.1\lib\net45\CommandLine.dll</HintPath>
    3636    </Reference>
     37    <Reference Include="HeuristicLab.Algorithms.ALPS-3.3">
     38      <HintPath>..\..\..\trunk\bin\HeuristicLab.Algorithms.ALPS-3.3.dll</HintPath>
     39    </Reference>
    3740    <Reference Include="HeuristicLab.Collections-3.3">
    3841      <HintPath>..\..\..\trunk\bin\HeuristicLab.Collections-3.3.dll</HintPath>
     
    4447      <HintPath>..\..\..\trunk\bin\HeuristicLab.Core-3.3.dll</HintPath>
    4548    </Reference>
     49    <Reference Include="HeuristicLab.Cplex-12.7.0">
     50      <HintPath>..\..\..\trunk\bin\HeuristicLab.Cplex-12.7.0.dll</HintPath>
     51    </Reference>
    4652    <Reference Include="HeuristicLab.Data-3.3">
    4753      <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>
    4868    </Reference>
    4969    <Reference Include="HeuristicLab.Problems.Instances-3.3">
     
    5272    <Reference Include="HeuristicLab.Problems.Instances.CordeauGQAP-3.3">
    5373      <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>
    5489    </Reference>
    5590    <Reference Include="System" />
     
    65100    <Compile Include="Program.cs" />
    66101    <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>
    67107  </ItemGroup>
    68108  <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>
    69114    <None Include="App.config" />
    70115    <None Include="packages.config" />
  • branches/1614_GeneralizedQAP/GQAPSolver/Program.cs

    r15904 r16076  
    11using System;
     2using System.IO;
    23using System.Linq;
    34using CommandLine;
     5using HeuristicLab.Algorithms.ALPS;
    46using HeuristicLab.Data;
     7using HeuristicLab.Optimization;
     8using HeuristicLab.Persistence.Default.Xml;
    59using HeuristicLab.Problems.GeneralizedQuadraticAssignment;
     10using HeuristicLab.Problems.GeneralizedQuadraticAssignment.Algorithms.CPLEX;
    611using HeuristicLab.Problems.GeneralizedQuadraticAssignment.Algorithms.Evolutionary;
    712using HeuristicLab.Problems.GeneralizedQuadraticAssignment.Algorithms.GRASP;
     13using HeuristicLab.Problems.GeneralizedQuadraticAssignment.Algorithms.LAHC;
    814using HeuristicLab.Problems.GeneralizedQuadraticAssignment.Algorithms.LocalSearch;
     15using HeuristicLab.Problems.GeneralizedQuadraticAssignment.Algorithms.LocalSolverNet;
    916using HeuristicLab.Problems.Instances.CordeauGQAP;
     17using HeuristicLab.Selection;
    1018
    1119namespace 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 }
    1321
    1422  class CLOptions {
     
    2331    public string ProblemInstance { get; set; }
    2432
    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")]
    2634    public AlgorithmType Algorithm { get; set; }
    2735
     
    3947    public int MaxEvaluations { get; set; }
    4048
    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)")]
    4261    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)")]
    4463    public double MutationProbability { get; set; }
    45 
    46     [Option("pertstr", Default = 0.5, HelpText = "Perturbation strength (ILS)")]
    47     public double PerturbationStrength { get; set; }
    4864
    4965    [Option("mu", Default = 10, HelpText = "Parent population size (ES)")]
     
    5167    [Option("lambda", Default = 10, HelpText = "Offspring population size (ES)")]
    5268    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)")]
    5470    public ESSelection Selection { get; set; }
    5571    [Option("recomb", Default = 0, HelpText = "Use recombination 0 or 1 (ES)")]
    5672    public int Recombination { get; set; }
     73
     74    [Option("pertstr", Default = 0.5, HelpText = "Perturbation strength (ILS)")]
     75    public double PerturbationStrength { get; set; }
    5776
    5877    [Option("eliteset", Default = 10, HelpText = "Size of the elite set (GRASP)")]
     
    82101      var descriptors = provider.GetDataDescriptors().ToList();
    83102      var avgBest = 0.0;
     103      var gqapInstance = provider.LoadData(descriptors.Single(x => x.Name == opts.ProblemInstance));
     104
    84105      for (var t = 0; t < opts.Tries; t++) {
    85         HeuristicLab.Optimization.IAlgorithm alg = null;
     106        IAlgorithm alg = null;
    86107        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;
    87150          case AlgorithmType.OSGA:
    88151            alg = new OSGA() {
     
    92155              PopulationSize = opts.PopulationSize,
    93156              MutationProbability = opts.MutationProbability,
    94               StopAtBestKnownQuality = true,
    95               Seed = (int)opts.Seed,
    96               SetSeedRandomly = false
    97             };
    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,
    105157              StopAtBestKnownQuality = true,
    106158              Seed = (int)opts.Seed,
     
    117169              Selection = opts.Selection,
    118170              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),
    119192              StopAtBestKnownQuality = true,
    120193              Seed = (int)opts.Seed,
     
    139212            };
    140213            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;
    141257        }
    142         if (alg == null) throw new InvalidOperationException("Unknown algorithm.");
     258        if (alg == null) throw new InvalidOperationException("Unknown algorithm " + opts.Algorithm + ".");
    143259        var prob = alg.Problem as GQAP;
    144260        if (prob == null) alg.Problem = prob = new GQAP();
    145         prob.Load(provider.LoadData(descriptors.Single(x => x.Name == opts.ProblemInstance)));
     261        prob.Load(gqapInstance);
    146262        alg.Start();
    147263        avgBest += ((DoubleValue)alg.Results["BestQuality"].Value).Value;
Note: See TracChangeset for help on using the changeset viewer.