Changeset 12743


Ignore:
Timestamp:
07/11/15 20:27:00 (6 years ago)
Author:
abeham
Message:

#2427:

  • Added grouping problem sample as Test
  • Added .hl file to Optimizers
  • Adapated StartPage
  • Changed MultiLLEManipulator to enable all manipulators by default
Location:
trunk/sources
Files:
1 added
4 edited
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Encodings.LinearLinkageEncoding/3.3/Manipulators/MultiLLEManipulator.cs

    r12701 r12743  
    5858          Operators.Add((ILinearLinkageManipulator)Activator.CreateInstance(type), true);
    5959      }
    60       Operators.SetItemCheckedState(Operators.OfType<SwapItemManipulator>().First(), false);
    61       Operators.SetItemCheckedState(Operators.OfType<GraftManipulator>().First(), false);
    6260      SelectedOperatorParameter.ActualName = "SelectedManipulationOperator";
    6361    }
  • trunk/sources/HeuristicLab.Optimizer/3.3/HeuristicLab.Optimizer-3.3.csproj

    r12722 r12743  
    146146    <EmbeddedResource Include="Documents\GridSearch_SVM_Regression_Script.hl" />
    147147    <EmbeddedResource Include="Documents\VNS_OP.hl" />
     148    <EmbeddedResource Include="Documents\GA_Grouping.hl" />
    148149    <None Include="Plugin.cs.frame" />
    149150    <Compile Include="OptimizerSingleDocumentMainForm.cs">
  • trunk/sources/HeuristicLab.Optimizer/3.3/StartPage.cs

    r12722 r12743  
    6565        using (Stream stream = assembly.GetManifestResourceStream(typeof(StartPage), "Documents.FirstSteps.rtf"))
    6666          firstStepsRichTextBox.LoadFile(stream, RichTextBoxStreamType.RichText);
    67       }
    68       catch (Exception) { }
     67      } catch (Exception) { }
    6968
    7069      samplesListView.Enabled = false;
     
    112111
    113112        OnAllSamplesLoaded();
    114       }
    115       finally {
     113      } finally {
    116114        MainFormManager.GetMainForm<HeuristicLab.MainForm.WindowsForms.MainForm>().RemoveOperationProgressFromView(samplesListView);
    117115      }
     
    126124          OnSampleLoaded(item, group, 1.0 / count);
    127125        }
    128       }
    129       catch (Exception) {
    130       }
    131       finally {
     126      } catch (Exception) {
     127      } finally {
    132128        if (File.Exists(path)) {
    133129          File.Delete(path); // make sure we remove the temporary file
     
    137133
    138134    private void FillGroupLookup() {
    139       var standardProblems = new List<string> { "ES_Griewank", "GA_TSP", "GA_VRP", "GE_ArtificialAnt",
     135      var standardProblems = new List<string> { "ES_Griewank", "GA_Grouping", "GA_TSP", "GA_VRP", "GE_ArtificialAnt",
    140136                "IslandGA_TSP", "LS_Knapsack", "PSO_Schwefel", "RAPGA_JSSP",
    141137                "SA_Rastrigin", "SGP_SantaFe","GP_Multiplexer", "SS_VRP", "TS_TSP", "TS_VRP", "VNS_OP" ,"VNS_TSP"
     
    185181          mainForm.SetWaitCursor();
    186182          mainForm.ShowContent((IContent)((IItem)samplesListView.SelectedItems[0].Tag).Clone());
    187         }
    188         finally {
     183        } finally {
    189184          mainForm.ResetWaitCursor();
    190185        }
  • trunk/sources/HeuristicLab.Tests/HeuristicLab-3.3/Samples/GAGroupingProblemSampleTest.cs

    r12731 r12743  
    2121
    2222using System.IO;
    23 using System.Linq;
    2423using HeuristicLab.Algorithms.GeneticAlgorithm;
    25 using HeuristicLab.Encodings.PermutationEncoding;
     24using HeuristicLab.Encodings.LinearLinkageEncoding;
    2625using HeuristicLab.Persistence.Default.Xml;
    27 using HeuristicLab.Problems.Instances.TSPLIB;
    28 using HeuristicLab.Problems.TravelingSalesman;
     26using HeuristicLab.Problems.Programmable;
    2927using HeuristicLab.Selection;
    3028using Microsoft.VisualStudio.TestTools.UnitTesting;
     
    3230namespace HeuristicLab.Tests {
    3331  [TestClass]
    34   public class GATspSampleTest {
    35     private const string SampleFileName = "GA_TSP";
     32  public class GAGroupingProblemSampleTest {
     33    private const string SampleFileName = "GA_Grouping";
     34    #region Code
     35    private const string ProblemCode = @"
     36using System;
     37using System.Linq;
     38using System.Collections.Generic;
     39using HeuristicLab.Common;
     40using HeuristicLab.Core;
     41using HeuristicLab.Data;
     42using HeuristicLab.Encodings.LinearLinkageEncoding;
     43using HeuristicLab.Optimization;
     44using HeuristicLab.Problems.Programmable;
     45
     46namespace HeuristicLab.Problems.Programmable {
     47  public class CompiledSingleObjectiveProblemDefinition : CompiledProblemDefinition, ISingleObjectiveProblemDefinition {
     48    private const int ProblemSize = 100;
     49    public bool Maximization { get { return false; } }
     50
     51    private bool[,] allowedTogether;
     52     
     53    public override void Initialize() {
     54      var encoding = new LinearLinkageEncoding(""lle"", length: ProblemSize);
     55      allowedTogether = new bool[encoding.Length, encoding.Length];
     56      var random = new System.Random(13);
     57      for (var i = 0; i < encoding.Length - 1; i++)
     58        for (var j = i + 1; j < encoding.Length; j++)
     59          allowedTogether[i, j] = allowedTogether[j, i] = random.Next(2) == 0;
     60     
     61      Encoding = encoding;
     62    }
     63
     64    public double Evaluate(Individual individual, IRandom random) {
     65      var penalty = 0;
     66      var groups = individual.LinearLinkage(""lle"").GetGroups().ToList();
     67      for (var i = 0; i < groups.Count; i++) {
     68        for (var j = 0; j < groups[i].Count; j++)
     69          for (var k = j + 1; k < groups[i].Count; k++)
     70            if (!allowedTogether[groups[i][j], groups[i][k]]) penalty++;
     71      }
     72      if (penalty > 0) return penalty + ProblemSize;
     73      else return groups.Count;
     74    }
     75
     76    public void Analyze(Individual[] individuals, double[] qualities, ResultCollection results, IRandom random) { }
     77
     78    public IEnumerable<Individual> GetNeighbors(Individual individual, IRandom random) {
     79      foreach (var move in ExhaustiveSwap2MoveGenerator.Generate(individual.LinearLinkage(""lle""))) {
     80        var neighbor = individual.Copy();
     81        var lle = neighbor.LinearLinkage(""lle"");
     82        Swap2MoveMaker.Apply(lle, move);
     83        yield return neighbor;
     84      }
     85    }
     86  }
     87}
     88";
     89    #endregion
    3690
    3791    [TestMethod]
    3892    [TestCategory("Samples.Create")]
    3993    [TestProperty("Time", "medium")]
    40     public void CreateGaTspSampleTest() {
    41       var ga = CreateGaTspSample();
     94    public void CreateGaGroupingProblemSampleTest() {
     95      var ga = CreateGaGroupingProblemSample();
    4296      string path = Path.Combine(SamplesUtils.SamplesDirectory, SampleFileName + SamplesUtils.SampleFileExtension);
    4397      XmlGenerator.Serialize(ga, path);
     
    47101    [TestCategory("Samples.Execute")]
    48102    [TestProperty("Time", "long")]
    49     public void RunGaTspSampleTest() {
    50       var ga = CreateGaTspSample();
     103    public void RunGaGroupingProblemSampleTest() {
     104      var ga = CreateGaGroupingProblemSample();
    51105      ga.SetSeedRandomly.Value = false;
    52106      SamplesUtils.RunAlgorithm(ga);
    53       Assert.AreEqual(12332, SamplesUtils.GetDoubleResult(ga, "BestQuality"));
    54       Assert.AreEqual(13123.2, SamplesUtils.GetDoubleResult(ga, "CurrentAverageQuality"));
    55       Assert.AreEqual(14538, SamplesUtils.GetDoubleResult(ga, "CurrentWorstQuality"));
     107      Assert.AreEqual(26, SamplesUtils.GetDoubleResult(ga, "BestQuality"));
     108      Assert.AreEqual(27.58, SamplesUtils.GetDoubleResult(ga, "CurrentAverageQuality"));
     109      Assert.AreEqual(105, SamplesUtils.GetDoubleResult(ga, "CurrentWorstQuality"));
    56110      Assert.AreEqual(99100, SamplesUtils.GetIntResult(ga, "EvaluatedSolutions"));
    57111    }
    58112
    59     private GeneticAlgorithm CreateGaTspSample() {
     113    private GeneticAlgorithm CreateGaGroupingProblemSample() {
    60114      GeneticAlgorithm ga = new GeneticAlgorithm();
    61115
    62116      #region Problem Configuration
    63       var provider = new TSPLIBTSPInstanceProvider();
    64       var instance = provider.GetDataDescriptors().Where(x => x.Name == "ch130").Single();
    65       TravelingSalesmanProblem tspProblem = new TravelingSalesmanProblem();
    66       tspProblem.Load(provider.LoadData(instance));
    67       tspProblem.UseDistanceMatrix.Value = true;
     117      var problem = new SingleObjectiveProgrammableProblem() {
     118        ProblemScript = { Code = ProblemCode }
     119      };
     120      problem.ProblemScript.Compile();
    68121      #endregion
    69122      #region Algorithm Configuration
    70       ga.Name = "Genetic Algorithm - TSP";
    71       ga.Description = "A genetic algorithm which solves the \"ch130\" traveling salesman problem (imported from TSPLIB)";
    72       ga.Problem = tspProblem;
    73       SamplesUtils.ConfigureGeneticAlgorithmParameters<ProportionalSelector, OrderCrossover2, InversionManipulator>(
    74         ga, 100, 1, 1000, 0.05);
     123      ga.Name = "Genetic Algorithm - Grouping Problem";
     124      ga.Description = "A genetic algorithm which solves a grouping problem using the linear linkage encoding.";
     125      ga.Problem = problem;
     126      SamplesUtils.ConfigureGeneticAlgorithmParameters<TournamentSelector, MultiLinearLinkageCrossover, MultiLinearLinkageManipulator>(
     127        ga, 100, 1, 1000, 0.05, 2);
    75128      #endregion
    76129
  • trunk/sources/HeuristicLab.Tests/HeuristicLab.Tests.csproj

    r12722 r12743  
    189189      <Private>False</Private>
    190190      <HintPath>..\bin\HeuristicLab.Encodings.IntegerVectorEncoding-3.3.dll</HintPath>
     191    </Reference>
     192    <Reference Include="HeuristicLab.Encodings.LinearLinkageEncoding-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
     193      <SpecificVersion>False</SpecificVersion>
     194      <HintPath>..\bin\HeuristicLab.Encodings.LinearLinkageEncoding-3.3.dll</HintPath>
    191195    </Reference>
    192196    <Reference Include="HeuristicLab.Encodings.PermutationEncoding-3.3">
     
    422426    <Compile Include="HeuristicLab-3.3\PluginDependenciesTest.cs" />
    423427    <Compile Include="HeuristicLab-3.3\PluginLoader.cs" />
     428    <Compile Include="HeuristicLab-3.3\Samples\GAGroupingProblemSampleTest.cs" />
    424429    <Compile Include="HeuristicLab-3.3\Samples\VnsOpSampleTest.cs" />
    425430    <Compile Include="HeuristicLab-3.3\Samples\EsGriewankSampleTest.cs" />
Note: See TracChangeset for help on using the changeset viewer.