Changeset 13396 for branches/ProblemRefactoring
- Timestamp:
- 11/25/15 16:22:37 (9 years ago)
- Location:
- branches/ProblemRefactoring
- Files:
-
- 4 added
- 1 deleted
- 39 edited
- 4 copied
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
branches/ProblemRefactoring/HeuristicLab.Analysis/3.3/AlleleFrequencyAnalysis/AlleleFrequencyAnalyzer.cs
r12012 r13396 37 37 [Item("AlleleFrequencyAnalyzer", "An operator for analyzing the frequency of alleles.")] 38 38 [StorableClass] 39 public abstract class AlleleFrequencyAnalyzer<T> : SingleSuccessorOperator, IAnalyzer, ISingleObjectiveOperator where T : class, I Item{39 public abstract class AlleleFrequencyAnalyzer<T> : SingleSuccessorOperator, IAnalyzer, ISingleObjectiveOperator where T : class, ISolution { 40 40 public virtual bool EnabledByDefault { 41 41 get { return false; } -
branches/ProblemRefactoring/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/BinaryVectorEncoding.cs
r13336 r13396 122 122 #endregion 123 123 124 public override void ConfigureOperators(IEnumerable<I Operator> operators) {124 public override void ConfigureOperators(IEnumerable<IItem> operators) { 125 125 ConfigureCreators(operators.OfType<IBinaryVectorCreator>()); 126 126 ConfigureCrossovers(operators.OfType<IBinaryVectorCrossover>()); -
branches/ProblemRefactoring/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/IntegerVectorEncoding.cs
r13364 r13396 187 187 #endregion 188 188 189 public override void ConfigureOperators(IEnumerable<I Operator> operators) {189 public override void ConfigureOperators(IEnumerable<IItem> operators) { 190 190 ConfigureBoundedOperators(operators.OfType<IBoundedIntegerVectorOperator>()); 191 191 ConfigureCreators(operators.OfType<IIntegerVectorCreator>()); -
branches/ProblemRefactoring/HeuristicLab.Encodings.LinearLinkageEncoding/3.3/LinearLinkageEncoding.cs
r13372 r13396 123 123 #endregion 124 124 125 public override void ConfigureOperators(IEnumerable<I Operator> operators) {125 public override void ConfigureOperators(IEnumerable<IItem> operators) { 126 126 ConfigureCreators(operators.OfType<ILinearLinkageCreator>()); 127 127 ConfigureCrossovers(operators.OfType<ILinearLinkageCrossover>()); -
branches/ProblemRefactoring/HeuristicLab.Encodings.PermutationEncoding/3.3/HeuristicLab.Encodings.PermutationEncoding-3.3.csproj
r11961 r13396 128 128 <Compile Include="Crossovers\PositionBasedCrossover.cs" /> 129 129 <Compile Include="Crossovers\UniformLikeCrossover.cs" /> 130 <Compile Include="Interfaces\IPermutationInversionMoveQualityOperator.cs" /> 131 <Compile Include="Interfaces\IPermutationLocalImprovementOperator.cs" /> 132 <Compile Include="Interfaces\IPermutationScrambleMoveQualityOperator.cs" /> 130 133 <Compile Include="Interfaces\IPermutationScrambleMoveOperator.cs" /> 131 134 <Compile Include="Interfaces\IPermutationMultiNeighborhoodShakingOperator.cs" /> 135 <Compile Include="Interfaces\IPermutationSolutionsOperator.cs" /> 136 <Compile Include="Interfaces\IPermutationSolutionOperator.cs" /> 137 <Compile Include="Interfaces\IPermutationSwap2MoveQualityOperator.cs" /> 132 138 <Compile Include="Interfaces\IPermutationSwap2MoveOperator.cs" /> 133 139 <Compile Include="Interfaces\IPermutationCreator.cs" /> … … 136 142 <Compile Include="Interfaces\IPermutationMoveOperator.cs" /> 137 143 <Compile Include="Interfaces\IPermutationOperator.cs" /> 144 <Compile Include="Interfaces\IPermutationTranslocationMoveQualityOperator.cs" /> 138 145 <Compile Include="Interfaces\IPermutationTranslocationMoveOperator.cs" /> 139 146 <Compile Include="Interfaces\IPermutationInversionMoveOperator.cs" /> -
branches/ProblemRefactoring/HeuristicLab.Encodings.PermutationEncoding/3.3/Interfaces/IPermutationCreator.cs
r13366 r13396 28 28 /// An interface which represents an operator for creating permutations. 29 29 /// </summary> 30 public interface IPermutationCreator : IPermutation Operator, ISolutionCreator<Permutation> {30 public interface IPermutationCreator : IPermutationSolutionOperator, ISolutionCreator<Permutation> { 31 31 IValueLookupParameter<IntValue> LengthParameter { get; } 32 ILookupParameter<Permutation> PermutationParameter { get; }33 32 IValueParameter<PermutationType> PermutationTypeParameter { get; } 34 33 } -
branches/ProblemRefactoring/HeuristicLab.Encodings.PermutationEncoding/3.3/Interfaces/IPermutationInversionMoveQualityOperator.cs
r13393 r13396 21 21 22 22 using HeuristicLab.Core; 23 using HeuristicLab.Data; 23 24 24 25 namespace HeuristicLab.Encodings.PermutationEncoding { 25 public interface IPermutationInversionMove Operator : IPermutationMoveOperator {26 ILookupParameter< InversionMove> InversionMoveParameter { get; }26 public interface IPermutationInversionMoveQualityOperator : IPermutationInversionMoveOperator { 27 ILookupParameter<DoubleValue> MoveQualityParameter { get; } 27 28 } 28 29 } -
branches/ProblemRefactoring/HeuristicLab.Encodings.PermutationEncoding/3.3/Interfaces/IPermutationManipulator.cs
r12012 r13396 20 20 #endregion 21 21 22 using HeuristicLab.Core;23 22 using HeuristicLab.Optimization; 24 23 … … 27 26 /// An interface which represents an operator for manipulating solutions. 28 27 /// </summary> 29 public interface IPermutationManipulator : IPermutationOperator, IManipulator { 30 ILookupParameter<Permutation> PermutationParameter { get; } 31 } 28 public interface IPermutationManipulator : IPermutationSolutionOperator, IManipulator { } 32 29 } -
branches/ProblemRefactoring/HeuristicLab.Encodings.PermutationEncoding/3.3/Interfaces/IPermutationScrambleMoveQualityOperator.cs
r13393 r13396 21 21 22 22 using HeuristicLab.Core; 23 using HeuristicLab.Data; 23 24 24 25 namespace HeuristicLab.Encodings.PermutationEncoding { 25 public interface IPermutationScrambleMove Operator : IPermutationMoveOperator {26 ILookupParameter< ScrambleMove> ScrambleMoveParameter { get; }26 public interface IPermutationScrambleMoveQualityOperator : IPermutationScrambleMoveOperator { 27 ILookupParameter<DoubleValue> MoveQualityParameter { get; } 27 28 } 28 29 } -
branches/ProblemRefactoring/HeuristicLab.Encodings.PermutationEncoding/3.3/Interfaces/IPermutationSwap2MoveQualityOperator.cs
r13393 r13396 21 21 22 22 using HeuristicLab.Core; 23 using HeuristicLab.Data; 23 24 24 25 namespace HeuristicLab.Encodings.PermutationEncoding { 25 public interface IPermutationSwap2Move Operator : IPermutationMoveOperator {26 ILookupParameter< Swap2Move> Swap2MoveParameter { get; }26 public interface IPermutationSwap2MoveQualityOperator : IPermutationSwap2MoveOperator { 27 ILookupParameter<DoubleValue> MoveQualityParameter { get; } 27 28 } 28 29 } -
branches/ProblemRefactoring/HeuristicLab.Encodings.PermutationEncoding/3.3/Interfaces/IPermutationTranslocationMoveQualityOperator.cs
r13393 r13396 21 21 22 22 using HeuristicLab.Core; 23 using HeuristicLab.Data; 23 24 24 25 namespace HeuristicLab.Encodings.PermutationEncoding { 25 public interface IPermutationTranslocationMove Operator : IPermutationMoveOperator {26 ILookupParameter< TranslocationMove> TranslocationMoveParameter { get; }26 public interface IPermutationTranslocationMoveQualityOperator : IPermutationTranslocationMoveOperator { 27 ILookupParameter<DoubleValue> MoveQualityParameter { get; } 27 28 } 28 29 } -
branches/ProblemRefactoring/HeuristicLab.Encodings.PermutationEncoding/3.3/Moves/Scramble/ScrambleMoveMaker.cs
r12012 r13396 31 31 [Item("ScrambleMoveMaker", "Peforms a scramble move on a given permutation and updates the quality.")] 32 32 [StorableClass] 33 public class ScrambleMoveMaker : SingleSuccessorOperator, IPermutationScrambleMove Operator, IMoveMaker, ISingleObjectiveOperator {33 public class ScrambleMoveMaker : SingleSuccessorOperator, IPermutationScrambleMoveQualityOperator, IMoveMaker, ISingleObjectiveOperator { 34 34 public override bool CanChangeName { 35 35 get { return false; } -
branches/ProblemRefactoring/HeuristicLab.Encodings.PermutationEncoding/3.3/Moves/Swap2/Swap2MoveHardTabuCriterion.cs
r12012 r13396 35 35 If the aspiration condition is activated, a move will not be considered tabu against a move in the tabu list if it leads to a better solution than the quality recorded with the move in the tabu list.")] 36 36 [StorableClass] 37 public class Swap2MoveHardTabuCriterion : SingleSuccessorOperator, IPermutationSwap2Move Operator, ITabuChecker {37 public class Swap2MoveHardTabuCriterion : SingleSuccessorOperator, IPermutationSwap2MoveQualityOperator, ITabuChecker { 38 38 public override bool CanChangeName { 39 39 get { return false; } -
branches/ProblemRefactoring/HeuristicLab.Encodings.PermutationEncoding/3.3/Moves/Swap2/Swap2MoveMaker.cs
r12012 r13396 31 31 [Item("Swap2MoveMaker", "Peforms a swap-2 move on a given permutation and updates the quality.")] 32 32 [StorableClass] 33 public class Swap2MoveMaker : SingleSuccessorOperator, IPermutationSwap2Move Operator, IMoveMaker, ISingleObjectiveOperator {33 public class Swap2MoveMaker : SingleSuccessorOperator, IPermutationSwap2MoveQualityOperator, IMoveMaker, ISingleObjectiveOperator { 34 34 public override bool CanChangeName { 35 35 get { return false; } -
branches/ProblemRefactoring/HeuristicLab.Encodings.PermutationEncoding/3.3/Moves/Swap2/Swap2MoveSoftTabuCriterion.cs
r12012 r13396 35 35 If the aspiration condition is activated, a move will not be considered tabu against a move in the tabu list if it leads to a better solution than the quality recorded with the move in the tabu list.")] 36 36 [StorableClass] 37 public class Swap2MoveSoftTabuCriterion : SingleSuccessorOperator, IPermutationSwap2Move Operator, ITabuChecker {37 public class Swap2MoveSoftTabuCriterion : SingleSuccessorOperator, IPermutationSwap2MoveQualityOperator, ITabuChecker { 38 38 public override bool CanChangeName { 39 39 get { return false; } -
branches/ProblemRefactoring/HeuristicLab.Encodings.PermutationEncoding/3.3/Moves/Swap2/Swap2MoveTabuMaker.cs
r12012 r13396 29 29 [Item("Swap2MoveTabuMaker", "Declares a given swap-2 move as tabu, by adding its attributes to the tabu list and also store the solution quality or the move quality (whichever is better).")] 30 30 [StorableClass] 31 public class Swap2MoveTabuMaker : TabuMaker, IPermutationSwap2Move Operator {31 public class Swap2MoveTabuMaker : TabuMaker, IPermutationSwap2MoveQualityOperator { 32 32 public ILookupParameter<Permutation> PermutationParameter { 33 33 get { return (ILookupParameter<Permutation>)Parameters["Permutation"]; } -
branches/ProblemRefactoring/HeuristicLab.Encodings.PermutationEncoding/3.3/Moves/ThreeOpt/TranslocationMoveHardTabuCriterion.cs
r12012 r13396 34 34 If the aspiration condition is activated, a move will not be considered tabu against a move in the tabu list if it leads to a better solution than the quality recorded with the move in the tabu list.")] 35 35 [StorableClass] 36 public class TranslocationMoveHardTabuCriterion : SingleSuccessorOperator, IPermutationTranslocationMove Operator, ITabuChecker {36 public class TranslocationMoveHardTabuCriterion : SingleSuccessorOperator, IPermutationTranslocationMoveQualityOperator, ITabuChecker { 37 37 public override bool CanChangeName { 38 38 get { return false; } -
branches/ProblemRefactoring/HeuristicLab.Encodings.PermutationEncoding/3.3/Moves/ThreeOpt/TranslocationMoveMaker.cs
r12012 r13396 31 31 [Item("TranslocationMoveMaker", "Peforms a translocation or insertion move (3-opt) on a given permutation and updates the quality.")] 32 32 [StorableClass] 33 public class TranslocationMoveMaker : SingleSuccessorOperator, IPermutationTranslocationMove Operator, IMoveMaker, ISingleObjectiveOperator {33 public class TranslocationMoveMaker : SingleSuccessorOperator, IPermutationTranslocationMoveQualityOperator, IMoveMaker, ISingleObjectiveOperator { 34 34 public override bool CanChangeName { 35 35 get { return false; } -
branches/ProblemRefactoring/HeuristicLab.Encodings.PermutationEncoding/3.3/Moves/ThreeOpt/TranslocationMoveSoftTabuCriterion.cs
r12012 r13396 34 34 If the aspiration condition is activated, a move will not be considered tabu against a move in the tabu list if it leads to a better solution than the quality recorded with the move in the tabu list.")] 35 35 [StorableClass] 36 public class TranslocationMoveSoftTabuCriterion : SingleSuccessorOperator, IPermutationTranslocationMove Operator, ITabuChecker {36 public class TranslocationMoveSoftTabuCriterion : SingleSuccessorOperator, IPermutationTranslocationMoveQualityOperator, ITabuChecker { 37 37 public override bool CanChangeName { 38 38 get { return false; } -
branches/ProblemRefactoring/HeuristicLab.Encodings.PermutationEncoding/3.3/Moves/ThreeOpt/TranslocationMoveTabuMaker.cs
r12012 r13396 29 29 [Item("TranslocationMoveTabuMaker", "Declares a given translocation or insertion move (3-opt) as tabu, by adding its attributes to the tabu list.")] 30 30 [StorableClass] 31 public class TranslocationMoveTabuMaker : TabuMaker, IPermutationTranslocationMove Operator {31 public class TranslocationMoveTabuMaker : TabuMaker, IPermutationTranslocationMoveQualityOperator { 32 32 public ILookupParameter<Permutation> PermutationParameter { 33 33 get { return (ILookupParameter<Permutation>)Parameters["Permutation"]; } -
branches/ProblemRefactoring/HeuristicLab.Encodings.PermutationEncoding/3.3/Moves/TwoOpt/InversionMoveHardTabuCriterion.cs
r12012 r13396 35 35 If the aspiration condition is activated, a move will not be considered tabu against a move in the tabu list if it leads to a better solution than the quality recorded with the move in the tabu list.")] 36 36 [StorableClass] 37 public class InversionMoveHardTabuCriterion : SingleSuccessorOperator, IPermutationInversionMove Operator, ITabuChecker {37 public class InversionMoveHardTabuCriterion : SingleSuccessorOperator, IPermutationInversionMoveQualityOperator, ITabuChecker { 38 38 public override bool CanChangeName { 39 39 get { return false; } -
branches/ProblemRefactoring/HeuristicLab.Encodings.PermutationEncoding/3.3/Moves/TwoOpt/InversionMoveMaker.cs
r12012 r13396 31 31 [Item("InversionMoveMaker", "Peforms an inversion move (2-opt) on a given permutation and updates the quality.")] 32 32 [StorableClass] 33 public class InversionMoveMaker : SingleSuccessorOperator, IPermutationInversionMove Operator, IMoveMaker, ISingleObjectiveOperator {33 public class InversionMoveMaker : SingleSuccessorOperator, IPermutationInversionMoveQualityOperator, IMoveMaker, ISingleObjectiveOperator { 34 34 public override bool CanChangeName { 35 35 get { return false; } -
branches/ProblemRefactoring/HeuristicLab.Encodings.PermutationEncoding/3.3/Moves/TwoOpt/InversionMoveSoftTabuCriterion.cs
r12012 r13396 35 35 If the aspiration condition is activated, a move will not be considered tabu against a move in the tabu list if it leads to a better solution than the quality recorded with the move in the tabu list.")] 36 36 [StorableClass] 37 public class InversionMoveSoftTabuCriterion : SingleSuccessorOperator, IPermutationInversionMove Operator, ITabuChecker {37 public class InversionMoveSoftTabuCriterion : SingleSuccessorOperator, IPermutationInversionMoveQualityOperator, ITabuChecker { 38 38 public override bool CanChangeName { 39 39 get { return false; } -
branches/ProblemRefactoring/HeuristicLab.Encodings.PermutationEncoding/3.3/Moves/TwoOpt/InversionMoveTabuMaker.cs
r12012 r13396 29 29 [Item("InversionMoveTabuMaker", "Declares a given inversion move (2-opt) as tabu, by adding its attributes to the tabu list and also store the solution quality or the move quality (whichever is better).")] 30 30 [StorableClass] 31 public class InversionMoveTabuMaker : TabuMaker, IPermutationInversionMove Operator {31 public class InversionMoveTabuMaker : TabuMaker, IPermutationInversionMoveQualityOperator { 32 32 public ILookupParameter<Permutation> PermutationParameter { 33 33 get { return (ILookupParameter<Permutation>)Parameters["Permutation"]; } -
branches/ProblemRefactoring/HeuristicLab.Encodings.PermutationEncoding/3.3/PermutationEncoding.cs
r13366 r13396 145 145 typeof (IPermutationScrambleMoveOperator), 146 146 typeof (IPermutationSwap2MoveOperator), 147 typeof (IPermutationTranslocationMoveOperator) 147 typeof (IPermutationTranslocationMoveOperator), 148 typeof (IPermutationLocalImprovementOperator), 149 typeof (IPermutationSolutionOperator), 150 typeof (IPermutationSolutionsOperator), 148 151 }; 149 152 } … … 160 163 #endregion 161 164 162 public override void ConfigureOperators(IEnumerable<I Operator> operators) {165 public override void ConfigureOperators(IEnumerable<IItem> operators) { 163 166 ConfigureCreators(operators.OfType<IPermutationCreator>()); 164 167 ConfigureCrossovers(operators.OfType<IPermutationCrossover>()); … … 170 173 ConfigureSwap2MoveOperators(operators.OfType<IPermutationSwap2MoveOperator>()); 171 174 ConfigureTranslocationMoveOperators(operators.OfType<IPermutationTranslocationMoveOperator>()); 175 ConfigureLocalImprovementOperators(operators.OfType<IPermutationLocalImprovementOperator>()); 176 ConfigureSolutionOperators(operators.OfType<IPermutationSolutionOperator>()); 177 ConfigureSolutionsOperators(operators.OfType<IPermutationSolutionsOperator>()); 172 178 } 173 179 … … 176 182 foreach (var creator in creators) { 177 183 creator.LengthParameter.ActualName = LengthParameter.Name; 178 creator.PermutationParameter.ActualName = Name;179 184 creator.PermutationTypeParameter.Value.Value = Type; 180 185 } … … 187 192 } 188 193 private void ConfigureManipulators(IEnumerable<IPermutationManipulator> manipulators) { 189 foreach (var manipulator in manipulators) { 190 manipulator.PermutationParameter.ActualName = Name; 191 } 194 // IPermutationManipulator does not contain additional parameters (already contained in IPermutationSolutionOperator) 192 195 } 193 196 private void ConfigureShakingOperators(IEnumerable<IPermutationMultiNeighborhoodShakingOperator> shakingOperators) { … … 221 224 } 222 225 } 223 226 private void ConfigureLocalImprovementOperators(IEnumerable<IPermutationLocalImprovementOperator> localImprovementOperators) { 227 // IPermutationLocalImprovementOperator does not contain additional parameters (already contained in IPermutationSolutionOperator) 228 } 229 private void ConfigureSolutionOperators(IEnumerable<IPermutationSolutionOperator> solutionOperators) { 230 foreach (var solutionOperator in solutionOperators) { 231 solutionOperator.PermutationParameter.ActualName = Name; 232 } 233 } 234 private void ConfigureSolutionsOperators(IEnumerable<IPermutationSolutionsOperator> solutionsOperators) { 235 foreach (var solutionsOperator in solutionsOperators) { 236 solutionsOperator.PermutationsParameter.ActualName = Name; 237 } 238 } 224 239 #endregion 225 240 } -
branches/ProblemRefactoring/HeuristicLab.Encodings.RealVectorEncoding/3.3/RealVectorEncoding.cs
r13361 r13396 197 197 } 198 198 199 public override void ConfigureOperators(IEnumerable<I Operator> operators) {199 public override void ConfigureOperators(IEnumerable<IItem> operators) { 200 200 ConfigureCreators(operators.OfType<IRealVectorCreator>()); 201 201 ConfigureCrossovers(operators.OfType<IRealVectorCrossover>()); -
branches/ProblemRefactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/SymbolicExpressionTreeEncoding.cs
r13382 r13396 282 282 #region Specific operator wiring 283 283 284 public override void ConfigureOperators(IEnumerable<I Operator> operators) {284 public override void ConfigureOperators(IEnumerable<IItem> operators) { 285 285 ConfigureTreeOperators(operators.OfType<ISymbolicExpressionTreeOperator>()); 286 286 ConfigureSizeConstraintOperators(operators.OfType<ISymbolicExpressionTreeSizeConstraintOperator>()); -
branches/ProblemRefactoring/HeuristicLab.Optimization/3.3/BasicProblems/CombinedEncoding.cs
r13376 r13396 88 88 } 89 89 90 public override void ConfigureOperators(IEnumerable<I Operator> operators) {90 public override void ConfigureOperators(IEnumerable<IItem> operators) { 91 91 foreach (var encOp in operators.OfType<IMultiEncodingOperator>()) 92 92 encOp.SolutionParameter.ActualName = Name; -
branches/ProblemRefactoring/HeuristicLab.Optimization/3.3/BasicProblems/Encoding.cs
r13351 r13396 100 100 } 101 101 102 public void ConfigureOperator(I Operator@operator) { ConfigureOperators(new[] { @operator }); }103 public abstract void ConfigureOperators(IEnumerable<I Operator> operators);102 public void ConfigureOperator(IItem @operator) { ConfigureOperators(new[] { @operator }); } 103 public abstract void ConfigureOperators(IEnumerable<IItem> operators); 104 104 105 105 public event EventHandler SolutionCreatorChanged; -
branches/ProblemRefactoring/HeuristicLab.Optimization/3.3/BasicProblems/Interfaces/IEncoding.cs
r13351 r13396 29 29 IEnumerable<IOperator> Operators { get; set; } 30 30 31 void ConfigureOperator(I Operator@operator);32 void ConfigureOperators(IEnumerable<I Operator> operators);31 void ConfigureOperator(IItem @operator); 32 void ConfigureOperators(IEnumerable<IItem> operators); 33 33 34 34 event EventHandler SolutionCreatorChanged; -
branches/ProblemRefactoring/HeuristicLab.Optimization/3.3/BasicProblems/Problem.cs
r13376 r13396 35 35 where TEvaluator : class, IEvaluator { 36 36 37 public string Filename { get; set; } 37 public string Filename { get; set; } // TODO: Really okay here? 38 38 39 39 protected IValueParameter<TEncoding> EncodingParameter { … … 71 71 Parameterize(); 72 72 } 73 RegisterEvents(); 74 } 75 protected Problem(TEncoding encoding) { 76 if (encoding == null) throw new ArgumentNullException("encoding"); 77 Parameters.Add(new ValueParameter<TEncoding>("Encoding", "Describes the configuration of the encoding, what the variables are called, what type they are and their bounds if any.", encoding)); 78 oldEncoding = Encoding; 79 SolutionCreator = Encoding.SolutionCreator; 80 Parameterize(); 81 73 82 RegisterEvents(); 74 83 } -
branches/ProblemRefactoring/HeuristicLab.Optimization/3.3/BasicProblems/SingleObjectiveProblem.cs
r13388 r13396 41 41 } 42 42 43 protected IFixedValueParameter<BoolValue> MaximizationParameter { 44 get { return (IFixedValueParameter<BoolValue>)Parameters["Maximization"]; } 45 } 46 43 47 public double BestKnownQuality { 44 48 get { … … 62 66 protected SingleObjectiveProblem() 63 67 : base() { 68 Parameters.Add(new FixedValueParameter<BoolValue>("Maximization", "Set to false if the problem should be minimized.", (BoolValue)new BoolValue(Maximization).AsReadOnly()) { Hidden = true }); 69 Parameters.Add(new OptionalValueParameter<DoubleValue>("BestKnownQuality", "The quality of the best known solution of this problem.")); 70 71 Operators.Add(Evaluator); 72 Operators.Add(new SingleObjectiveAnalyzer<TSolution>()); 73 Operators.Add(new SingleObjectiveImprover<TSolution>()); 74 Operators.Add(new SingleObjectiveMoveEvaluator<TSolution>()); 75 Operators.Add(new SingleObjectiveMoveGenerator<TSolution>()); 76 Operators.Add(new SingleObjectiveMoveMaker<TSolution>()); 77 78 ParameterizeOperators(); 79 } 80 81 protected SingleObjectiveProblem(TEncoding encoding) 82 : base(encoding) { 64 83 Parameters.Add(new FixedValueParameter<BoolValue>("Maximization", "Set to false if the problem should be minimized.", (BoolValue)new BoolValue(Maximization).AsReadOnly()) { Hidden = true }); 65 84 Parameters.Add(new OptionalValueParameter<DoubleValue>("BestKnownQuality", "The quality of the best known solution of this problem.")); -
branches/ProblemRefactoring/HeuristicLab.Optimization/3.3/Interfaces/ISolutionCreator.cs
r13336 r13396 28 28 public interface ISolutionCreator : IOperator { } 29 29 30 public interface ISolutionCreator<TSolution> : ISolutionCreator where TSolution : class, ISolution { } 30 public interface ISolutionCreator<TSolution> : ISolutionCreator where TSolution : class, ISolution { 31 //ILookupParameter<TSolution> SolutionParameter { get; } // TODO: unify encoding specific parameters by defining ISolutionOperator and ISolutionsOperator 32 } 31 33 } -
branches/ProblemRefactoring/HeuristicLab.Problems.QuadraticAssignment.Algorithms/3.3/RobustTabooSeachOperator.cs
r12855 r13396 31 31 32 32 namespace HeuristicLab.Problems.QuadraticAssignment.Algorithms { 33 [Item("RobustTabooSearchOperator", "Performs an iteration of the robust taboo search algorithm as descr bied in Taillard 1991.")]33 [Item("RobustTabooSearchOperator", "Performs an iteration of the robust taboo search algorithm as described in Taillard 1991.")] 34 34 [StorableClass] 35 public sealed class RobustTabooSeachOperator : SingleSuccessorOperator, IIterationBasedOperator, IStochasticOperator, ISingleObjectiveOperator {35 public sealed class RobustTabooSeachOperator : SingleSuccessorOperator, IIterationBasedOperator, IStochasticOperator, ISingleObjectiveOperator, IPermutationSolutionOperator { 36 36 37 37 #region Parameter Properties -
branches/ProblemRefactoring/HeuristicLab.Problems.QuadraticAssignment.Algorithms/3.3/RobustTabooSearch.cs
r13173 r13396 401 401 402 402 mainOperator.DistancesParameter.ActualName = Problem.DistancesParameter.Name; 403 mainOperator.PermutationParameter.ActualName = Problem.SolutionCreator.PermutationParameter.ActualName;404 403 mainOperator.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName; 405 404 mainOperator.WeightsParameter.ActualName = Problem.WeightsParameter.Name; 405 406 Problem.Encoding.ConfigureOperators(new IOperator[] { mainOperator }); 406 407 } 407 408 } -
branches/ProblemRefactoring/HeuristicLab.Problems.QuadraticAssignment/3.3/Analyzers/BestQAPSolutionAnalyzer.cs
r12012 r13396 36 36 [Item("BestQAPSolutionAnalyzer", "An operator for analyzing the best solution of Quadratic Assignment Problems.")] 37 37 [StorableClass] 38 public sealed class BestQAPSolutionAnalyzer : SingleSuccessorOperator, IAnalyzer, ISingleObjectiveOperator {38 public sealed class BestQAPSolutionAnalyzer : SingleSuccessorOperator, IAnalyzer, ISingleObjectiveOperator, IPermutationSolutionsOperator { 39 39 public bool EnabledByDefault { 40 40 get { return true; } 41 41 } 42 42 43 public LookupParameter<BoolValue> MaximizationParameter {44 get { return ( LookupParameter<BoolValue>)Parameters["Maximization"]; }43 public ILookupParameter<BoolValue> MaximizationParameter { 44 get { return (ILookupParameter<BoolValue>)Parameters["Maximization"]; } 45 45 } 46 public LookupParameter<DoubleMatrix> DistancesParameter {47 get { return ( LookupParameter<DoubleMatrix>)Parameters["Distances"]; }46 public ILookupParameter<DoubleMatrix> DistancesParameter { 47 get { return (ILookupParameter<DoubleMatrix>)Parameters["Distances"]; } 48 48 } 49 public LookupParameter<DoubleMatrix> WeightsParameter {50 get { return ( LookupParameter<DoubleMatrix>)Parameters["Weights"]; }49 public ILookupParameter<DoubleMatrix> WeightsParameter { 50 get { return (ILookupParameter<DoubleMatrix>)Parameters["Weights"]; } 51 51 } 52 public ScopeTreeLookupParameter<Permutation> PermutationParameter {53 get { return ( ScopeTreeLookupParameter<Permutation>)Parameters["Permutation"]; }52 public IScopeTreeLookupParameter<Permutation> PermutationsParameter { 53 get { return (IScopeTreeLookupParameter<Permutation>)Parameters["Permutations"]; } 54 54 } 55 public ScopeTreeLookupParameter<DoubleValue> QualityParameter {56 get { return ( ScopeTreeLookupParameter<DoubleValue>)Parameters["Quality"]; }55 public IScopeTreeLookupParameter<DoubleValue> QualityParameter { 56 get { return (IScopeTreeLookupParameter<DoubleValue>)Parameters["Quality"]; } 57 57 } 58 public LookupParameter<QAPAssignment> BestSolutionParameter {59 get { return ( LookupParameter<QAPAssignment>)Parameters["BestSolution"]; }58 public ILookupParameter<QAPAssignment> BestSolutionParameter { 59 get { return (ILookupParameter<QAPAssignment>)Parameters["BestSolution"]; } 60 60 } 61 public ValueLookupParameter<ResultCollection> ResultsParameter {62 get { return ( ValueLookupParameter<ResultCollection>)Parameters["Results"]; }61 public IValueLookupParameter<ResultCollection> ResultsParameter { 62 get { return (IValueLookupParameter<ResultCollection>)Parameters["Results"]; } 63 63 } 64 public LookupParameter<DoubleValue> BestKnownQualityParameter {65 get { return ( LookupParameter<DoubleValue>)Parameters["BestKnownQuality"]; }64 public ILookupParameter<DoubleValue> BestKnownQualityParameter { 65 get { return (ILookupParameter<DoubleValue>)Parameters["BestKnownQuality"]; } 66 66 } 67 public LookupParameter<ItemSet<Permutation>> BestKnownSolutionsParameter {68 get { return ( LookupParameter<ItemSet<Permutation>>)Parameters["BestKnownSolutions"]; }67 public ILookupParameter<ItemSet<Permutation>> BestKnownSolutionsParameter { 68 get { return (ILookupParameter<ItemSet<Permutation>>)Parameters["BestKnownSolutions"]; } 69 69 } 70 public LookupParameter<Permutation> BestKnownSolutionParameter {71 get { return ( LookupParameter<Permutation>)Parameters["BestKnownSolution"]; }70 public ILookupParameter<Permutation> BestKnownSolutionParameter { 71 get { return (ILookupParameter<Permutation>)Parameters["BestKnownSolution"]; } 72 72 } 73 73 … … 83 83 Parameters.Add(new LookupParameter<DoubleMatrix>("Distances", "The distances between the locations.")); 84 84 Parameters.Add(new LookupParameter<DoubleMatrix>("Weights", "The weights between the facilities.")); 85 Parameters.Add(new ScopeTreeLookupParameter<Permutation>("Permutation ", "The QAP solutions from which the best solution should be analyzed."));85 Parameters.Add(new ScopeTreeLookupParameter<Permutation>("Permutations", "The QAP solutions from which the best solution should be analyzed.")); 86 86 Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Quality", "The qualities of the QAP solutions which should be analyzed.")); 87 87 Parameters.Add(new LookupParameter<QAPAssignment>("BestSolution", "The best QAP solution.")); … … 109 109 DoubleMatrix distances = DistancesParameter.ActualValue; 110 110 DoubleMatrix weights = WeightsParameter.ActualValue; 111 ItemArray<Permutation> permutations = Permutation Parameter.ActualValue;111 ItemArray<Permutation> permutations = PermutationsParameter.ActualValue; 112 112 ItemArray<DoubleValue> qualities = QualityParameter.ActualValue; 113 113 ResultCollection results = ResultsParameter.ActualValue; -
branches/ProblemRefactoring/HeuristicLab.Problems.QuadraticAssignment/3.3/Analyzers/QAPAlleleFrequencyAnalyzer.cs
r12012 r13396 36 36 [StorableClass] 37 37 public sealed class QAPAlleleFrequencyAnalyzer : AlleleFrequencyAnalyzer<Permutation> { 38 public LookupParameter<DoubleMatrix> WeightsParameter {39 get { return ( LookupParameter<DoubleMatrix>)Parameters["Weights"]; }38 public ILookupParameter<DoubleMatrix> WeightsParameter { 39 get { return (ILookupParameter<DoubleMatrix>)Parameters["Weights"]; } 40 40 } 41 public LookupParameter<DoubleMatrix> DistancesParameter {42 get { return ( LookupParameter<DoubleMatrix>)Parameters["Distances"]; }41 public ILookupParameter<DoubleMatrix> DistancesParameter { 42 get { return (ILookupParameter<DoubleMatrix>)Parameters["Distances"]; } 43 43 } 44 44 -
branches/ProblemRefactoring/HeuristicLab.Problems.QuadraticAssignment/3.3/HeuristicLab.Problems.QuadraticAssignment-3.3.csproj
r11623 r13396 124 124 <Compile Include="Evaluators\QAPScrambleMoveEvaluator.cs" /> 125 125 <Compile Include="Evaluators\QAPSwap2MoveEvaluator.cs" /> 126 <Compile Include="Evaluators\QAPEvaluator.cs" />127 126 <Compile Include="Evaluators\QAPInversionMoveEvaluator.cs" /> 128 127 <Compile Include="Evaluators\QAPMoveEvaluator.cs" /> … … 130 129 <SubType>Code</SubType> 131 130 </Compile> 132 <Compile Include="Interfaces\IQAP Evaluator.cs" />131 <Compile Include="Interfaces\IQAPLocalImprovementOperator.cs" /> 133 132 <Compile Include="Interfaces\IQAPMoveEvaluator.cs" /> 134 133 <Compile Include="LocalImprovement\QAPExhaustiveInsertionLocalImprovement.cs" /> … … 224 223 </ProjectReference> 225 224 </ItemGroup> 225 <ItemGroup> 226 <Folder Include="SimilarityCalculators\" /> 227 </ItemGroup> 226 228 <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> 227 229 <PropertyGroup> -
branches/ProblemRefactoring/HeuristicLab.Problems.QuadraticAssignment/3.3/Interfaces/IQAPLocalImprovementOperator.cs
r13393 r13396 23 23 using HeuristicLab.Data; 24 24 using HeuristicLab.Encodings.PermutationEncoding; 25 using HeuristicLab.Optimization;26 25 27 26 namespace HeuristicLab.Problems.QuadraticAssignment { 28 public interface IQAPEvaluator : ISingleObjectiveEvaluator { 29 ILookupParameter<Permutation> PermutationParameter { get; } 27 public interface IQAPLocalImprovementOperator : IPermutationLocalImprovementOperator { 30 28 ILookupParameter<DoubleMatrix> DistancesParameter { get; } 29 ILookupParameter<BoolValue> MaximizationParameter { get; } 30 ILookupParameter<DoubleValue> QualityParameter { get; } 31 31 ILookupParameter<DoubleMatrix> WeightsParameter { get; } 32 32 } -
branches/ProblemRefactoring/HeuristicLab.Problems.QuadraticAssignment/3.3/LocalImprovement/QAPExhaustiveInsertionLocalImprovement.cs
r12012 r13396 34 34 [Item("QAPExhaustiveInsertionLocalImprovement", "Takes a solution and finds the local optimum with respect to the insertion neighborhood by decending along the steepest gradient.")] 35 35 [StorableClass] 36 public class QAPExhaustiveInsertionLocalImprovement : SingleSuccessorOperator, I LocalImprovementOperator, ISingleObjectiveOperator {36 public class QAPExhaustiveInsertionLocalImprovement : SingleSuccessorOperator, IQAPLocalImprovementOperator, ISingleObjectiveOperator { 37 37 38 38 public ILookupParameter<IntValue> LocalIterationsParameter { … … 52 52 } 53 53 54 public ILookupParameter<Permutation> AssignmentParameter {55 get { return (ILookupParameter<Permutation>)Parameters[" Assignment"]; }54 public ILookupParameter<Permutation> PermutationParameter { 55 get { return (ILookupParameter<Permutation>)Parameters["Permutation"]; } 56 56 } 57 57 … … 83 83 Parameters.Add(new LookupParameter<IntValue>("EvaluatedSolutions", "The amount of evaluated solutions (here a move is counted only as 4/n evaluated solutions with n being the length of the permutation).")); 84 84 Parameters.Add(new LookupParameter<ResultCollection>("Results", "The collection where to store results.")); 85 Parameters.Add(new LookupParameter<Permutation>(" Assignment", "The permutation that is to be locally optimized."));85 Parameters.Add(new LookupParameter<Permutation>("Permutation", "The permutation that is to be locally optimized.")); 86 86 Parameters.Add(new LookupParameter<DoubleValue>("Quality", "The quality value of the assignment.")); 87 87 Parameters.Add(new LookupParameter<BoolValue>("Maximization", "True if the problem should be maximized or minimized.")); … … 122 122 public override IOperation Apply() { 123 123 var maxIterations = MaximumIterationsParameter.ActualValue.Value; 124 var assignment = AssignmentParameter.ActualValue;124 var assignment = PermutationParameter.ActualValue; 125 125 var maximization = MaximizationParameter.ActualValue.Value; 126 126 var weights = WeightsParameter.ActualValue; -
branches/ProblemRefactoring/HeuristicLab.Problems.QuadraticAssignment/3.3/LocalImprovement/QAPExhaustiveInversionLocalImprovement.cs
r12811 r13396 34 34 [Item("QAPExhaustiveInversionLocalImprovement", "Takes a solution and finds the local optimum with respect to the inversion neighborhood by decending along the steepest gradient.")] 35 35 [StorableClass] 36 public class QAPExhaustiveInversionLocalImprovement : SingleSuccessorOperator, I LocalImprovementOperator, ISingleObjectiveOperator {36 public class QAPExhaustiveInversionLocalImprovement : SingleSuccessorOperator, IQAPLocalImprovementOperator, ISingleObjectiveOperator { 37 37 38 38 public ILookupParameter<IntValue> LocalIterationsParameter { … … 52 52 } 53 53 54 public ILookupParameter<Permutation> AssignmentParameter {55 get { return (ILookupParameter<Permutation>)Parameters[" Assignment"]; }54 public ILookupParameter<Permutation> PermutationParameter { 55 get { return (ILookupParameter<Permutation>)Parameters["Permutation"]; } 56 56 } 57 57 … … 83 83 Parameters.Add(new LookupParameter<IntValue>("EvaluatedSolutions", "The amount of evaluated solutions (here a move is counted only as 4/n evaluated solutions with n being the length of the permutation).")); 84 84 Parameters.Add(new LookupParameter<ResultCollection>("Results", "The collection where to store results.")); 85 Parameters.Add(new LookupParameter<Permutation>(" Assignment", "The permutation that is to be locally optimized."));85 Parameters.Add(new LookupParameter<Permutation>("Permutation", "The permutation that is to be locally optimized.")); 86 86 Parameters.Add(new LookupParameter<DoubleValue>("Quality", "The quality value of the assignment.")); 87 87 Parameters.Add(new LookupParameter<BoolValue>("Maximization", "True if the problem should be maximized or minimized.")); … … 119 119 public override IOperation Apply() { 120 120 var maxIterations = MaximumIterationsParameter.ActualValue.Value; 121 var assignment = AssignmentParameter.ActualValue;121 var assignment = PermutationParameter.ActualValue; 122 122 var maximization = MaximizationParameter.ActualValue.Value; 123 123 var weights = WeightsParameter.ActualValue; -
branches/ProblemRefactoring/HeuristicLab.Problems.QuadraticAssignment/3.3/LocalImprovement/QAPExhaustiveSwap2LocalImprovement.cs
r12012 r13396 34 34 [Item("QAPExhaustiveSwap2LocalImprovement", "Takes a solution and finds the local optimum with respect to the swap2 neighborhood by decending along the steepest gradient.")] 35 35 [StorableClass] 36 public class QAPExhaustiveSwap2LocalImprovement : SingleSuccessorOperator, I LocalImprovementOperator, ISingleObjectiveOperator {36 public class QAPExhaustiveSwap2LocalImprovement : SingleSuccessorOperator, IQAPLocalImprovementOperator, ISingleObjectiveOperator { 37 37 38 38 public ILookupParameter<IntValue> LocalIterationsParameter { … … 52 52 } 53 53 54 public ILookupParameter<Permutation> AssignmentParameter {55 get { return (ILookupParameter<Permutation>)Parameters[" Assignment"]; }54 public ILookupParameter<Permutation> PermutationParameter { 55 get { return (ILookupParameter<Permutation>)Parameters["Permutation"]; } 56 56 } 57 57 … … 87 87 Parameters.Add(new LookupParameter<IntValue>("EvaluatedSolutions", "The amount of evaluated solutions (here a move is counted only as 4/n evaluated solutions with n being the length of the permutation).")); 88 88 Parameters.Add(new LookupParameter<ResultCollection>("Results", "The collection where to store results.")); 89 Parameters.Add(new LookupParameter<Permutation>(" Assignment", "The permutation that is to be locally optimized."));89 Parameters.Add(new LookupParameter<Permutation>("Permutation", "The permutation that is to be locally optimized.")); 90 90 Parameters.Add(new LookupParameter<DoubleValue>("Quality", "The quality value of the assignment.")); 91 91 Parameters.Add(new LookupParameter<BoolValue>("Maximization", "True if the problem should be maximized or minimized.")); … … 175 175 public override IOperation Apply() { 176 176 var maxIterations = MaximumIterationsParameter.ActualValue.Value; 177 var assignment = AssignmentParameter.ActualValue;177 var assignment = PermutationParameter.ActualValue; 178 178 var maximization = MaximizationParameter.ActualValue.Value; 179 179 var weights = WeightsParameter.ActualValue; -
branches/ProblemRefactoring/HeuristicLab.Problems.QuadraticAssignment/3.3/LocalImprovement/QAPStochasticScrambleLocalImprovement.cs
r12811 r13396 34 34 [Item("QAPStochasticScrambleLocalImprovement", "Takes a solution and finds the local optimum with respect to the scramble neighborhood by decending along the steepest gradient.")] 35 35 [StorableClass] 36 public class QAPStochasticScrambleLocalImprovement : SingleSuccessorOperator, I LocalImprovementOperator, IStochasticOperator, ISingleObjectiveOperator {36 public class QAPStochasticScrambleLocalImprovement : SingleSuccessorOperator, IQAPLocalImprovementOperator, IStochasticOperator, ISingleObjectiveOperator { 37 37 38 38 public ILookupParameter<IntValue> LocalIterationsParameter { … … 56 56 } 57 57 58 public ILookupParameter<Permutation> AssignmentParameter {59 get { return (ILookupParameter<Permutation>)Parameters[" Assignment"]; }58 public ILookupParameter<Permutation> PermutationParameter { 59 get { return (ILookupParameter<Permutation>)Parameters["Permutation"]; } 60 60 } 61 61 … … 92 92 Parameters.Add(new LookupParameter<IntValue>("EvaluatedSolutions", "The amount of evaluated solutions (here a move is counted only as 4/n evaluated solutions with n being the length of the permutation).")); 93 93 Parameters.Add(new LookupParameter<ResultCollection>("Results", "The collection where to store results.")); 94 Parameters.Add(new LookupParameter<Permutation>(" Assignment", "The permutation that is to be locally optimized."));94 Parameters.Add(new LookupParameter<Permutation>("Permutation", "The permutation that is to be locally optimized.")); 95 95 Parameters.Add(new LookupParameter<DoubleValue>("Quality", "The quality value of the assignment.")); 96 96 Parameters.Add(new LookupParameter<BoolValue>("Maximization", "True if the problem should be maximized or minimized.")); … … 132 132 var maxIterations = MaximumIterationsParameter.ActualValue.Value; 133 133 var neighborhoodSize = NeighborhoodSizeParameter.ActualValue.Value; 134 var assignment = AssignmentParameter.ActualValue;134 var assignment = PermutationParameter.ActualValue; 135 135 var maximization = MaximizationParameter.ActualValue.Value; 136 136 var weights = WeightsParameter.ActualValue; -
branches/ProblemRefactoring/HeuristicLab.Problems.QuadraticAssignment/3.3/QuadraticAssignmentProblem.cs
r13377 r13396 38 38 [Creatable(CreatableAttribute.Categories.CombinatorialProblems, Priority = 140)] 39 39 [StorableClass] 40 public sealed class QuadraticAssignmentProblem : SingleObjectiveHeuristicOptimizationProblem<IQAPEvaluator, IPermutationCreator>, 41 ISingleObjectiveProblem<PermutationEncoding, Permutation>, IStorableContent, 40 public sealed class QuadraticAssignmentProblem : SingleObjectiveProblem<PermutationEncoding, Permutation>, 42 41 IProblemInstanceConsumer<QAPData>, 43 42 IProblemInstanceConsumer<TSPData> { 44 public string Filename { get; set; }45 43 46 44 public static new Image StaticItemImage { 47 get { return HeuristicLab.Common.Resources.VSImageLibrary.Type; } 48 } 45 get { return Common.Resources.VSImageLibrary.Type; } 46 } 47 48 public override bool Maximization { get { return false; } } 49 49 50 50 #region Parameter Properties … … 115 115 } 116 116 public QuadraticAssignmentProblem() 117 : base(new QAPEvaluator(), new RandomPermutationCreator()) {117 : base(new PermutationEncoding("Assignment") { Length = 5 }) { 118 118 Parameters.Add(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)); 119 119 Parameters.Add(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)); … … 122 122 Parameters.Add(new OptionalValueParameter<DoubleValue>("LowerBound", "The Gilmore-Lawler lower bound to the solution quality.")); 123 123 Parameters.Add(new OptionalValueParameter<DoubleValue>("AverageQuality", "The expected quality of a random solution.")); 124 125 Maximization.Value = false;126 MaximizationParameter.Hidden = true;127 124 128 125 WeightsParameter.GetsCollected = false; … … 144 141 }); 145 142 146 SolutionCreator.PermutationParameter.ActualName = "Assignment";147 ParameterizeSolutionCreator();148 ParameterizeEvaluator();149 150 143 InitializeOperators(); 151 144 RegisterEventHandlers(); 152 145 } 153 146 147 public override double Evaluate(Permutation assignment, IRandom random) { 148 return Evaluate(assignment); 149 } 150 151 public double Evaluate(Permutation assignment) { 152 double quality = 0; 153 for (int i = 0; i < assignment.Length; i++) { 154 for (int j = 0; j < assignment.Length; j++) { 155 quality += Weights[i, j] * Distances[assignment[i], assignment[j]]; 156 } 157 } 158 return quality; 159 } 160 154 161 public override IDeepCloneable Clone(Cloner cloner) { 155 162 return new QuadraticAssignmentProblem(this, cloner); … … 158 165 [StorableHook(HookType.AfterDeserialization)] 159 166 private void AfterDeserialization() { 160 // BackwardsCompatibility3.3161 #region Backwards compatible code, remove with 3.4162 if (!Parameters.ContainsKey("BestKnownSolutions")) {163 Parameters.Add(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));164 } else if (Parameters["BestKnownSolutions"].GetType().Equals(typeof(OptionalValueParameter<ItemList<Permutation>>))) {165 ItemList<Permutation> list = ((OptionalValueParameter<ItemList<Permutation>>)Parameters["BestKnownSolutions"]).Value;166 Parameters.Remove("BestKnownSolutions");167 Parameters.Add(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.", (list != null ? new ItemSet<Permutation>(list) : null)));168 }169 if (Parameters.ContainsKey("DistanceMatrix")) {170 DoubleMatrix d = ((ValueParameter<DoubleMatrix>)Parameters["DistanceMatrix"]).Value;171 Parameters.Remove("DistanceMatrix");172 Parameters.Add(new ValueParameter<DoubleMatrix>("Distances", "The distance matrix which can either be specified directly without the coordinates, or can be calculated automatically from the coordinates.", d));173 }174 if (!Parameters.ContainsKey("LowerBound")) {175 Parameters.Add(new OptionalValueParameter<DoubleValue>("LowerBound", "The Gilmore-Lawler lower bound to the solution quality."));176 LowerBound = new DoubleValue(GilmoreLawlerBoundCalculator.CalculateLowerBound(Weights, Distances));177 }178 if (!Parameters.ContainsKey("AverageQuality")) {179 Parameters.Add(new OptionalValueParameter<DoubleValue>("AverageQuality", "The expected quality of a random solution."));180 AverageQuality = new DoubleValue(ComputeAverageQuality());181 }182 #endregion183 167 RegisterEventHandlers(); 184 168 } … … 186 170 #region Events 187 171 protected override void OnSolutionCreatorChanged() { 188 SolutionCreator.PermutationParameter.ActualNameChanged += new EventHandler(SolutionCreator_PermutationParameter_ActualNameChanged); 189 ParameterizeSolutionCreator(); 190 ParameterizeEvaluator(); 191 ParameterizeAnalyzers(); 192 ParameterizeOperators(); 172 Parameterize(); 193 173 base.OnSolutionCreatorChanged(); 194 174 } 195 175 protected override void OnEvaluatorChanged() { 196 Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged); 197 ParameterizeEvaluator(); 198 ParameterizeAnalyzers(); 199 ParameterizeOperators(); 176 Evaluator.QualityParameter.ActualNameChanged += Evaluator_QualityParameter_ActualNameChanged; 177 Parameterize(); 200 178 base.OnEvaluatorChanged(); 201 179 } 202 203 private void SolutionCreator_PermutationParameter_ActualNameChanged(object sender, EventArgs e) {204 ParameterizeEvaluator();205 ParameterizeAnalyzers();206 ParameterizeOperators();207 }208 180 private void Evaluator_QualityParameter_ActualNameChanged(object sender, EventArgs e) { 209 ParameterizeAnalyzers(); 210 ParameterizeOperators(); 181 Parameterize(); 211 182 } 212 183 private void WeightsParameter_ValueChanged(object sender, EventArgs e) { 213 Weights.RowsChanged += new EventHandler(Weights_RowsChanged); 214 Weights.ColumnsChanged += new EventHandler(Weights_ColumnsChanged); 215 Weights.ToStringChanged += new EventHandler(Weights_ToStringChanged); 216 ParameterizeSolutionCreator(); 217 ParameterizeEvaluator(); 218 ParameterizeOperators(); 184 Weights.RowsChanged += Weights_RowsChanged; 185 Weights.ColumnsChanged += Weights_ColumnsChanged; 186 Weights.ToStringChanged += Weights_ToStringChanged; 219 187 AdjustDistanceMatrix(); 220 188 } … … 223 191 ((IStringConvertibleMatrix)Weights).Columns = Weights.Rows; 224 192 else { 225 ParameterizeSolutionCreator();226 ParameterizeEvaluator();227 ParameterizeOperators();228 193 AdjustDistanceMatrix(); 229 194 } … … 233 198 ((IStringConvertibleMatrix)Weights).Rows = Weights.Columns; 234 199 else { 235 ParameterizeSolutionCreator();236 ParameterizeEvaluator();237 ParameterizeOperators();238 200 AdjustDistanceMatrix(); 239 201 } … … 243 205 } 244 206 private void DistancesParameter_ValueChanged(object sender, EventArgs e) { 245 Distances.RowsChanged += new EventHandler(Distances_RowsChanged); 246 Distances.ColumnsChanged += new EventHandler(Distances_ColumnsChanged); 247 Distances.ToStringChanged += new EventHandler(Distances_ToStringChanged); 248 ParameterizeSolutionCreator(); 249 ParameterizeEvaluator(); 250 ParameterizeOperators(); 207 Distances.RowsChanged += Distances_RowsChanged; 208 Distances.ColumnsChanged += Distances_ColumnsChanged; 209 Distances.ToStringChanged += Distances_ToStringChanged; 251 210 AdjustWeightsMatrix(); 252 211 } … … 255 214 ((IStringConvertibleMatrix)Distances).Columns = Distances.Rows; 256 215 else { 257 ParameterizeSolutionCreator();258 ParameterizeEvaluator();259 ParameterizeOperators();260 216 AdjustWeightsMatrix(); 261 217 } … … 265 221 ((IStringConvertibleMatrix)Distances).Rows = Distances.Columns; 266 222 else { 267 ParameterizeSolutionCreator();268 ParameterizeEvaluator();269 ParameterizeOperators();270 223 AdjustWeightsMatrix(); 271 224 } … … 277 230 278 231 private void RegisterEventHandlers() { 279 SolutionCreator.PermutationParameter.ActualNameChanged += new EventHandler(SolutionCreator_PermutationParameter_ActualNameChanged); 280 Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged); 281 WeightsParameter.ValueChanged += new EventHandler(WeightsParameter_ValueChanged); 282 Weights.RowsChanged += new EventHandler(Weights_RowsChanged); 283 Weights.ColumnsChanged += new EventHandler(Weights_ColumnsChanged); 284 Weights.ToStringChanged += new EventHandler(Weights_ToStringChanged); 285 DistancesParameter.ValueChanged += new EventHandler(DistancesParameter_ValueChanged); 286 Distances.RowsChanged += new EventHandler(Distances_RowsChanged); 287 Distances.ColumnsChanged += new EventHandler(Distances_ColumnsChanged); 288 Distances.ToStringChanged += new EventHandler(Distances_ToStringChanged); 232 WeightsParameter.ValueChanged += WeightsParameter_ValueChanged; 233 Weights.RowsChanged += Weights_RowsChanged; 234 Weights.ColumnsChanged += Weights_ColumnsChanged; 235 Weights.ToStringChanged += Weights_ToStringChanged; 236 DistancesParameter.ValueChanged += DistancesParameter_ValueChanged; 237 Distances.RowsChanged += Distances_RowsChanged; 238 Distances.ColumnsChanged += Distances_ColumnsChanged; 239 Distances.ToStringChanged += Distances_ToStringChanged; 289 240 } 290 241 … … 297 248 }); 298 249 Operators.AddRange(defaultOperators); 299 Operators.AddRange(ApplicationManager.Manager.GetInstances<IPermutationOperator>().Except(defaultOperators, new TypeEqualityComparer<IPermutationOperator>()));300 Operators.RemoveAll(x => x is ISingleObjectiveMoveEvaluator);301 250 Operators.AddRange(ApplicationManager.Manager.GetInstances<IQAPMoveEvaluator>()); 251 Operators.AddRange(ApplicationManager.Manager.GetInstances<IQAPLocalImprovementOperator>()); 302 252 Operators.Add(new BestQAPSolutionAnalyzer()); 303 253 Operators.Add(new QAPAlleleFrequencyAnalyzer()); 304 254 Operators.Add(new QAPPopulationDiversityAnalyzer()); 305 255 306 Operators.Add(new QAPExhaustiveInsertionLocalImprovement());307 Operators.Add(new QAPExhaustiveInversionLocalImprovement());308 Operators.Add(new QAPStochasticScrambleLocalImprovement());309 Operators.Add(new QAPExhaustiveSwap2LocalImprovement());310 311 256 Operators.Add(new QAPSimilarityCalculator()); 312 ParameterizeAnalyzers(); 313 ParameterizeOperators(); 314 } 315 private void ParameterizeSolutionCreator() { 316 if (SolutionCreator != null) { 317 SolutionCreator.PermutationTypeParameter.Value = new PermutationType(PermutationTypes.Absolute); 318 SolutionCreator.LengthParameter.Value = new IntValue(Weights.Rows); 319 } 320 } 321 private void ParameterizeEvaluator() { 322 if (Evaluator != null) { 323 Evaluator.PermutationParameter.ActualName = SolutionCreator.PermutationParameter.ActualName; 324 Evaluator.DistancesParameter.ActualName = DistancesParameter.Name; 325 Evaluator.WeightsParameter.ActualName = WeightsParameter.Name; 326 } 327 } 328 private void ParameterizeAnalyzers() { 257 Parameterize(); 258 } 259 private void Parameterize() { 260 var operators = new List<IItem>(); 329 261 if (BestQAPSolutionAnalyzer != null) { 262 operators.Add(BestQAPSolutionAnalyzer); 330 263 BestQAPSolutionAnalyzer.QualityParameter.ActualName = Evaluator.QualityParameter.ActualName; 331 264 BestQAPSolutionAnalyzer.DistancesParameter.ActualName = DistancesParameter.Name; 332 265 BestQAPSolutionAnalyzer.WeightsParameter.ActualName = WeightsParameter.Name; 333 BestQAPSolutionAnalyzer.PermutationParameter.ActualName = SolutionCreator.PermutationParameter.ActualName;334 BestQAPSolutionAnalyzer.ResultsParameter.ActualName = "Results";335 266 BestQAPSolutionAnalyzer.BestKnownQualityParameter.ActualName = BestKnownQualityParameter.Name; 336 267 BestQAPSolutionAnalyzer.BestKnownSolutionsParameter.ActualName = BestKnownSolutionsParameter.Name; … … 338 269 } 339 270 if (QAPAlleleFrequencyAnalyzer != null) { 271 operators.Add(QAPAlleleFrequencyAnalyzer); 340 272 QAPAlleleFrequencyAnalyzer.QualityParameter.ActualName = Evaluator.QualityParameter.ActualName; 341 273 QAPAlleleFrequencyAnalyzer.BestKnownSolutionParameter.ActualName = BestKnownSolutionParameter.Name; 342 274 QAPAlleleFrequencyAnalyzer.DistancesParameter.ActualName = DistancesParameter.Name; 343 275 QAPAlleleFrequencyAnalyzer.MaximizationParameter.ActualName = MaximizationParameter.Name; 344 QAPAlleleFrequencyAnalyzer.ResultsParameter.ActualName = "Results";345 QAPAlleleFrequencyAnalyzer.SolutionParameter.ActualName = SolutionCreator.PermutationParameter.ActualName;346 276 QAPAlleleFrequencyAnalyzer.WeightsParameter.ActualName = WeightsParameter.Name; 347 277 } 348 278 if (QAPPopulationDiversityAnalyzer != null) { 279 operators.Add(QAPPopulationDiversityAnalyzer); 349 280 QAPPopulationDiversityAnalyzer.MaximizationParameter.ActualName = MaximizationParameter.Name; 350 281 QAPPopulationDiversityAnalyzer.QualityParameter.ActualName = Evaluator.QualityParameter.ActualName; 351 QAPPopulationDiversityAnalyzer.ResultsParameter.ActualName = "Results"; 352 QAPPopulationDiversityAnalyzer.SolutionParameter.ActualName = SolutionCreator.PermutationParameter.ActualName; 353 } 354 } 355 private void ParameterizeOperators() { 356 foreach (IPermutationCrossover op in Operators.OfType<IPermutationCrossover>()) { 357 op.ParentsParameter.ActualName = SolutionCreator.PermutationParameter.ActualName; 358 op.ChildParameter.ActualName = SolutionCreator.PermutationParameter.ActualName; 359 } 360 foreach (IPermutationManipulator op in Operators.OfType<IPermutationManipulator>()) { 361 op.PermutationParameter.ActualName = SolutionCreator.PermutationParameter.ActualName; 362 } 363 foreach (IPermutationMoveOperator op in Operators.OfType<IPermutationMoveOperator>()) { 364 op.PermutationParameter.ActualName = SolutionCreator.PermutationParameter.ActualName; 365 } 366 if (Operators.OfType<IMoveGenerator>().Any()) { 367 if (Operators.OfType<IMoveGenerator>().OfType<IPermutationInversionMoveOperator>().Any()) { 368 string inversionMove = Operators.OfType<IMoveGenerator>().OfType<IPermutationInversionMoveOperator>().First().InversionMoveParameter.ActualName; 369 foreach (IPermutationInversionMoveOperator op in Operators.OfType<IPermutationInversionMoveOperator>()) 370 op.InversionMoveParameter.ActualName = inversionMove; 371 } 372 if (Operators.OfType<IMoveGenerator>().OfType<IPermutationTranslocationMoveOperator>().Any()) { 373 string translocationMove = Operators.OfType<IMoveGenerator>().OfType<IPermutationTranslocationMoveOperator>().First().TranslocationMoveParameter.ActualName; 374 foreach (IPermutationTranslocationMoveOperator op in Operators.OfType<IPermutationTranslocationMoveOperator>()) 375 op.TranslocationMoveParameter.ActualName = translocationMove; 376 } 377 if (Operators.OfType<IMoveGenerator>().OfType<IPermutationSwap2MoveOperator>().Any()) { 378 string swapMove = Operators.OfType<IMoveGenerator>().OfType<IPermutationSwap2MoveOperator>().First().Swap2MoveParameter.ActualName; 379 foreach (IPermutationSwap2MoveOperator op in Operators.OfType<IPermutationSwap2MoveOperator>()) { 380 op.Swap2MoveParameter.ActualName = swapMove; 381 } 382 } 383 } 384 foreach (var op in Operators.OfType<IPermutationMultiNeighborhoodShakingOperator>()) 385 op.PermutationParameter.ActualName = SolutionCreator.PermutationParameter.ActualName; 386 387 QAPExhaustiveSwap2LocalImprovement localOpt = Operators.OfType<QAPExhaustiveSwap2LocalImprovement>().SingleOrDefault(); 388 if (localOpt != null) { 389 localOpt.AssignmentParameter.ActualName = SolutionCreator.PermutationParameter.ActualName; 282 } 283 foreach (var localOpt in Operators.OfType<IQAPLocalImprovementOperator>()) { 284 operators.Add(localOpt); 390 285 localOpt.DistancesParameter.ActualName = DistancesParameter.Name; 391 286 localOpt.MaximizationParameter.ActualName = MaximizationParameter.Name; … … 394 289 } 395 290 396 QAPSimilarityCalculator similarityCalculator = Operators.OfType<QAPSimilarityCalculator>().SingleOrDefault(); 291 foreach (var moveOp in Operators.OfType<IQAPMoveEvaluator>()) { 292 operators.Add(moveOp); 293 moveOp.DistancesParameter.ActualName = DistancesParameter.Name; 294 moveOp.WeightsParameter.ActualName = WeightsParameter.Name; 295 moveOp.QualityParameter.ActualName = Evaluator.QualityParameter.Name; 296 297 var swaMoveOp = moveOp as QAPSwap2MoveEvaluator; 298 if (swaMoveOp != null) { 299 var moveQualityName = swaMoveOp.MoveQualityParameter.ActualName; 300 foreach (var o in Encoding.Operators.OfType<IPermutationSwap2MoveQualityOperator>()) 301 o.MoveQualityParameter.ActualName = moveQualityName; 302 } 303 var invMoveOp = moveOp as QAPInversionMoveEvaluator; 304 if (invMoveOp != null) { 305 var moveQualityName = invMoveOp.MoveQualityParameter.ActualName; 306 foreach (var o in Encoding.Operators.OfType<IPermutationInversionMoveQualityOperator>()) 307 o.MoveQualityParameter.ActualName = moveQualityName; 308 } 309 var traMoveOp = moveOp as QAPTranslocationMoveEvaluator; 310 if (traMoveOp != null) { 311 var moveQualityName = traMoveOp.MoveQualityParameter.ActualName; 312 foreach (var o in Encoding.Operators.OfType<IPermutationTranslocationMoveQualityOperator>()) 313 o.MoveQualityParameter.ActualName = moveQualityName; 314 } 315 var scrMoveOp = moveOp as QAPScrambleMoveEvaluator; 316 if (scrMoveOp != null) { 317 var moveQualityName = scrMoveOp.MoveQualityParameter.ActualName; 318 foreach (var o in Encoding.Operators.OfType<IPermutationScrambleMoveQualityOperator>()) 319 o.MoveQualityParameter.ActualName = moveQualityName; 320 } 321 } 322 var similarityCalculator = Operators.OfType<QAPSimilarityCalculator>().SingleOrDefault(); 397 323 if (similarityCalculator != null) { 398 similarityCalculator.SolutionVariableName = SolutionCreator.PermutationParameter.ActualName;324 similarityCalculator.SolutionVariableName = Encoding.Name; 399 325 similarityCalculator.QualityVariableName = Evaluator.QualityParameter.ActualName; 400 326 } 327 328 if (operators.Count > 0) Encoding.ConfigureOperators(operators); 401 329 } 402 330 … … 404 332 if (Distances.Rows != Weights.Rows || Distances.Columns != Weights.Columns) { 405 333 ((IStringConvertibleMatrix)Distances).Rows = Weights.Rows; 334 Encoding.Length = Weights.Rows; 406 335 } 407 336 } … … 410 339 if (Weights.Rows != Distances.Rows || Weights.Columns != Distances.Columns) { 411 340 ((IStringConvertibleMatrix)Weights).Rows = Distances.Rows; 341 Encoding.Length = Distances.Rows; 412 342 } 413 343 } … … 418 348 LowerBound = new DoubleValue(GilmoreLawlerBoundCalculator.CalculateLowerBound(Weights, Distances, out lbSolution)); 419 349 // evalute the LAP optimal solution as if it was a QAP solution 420 var lbSolutionQuality = QAPEvaluator.Apply(lbSolution, Weights, Distances);350 var lbSolutionQuality = Evaluate(lbSolution); 421 351 // in case both qualities are the same it means that the LAP optimum is also a QAP optimum 422 352 if (LowerBound.Value.IsAlmost(lbSolutionQuality)) { 423 353 BestKnownSolution = lbSolution; 424 BestKnownQuality = new DoubleValue(LowerBound.Value);354 BestKnownQuality = LowerBound.Value; 425 355 } 426 356 AverageQuality = new DoubleValue(ComputeAverageQuality()); … … 451 381 Description = data.Description; 452 382 Load(weights, distances); 453 if (data.BestKnownQuality.HasValue) BestKnownQuality = new DoubleValue(data.BestKnownQuality.Value);383 if (data.BestKnownQuality.HasValue) BestKnownQuality = data.BestKnownQuality.Value; 454 384 EvaluateAndLoadAssignment(data.BestKnownAssignment); 455 385 OnReset(); … … 466 396 Description = data.Description; 467 397 Load(weights, distances); 468 if (data.BestKnownQuality.HasValue) BestKnownQuality = new DoubleValue(data.BestKnownQuality.Value);398 if (data.BestKnownQuality.HasValue) BestKnownQuality = data.BestKnownQuality.Value; 469 399 EvaluateAndLoadAssignment(data.BestKnownTour); 470 400 OnReset(); … … 485 415 Weights = weights; 486 416 Distances = distances; 487 488 BestKnownQuality = null; 417 Encoding.Length = weights.Rows; 418 419 BestKnownQualityParameter.Value = null; 489 420 BestKnownSolution = null; 490 421 BestKnownSolutions = null; … … 495 426 if (assignment == null || assignment.Length == 0) return; 496 427 var vector = new Permutation(PermutationTypes.Absolute, assignment); 497 var result = QAPEvaluator.Apply(vector, Weights, Distances);498 BestKnownQuality = new DoubleValue(result);428 var result = Evaluate(vector); 429 BestKnownQuality = result; 499 430 BestKnownSolution = vector; 500 BestKnownSolutions = new ItemSet<Permutation>(); 501 BestKnownSolutions.Add((Permutation)vector.Clone()); 431 BestKnownSolutions = new ItemSet<Permutation> { (Permutation)vector.Clone() }; 502 432 } 503 433 }
Note: See TracChangeset
for help on using the changeset viewer.