Free cookie consent management tool by TermsFeed Policy Generator

Changeset 17965


Ignore:
Timestamp:
04/27/21 10:41:43 (4 years ago)
Author:
chaider
Message:

#3073 Added constraints for ShapeConstraintsSampleTest and fixed values

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/HeuristicLab.Tests/HeuristicLab-3.3/Samples/ShapeConstrainedRegressionSampleTest.cs

    r17958 r17965  
    1919 */
    2020#endregion
     21
     22using System;
    2123using System.IO;
    2224using System.Linq;
     
    2426using HeuristicLab.Algorithms.GeneticAlgorithm;
    2527using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
     28using HeuristicLab.Problems.DataAnalysis;
    2629using HeuristicLab.Problems.DataAnalysis.Symbolic.Regression;
    2730using HeuristicLab.Problems.Instances.DataAnalysis;
     
    3639
    3740    [TestMethod]
    38     [TestCategory("Samples.Create")]
    39     [TestProperty("Time", "medium")]
    40     public void CreateShapeConstrainedRegressionSampleTest() {
    41       var ga = CreateShapeConstrainedRegressionSample();
    42       string path = Path.Combine(SamplesUtils.SamplesDirectory, SampleFileName + SamplesUtils.SampleFileExtension);
    43       serializer.Serialize(ga, path);
    44     }
    45     [TestMethod]
    4641    [TestCategory("Samples.Execute")]
    4742    [TestProperty("Time", "long")]
     
    5146      SamplesUtils.RunAlgorithm(ga);
    5247
    53       Assert.AreEqual(0.0780908301423225, SamplesUtils.GetDoubleResult(ga, "BestQuality"), 1E-8);
    54       Assert.AreEqual(0.381314019205066, SamplesUtils.GetDoubleResult(ga, "CurrentAverageQuality"), 1E-8);
    55       Assert.AreEqual(1.0000000000000002, SamplesUtils.GetDoubleResult(ga, "CurrentWorstQuality"), 1E-8);
     48      Assert.AreEqual(0.317642788600248, SamplesUtils.GetDoubleResult(ga, "BestQuality"), 1E-8);
     49      Assert.AreEqual(40.9805778810063, SamplesUtils.GetDoubleResult(ga, "CurrentAverageQuality"), 1E-8);
     50      Assert.AreEqual(3359.91748220025, SamplesUtils.GetDoubleResult(ga, "CurrentWorstQuality"), 1E-8);
    5651      Assert.AreEqual(150200, SamplesUtils.GetIntResult(ga, "EvaluatedSolutions"));
    5752    }
     
    6358      var problem = new ShapeConstrainedRegressionSingleObjectiveProblem();
    6459      problem.Load(provider.LoadData(instance));
     60      var problemData = (IShapeConstrainedRegressionProblemData)problem.ProblemData;
     61      problemData.ShapeConstraints.Add(new ShapeConstraint(new Interval(double.NegativeInfinity, 0), 1.0));
     62      problemData.ShapeConstraints.Add(new ShapeConstraint("G", 1, new Interval(double.NegativeInfinity, 0), 1.0));
     63      problemData.ShapeConstraints.Add(new ShapeConstraint("c", 1, new Interval(0, double.PositiveInfinity), 1.0));
     64      problemData.ShapeConstraints.Add(new ShapeConstraint("m1", 1, new Interval(double.NegativeInfinity, 0), 1.0));
     65      problemData.ShapeConstraints.Add(new ShapeConstraint("m2", 1, new Interval(double.NegativeInfinity, 0), 1.0));
     66      problemData.ShapeConstraints.Add(new ShapeConstraint("r", 1, new Interval(0, double.PositiveInfinity), 1.0));
     67
     68      problemData.VariableRanges.SetInterval("G", new Interval(1, 2));
     69      problemData.VariableRanges.SetInterval("c", new Interval(1, 2));
     70      problemData.VariableRanges.SetInterval("m1", new Interval(1, 5));
     71      problemData.VariableRanges.SetInterval("m2", new Interval(1, 5));
     72      problemData.VariableRanges.SetInterval("r", new Interval(1, 2));
     73      problem.ProblemData = problemData;
     74
    6575
    6676      #region Algorithm Configuration
Note: See TracChangeset for help on using the changeset viewer.