public GeneticAlgorithm CreateGpLawnMowerSample() {
      GeneticAlgorithm ga = new GeneticAlgorithm();

      #region Problem Configuration

      var problem = new Problems.GeneticProgramming.LawnMower.Problem();

      #endregion
      #region Algorithm Configuration

      ga.Name = "Genetic Programming - Lawn Mower";
      ga.Description = "A standard genetic programming algorithm to solve the lawn mower problem";
      ga.Problem = problem;
      SamplesUtils
        .ConfigureGeneticAlgorithmParameters
        <TournamentSelector, SubtreeCrossover, MultiSymbolicExpressionTreeArchitectureManipulator>(
          ga, 1000, 1, 50, 0.25, 5);
      var mutator = (MultiSymbolicExpressionTreeArchitectureManipulator)ga.Mutator;
      mutator.Operators.SetItemCheckedState(mutator.Operators
        .OfType<OnePointShaker>()
        .Single(), false);

      #endregion

      return ga;
    }
    public GeneticAlgorithm CreateGpArtificialAntSample() {
      GeneticAlgorithm ga = new GeneticAlgorithm();

      #region Problem Configuration
      Problem antProblem = new Problem();
      antProblem.BestKnownQuality = 89;
      antProblem.Encoding.TreeDepth = 10;
      antProblem.Encoding.TreeLength = 100;
      antProblem.Encoding.FunctionDefinitions = 3;
      antProblem.Encoding.FunctionArguments = 3;
      antProblem.MaxTimeSteps.Value = 600;
      #endregion
      #region Algorithm Configuration
      ga.Name = "Genetic Programming - Artificial Ant";
      ga.Description = "A standard genetic programming algorithm to solve the artificial ant problem (Santa-Fe trail)";
      ga.Problem = antProblem;
      SamplesUtils.ConfigureGeneticAlgorithmParameters<TournamentSelector, SubtreeCrossover, MultiSymbolicExpressionTreeArchitectureManipulator>(
        ga, 1000, 1, 50, 0.15, 5);
      var mutator = (MultiSymbolicExpressionTreeArchitectureManipulator)ga.Mutator;
      mutator.Operators.SetItemCheckedState(mutator.Operators
        .OfType<FullTreeShaker>()
        .Single(), false);
      mutator.Operators.SetItemCheckedState(mutator.Operators
        .OfType<OnePointShaker>()
        .Single(), false);
      mutator.Operators.SetItemCheckedState(mutator.Operators
        .OfType<ArgumentDeleter>()
        .Single(), false);
      mutator.Operators.SetItemCheckedState(mutator.Operators
        .OfType<SubroutineDeleter>()
        .Single(), false);
      #endregion

      return ga;
    }
예제 #3
0
    private GeneticAlgorithm CreateGaVrpSample() {
      GeneticAlgorithm ga = new GeneticAlgorithm();

      #region Problem Configuration
      VehicleRoutingProblem vrpProblem = new VehicleRoutingProblem();

      SolomonFormatInstanceProvider instanceProvider = new SolomonInstanceProvider();
      CVRPTWData data = instanceProvider.Import(@"Test Resources\C101.txt", @"Test Resources\C101.opt.txt") as CVRPTWData;
      vrpProblem.Load(data);
      vrpProblem.Name = "C101 VRP (imported from Solomon)";
      vrpProblem.Description = "Represents a Vehicle Routing Problem.";
      CVRPTWProblemInstance instance = vrpProblem.ProblemInstance as CVRPTWProblemInstance;
      instance.DistanceFactor.Value = 1;
      instance.FleetUsageFactor.Value = 100;
      instance.OverloadPenalty.Value = 100;
      instance.TardinessPenalty.Value = 100;
      instance.TimeFactor.Value = 0;
      vrpProblem.MaximizationParameter.Value.Value = false;
      instance.UseDistanceMatrix.Value = true;
      instance.Vehicles.Value = 25;
      #endregion
      #region Algorithm Configuration
      ga.Name = "Genetic Algorithm - VRP";
      ga.Description = "A genetic algorithm which solves the \"C101\" vehicle routing problem (imported from Solomon)";
      ga.Problem = vrpProblem;
      SamplesUtils.ConfigureGeneticAlgorithmParameters<TournamentSelector, MultiVRPSolutionCrossover, MultiVRPSolutionManipulator>(
        ga, 100, 1, 1000, 0.05, 3);

      var xOver = (MultiVRPSolutionCrossover)ga.Crossover;
      foreach (var op in xOver.Operators) {
        xOver.Operators.SetItemCheckedState(op, false);
      }
      xOver.Operators.SetItemCheckedState(xOver.Operators
        .OfType<PotvinRouteBasedCrossover>()
        .Single(), true);
      xOver.Operators.SetItemCheckedState(xOver.Operators
        .OfType<PotvinSequenceBasedCrossover>()
        .Single(), true);

      var manipulator = (MultiVRPSolutionManipulator)ga.Mutator;
      foreach (var op in manipulator.Operators) {
        manipulator.Operators.SetItemCheckedState(op, false);
      }
      manipulator.Operators.SetItemCheckedState(manipulator.Operators
        .OfType<PotvinOneLevelExchangeMainpulator>()
        .Single(), true);
      manipulator.Operators.SetItemCheckedState(manipulator.Operators
        .OfType<PotvinTwoLevelExchangeManipulator>()
        .Single(), true);
      #endregion

      return ga;
    }
예제 #4
0
    private GeneticAlgorithm CreateGaBppSample() {
      GeneticAlgorithm ga = new GeneticAlgorithm();

      #region Problem Configuration
      var bpp = new PermutationProblem();
      #endregion
      #region Algorithm Configuration
      ga.Name = "Genetic Algorithm - Bin Packing Problem (3D)";
      ga.Description = "A genetic algorithm which solves the a 3d bin packing problem instance";
      ga.Problem = bpp;
      SamplesUtils.ConfigureGeneticAlgorithmParameters<TournamentSelector, PartiallyMatchedCrossover, Swap2Manipulator>(
        ga, 300, 1, 50, 0.05, 3);
      #endregion

      return ga;
    }
    // there is no unit test for running the sample because a JDK installation would be necessary (and this is not the case on our build server)

    public GeneticAlgorithm CreateGpRobocodeSample() {
      GeneticAlgorithm ga = new GeneticAlgorithm();

      #region Problem Configuration
      Problem antProblem = new Problem();
      #endregion
      #region Algorithm Configuration
      ga.Name = "Genetic Programming - Robocode Java Source";
      ga.Description = "A standard genetic programming algorithm to evolve the java source code for a robocode bot (see http://robocode.sourceforge.net/). An installation of Java SE Developmen Kit (JDK) >= 1.6 is necessary to run this sample.";
      ga.Problem = antProblem;
      SamplesUtils.ConfigureGeneticAlgorithmParameters<TournamentSelector, SubtreeCrossover, MultiSymbolicExpressionTreeArchitectureManipulator>(
        ga, 50, 1, 50, 0.15, 2);

      ga.Engine = new SequentialEngine.SequentialEngine();
      #endregion

      return ga;
    }
예제 #6
0
    private GeneticAlgorithm CreateGaTspSample() {
      GeneticAlgorithm ga = new GeneticAlgorithm();

      #region Problem Configuration
      var provider = new TSPLIBTSPInstanceProvider();
      var instance = provider.GetDataDescriptors().Where(x => x.Name == "ch130").Single();
      TravelingSalesmanProblem tspProblem = new TravelingSalesmanProblem();
      tspProblem.Load(provider.LoadData(instance));
      tspProblem.UseDistanceMatrix.Value = true;
      #endregion
      #region Algorithm Configuration
      ga.Name = "Genetic Algorithm - TSP";
      ga.Description = "A genetic algorithm which solves the \"ch130\" traveling salesman problem (imported from TSPLIB)";
      ga.Problem = tspProblem;
      SamplesUtils.ConfigureGeneticAlgorithmParameters<ProportionalSelector, OrderCrossover2, InversionManipulator>(
        ga, 100, 1, 1000, 0.05);
      #endregion

      return ga;
    }
    private GeneticAlgorithm CreateGpSymbolicClassificationSample() {
      GeneticAlgorithm ga = new GeneticAlgorithm();
      #region Problem Configuration
      SymbolicClassificationSingleObjectiveProblem symbClassProblem = new SymbolicClassificationSingleObjectiveProblem();
      symbClassProblem.Name = "Mammography Classification Problem";
      symbClassProblem.Description = "Mammography dataset imported from the UCI machine learning repository (http://archive.ics.uci.edu/ml/datasets/Mammographic+Mass)";
      UCIInstanceProvider provider = new UCIInstanceProvider();
      var instance = provider.GetDataDescriptors().Where(x => x.Name.Equals("Mammography, M. Elter, 2007")).Single();
      var mammoData = (ClassificationProblemData)provider.LoadData(instance);
      mammoData.TargetVariableParameter.Value = mammoData.TargetVariableParameter.ValidValues
        .First(v => v.Value == "Severity");
      mammoData.InputVariables.SetItemCheckedState(
        mammoData.InputVariables.Single(x => x.Value == "BI-RADS"), false);
      mammoData.InputVariables.SetItemCheckedState(
        mammoData.InputVariables.Single(x => x.Value == "Age"), true);
      mammoData.InputVariables.SetItemCheckedState(
        mammoData.InputVariables.Single(x => x.Value == "Shape"), true);
      mammoData.InputVariables.SetItemCheckedState(
        mammoData.InputVariables.Single(x => x.Value == "Margin"), true);
      mammoData.InputVariables.SetItemCheckedState(
        mammoData.InputVariables.Single(x => x.Value == "Density"), true);
      mammoData.InputVariables.SetItemCheckedState(
        mammoData.InputVariables.Single(x => x.Value == "Severity"), false);
      mammoData.TrainingPartition.Start = 0;
      mammoData.TrainingPartition.End = 800;
      mammoData.TestPartition.Start = 800;
      mammoData.TestPartition.End = 961;
      mammoData.Name = "Data imported from mammographic_masses.csv";
      mammoData.Description = "Original dataset: http://archive.ics.uci.edu/ml/datasets/Mammographic+Mass, missing values have been replaced with median values.";
      symbClassProblem.ProblemData = mammoData;

      // configure grammar
      var grammar = new TypeCoherentExpressionGrammar();
      grammar.ConfigureAsDefaultClassificationGrammar();
      grammar.Symbols.OfType<VariableCondition>().Single().Enabled = false;
      var varSymbol = grammar.Symbols.OfType<Variable>().Where(x => !(x is LaggedVariable)).Single();
      varSymbol.WeightMu = 1.0;
      varSymbol.WeightSigma = 1.0;
      varSymbol.WeightManipulatorMu = 0.0;
      varSymbol.WeightManipulatorSigma = 0.05;
      varSymbol.MultiplicativeWeightManipulatorSigma = 0.03;
      var constSymbol = grammar.Symbols.OfType<Constant>().Single();
      constSymbol.MaxValue = 20;
      constSymbol.MinValue = -20;
      constSymbol.ManipulatorMu = 0.0;
      constSymbol.ManipulatorSigma = 1;
      constSymbol.MultiplicativeManipulatorSigma = 0.03;
      symbClassProblem.SymbolicExpressionTreeGrammar = grammar;

      // configure remaining problem parameters
      symbClassProblem.BestKnownQuality.Value = 0.0;
      symbClassProblem.FitnessCalculationPartition.Start = 0;
      symbClassProblem.FitnessCalculationPartition.End = 400;
      symbClassProblem.ValidationPartition.Start = 400;
      symbClassProblem.ValidationPartition.End = 800;
      symbClassProblem.RelativeNumberOfEvaluatedSamples.Value = 1;
      symbClassProblem.MaximumSymbolicExpressionTreeLength.Value = 100;
      symbClassProblem.MaximumSymbolicExpressionTreeDepth.Value = 10;
      symbClassProblem.MaximumFunctionDefinitions.Value = 0;
      symbClassProblem.MaximumFunctionArguments.Value = 0;
      symbClassProblem.EvaluatorParameter.Value = new SymbolicClassificationSingleObjectiveMeanSquaredErrorEvaluator();
      #endregion
      #region Algorithm Configuration
      ga.Problem = symbClassProblem;
      ga.Name = "Genetic Programming - Symbolic Classification";
      ga.Description = "A standard genetic programming algorithm to solve a classification problem (Mammographic+Mass dataset)";
      SamplesUtils.ConfigureGeneticAlgorithmParameters<TournamentSelector, SubtreeCrossover, MultiSymbolicExpressionTreeManipulator>(
        ga, 1000, 1, 100, 0.15, 5
        );

      var mutator = (MultiSymbolicExpressionTreeManipulator)ga.Mutator;
      mutator.Operators.OfType<FullTreeShaker>().Single().ShakingFactor = 0.1;
      mutator.Operators.OfType<OnePointShaker>().Single().ShakingFactor = 1.0;

      ga.Analyzer.Operators.SetItemCheckedState(
        ga.Analyzer.Operators
        .OfType<SymbolicClassificationSingleObjectiveOverfittingAnalyzer>()
        .Single(), false);
      ga.Analyzer.Operators.SetItemCheckedState(
        ga.Analyzer.Operators
        .OfType<SymbolicDataAnalysisAlleleFrequencyAnalyzer>()
        .First(), false);
      #endregion
      return ga;
    }
예제 #8
0
 private GeneticAlgorithm(GeneticAlgorithm original, Cloner cloner)
   : base(original, cloner) {
   qualityAnalyzer = cloner.Clone(original.qualityAnalyzer);
   Initialize();
 }
예제 #9
0
    public void ParallelAlgorithmExecutions() {
      int n = 60;
      var tasks = new Task[n];

      TestContext.WriteLine("creating tasks...");
      for (int i = 0; i < n; i++) {
        tasks[i] = new Task((iobj) => {
          int locali = (int)iobj;
          GeneticAlgorithm ga = new GeneticAlgorithm();
          ga.Name = "Alg " + locali;
          ga.PopulationSize.Value = 5;
          ga.MaximumGenerations.Value = 5;
          ga.Engine = new SequentialEngine.SequentialEngine();
          ga.Problem = new SingleObjectiveTestFunctionProblem();
          ga.Prepare(true);
          Console.WriteLine("{0}; Objects before execution: {1}", ga.Name, ga.GetObjectGraphObjects().Count());
          var sw = new Stopwatch();
          sw.Start();
          ga.StartSync(new CancellationToken());
          sw.Stop();
          Console.WriteLine("{0}; Objects after execution: {1}", ga.Name, ga.GetObjectGraphObjects().Count());
          Console.WriteLine("{0}; ExecutionTime: {1} ", ga.Name, sw.Elapsed);
        }, i);
      }
      TestContext.WriteLine("starting tasks...");
      for (int i = 0; i < n; i++) {
        tasks[i].Start();
      }
      TestContext.WriteLine("waiting for tasks to finish...");
      Task.WaitAll(tasks);
    }
예제 #10
0
    public void AlgorithmExecutions() {
      var algs = new List<IAlgorithm>();

      Stopwatch sw = new Stopwatch();
      for (int i = 0; i < 100; i++) {
        GeneticAlgorithm ga = new GeneticAlgorithm();
        ga.PopulationSize.Value = 5;
        ga.MaximumGenerations.Value = 5;
        ga.Engine = new SequentialEngine.SequentialEngine();
        ga.Problem = new SingleObjectiveTestFunctionProblem();

        sw.Start();
        algs.Add(ga);

        var cancellationTokenSource = new CancellationTokenSource();
        ga.StartSync(cancellationTokenSource.Token);
        sw.Stop();
        TestContext.WriteLine("{0}: {1} ", i, sw.Elapsed);
        sw.Reset();
      }
    }
    private GeneticAlgorithm CreateGaGroupingProblemSample() {
      GeneticAlgorithm ga = new GeneticAlgorithm();

      #region Problem Configuration
      var problem = new SingleObjectiveProgrammableProblem() {
        ProblemScript = { Code = ProblemCode }
      };
      problem.ProblemScript.Compile();
      #endregion
      #region Algorithm Configuration
      ga.Name = "Genetic Algorithm - Grouping Problem";
      ga.Description = "A genetic algorithm which solves a grouping problem using the linear linkage encoding.";
      ga.Problem = problem;
      SamplesUtils.ConfigureGeneticAlgorithmParameters<TournamentSelector, MultiLinearLinkageCrossover, MultiLinearLinkageManipulator>(
        ga, 100, 1, 1000, 0.05, 2);
      #endregion

      return ga;
    }
예제 #12
0
 private GeneticAlgorithm(GeneticAlgorithm original, Cloner cloner)
     : base(original, cloner)
 {
     qualityAnalyzer = cloner.Clone(original.qualityAnalyzer);
     Initialize();
 }
예제 #13
0
    private GeneticAlgorithm CreateGpSymbolicRegressionSample() {
      GeneticAlgorithm ga = new GeneticAlgorithm();
      #region Problem Configuration
      CFGPythonProblem cfgPythonProblem = new CFGPythonProblem();
      cfgPythonProblem.Name = "Negative To Zero Problem";
      cfgPythonProblem.Description = "Negative To Zero (described in: http://dl.acm.org/citation.cfm?id=2754769)";
      BenchmarkSuiteInstanceProvider provider = new BenchmarkSuiteInstanceProvider();
      var instance = provider.GetDataDescriptors().Where(x => x.Name.Equals("Negative To Zero")).Single();
      CFGData data = (CFGData)provider.LoadData(instance);
      data.Input = File.ReadAllLines(@"Data\Negative_To_Zero-Input.txt");
      data.Output = File.ReadAllLines(@"Data\Negative_To_Zero-Output.txt");
      cfgPythonProblem.Load(data);

      // configure remaining problem parameters
      cfgPythonProblem.MaximumSymbolicExpressionTreeLengthParameter.Value.Value = 250;
      cfgPythonProblem.MaximumSymbolicExpressionTreeDepthParameter.Value.Value = 100;
      #endregion
      #region Algorithm Configuration
      ga.Problem = cfgPythonProblem;
      ga.Name = "Genetic Programming - CFG Python";
      ga.Description = "A standard genetic programming algorithm to solve a cfg python problem";
      SamplesUtils.ConfigureGeneticAlgorithmParameters<TournamentSelector, SubtreeCrossover, MultiSymbolicExpressionTreeManipulator>(
        ga, 500, 1, 10, 0.05, 5);
      var mutator = (MultiSymbolicExpressionTreeManipulator)ga.Mutator;
      mutator.Operators.SetItemCheckedState(mutator.Operators
        .OfType<FullTreeShaker>()
        .Single(), false);
      mutator.Operators.SetItemCheckedState(mutator.Operators
        .OfType<OnePointShaker>()
        .Single(), false);
      #endregion
      return ga;
    }
    private GeneticAlgorithm CreateGpSymbolicRegressionSample() {
      GeneticAlgorithm ga = new GeneticAlgorithm();
      #region Problem Configuration
      SymbolicRegressionSingleObjectiveProblem symbRegProblem = new SymbolicRegressionSingleObjectiveProblem();
      symbRegProblem.Name = "Tower Symbolic Regression Problem";
      symbRegProblem.Description = "Tower Dataset (downloaded from: http://www.symbolicregression.com/?q=towerProblem)";
      RegressionRealWorldInstanceProvider provider = new RegressionRealWorldInstanceProvider();
      var instance = provider.GetDataDescriptors().Where(x => x.Name.Equals("Tower")).Single();
      var towerProblemData = (RegressionProblemData)provider.LoadData(instance);
      towerProblemData.TargetVariableParameter.Value = towerProblemData.TargetVariableParameter.ValidValues
        .First(v => v.Value == "towerResponse");
      towerProblemData.InputVariables.SetItemCheckedState(
        towerProblemData.InputVariables.Single(x => x.Value == "x1"), true);
      towerProblemData.InputVariables.SetItemCheckedState(
        towerProblemData.InputVariables.Single(x => x.Value == "x7"), false);
      towerProblemData.InputVariables.SetItemCheckedState(
        towerProblemData.InputVariables.Single(x => x.Value == "x11"), false);
      towerProblemData.InputVariables.SetItemCheckedState(
        towerProblemData.InputVariables.Single(x => x.Value == "x16"), false);
      towerProblemData.InputVariables.SetItemCheckedState(
        towerProblemData.InputVariables.Single(x => x.Value == "x21"), false);
      towerProblemData.InputVariables.SetItemCheckedState(
        towerProblemData.InputVariables.Single(x => x.Value == "x25"), false);
      towerProblemData.InputVariables.SetItemCheckedState(
        towerProblemData.InputVariables.Single(x => x.Value == "towerResponse"), false);
      towerProblemData.TrainingPartition.Start = 0;
      towerProblemData.TrainingPartition.End = 3136;
      towerProblemData.TestPartition.Start = 3136;
      towerProblemData.TestPartition.End = 4999;
      towerProblemData.Name = "Data imported from towerData.txt";
      towerProblemData.Description = "Chemical concentration at top of distillation tower, dataset downloaded from: http://vanillamodeling.com/realproblems.html, best R² achieved with nu-SVR = 0.97";
      symbRegProblem.ProblemData = towerProblemData;

      // configure grammar
      var grammar = new TypeCoherentExpressionGrammar();
      grammar.ConfigureAsDefaultRegressionGrammar();
      grammar.Symbols.OfType<VariableCondition>().Single().InitialFrequency = 0.0;
      var varSymbol = grammar.Symbols.OfType<Variable>().Where(x => !(x is LaggedVariable)).Single();
      varSymbol.WeightMu = 1.0;
      varSymbol.WeightSigma = 1.0;
      varSymbol.WeightManipulatorMu = 0.0;
      varSymbol.WeightManipulatorSigma = 0.05;
      varSymbol.MultiplicativeWeightManipulatorSigma = 0.03;
      var constSymbol = grammar.Symbols.OfType<Constant>().Single();
      constSymbol.MaxValue = 20;
      constSymbol.MinValue = -20;
      constSymbol.ManipulatorMu = 0.0;
      constSymbol.ManipulatorSigma = 1;
      constSymbol.MultiplicativeManipulatorSigma = 0.03;
      symbRegProblem.SymbolicExpressionTreeGrammar = grammar;

      // configure remaining problem parameters
      symbRegProblem.BestKnownQuality.Value = 0.97;
      symbRegProblem.FitnessCalculationPartition.Start = 0;
      symbRegProblem.FitnessCalculationPartition.End = 2300;
      symbRegProblem.ValidationPartition.Start = 2300;
      symbRegProblem.ValidationPartition.End = 3136;
      symbRegProblem.RelativeNumberOfEvaluatedSamples.Value = 1;
      symbRegProblem.MaximumSymbolicExpressionTreeLength.Value = 150;
      symbRegProblem.MaximumSymbolicExpressionTreeDepth.Value = 12;
      symbRegProblem.MaximumFunctionDefinitions.Value = 0;
      symbRegProblem.MaximumFunctionArguments.Value = 0;

      symbRegProblem.EvaluatorParameter.Value = new SymbolicRegressionSingleObjectivePearsonRSquaredEvaluator();
      #endregion
      #region Algorithm Configuration
      ga.Problem = symbRegProblem;
      ga.Name = "Genetic Programming - Symbolic Regression";
      ga.Description = "A standard genetic programming algorithm to solve a symbolic regression problem (tower dataset)";
      SamplesUtils.ConfigureGeneticAlgorithmParameters<TournamentSelector, SubtreeCrossover, MultiSymbolicExpressionTreeManipulator>(
        ga, 1000, 1, 50, 0.15, 5);
      var mutator = (MultiSymbolicExpressionTreeManipulator)ga.Mutator;
      mutator.Operators.OfType<FullTreeShaker>().Single().ShakingFactor = 0.1;
      mutator.Operators.OfType<OnePointShaker>().Single().ShakingFactor = 1.0;

      ga.Analyzer.Operators.SetItemCheckedState(
        ga.Analyzer.Operators
        .OfType<SymbolicRegressionSingleObjectiveOverfittingAnalyzer>()
        .Single(), false);
      ga.Analyzer.Operators.SetItemCheckedState(
        ga.Analyzer.Operators
        .OfType<SymbolicDataAnalysisAlleleFrequencyAnalyzer>()
        .First(), false);
      #endregion
      return ga;
    }