- Timestamp:
- 01/11/12 09:16:27 (13 years ago)
- Location:
- branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3
- Property svn:ignore
-
old new 1 1 Plugin.cs 2 2 obj 3 bin
-
- Property svn:ignore
-
branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Analyzers/BestGQAPSolutionAnalyzer.cs
r6956 r7311 37 37 [StorableClass] 38 38 public sealed class BestGQAPSolutionAnalyzer : SingleSuccessorOperator, IAnalyzer { 39 40 public bool EnabledByDefault { 41 get { return true; } 42 } 43 39 44 public LookupParameter<BoolValue> MaximizationParameter { 40 45 get { return (LookupParameter<BoolValue>)Parameters["Maximization"]; } … … 64 69 get { return (LookupParameter<IntegerVector>)Parameters["BestKnownSolution"]; } 65 70 } 71 public ILookupParameter<StringArray> EquipmentNamesParameter { 72 get { return (ILookupParameter<StringArray>)Parameters["EquipmentNames"]; } 73 } 74 public ILookupParameter<StringArray> LocationNamesParameter { 75 get { return (ILookupParameter<StringArray>)Parameters["LocationNames"]; } 76 } 66 77 67 78 [StorableConstructor] … … 82 93 Parameters.Add(new LookupParameter<DoubleValue>("BestKnownQuality", "The quality of the best known solution of this GQAP instance.")); 83 94 Parameters.Add(new LookupParameter<IntegerVector>("BestKnownSolution", "The best known solution of this GQAP instance.")); 95 Parameters.Add(new LookupParameter<StringArray>("EquipmentNames", "A list of names that describes the equipments.")); 96 Parameters.Add(new LookupParameter<StringArray>("LocationNames", "A list of names that describes the locations.")); 97 } 98 99 [StorableHook(HookType.AfterDeserialization)] 100 private void AfterDeserializationHook() { 101 // BackwardsCompatibility3.3 102 #region Backwards compatible code, remove with 3.4 103 if (!Parameters.ContainsKey("EquipmentNames")) 104 Parameters.Add(new LookupParameter<StringArray>("EquipmentNames", "Optional: A list of names that describes the equipments.")); 105 if (!Parameters.ContainsKey("LocationNames")) 106 Parameters.Add(new LookupParameter<StringArray>("LocationNames", "Optional: A list of names that describes the locations.")); 107 #endregion 84 108 } 85 109 … … 107 131 GQAPAssignment assignment = BestSolutionParameter.ActualValue; 108 132 if (assignment == null) { 109 assignment = new GQAPAssignment(weights, (IntegerVector)assignments[i].Clone(), new DoubleValue(qualities[i].Value)); 133 StringArray equipmentNames = EquipmentNamesParameter.ActualValue; 134 StringArray locationNames = LocationNamesParameter.ActualValue; 135 assignment = new GQAPAssignment(weights, (IntegerVector)assignments[i].Clone(), new DoubleValue(qualities[i].Value), equipmentNames, locationNames); 110 136 assignment.Distances = distances; 111 137 BestSolutionParameter.ActualValue = assignment; -
branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Evaluators/GQAPEvaluator.cs
r6956 r7311 20 20 #endregion 21 21 22 using System; 22 23 using System.Linq; 23 24 using HeuristicLab.Common; … … 98 99 double infeasibility = 0; 99 100 101 if (weights.Rows != weights.Columns || distances.Rows != distances.Columns 102 || weights.Rows != installCosts.Rows || distances.Rows != installCosts.Columns 103 || demands.Length != weights.Rows || capacities.Length != distances.Rows) 104 throw new InvalidOperationException("ERROR: The problem configuration is not valid! Check the sizes of the weights (NxN), distances (MxM) and installation costs (NxM) matrices as well as the length of the demand (N) and capacities (M) vectors."); 105 100 106 int len = assignment.Length; 101 107 for (int i = 0; i < len; i++) { -
branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/GQAPAssignment.cs
r6956 r7311 76 76 } 77 77 78 [Storable] 79 private StringArray equipmentNames; 80 public StringArray EquipmentNames { 81 get { return equipmentNames; } 82 set { 83 bool changed = (equipmentNames != value); 84 equipmentNames = value; 85 if (changed) OnPropertyChanged("EquipmentNames"); 86 } 87 } 88 89 [Storable] 90 private StringArray locationNames; 91 public StringArray LocationNames { 92 get { return locationNames; } 93 set { 94 bool changed = (locationNames != value); 95 locationNames = value; 96 if (changed) OnPropertyChanged("LocationNames"); 97 } 98 } 99 78 100 [StorableConstructor] 79 101 private GQAPAssignment(bool deserializing) : base(deserializing) { } … … 84 106 assignment = cloner.Clone(original.assignment); 85 107 quality = cloner.Clone(original.quality); 108 equipmentNames = cloner.Clone(original.equipmentNames); 109 locationNames = cloner.Clone(original.locationNames); 86 110 } 87 111 public GQAPAssignment(DoubleMatrix weights, IntegerVector assignment) { … … 92 116 : this(weights, assignment) { 93 117 this.quality = quality; 118 } 119 public GQAPAssignment(DoubleMatrix weights, IntegerVector assignment, DoubleValue quality, StringArray equipmentNames, StringArray locationNames) 120 : this(weights, assignment, quality) { 121 this.equipmentNames = equipmentNames; 122 this.locationNames = locationNames; 94 123 } 95 124 -
branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/GeneralizedQuadraticAssignmentProblem.cs
r6956 r7311 20 20 #endregion 21 21 22 using System; 22 23 using System.Drawing; 23 24 using System.Linq; … … 35 36 [Creatable("Problems")] 36 37 [StorableClass] 37 public sealed class GeneralizedQuadraticAssignmentProblem : SingleObjectiveHeuristicOptimizationProblem<IGQAPEvaluator, IIntegerVectorCreator> {38 public sealed class GeneralizedQuadraticAssignmentProblem : SingleObjectiveHeuristicOptimizationProblem<IGQAPEvaluator, IIntegerVectorCreator>, IStorableContent { 38 39 public override Image ItemImage { 39 40 get { return HeuristicLab.Common.Resources.VSImageLibrary.Type; } 40 41 } 42 43 public string Filename { get; set; } 41 44 42 45 #region Parameter Properties … … 62 65 get { return (OptionalValueParameter<IItem>)Parameters["BestKnownSolution"]; } 63 66 } 64 65 67 #endregion 66 68 … … 90 92 set { CapacitiesParameter.Value = value; } 91 93 } 92 93 94 #endregion 94 95 … … 116 117 Parameters.Add(new ValueParameter<DoubleArray>("Capacities", "The capacities vector describes the available space at the locations.", new DoubleArray())); 117 118 Parameters.Add(new OptionalValueParameter<IItem>("BestKnownSolution", "The best known solution (if available)", null)); 119 Parameters.Add(new OptionalValueParameter<StringArray>("EquipmentNames", "Optional: A list of names that describes the equipments.", null, false)); 120 Parameters.Add(new OptionalValueParameter<StringArray>("LocationNames", "Optional: A list of names that describes the locations.", null, false)); 118 121 119 122 WeightsParameter.ReactOnValueToStringChangedAndValueItemImageChanged = false; … … 133 136 Distances[0, 2] = Distances[2, 0] = 2; 134 137 135 InstallationCosts = new DoubleMatrix( 3, 3);138 InstallationCosts = new DoubleMatrix(5, 3); 136 139 137 140 TransportationCosts = 1; … … 143 146 Capacities[0] = 4; Capacities[1] = 1; Capacities[2] = 4; 144 147 145 ParameterizeSolutionCreator(); 146 ParameterizeEvaluator(); 148 Parameterize(); 147 149 148 150 InitializeOperators(); … … 155 157 156 158 #region Events 157 // TODO: Add your event handlers here 159 protected override void OnOperatorsChanged() { 160 base.OnOperatorsChanged(); 161 Parameterize(); 162 } 163 protected override void OnEvaluatorChanged() { 164 base.OnEvaluatorChanged(); 165 Parameterize(); 166 Evaluator.QualityParameter.ActualNameChanged += new System.EventHandler(Evaluator_QualityParameter_ActualNameChanged); 167 } 168 protected override void OnSolutionCreatorChanged() { 169 base.OnSolutionCreatorChanged(); 170 Parameterize(); 171 SolutionCreator.IntegerVectorParameter.ActualNameChanged += new EventHandler(SolutionCreator_IntegerVectorParameter_ActualNameChanged); 172 } 173 174 private void Evaluator_QualityParameter_ActualNameChanged(object sender, EventArgs e) { 175 Parameterize(); 176 } 177 private void SolutionCreator_IntegerVectorParameter_ActualNameChanged(object sender, EventArgs e) { 178 Parameterize(); 179 } 158 180 #endregion 159 181 … … 161 183 [StorableHook(HookType.AfterDeserialization)] 162 184 private void AfterDeserializationHook() { 185 // BackwardsCompatibility3.3 186 #region Backwards compatible code, remove with 3.4 187 if (!Parameters.ContainsKey("EquipmentNames")) 188 Parameters.Add(new OptionalValueParameter<StringArray>("EquipmentNames", "Optional: A list of names that describes the equipments.", null, false)); 189 if (!Parameters.ContainsKey("LocationNames")) 190 Parameters.Add(new OptionalValueParameter<StringArray>("LocationNames", "Optional: A list of names that describes the locations.", null, false)); 191 #endregion 163 192 AttachEventHandlers(); 164 193 } 165 194 166 195 private void AttachEventHandlers() { 167 // TODO: Add event handlers to the parameters here 196 Evaluator.QualityParameter.ActualNameChanged += new System.EventHandler(Evaluator_QualityParameter_ActualNameChanged); 197 SolutionCreator.IntegerVectorParameter.ActualNameChanged += new EventHandler(SolutionCreator_IntegerVectorParameter_ActualNameChanged); 168 198 } 169 199 … … 172 202 Operators.RemoveAll(x => x is ISingleObjectiveMoveEvaluator); 173 203 Operators.Add(new BestGQAPSolutionAnalyzer()); 174 ParameterizeAnalyzers(); 175 ParameterizeOperators(); 176 } 177 private void ParameterizeAnalyzers() { 204 Parameterize(); 205 } 206 207 private void Parameterize() { 208 Evaluator.WeightsParameter.ActualName = WeightsParameter.Name; 209 Evaluator.DistancesParameter.ActualName = DistancesParameter.Name; 210 Evaluator.InstallationCostsParameter.ActualName = InstallationCostsParameter.Name; 211 Evaluator.TransportationCostsParameter.ActualName = TransportationCostsParameter.Name; 212 Evaluator.DemandsParameter.ActualName = DemandsParameter.Name; 213 Evaluator.CapacitiesParameter.ActualName = CapacitiesParameter.Name; 214 Evaluator.AssignmentParameter.ActualName = "Assignment"; 215 216 SolutionCreator.LengthParameter.Value = new IntValue(Demands.Length); 217 SolutionCreator.MinimumParameter.Value = new IntValue(0); 218 SolutionCreator.MaximumParameter.Value = new IntValue(Capacities.Length); 219 SolutionCreator.IntegerVectorParameter.ActualName = "Assignment"; 220 221 foreach (IIntegerVectorCrossover op in Operators.OfType<IIntegerVectorCrossover>()) { 222 op.ParentsParameter.ActualName = SolutionCreator.IntegerVectorParameter.ActualName; 223 op.ChildParameter.ActualName = SolutionCreator.IntegerVectorParameter.ActualName; 224 } 225 foreach (IIntegerVectorManipulator op in Operators.OfType<IIntegerVectorManipulator>()) { 226 op.IntegerVectorParameter.ActualName = SolutionCreator.IntegerVectorParameter.ActualName; 227 } 228 178 229 if (BestSolutionAnalyzer != null) { 179 230 BestSolutionAnalyzer.QualityParameter.ActualName = Evaluator.QualityParameter.ActualName; … … 186 237 } 187 238 } 188 private void ParameterizeOperators() {189 foreach (IIntegerVectorCrossover op in Operators.OfType<IIntegerVectorCrossover>()) {190 op.ParentsParameter.ActualName = SolutionCreator.IntegerVectorParameter.ActualName;191 op.ChildParameter.ActualName = SolutionCreator.IntegerVectorParameter.ActualName;192 }193 foreach (IIntegerVectorManipulator op in Operators.OfType<IIntegerVectorManipulator>()) {194 op.IntegerVectorParameter.ActualName = SolutionCreator.IntegerVectorParameter.ActualName;195 }196 }197 private void ParameterizeSolutionCreator() {198 SolutionCreator.LengthParameter.Value = new IntValue(Demands.Length);199 SolutionCreator.MinimumParameter.Value = new IntValue(0);200 SolutionCreator.MaximumParameter.Value = new IntValue(Capacities.Length);201 SolutionCreator.IntegerVectorParameter.ActualName = "Assignment";202 }203 private void ParameterizeEvaluator() {204 Evaluator.WeightsParameter.ActualName = WeightsParameter.Name;205 Evaluator.DistancesParameter.ActualName = DistancesParameter.Name;206 Evaluator.InstallationCostsParameter.ActualName = InstallationCostsParameter.Name;207 Evaluator.TransportationCostsParameter.ActualName = TransportationCostsParameter.Name;208 Evaluator.DemandsParameter.ActualName = DemandsParameter.Name;209 Evaluator.CapacitiesParameter.ActualName = CapacitiesParameter.Name;210 Evaluator.AssignmentParameter.ActualName = "Assignment";211 }212 239 #endregion 213 240 }
Note: See TracChangeset
for help on using the changeset viewer.