Free cookie consent management tool by TermsFeed Policy Generator

Changeset 17270 for branches


Ignore:
Timestamp:
09/26/19 10:02:47 (5 years ago)
Author:
abeham
Message:

#2521: worked on removing virtual from Maximization for single-objective problems

Location:
branches/2521_ProblemRefactoring
Files:
21 edited

Legend:

Unmodified
Added
Removed
  • branches/2521_ProblemRefactoring/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/GaussianProcessCovarianceOptimizationProblem.cs

    r17226 r17270  
    135135    #endregion
    136136
    137     public override bool Maximization {
    138       get { return true; } // return log likelihood (instead of negative log likelihood as in GPR
    139     }
    140 
    141137    // problem stores a few variables for information exchange from Evaluate() to Analyze()
    142138    private readonly object problemStateLocker = new object();
     
    151147
    152148    public GaussianProcessCovarianceOptimizationProblem() : base(new SymbolicExpressionTreeEncoding()) {
     149      Maximization = true; // return log likelihood (instead of negative log likelihood as in GPR)
    153150      Parameters.Add(new ValueParameter<IRegressionProblemData>(ProblemDataParameterName, "The data for the regression problem", new RegressionProblemData()));
    154151      Parameters.Add(new FixedValueParameter<IntValue>(ConstantOptIterationsParameterName, "Number of optimization steps for hyperparameter values", new IntValue(50)));
  • branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/BasicProblems/SingleObjectiveProblem.cs

    r17226 r17270  
    3838    where TEncodedSolution : class, IEncodedSolution {
    3939
    40     protected IValueParameter<DoubleValue> BestKnownQualityParameter {
    41       get { return (IValueParameter<DoubleValue>)Parameters["BestKnownQuality"]; }
    42     }
    43 
    44     protected IFixedValueParameter<BoolValue> MaximizationParameter {
    45       get { return (IFixedValueParameter<BoolValue>)Parameters["Maximization"]; }
    46     }
     40    [Storable] protected IValueParameter<DoubleValue> BestKnownQualityParameter { get; set; }
     41    [Storable] protected IValueParameter<BoolValue> MaximizationParameter { get; set; }
    4742
    4843    public double BestKnownQuality {
     
    6156    }
    6257
     58    public bool Maximization {
     59      get { return MaximizationParameter.Value.Value; }
     60      protected set {
     61        if (MaximizationParameter.Value.Value == value) return;
     62        MaximizationParameter.Value = new BoolValue(value).AsReadOnly();
     63      }
     64    }
     65
    6366    [StorableConstructor]
    6467    protected SingleObjectiveProblem(StorableConstructorFlag _) : base(_) { }
     
    6669    protected SingleObjectiveProblem(SingleObjectiveProblem<TEncoding, TEncodedSolution> original, Cloner cloner)
    6770      : base(original, cloner) {
     71      BestKnownQualityParameter = cloner.Clone(original.BestKnownQualityParameter);
     72      MaximizationParameter = cloner.Clone(original.MaximizationParameter);
    6873      ParameterizeOperators();
    6974    }
    7075 
    7176    protected SingleObjectiveProblem() : base() {
    72       Parameters.Add(new FixedValueParameter<BoolValue>("Maximization", "Set to false if the problem should be minimized.", (BoolValue)new BoolValue(Maximization).AsReadOnly()) { Hidden = true });
    73       Parameters.Add(new OptionalValueParameter<DoubleValue>("BestKnownQuality", "The quality of the best known solution of this problem."));
     77      Parameters.Add(MaximizationParameter = new ValueParameter<BoolValue>("Maximization", "Whether the problem should be maximized (True) or minimized (False).", new BoolValue(false).AsReadOnly()) { Hidden = true, ReadOnly = true });
     78      Parameters.Add(BestKnownQualityParameter = new OptionalValueParameter<DoubleValue>("BestKnownQuality", "The quality of the best known solution of this problem."));
    7479
    7580      Operators.Add(Evaluator);
     
    8489
    8590    protected SingleObjectiveProblem(TEncoding encoding) : base(encoding) {
    86       Parameters.Add(new FixedValueParameter<BoolValue>("Maximization", "Set to false if the problem should be minimized.", (BoolValue)new BoolValue(Maximization).AsReadOnly()) { Hidden = true });
    87       Parameters.Add(new OptionalValueParameter<DoubleValue>("BestKnownQuality", "The quality of the best known solution of this problem."));
     91      Parameters.Add(MaximizationParameter = new ValueParameter<BoolValue>("Maximization", "Set to false if the problem should be minimized.", new BoolValue(false).AsReadOnly()) { Hidden = true, ReadOnly = true });
     92      Parameters.Add(BestKnownQualityParameter = new OptionalValueParameter<DoubleValue>("BestKnownQuality", "The quality of the best known solution of this problem."));
    8893
    8994      Operators.Add(Evaluator);
     
    102107    }
    103108
    104     public abstract bool Maximization { get; }
    105109    public abstract double Evaluate(TEncodedSolution solution, IRandom random);
    106110    public virtual void Analyze(TEncodedSolution[] solutions, double[] qualities, ResultCollection results, IRandom random) { }
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.Binary/3.3/DeceptiveTrapProblem.cs

    r17226 r17270  
    4444    }
    4545
    46     public override bool Maximization {
    47       get { return true; }
    48     }
    49 
    5046    private const string TrapSizeParameterName = "Trap Size";
    5147
     
    6460
    6561    public DeceptiveTrapProblem() : base() {
     62      Maximization = true;
    6663      Parameters.Add(new FixedValueParameter<IntValue>(TrapSizeParameterName, "", new IntValue(7)));
    6764      Encoding.Length = 49;
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.Binary/3.3/HIFFProblem.cs

    r17226 r17270  
    4242    }
    4343
    44     public override bool Maximization {
    45       get { return true; }
    46     }
    47 
    4844    public HIFFProblem() : base() {
     45      Maximization = true;
    4946      Encoding.Length = 64;
    5047    }
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.Binary/3.3/OneMaxProblem.cs

    r17226 r17270  
    3232  [StorableType("A290ADDE-33F5-4607-ABC0-19349CD0FBF1")]
    3333  public class OneMaxProblem : BinaryVectorProblem {
    34     public override bool Maximization {
    35       get { return true; }
    36     }
    3734
    3835    public OneMaxProblem() : base() {
     36      Maximization = true;
    3937      Encoding.Length = 10;
    4038      BestKnownQuality = Encoding.Length;
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.ExternalEvaluation/3.4/SingleObjectiveExternalEvaluationProblem.cs

    r16816 r17270  
    9393    public ExternalEvaluationProblem(TEncoding encoding)
    9494      : base(encoding) {
    95       Parameters.Remove("Maximization"); // readonly in base class
    96       Parameters.Add(new FixedValueParameter<BoolValue>("Maximization", "Set to false if the problem should be minimized.", new BoolValue()));
     95      MaximizationParameter.ReadOnly = false;
     96      MaximizationParameter.Value = new BoolValue(); // is a read-only boolvalue in base class
    9797      Parameters.Add(new OptionalValueParameter<EvaluationCache>("Cache", "Cache of previously evaluated solutions."));
    9898      Parameters.Add(new ValueParameter<CheckedItemCollection<IEvaluationServiceClient>>("Clients", "The clients that are used to communicate with the external application.", new CheckedItemCollection<IEvaluationServiceClient>() { new EvaluationServiceClient() }));
     
    104104
    105105    #region Single Objective Problem Overrides
    106     public override bool Maximization {
    107       get { return Parameters.ContainsKey("Maximization") && ((IValueParameter<BoolValue>)Parameters["Maximization"]).Value.Value; }
    108     }
    109 
    110     public virtual void SetMaximization(bool maximization) {
    111       MaximizationParameter.Value.Value = maximization;
    112     }
    113 
    114106    public override double Evaluate(TEncodedSolution solution, IRandom random) {
    115107      var qualityMessage = Evaluate(BuildSolutionMessage(solution));
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.GeneticProgramming/3.3/ArtificialAnt/Problem.cs

    r17226 r17270  
    9898    #endregion
    9999
    100     public override bool Maximization {
    101       get { return true; }
    102     }
    103 
    104100    #region item cloning and persistence
    105101    // persistence
     
    117113
    118114    public Problem() : base(new SymbolicExpressionTreeEncoding()) {
     115      Maximization = true;
    119116      BoolMatrix world = new BoolMatrix(ToBoolMatrix(santaFeAntTrail));
    120117      Parameters.Add(new ValueParameter<BoolMatrix>("World", "The world for the artificial ant with scattered food items.", world));
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.GeneticProgramming/3.3/BasicSymbolicRegression/Problem.cs

    r17226 r17270  
    6060    public event EventHandler ProblemDataChanged;
    6161
    62     public override bool Maximization {
    63       get { return true; }
    64     }
    65 
    6662    #region item cloning and persistence
    6763    // persistence
     
    8278
    8379    public Problem() : base(new SymbolicExpressionTreeEncoding()) {
     80      Maximization = true;
    8481      Parameters.Add(new ValueParameter<IRegressionProblemData>(ProblemDataParameterName, "The data for the regression problem", new RegressionProblemData()));
    8582
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.GeneticProgramming/3.3/Boolean/EvenParityProblem.cs

    r17226 r17270  
    5454    #endregion
    5555
    56     public override bool Maximization {
    57       get { return true; }
    58     }
    59 
    6056    #region item cloning and persistence
    6157    // persistence
     
    7975    public EvenParityProblem()
    8076      : base(new SymbolicExpressionTreeEncoding()) {
     77      Maximization = true;
    8178      Parameters.Add(new FixedValueParameter<IntValue>(NumberOfBitsParameterName, "The number of bits for the input parameter for the even parity function", new IntValue(4)));
    8279
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.GeneticProgramming/3.3/Boolean/MultiplexerProblem.cs

    r17226 r17270  
    5656    #endregion
    5757
    58     public override bool Maximization {
    59       get { return true; }
    60     }
    61 
    6258    #region item cloning and persistence
    6359    // persistence
     
    8278    public MultiplexerProblem()
    8379      : base(new SymbolicExpressionTreeEncoding()) {
     80      Maximization = true;
    8481      Parameters.Add(new FixedValueParameter<IntValue>(NumberOfBitsParameterName,
    8582        "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",
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.GeneticProgramming/3.3/LawnMower/Problem.cs

    r17226 r17270  
    4646    }
    4747
    48     public override bool Maximization {
    49       get { return true; }
    50     }
    51 
    5248    #region item cloning and persistence
    5349    [StorableConstructor]
     
    6359
    6460    public Problem() : base(new SymbolicExpressionTreeEncoding()) {
     61      Maximization = true;
    6562      Parameters.Add(new FixedValueParameter<IntValue>(LawnWidthParameterName, "Width of the lawn.", new IntValue(8)));
    6663      Parameters.Add(new FixedValueParameter<IntValue>(LawnLengthParameterName, "Length of the lawn.", new IntValue(8)));
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.GeneticProgramming/3.3/robocode/Problem.cs

    r17226 r17270  
    7474
    7575    public Problem() : base(new SymbolicExpressionTreeEncoding(new Grammar(), maximumLength: 1000, maximumDepth: 10)) {
     76      Maximization = true;
    7677      DirectoryValue robocodeDir = new DirectoryValue { Value = @"robocode" };
    7778
     
    124125    }
    125126
    126     public override bool Maximization {
    127       get { return true; }
    128     }
    129 
    130127    private void RegisterEventHandlers() {
    131128      RobocodePathParameter.Value.StringValue.ValueChanged += RobocodePathParameter_ValueChanged;
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.GrammaticalEvolution/3.4/ArtificialAnt/GEArtificialAntProblem.cs

    r17226 r17270  
    6868    private void AfterDeserialization() { }
    6969
    70     public override bool Maximization {
    71       get { return true; }
    72     }
    73 
    7470    [Storable]
    7571    // parameters of the wrapped problem cannot be changed therefore it is not strictly necessary to clone and store it
     
    8682
    8783    public GEArtificialAntProblem() : base(new IntegerVectorEncoding()) {
     84      Maximization = true;
    8885      wrappedAntProblem = new HeuristicLab.Problems.GeneticProgramming.ArtificialAnt.Problem();
    8986      Parameters.Add(new ValueParameter<BoolMatrix>("World", "The world for the artificial ant with scattered food items.", wrappedAntProblem.World));
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.GraphColoring/3.3/GraphColoringProblem.cs

    r17226 r17270  
    4242    IProblemInstanceConsumer<GCPData>, IProblemInstanceExporter<GCPData> {
    4343
    44     public override bool Maximization {
    45       get { return false; }
    46     }
    47 
    4844    [Storable]
    4945    private IValueParameter<IntMatrix> adjacencyListParameter;
     
    7672    }
    7773    public GraphColoringProblem() {
     74      Maximization = false;
    7875      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."));
    7976      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)));
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.Knapsack/3.3/KnapsackProblem.cs

    r17226 r17270  
    3838  [StorableType("8CEDAFA2-6E0A-4D4B-B6C6-F85CC58B824E")]
    3939  public sealed class KnapsackProblem : BinaryVectorProblem {
    40     public override bool Maximization { get { return true; } }
    4140
    4241    #region Parameter Properties
     
    8584    public KnapsackProblem()
    8685      : base(new BinaryVectorEncoding("Selection")) {
     86      Maximization = true;
    8787      Parameters.Add(new ValueParameter<IntValue>("KnapsackCapacity", "Capacity of the Knapsack.", new IntValue(1)));
    8888      Parameters.Add(new ValueParameter<IntArray>("Weights", "The weights of the items.", new IntArray(5)));
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.NK/3.3/NKLandscape.cs

    r17226 r17270  
    2323using System.Linq;
    2424using System.Security.Cryptography;
     25using HEAL.Attic;
    2526using HeuristicLab.Common;
    2627using HeuristicLab.Core;
     
    2829using HeuristicLab.Encodings.BinaryVectorEncoding;
    2930using HeuristicLab.Parameters;
    30 using HEAL.Attic;
    3131using HeuristicLab.PluginInfrastructure;
    32 using HeuristicLab.Problems.Binary;
    3332using HeuristicLab.Random;
    3433
     
    3837  [StorableType("04294537-87F2-4A9F-BC14-7D4CA700F326")]
    3938  public sealed class NKLandscape : BinaryVectorProblem {
    40     public override bool Maximization {
    41       get { return false; }
    42     }
    4339
    4440    #region Parameters
     
    144140    public NKLandscape()
    145141      : base() {
     142      Maximization = false;
    146143      random = new MersenneTwister();
    147144
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.PTSP/3.3/ProbabilisticTSP.cs

    r17264 r17270  
    5858    #endregion
    5959
    60     public override bool Maximization {
    61       get { return false; }
    62     }
    63 
    6460    [StorableConstructor]
    6561    protected ProbabilisticTSP(StorableConstructorFlag _) : base(_) { }
     
    7066    }
    7167    protected ProbabilisticTSP() : base(new PermutationEncoding("Tour")) {
     68      Maximization = false;
    7269      Parameters.Add(PTSPDataParameter = new ValueParameter<IProbabilisticTSPData>("PTSP Data", "The main parameters for the pTSP."));
    7370      Parameters.Add(BestKnownSolutionParameter = new OptionalValueParameter<IProbabilisticTSPSolution>("BestKnownSolution", "The best known solution of this pTSP instance."));
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.Programmable/3.3/SingleObjectiveProgrammableProblem.cs

    r17226 r17270  
    2727using HeuristicLab.Common.Resources;
    2828using HeuristicLab.Core;
    29 using HeuristicLab.Data;
    3029using HeuristicLab.Optimization;
    3130using HeuristicLab.Parameters;
     
    9493
    9594    private void OnProblemDefinitionChanged() {
    96       Parameters.Remove("Maximization");
    97       Parameters.Add(new FixedValueParameter<BoolValue>("Maximization", "Set to false if the problem should be minimized.", (BoolValue)new BoolValue(Maximization).AsReadOnly()) { Hidden = true });
     95      Maximization = ProblemDefinition.Maximization;
    9896      Encoding = (TEncoding)ProblemScript.Encoding.Clone();
    9997
     
    107105    private void OnProblemScriptNameChanged() {
    108106      Name = ProblemScript.Name;
    109     }
    110 
    111     public override bool Maximization {
    112       get { return Parameters.ContainsKey("ProblemScript") && ProblemDefinition.Maximization; }
    113107    }
    114108
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.QuadraticAssignment/3.3/QuadraticAssignmentProblem.cs

    r17253 r17270  
    4747    }
    4848
    49     public override bool Maximization { get { return false; } }
    50 
    5149    #region Parameter Properties
    5250    [Storable] public IValueParameter<ItemSet<Permutation>> BestKnownSolutionsParameter { get; private set; }
     
    107105    public QuadraticAssignmentProblem()
    108106      : base(new PermutationEncoding("Assignment") { Length = 5 }) {
     107      Maximization = false;
    109108      Parameters.Add(BestKnownSolutionsParameter = new OptionalValueParameter<ItemSet<Permutation>>("BestKnownSolutions", "The list of best known solutions which is updated whenever a new better solution is found or may be the optimal solution if it is known beforehand.", null));
    110109      Parameters.Add(BestKnownSolutionParameter = new OptionalValueParameter<Permutation>("BestKnownSolution", "The best known solution which is updated whenever a new better solution is found or may be the optimal solution if it is known beforehand.", null));
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.TestFunctions/3.3/SingleObjectiveTestFunctionProblem.cs

    r17226 r17270  
    4040    IProblemInstanceConsumer<SOTFData> {
    4141
    42     public override bool Maximization {
    43       get { return Parameters.ContainsKey("TestFunction") && TestFunction.Maximization; }
    44     }
    45 
    4642    #region Parameter Properties
    4743    private IFixedValueParameter<IntValue> ProblemSizeParameter {
     
    8682      Parameters.Add(new OptionalValueParameter<RealVector>("BestKnownSolution", "The best known solution for this test function instance."));
    8783      Parameters.Add(new ValueParameter<ISingleObjectiveTestFunction>("TestFunction", "The function that is to be optimized.", new Ackley()));
     84      Maximization = TestFunction.Maximization;
    8885
    8986      Encoding.LengthParameter = ProblemSizeParameter;
     
    170167      var bestSolution = TestFunction.GetBestKnownSolution(ProblemSize);
    171168      BestKnownSolutionParameter.Value = bestSolution;
     169      Maximization = TestFunction.Maximization;
    172170
    173171      OnReset();
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.TravelingSalesman/3.3/TSP.cs

    r17253 r17270  
    4444    public static int DistanceMatrixSizeLimit { get; set; } = 1000;
    4545
    46     public override bool Maximization => false;
    47 
    4846    [Storable] public IValueParameter<ITSPData> TSPDataParameter { get; private set; }
    4947    [Storable] public IValueParameter<ITSPSolution> BestKnownSolutionParameter { get; private set; }
     
    6866
    6967    public TSP() : base(new PermutationEncoding("Tour", 16, PermutationTypes.RelativeUndirected)) {
     68      Maximization = false;
    7069      Parameters.Add(TSPDataParameter = new ValueParameter<ITSPData>("TSPData", "The main parameters of the TSP."));
    7170      Parameters.Add(BestKnownSolutionParameter = new OptionalValueParameter<ITSPSolution>("BestKnownSolution", "The best known solution."));
Note: See TracChangeset for help on using the changeset viewer.