Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
06/22/11 16:43:23 (13 years ago)
Author:
gkronber
Message:

#1553: split GA unit tests into two sets, one set for creating the samples and one set to run the samples and check results.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab/3.3/Tests/GeneticAlgorithmSamplesTest.cs

    r6442 r6468  
    2828  [TestClass]
    2929  public class GeneticAlgorithmSamplesTest {
    30     [TestMethod]
    31     public void CreateTSPSample() {
     30    #region TSP
     31    [TestMethod]
     32    public void CreateTSPSampleTest() {
     33      var ga = CreateTSPSample();
     34      XmlGenerator.Serialize(ga, "../../GA_TSP.hl");
     35    }
     36    [TestMethod]
     37    public void RunTSPSampleTest() {
     38      var ga = CreateTSPSample();
     39      ga.SetSeedRandomly.Value = false;
     40      RunAlgorithm(ga);
     41      Assert.AreEqual(12332, GetDoubleResult(ga, "BestQuality"));
     42      Assert.AreEqual(13123.2, GetDoubleResult(ga, "CurrentAverageQuality"));
     43      Assert.AreEqual(14538, GetDoubleResult(ga, "CurrentWorstQuality"));
     44      Assert.AreEqual(99100, GetIntResult(ga, "EvaluatedSolutions"));
     45    }
     46
     47    private GeneticAlgorithm CreateTSPSample() {
    3248      GeneticAlgorithm ga = new GeneticAlgorithm();
    3349      #region problem configuration
     
    6480        .Single(), false);
    6581      #endregion
    66 
    67       XmlGenerator.Serialize(ga, "../../GA_TSP.hl");
    68 
     82      return ga;
     83    }
     84
     85    #endregion
     86    #region VRP
     87    [TestMethod]
     88    public void CreateVRPSampleTest() {
     89      var ga = CreateVRPSample();
     90      XmlGenerator.Serialize(ga, "../../GA_VRP.hl");
     91    }
     92
     93    [TestMethod]
     94    public void RunVRPSampleTest() {
     95      var ga = CreateVRPSample();
     96      ga.SetSeedRandomly.Value = false;
    6997      RunAlgorithm(ga);
    70     }
    71     [TestMethod]
    72     public void CreateVRPSample() {
     98      Assert.AreEqual(1828.9368669428336, GetDoubleResult(ga, "BestQuality"));
     99      Assert.AreEqual(1832.0882694567929, GetDoubleResult(ga, "CurrentAverageQuality"));
     100      Assert.AreEqual(1948.386456294867, GetDoubleResult(ga, "CurrentWorstQuality"));
     101      Assert.AreEqual(99100, GetIntResult(ga, "EvaluatedSolutions"));
     102    }
     103
     104    private GeneticAlgorithm CreateVRPSample() {
    73105      GeneticAlgorithm ga = new GeneticAlgorithm();
    74106      #region problem configuration
     
    129161        .Single(), true);
    130162      #endregion
    131 
    132       XmlGenerator.Serialize(ga, "../../GA_VRP.hl");
    133 
     163      return ga;
     164    }
     165
     166    #endregion
     167    #region ArtificialAnt
     168
     169    [TestMethod]
     170    public void CreateArtificialAntSampleTest() {
     171      var ga = CreateArtificialAntSample();
     172      XmlGenerator.Serialize(ga, "../../SGP_SantaFe.hl");
     173    }
     174
     175    [TestMethod]
     176    public void RunArtificialAntSampleTest() {
     177      var ga = CreateArtificialAntSample();
     178      ga.SetSeedRandomly.Value = false;
    134179      RunAlgorithm(ga);
    135     }
    136 
    137     [TestMethod]
    138     public void CreateArtificialAntSample() {
     180      Assert.AreEqual(89, GetDoubleResult(ga, "BestQuality"));
     181      Assert.AreEqual(79.834, GetDoubleResult(ga, "CurrentAverageQuality"));
     182      Assert.AreEqual(0, GetDoubleResult(ga, "CurrentWorstQuality"));
     183      Assert.AreEqual(100900, GetIntResult(ga, "EvaluatedSolutions"));
     184    }
     185
     186    public GeneticAlgorithm CreateArtificialAntSample() {
    139187      GeneticAlgorithm ga = new GeneticAlgorithm();
    140188      #region problem configuration
     
    167215        .Single(), false);
    168216      #endregion
    169 
    170       XmlGenerator.Serialize(ga, "../../SGP_SantaFe.hl");
    171 
     217      return ga;
     218    }
     219
     220    #endregion
     221    #region symbolic regression
     222    [TestMethod]
     223    public void CreateSymbolicRegressionSampleTest() {
     224      var ga = CreateSymbolicRegressionSample();
     225      XmlGenerator.Serialize(ga, "../../SGP_SymbReg.hl");
     226    }
     227    [TestMethod]
     228    public void RunSymbolicRegressionSampleTest() {
     229      var ga = CreateSymbolicRegressionSample();
     230      ga.SetSeedRandomly.Value = false;
    172231      RunAlgorithm(ga);
    173     }
    174 
    175     [TestMethod]
    176     public void CreateSymbolicRegressionSample() {
     232      Assert.AreEqual(0.87577096276191879, GetDoubleResult(ga, "BestQuality"));
     233      Assert.AreEqual(0.65140971696668726, GetDoubleResult(ga, "CurrentAverageQuality"));
     234      Assert.AreEqual(0, GetDoubleResult(ga, "CurrentWorstQuality"));
     235      Assert.AreEqual(100900, GetIntResult(ga, "EvaluatedSolutions"));
     236    }
     237
     238    private GeneticAlgorithm CreateSymbolicRegressionSample() {
    177239      GeneticAlgorithm ga = new GeneticAlgorithm();
    178240      #region problem configuration
     
    269331        .Single(), false);
    270332      #endregion
    271 
    272       XmlGenerator.Serialize(ga, "../../SGP_SymbReg.hl");
    273 
     333      return ga;
     334    }
     335    #endregion
     336    #region symbolic classification
     337
     338    [TestMethod]
     339    public void CreateSymbolicClassificationSampleTest() {
     340      var ga = CreateSymbolicClassificationSample();
     341      XmlGenerator.Serialize(ga, "../../SGP_SymbClass.hl");
     342    }
     343
     344    [TestMethod]
     345    public void RunSymbolicClassificationSampleTest() {
     346      var ga = CreateSymbolicClassificationSample();
     347      ga.SetSeedRandomly.Value = false;
    274348      RunAlgorithm(ga);
    275     }
    276 
    277     [TestMethod]
    278     public void CreateSymbolicClassificationSample() {
     349      Assert.AreEqual(0.1385094551576456, GetDoubleResult(ga, "BestQuality"));
     350      Assert.AreEqual(2.8817699057253576, GetDoubleResult(ga, "CurrentAverageQuality"));
     351      Assert.AreEqual(100.62175156249987, GetDoubleResult(ga, "CurrentWorstQuality"));
     352      Assert.AreEqual(100900, GetIntResult(ga, "EvaluatedSolutions"));
     353    }
     354
     355    private GeneticAlgorithm CreateSymbolicClassificationSample() {
    279356      GeneticAlgorithm ga = new GeneticAlgorithm();
    280357      #region problem configuration
     
    366443        .Single(), false);
    367444      #endregion
    368 
    369       XmlGenerator.Serialize(ga, "../../SGP_SymbClass.hl");
    370 
    371       RunAlgorithm(ga);
    372     }
     445      return ga;
     446    }
     447    #endregion
    373448
    374449    private void ConfigureGeneticAlgorithmParameters<S, C, M>(GeneticAlgorithm ga, int popSize, int elites, int maxGens, double mutationRate, int tournGroupSize = 0)
     
    413488      Assert.AreEqual(ex, null);
    414489    }
     490
     491    private double GetDoubleResult(GeneticAlgorithm ga, string resultName) {
     492      return ((DoubleValue)ga.Results[resultName].Value).Value;
     493    }
     494    private int GetIntResult(GeneticAlgorithm ga, string resultName) {
     495      return ((IntValue)ga.Results[resultName].Value).Value;
     496    }
    415497  }
    416498}
Note: See TracChangeset for help on using the changeset viewer.