- Timestamp:
- 09/26/19 10:02:47 (5 years ago)
- Location:
- branches/2521_ProblemRefactoring
- Files:
-
- 21 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2521_ProblemRefactoring/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/GaussianProcessCovarianceOptimizationProblem.cs
r17226 r17270 135 135 #endregion 136 136 137 public override bool Maximization {138 get { return true; } // return log likelihood (instead of negative log likelihood as in GPR139 }140 141 137 // problem stores a few variables for information exchange from Evaluate() to Analyze() 142 138 private readonly object problemStateLocker = new object(); … … 151 147 152 148 public GaussianProcessCovarianceOptimizationProblem() : base(new SymbolicExpressionTreeEncoding()) { 149 Maximization = true; // return log likelihood (instead of negative log likelihood as in GPR) 153 150 Parameters.Add(new ValueParameter<IRegressionProblemData>(ProblemDataParameterName, "The data for the regression problem", new RegressionProblemData())); 154 151 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 38 38 where TEncodedSolution : class, IEncodedSolution { 39 39 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; } 47 42 48 43 public double BestKnownQuality { … … 61 56 } 62 57 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 63 66 [StorableConstructor] 64 67 protected SingleObjectiveProblem(StorableConstructorFlag _) : base(_) { } … … 66 69 protected SingleObjectiveProblem(SingleObjectiveProblem<TEncoding, TEncodedSolution> original, Cloner cloner) 67 70 : base(original, cloner) { 71 BestKnownQualityParameter = cloner.Clone(original.BestKnownQualityParameter); 72 MaximizationParameter = cloner.Clone(original.MaximizationParameter); 68 73 ParameterizeOperators(); 69 74 } 70 75 71 76 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.")); 74 79 75 80 Operators.Add(Evaluator); … … 84 89 85 90 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.")); 88 93 89 94 Operators.Add(Evaluator); … … 102 107 } 103 108 104 public abstract bool Maximization { get; }105 109 public abstract double Evaluate(TEncodedSolution solution, IRandom random); 106 110 public virtual void Analyze(TEncodedSolution[] solutions, double[] qualities, ResultCollection results, IRandom random) { } -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.Binary/3.3/DeceptiveTrapProblem.cs
r17226 r17270 44 44 } 45 45 46 public override bool Maximization {47 get { return true; }48 }49 50 46 private const string TrapSizeParameterName = "Trap Size"; 51 47 … … 64 60 65 61 public DeceptiveTrapProblem() : base() { 62 Maximization = true; 66 63 Parameters.Add(new FixedValueParameter<IntValue>(TrapSizeParameterName, "", new IntValue(7))); 67 64 Encoding.Length = 49; -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.Binary/3.3/HIFFProblem.cs
r17226 r17270 42 42 } 43 43 44 public override bool Maximization {45 get { return true; }46 }47 48 44 public HIFFProblem() : base() { 45 Maximization = true; 49 46 Encoding.Length = 64; 50 47 } -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.Binary/3.3/OneMaxProblem.cs
r17226 r17270 32 32 [StorableType("A290ADDE-33F5-4607-ABC0-19349CD0FBF1")] 33 33 public class OneMaxProblem : BinaryVectorProblem { 34 public override bool Maximization {35 get { return true; }36 }37 34 38 35 public OneMaxProblem() : base() { 36 Maximization = true; 39 37 Encoding.Length = 10; 40 38 BestKnownQuality = Encoding.Length; -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.ExternalEvaluation/3.4/SingleObjectiveExternalEvaluationProblem.cs
r16816 r17270 93 93 public ExternalEvaluationProblem(TEncoding encoding) 94 94 : base(encoding) { 95 Parameters.Remove("Maximization"); // readonly in base class96 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 97 97 Parameters.Add(new OptionalValueParameter<EvaluationCache>("Cache", "Cache of previously evaluated solutions.")); 98 98 Parameters.Add(new ValueParameter<CheckedItemCollection<IEvaluationServiceClient>>("Clients", "The clients that are used to communicate with the external application.", new CheckedItemCollection<IEvaluationServiceClient>() { new EvaluationServiceClient() })); … … 104 104 105 105 #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 114 106 public override double Evaluate(TEncodedSolution solution, IRandom random) { 115 107 var qualityMessage = Evaluate(BuildSolutionMessage(solution)); -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.GeneticProgramming/3.3/ArtificialAnt/Problem.cs
r17226 r17270 98 98 #endregion 99 99 100 public override bool Maximization {101 get { return true; }102 }103 104 100 #region item cloning and persistence 105 101 // persistence … … 117 113 118 114 public Problem() : base(new SymbolicExpressionTreeEncoding()) { 115 Maximization = true; 119 116 BoolMatrix world = new BoolMatrix(ToBoolMatrix(santaFeAntTrail)); 120 117 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 60 60 public event EventHandler ProblemDataChanged; 61 61 62 public override bool Maximization {63 get { return true; }64 }65 66 62 #region item cloning and persistence 67 63 // persistence … … 82 78 83 79 public Problem() : base(new SymbolicExpressionTreeEncoding()) { 80 Maximization = true; 84 81 Parameters.Add(new ValueParameter<IRegressionProblemData>(ProblemDataParameterName, "The data for the regression problem", new RegressionProblemData())); 85 82 -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.GeneticProgramming/3.3/Boolean/EvenParityProblem.cs
r17226 r17270 54 54 #endregion 55 55 56 public override bool Maximization {57 get { return true; }58 }59 60 56 #region item cloning and persistence 61 57 // persistence … … 79 75 public EvenParityProblem() 80 76 : base(new SymbolicExpressionTreeEncoding()) { 77 Maximization = true; 81 78 Parameters.Add(new FixedValueParameter<IntValue>(NumberOfBitsParameterName, "The number of bits for the input parameter for the even parity function", new IntValue(4))); 82 79 -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.GeneticProgramming/3.3/Boolean/MultiplexerProblem.cs
r17226 r17270 56 56 #endregion 57 57 58 public override bool Maximization {59 get { return true; }60 }61 62 58 #region item cloning and persistence 63 59 // persistence … … 82 78 public MultiplexerProblem() 83 79 : base(new SymbolicExpressionTreeEncoding()) { 80 Maximization = true; 84 81 Parameters.Add(new FixedValueParameter<IntValue>(NumberOfBitsParameterName, 85 82 "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 46 46 } 47 47 48 public override bool Maximization {49 get { return true; }50 }51 52 48 #region item cloning and persistence 53 49 [StorableConstructor] … … 63 59 64 60 public Problem() : base(new SymbolicExpressionTreeEncoding()) { 61 Maximization = true; 65 62 Parameters.Add(new FixedValueParameter<IntValue>(LawnWidthParameterName, "Width of the lawn.", new IntValue(8))); 66 63 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 74 74 75 75 public Problem() : base(new SymbolicExpressionTreeEncoding(new Grammar(), maximumLength: 1000, maximumDepth: 10)) { 76 Maximization = true; 76 77 DirectoryValue robocodeDir = new DirectoryValue { Value = @"robocode" }; 77 78 … … 124 125 } 125 126 126 public override bool Maximization {127 get { return true; }128 }129 130 127 private void RegisterEventHandlers() { 131 128 RobocodePathParameter.Value.StringValue.ValueChanged += RobocodePathParameter_ValueChanged; -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.GrammaticalEvolution/3.4/ArtificialAnt/GEArtificialAntProblem.cs
r17226 r17270 68 68 private void AfterDeserialization() { } 69 69 70 public override bool Maximization {71 get { return true; }72 }73 74 70 [Storable] 75 71 // parameters of the wrapped problem cannot be changed therefore it is not strictly necessary to clone and store it … … 86 82 87 83 public GEArtificialAntProblem() : base(new IntegerVectorEncoding()) { 84 Maximization = true; 88 85 wrappedAntProblem = new HeuristicLab.Problems.GeneticProgramming.ArtificialAnt.Problem(); 89 86 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 42 42 IProblemInstanceConsumer<GCPData>, IProblemInstanceExporter<GCPData> { 43 43 44 public override bool Maximization {45 get { return false; }46 }47 48 44 [Storable] 49 45 private IValueParameter<IntMatrix> adjacencyListParameter; … … 76 72 } 77 73 public GraphColoringProblem() { 74 Maximization = false; 78 75 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.")); 79 76 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 38 38 [StorableType("8CEDAFA2-6E0A-4D4B-B6C6-F85CC58B824E")] 39 39 public sealed class KnapsackProblem : BinaryVectorProblem { 40 public override bool Maximization { get { return true; } }41 40 42 41 #region Parameter Properties … … 85 84 public KnapsackProblem() 86 85 : base(new BinaryVectorEncoding("Selection")) { 86 Maximization = true; 87 87 Parameters.Add(new ValueParameter<IntValue>("KnapsackCapacity", "Capacity of the Knapsack.", new IntValue(1))); 88 88 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 23 23 using System.Linq; 24 24 using System.Security.Cryptography; 25 using HEAL.Attic; 25 26 using HeuristicLab.Common; 26 27 using HeuristicLab.Core; … … 28 29 using HeuristicLab.Encodings.BinaryVectorEncoding; 29 30 using HeuristicLab.Parameters; 30 using HEAL.Attic;31 31 using HeuristicLab.PluginInfrastructure; 32 using HeuristicLab.Problems.Binary;33 32 using HeuristicLab.Random; 34 33 … … 38 37 [StorableType("04294537-87F2-4A9F-BC14-7D4CA700F326")] 39 38 public sealed class NKLandscape : BinaryVectorProblem { 40 public override bool Maximization {41 get { return false; }42 }43 39 44 40 #region Parameters … … 144 140 public NKLandscape() 145 141 : base() { 142 Maximization = false; 146 143 random = new MersenneTwister(); 147 144 -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.PTSP/3.3/ProbabilisticTSP.cs
r17264 r17270 58 58 #endregion 59 59 60 public override bool Maximization {61 get { return false; }62 }63 64 60 [StorableConstructor] 65 61 protected ProbabilisticTSP(StorableConstructorFlag _) : base(_) { } … … 70 66 } 71 67 protected ProbabilisticTSP() : base(new PermutationEncoding("Tour")) { 68 Maximization = false; 72 69 Parameters.Add(PTSPDataParameter = new ValueParameter<IProbabilisticTSPData>("PTSP Data", "The main parameters for the pTSP.")); 73 70 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 27 27 using HeuristicLab.Common.Resources; 28 28 using HeuristicLab.Core; 29 using HeuristicLab.Data;30 29 using HeuristicLab.Optimization; 31 30 using HeuristicLab.Parameters; … … 94 93 95 94 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; 98 96 Encoding = (TEncoding)ProblemScript.Encoding.Clone(); 99 97 … … 107 105 private void OnProblemScriptNameChanged() { 108 106 Name = ProblemScript.Name; 109 }110 111 public override bool Maximization {112 get { return Parameters.ContainsKey("ProblemScript") && ProblemDefinition.Maximization; }113 107 } 114 108 -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.QuadraticAssignment/3.3/QuadraticAssignmentProblem.cs
r17253 r17270 47 47 } 48 48 49 public override bool Maximization { get { return false; } }50 51 49 #region Parameter Properties 52 50 [Storable] public IValueParameter<ItemSet<Permutation>> BestKnownSolutionsParameter { get; private set; } … … 107 105 public QuadraticAssignmentProblem() 108 106 : base(new PermutationEncoding("Assignment") { Length = 5 }) { 107 Maximization = false; 109 108 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)); 110 109 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 40 40 IProblemInstanceConsumer<SOTFData> { 41 41 42 public override bool Maximization {43 get { return Parameters.ContainsKey("TestFunction") && TestFunction.Maximization; }44 }45 46 42 #region Parameter Properties 47 43 private IFixedValueParameter<IntValue> ProblemSizeParameter { … … 86 82 Parameters.Add(new OptionalValueParameter<RealVector>("BestKnownSolution", "The best known solution for this test function instance.")); 87 83 Parameters.Add(new ValueParameter<ISingleObjectiveTestFunction>("TestFunction", "The function that is to be optimized.", new Ackley())); 84 Maximization = TestFunction.Maximization; 88 85 89 86 Encoding.LengthParameter = ProblemSizeParameter; … … 170 167 var bestSolution = TestFunction.GetBestKnownSolution(ProblemSize); 171 168 BestKnownSolutionParameter.Value = bestSolution; 169 Maximization = TestFunction.Maximization; 172 170 173 171 OnReset(); -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.TravelingSalesman/3.3/TSP.cs
r17253 r17270 44 44 public static int DistanceMatrixSizeLimit { get; set; } = 1000; 45 45 46 public override bool Maximization => false;47 48 46 [Storable] public IValueParameter<ITSPData> TSPDataParameter { get; private set; } 49 47 [Storable] public IValueParameter<ITSPSolution> BestKnownSolutionParameter { get; private set; } … … 68 66 69 67 public TSP() : base(new PermutationEncoding("Tour", 16, PermutationTypes.RelativeUndirected)) { 68 Maximization = false; 70 69 Parameters.Add(TSPDataParameter = new ValueParameter<ITSPData>("TSPData", "The main parameters of the TSP.")); 71 70 Parameters.Add(BestKnownSolutionParameter = new OptionalValueParameter<ITSPSolution>("BestKnownSolution", "The best known solution."));
Note: See TracChangeset
for help on using the changeset viewer.