Free cookie consent management tool by TermsFeed Policy Generator

Changeset 17778


Ignore:
Timestamp:
10/29/20 14:44:19 (4 years ago)
Author:
abeham
Message:

#2521: working on refactoring

Location:
branches/2521_ProblemRefactoring
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.GeneticProgramming/3.3/ArtificialAnt/Problem.cs

    r17745 r17778  
    7878
    7979    #region Parameter Properties
    80     public IValueParameter<BoolMatrix> WorldParameter {
    81       get { return (IValueParameter<BoolMatrix>)Parameters["World"]; }
    82     }
    83     public IFixedValueParameter<IntValue> MaxTimeStepsParameter {
    84       get { return (IFixedValueParameter<IntValue>)Parameters["MaximumTimeSteps"]; }
    85     }
     80    [Storable] public IValueParameter<BoolMatrix> WorldParameter { get; private set; }
     81    [Storable] public IFixedValueParameter<IntValue> MaxTimeStepsParameter { get; private set; }
    8682    #endregion
    8783
     
    105101
    106102    // cloning
    107     private Problem(Problem original, Cloner cloner) : base(original, cloner) { }
     103    private Problem(Problem original, Cloner cloner) : base(original, cloner) {
     104      WorldParameter = cloner.Clone(original.WorldParameter);
     105      MaxTimeStepsParameter = cloner.Clone(original.MaxTimeStepsParameter);
     106    }
    108107    public override IDeepCloneable Clone(Cloner cloner) {
    109108      return new Problem(this, cloner);
     
    114113      Maximization = true;
    115114      BoolMatrix world = new BoolMatrix(ToBoolMatrix(santaFeAntTrail));
    116       Parameters.Add(new ValueParameter<BoolMatrix>("World", "The world for the artificial ant with scattered food items.", world));
    117       Parameters.Add(new FixedValueParameter<IntValue>("MaximumTimeSteps", "The number of time steps the artificial ant has available to collect all food items.", new IntValue(600)));
     115      Parameters.Add(WorldParameter = new ValueParameter<BoolMatrix>("World", "The world for the artificial ant with scattered food items.", world));
     116      Parameters.Add(MaxTimeStepsParameter = new FixedValueParameter<IntValue>("MaximumTimeSteps", "The number of time steps the artificial ant has available to collect all food items.", new IntValue(600)));
    118117
    119118      var g = new SimpleSymbolicExpressionGrammar();
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.GeneticProgramming/3.3/BasicSymbolicRegression/Problem.cs

    r17655 r17778  
    3939  [StorableType("72011B73-28C6-4D5E-BEDF-27425BC87B9C")]
    4040  public sealed class Problem : SymbolicExpressionTreeProblem, IRegressionProblem, IProblemInstanceConsumer<IRegressionProblemData>, IProblemInstanceExporter<IRegressionProblemData> {
    41 
    42     #region parameter names
    43     private const string ProblemDataParameterName = "ProblemData";
    44     #endregion
    45 
     41   
    4642    #region Parameter Properties
    47     public IValueParameter<IRegressionProblemData> ProblemDataParameter {
    48       get { return (IValueParameter<IRegressionProblemData>)Parameters[ProblemDataParameterName]; }
    49     }
     43    [Storable] public IValueParameter<IRegressionProblemData> ProblemDataParameter { get; private set; }
    5044    #endregion
    5145
     
    7266    private Problem(Problem original, Cloner cloner)
    7367      : base(original, cloner) {
     68      ProblemDataParameter = cloner.Clone(original.ProblemDataParameter);
    7469      RegisterEventHandlers();
    7570    }
     
    7974    public Problem() : base(new SymbolicExpressionTreeEncoding()) {
    8075      Maximization = true;
    81       Parameters.Add(new ValueParameter<IRegressionProblemData>(ProblemDataParameterName, "The data for the regression problem", new RegressionProblemData()));
     76      Parameters.Add(ProblemDataParameter = new ValueParameter<IRegressionProblemData>("ProblemData", "The data for the regression problem", new RegressionProblemData()));
    8277
    8378      Encoding.TreeLength = 100;
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.GeneticProgramming/3.3/Boolean/EvenParityProblem.cs

    r17655 r17778  
    3939  public sealed class EvenParityProblem : SymbolicExpressionTreeProblem {
    4040
    41     #region parameter names
    42     private const string NumberOfBitsParameterName = "NumberOfBits";
    43     #endregion
    44 
    4541    #region Parameter Properties
    46     public IFixedValueParameter<IntValue> NumberOfBitsParameter {
    47       get { return (IFixedValueParameter<IntValue>)Parameters[NumberOfBitsParameterName]; }
    48     }
     42    [Storable] public IFixedValueParameter<IntValue> NumberOfBitsParameter { get; private set; }
    4943    #endregion
    5044
     
    6862    private EvenParityProblem(EvenParityProblem original, Cloner cloner)
    6963      : base(original, cloner) {
     64      NumberOfBitsParameter = cloner.Clone(original.NumberOfBitsParameter);
    7065      RegisterEventHandlers();
    7166    }
     
    7873      : base(new SymbolicExpressionTreeEncoding()) {
    7974      Maximization = true;
    80       Parameters.Add(new FixedValueParameter<IntValue>(NumberOfBitsParameterName, "The number of bits for the input parameter for the even parity function", new IntValue(4)));
     75      Parameters.Add(NumberOfBitsParameter = new FixedValueParameter<IntValue>("NumberOfBits", "The number of bits for the input parameter for the even parity function", new IntValue(4)));
    8176
    8277      Encoding.TreeLength = 100;
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.GeneticProgramming/3.3/Boolean/MultiplexerProblem.cs

    r17655 r17778  
    4141  public sealed class MultiplexerProblem : SymbolicExpressionTreeProblem {
    4242
    43     #region parameter names
    44     private const string NumberOfBitsParameterName = "NumberOfBits";
    45     #endregion
    46 
    4743    #region Parameter Properties
    48     public IFixedValueParameter<IntValue> NumberOfBitsParameter {
    49       get { return (IFixedValueParameter<IntValue>)Parameters[NumberOfBitsParameterName]; }
    50     }
     44    [Storable] public IFixedValueParameter<IntValue> NumberOfBitsParameter { get; private set; }
    5145    #endregion
    5246
     
    7064    private MultiplexerProblem(MultiplexerProblem original, Cloner cloner)
    7165      : base(original, cloner) {
     66      NumberOfBitsParameter = cloner.Clone(original.NumberOfBitsParameter);
    7267      RegisterEventHandlers();
    7368    }
     
    8176      : base(new SymbolicExpressionTreeEncoding()) {
    8277      Maximization = true;
    83       Parameters.Add(new FixedValueParameter<IntValue>(NumberOfBitsParameterName,
     78      Parameters.Add(NumberOfBitsParameter = new FixedValueParameter<IntValue>("NumberOfBits",
    8479        "The number of bits for the input parameter for the multiplexer function. This is the sum of the number of address bits and the number of input lines. E.g. the 11-MUX has 3 address bits and 8 input lines",
    8580        new IntValue(11)));
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.GeneticProgramming/3.3/LawnMower/Problem.cs

    r17745 r17778  
    3535  [Item("Lawn Mower Problem", "The lawn mower demo problem for genetic programming.")]
    3636  public class Problem : SymbolicExpressionTreeProblem {
    37     private const string LawnWidthParameterName = "LawnWidth";
    38     private const string LawnLengthParameterName = "LawnLength";
    39 
    40     public IFixedValueParameter<IntValue> LawnWidthParameter {
    41       get { return (IFixedValueParameter<IntValue>)Parameters[LawnWidthParameterName]; }
    42     }
    43     public IFixedValueParameter<IntValue> LawnLengthParameter {
    44       get { return (IFixedValueParameter<IntValue>)Parameters[LawnLengthParameterName]; }
    45     }
     37    [Storable] public IFixedValueParameter<IntValue> LawnWidthParameter { get; private set; }
     38    [Storable] public IFixedValueParameter<IntValue> LawnLengthParameter { get; private set; }
    4639
    4740    #region item cloning and persistence
     
    5144    private void AfterDeserialization() { }
    5245
    53     protected Problem(Problem original, Cloner cloner) : base(original, cloner) { }
     46    protected Problem(Problem original, Cloner cloner) : base(original, cloner) {
     47      LawnWidthParameter = cloner.Clone(original.LawnWidthParameter);
     48      LawnLengthParameter = cloner.Clone(original.LawnLengthParameter);
     49    }
    5450    public override IDeepCloneable Clone(Cloner cloner) {
    5551      return new Problem(this, cloner);
     
    5955    public Problem() : base(new SymbolicExpressionTreeEncoding()) {
    6056      Maximization = true;
    61       Parameters.Add(new FixedValueParameter<IntValue>(LawnWidthParameterName, "Width of the lawn.", new IntValue(8)));
    62       Parameters.Add(new FixedValueParameter<IntValue>(LawnLengthParameterName, "Length of the lawn.", new IntValue(8)));
     57      Parameters.Add(LawnWidthParameter = new FixedValueParameter<IntValue>("LawnWidth", "Width of the lawn.", new IntValue(8)));
     58      Parameters.Add(LawnLengthParameter = new FixedValueParameter<IntValue>("LawnLength", "Length of the lawn.", new IntValue(8)));
    6359
    6460      var g = new SimpleSymbolicExpressionGrammar();
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.GeneticProgramming/3.3/robocode/Problem.cs

    r17745 r17778  
    3434  [Item("Robocode Problem", "Evolution of a robocode program in java using genetic programming.")]
    3535  public class Problem : SymbolicExpressionTreeProblem {
    36     #region Parameter Names
    37     private const string RobocodePathParamaterName = "RobocodePath";
    38     private const string NrOfRoundsParameterName = "NrOfRounds";
    39     private const string EnemiesParameterName = "Enemies";
    40     #endregion
    41 
     36   
    4237    #region Parameters
    43     public IFixedValueParameter<DirectoryValue> RobocodePathParameter {
    44       get { return (IFixedValueParameter<DirectoryValue>)Parameters[RobocodePathParamaterName]; }
    45     }
    46     public IFixedValueParameter<IntValue> NrOfRoundsParameter {
    47       get { return (IFixedValueParameter<IntValue>)Parameters[NrOfRoundsParameterName]; }
    48     }
    49     public IValueParameter<EnemyCollection> EnemiesParameter {
    50       get { return (IValueParameter<EnemyCollection>)Parameters[EnemiesParameterName]; }
    51     }
     38    [Storable] public IFixedValueParameter<DirectoryValue> RobocodePathParameter { get; private set; }
     39    [Storable] public IFixedValueParameter<IntValue> NrOfRoundsParameter { get; private set; }
     40    [Storable] public IValueParameter<EnemyCollection> EnemiesParameter { get; private set; }
    5241
    5342    public string RobocodePath {
     
    7160    protected Problem(Problem original, Cloner cloner)
    7261      : base(original, cloner) {
     62      RobocodePathParameter = cloner.Clone(original.RobocodePathParameter);
     63      NrOfRoundsParameter = cloner.Clone(original.NrOfRoundsParameter);
     64      EnemiesParameter = cloner.Clone(original.EnemiesParameter);
     65
    7366      RegisterEventHandlers();
    7467    }
     
    8275
    8376
    84       Parameters.Add(new FixedValueParameter<DirectoryValue>(RobocodePathParamaterName, "Path of the Robocode installation.", robocodeDir));
    85       Parameters.Add(new FixedValueParameter<IntValue>(NrOfRoundsParameterName, "Number of rounds a robot has to fight against each opponent.", new IntValue(3)));
    86       Parameters.Add(new ValueParameter<EnemyCollection>(EnemiesParameterName, "The enemies that should be battled.", robotList));
     77      Parameters.Add(RobocodePathParameter = new FixedValueParameter<DirectoryValue>("RobocodePath", "Path of the Robocode installation.", robocodeDir));
     78      Parameters.Add(NrOfRoundsParameter = new FixedValueParameter<IntValue>("NrOfRounds", "Number of rounds a robot has to fight against each opponent.", new IntValue(3)));
     79      Parameters.Add(EnemiesParameter = new ValueParameter<EnemyCollection>("Enemies", "The enemies that should be battled.", robotList));
    8780
    8881      Encoding.FunctionArguments = 0;
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.GraphColoring/3.3/GraphColoringProblem.cs

    r17745 r17778  
    4343    IProblemInstanceConsumer<GCPData>, IProblemInstanceExporter<GCPData> {
    4444
    45     [Storable]
    46     private IValueParameter<IntMatrix> adjacencyListParameter;
    47     public IValueParameter<IntMatrix> AdjacencyListParameter {
    48       get { return adjacencyListParameter; }
    49     }
    50     [Storable]
    51     private IValueParameter<EnumValue<FitnessFunction>> fitnessFunctionParameter;
    52     public IValueParameter<EnumValue<FitnessFunction>> FitnessFunctionParameter {
    53       get { return fitnessFunctionParameter; }
    54     }
     45    [Storable] public IValueParameter<IntMatrix> AdjacencyListParameter { get; private set; }
     46    [Storable] public IValueParameter<EnumValue<FitnessFunction>> FitnessFunctionParameter { get; private set; }
     47    [Storable] public IValueParameter<IntValue> BestKnownColorsParameter { get; private set; }
     48    [Storable] public IResult<IntValue> BestSolutionColorsResult { get; private set; }
     49    [Storable] public IResult<IntValue> BestSolutionConflicts { get; private set; }
     50
    5551    public FitnessFunction FitnessFunction {
    56       get { return fitnessFunctionParameter.Value.Value; }
    57       set { fitnessFunctionParameter.Value.Value = value; }
    58     }
    59     [Storable]
    60     private IValueParameter<IntValue> bestKnownColorsParameter;
    61     public IValueParameter<IntValue> BestKnownColorsParameter {
    62       get { return bestKnownColorsParameter; }
     52      get { return FitnessFunctionParameter.Value.Value; }
     53      set { FitnessFunctionParameter.Value.Value = value; }
    6354    }
    6455
     
    6758    private GraphColoringProblem(GraphColoringProblem original, Cloner cloner)
    6859      : base(original, cloner) {
    69       adjacencyListParameter = cloner.Clone(original.adjacencyListParameter);
    70       fitnessFunctionParameter = cloner.Clone(original.fitnessFunctionParameter);
    71       bestKnownColorsParameter = cloner.Clone(original.bestKnownColorsParameter);
     60      AdjacencyListParameter = cloner.Clone(original.AdjacencyListParameter);
     61      FitnessFunctionParameter = cloner.Clone(original.FitnessFunctionParameter);
     62      BestKnownColorsParameter = cloner.Clone(original.BestKnownColorsParameter);
    7263      RegisterEventHandlers();
    7364    }
    7465    public GraphColoringProblem() {
    7566      Maximization = false;
    76       Parameters.Add(adjacencyListParameter = new ValueParameter<IntMatrix>("Adjacency List", "The adjacency list that describes the (symmetric) edges in the graph with nodes from 0 to N-1.") { ReadOnly = true });
    77       Parameters.Add(fitnessFunctionParameter = new ValueParameter<EnumValue<FitnessFunction>>("Fitness Function", "The function to use for evaluating the quality of a solution.", new EnumValue<FitnessFunction>(FitnessFunction.Penalized)));
    78       Parameters.Add(bestKnownColorsParameter = new OptionalValueParameter<IntValue>("BestKnownColors", "The least amount of colors in a valid coloring.") { ReadOnly = true });
     67      Parameters.Add(AdjacencyListParameter = new ValueParameter<IntMatrix>("Adjacency List", "The adjacency list that describes the (symmetric) edges in the graph with nodes from 0 to N-1.") { ReadOnly = true });
     68      Parameters.Add(FitnessFunctionParameter = new ValueParameter<EnumValue<FitnessFunction>>("Fitness Function", "The function to use for evaluating the quality of a solution.", new EnumValue<FitnessFunction>(FitnessFunction.Penalized)));
     69      Parameters.Add(BestKnownColorsParameter = new OptionalValueParameter<IntValue>("BestKnownColors", "The least amount of colors in a valid coloring.") { ReadOnly = true });
     70      Results.Add(BestSolutionColorsResult = new Result<IntValue>("Best Solution Colors", "The number of best solution found so far."));
    7971
    8072      var imat = new IntMatrix(defaultInstance.Length, 2);
     
    10496
    10597    private void RegisterEventHandlers() {
    106       fitnessFunctionParameter.ValueChanged += FitnessFunctionParameterOnValueChanged;
    107       fitnessFunctionParameter.Value.ValueChanged += FitnessFunctionOnValueChanged;
     98      FitnessFunctionParameter.ValueChanged += FitnessFunctionParameterOnValueChanged;
     99      FitnessFunctionParameter.Value.ValueChanged += FitnessFunctionOnValueChanged;
    108100    }
    109101
    110102    private void FitnessFunctionParameterOnValueChanged(object sender, EventArgs eventArgs) {
    111       fitnessFunctionParameter.Value.ValueChanged += FitnessFunctionOnValueChanged;
     103      FitnessFunctionParameter.Value.ValueChanged += FitnessFunctionOnValueChanged;
    112104      FitnessFunctionOnValueChanged(sender, eventArgs);
    113105    }
     
    126118
    127119    public override ISingleObjectiveEvaluationResult Evaluate(LinearLinkage lle, IRandom random, CancellationToken cancellationToken) {
    128       var adjList = adjacencyListParameter.Value;
     120      var adjList = AdjacencyListParameter.Value;
    129121      var llee = lle.ToEndLinks(); // LLE-e encoding uses the highest indexed member as group number
    130122
Note: See TracChangeset for help on using the changeset viewer.