Changeset 5562 for branches/QAP/HeuristicLab.Problems.QuadraticAssignment
- Timestamp:
- 02/25/11 11:37:01 (14 years ago)
- Location:
- branches/QAP/HeuristicLab.Problems.QuadraticAssignment/3.3
- Files:
-
- 256 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/QAP/HeuristicLab.Problems.QuadraticAssignment/3.3
- Property svn:ignore
-
old new 2 2 obj 3 3 Plugin.cs 4 *.user
-
- Property svn:ignore
-
branches/QAP/HeuristicLab.Problems.QuadraticAssignment/3.3/Evaluators/QAPEvaluator.cs
r5558 r5562 64 64 } 65 65 66 public override IDeepCloneable Clone(Cloner cloner) { 67 return new QAPEvaluator(this, cloner); 68 } 69 70 public static double Apply(Permutation assignment, DoubleMatrix weights, Func<int, int, double> distance) { 71 double quality = 0; 72 for (int i = 0; i < assignment.Length; i++) { 73 for (int j = 0; j < assignment.Length; j++) { 74 quality += weights[i, j] * distance(assignment[i], assignment[j]); 75 } 76 } 77 return quality; 78 } 79 66 80 public override IOperation Apply() { 67 81 Permutation assignment = PermutationParameter.ActualValue; 68 82 bool useDistanceMatrix = UseDistanceMatrixParameter.ActualValue.Value; 69 83 DoubleMatrix weights = WeightsParameter.ActualValue; 70 double quality = 0; 84 double quality; 85 71 86 if (useDistanceMatrix) { 72 87 DoubleMatrix distanceMatrix = DistanceMatrixParameter.ActualValue; 73 for (int facility = 0; facility < assignment.Length; facility++) { 74 int location = assignment[facility]; 75 for (int i = 0; i < weights.Columns; i++) { 76 double w = weights[facility, i]; 77 if (facility != i && Math.Abs(w) > double.Epsilon) 78 quality += w * distanceMatrix[location, assignment[i]]; 79 } 80 } 88 quality = Apply(assignment, weights, (x, y) => distanceMatrix[x, y]); 81 89 } else { 82 90 DoubleMatrix coordinates = CoordinatesParameter.ActualValue; 83 for (int facility = 0; facility < assignment.Length; facility++) { 84 int location = assignment[facility]; 85 for (int i = 0; i < weights.Columns; i++) { 86 double w = weights[facility, i]; 87 if (facility != i && Math.Abs(w) > double.Epsilon) 88 quality += w * Distance(coordinates, location, assignment[i]); 89 } 90 } 91 quality = Apply(assignment, weights, (x, y) => Distance(coordinates, x, y)); 91 92 } 93 92 94 QualityParameter.ActualValue = new DoubleValue(quality); 95 93 96 return base.Apply(); 94 97 } -
branches/QAP/HeuristicLab.Problems.QuadraticAssignment/3.3/HeuristicLab.Problems.QuadraticAssignment-3.3.csproj
r5558 r5562 143 143 <Compile Include="Evaluators\QAPEvaluator.cs" /> 144 144 <Compile Include="Interfaces\IQAPEvaluator.cs" /> 145 <Compile Include="Parsers\QAPLIBParser.cs" /> 145 146 <Compile Include="QuadraticAssignmentProblem.cs" /> 147 <EmbeddedResource Include="Data\bur26a.dat" /> 148 <EmbeddedResource Include="Data\bur26b.dat" /> 149 <EmbeddedResource Include="Data\bur26c.dat" /> 150 <EmbeddedResource Include="Data\bur26d.dat" /> 151 <EmbeddedResource Include="Data\bur26e.dat" /> 152 <EmbeddedResource Include="Data\bur26f.dat" /> 153 <EmbeddedResource Include="Data\bur26g.dat" /> 154 <EmbeddedResource Include="Data\bur26h.dat" /> 155 <EmbeddedResource Include="Data\chr12a.dat" /> 156 <EmbeddedResource Include="Data\chr12b.dat" /> 157 <EmbeddedResource Include="Data\chr12c.dat" /> 158 <EmbeddedResource Include="Data\chr15a.dat" /> 159 <EmbeddedResource Include="Data\chr15b.dat" /> 160 <EmbeddedResource Include="Data\chr15c.dat" /> 161 <EmbeddedResource Include="Data\chr18a.dat" /> 162 <EmbeddedResource Include="Data\chr18b.dat" /> 163 <EmbeddedResource Include="Data\chr20a.dat" /> 164 <EmbeddedResource Include="Data\chr20b.dat" /> 165 <EmbeddedResource Include="Data\chr20c.dat" /> 166 <EmbeddedResource Include="Data\chr22a.dat" /> 167 <EmbeddedResource Include="Data\chr22b.dat" /> 168 <EmbeddedResource Include="Data\chr25a.dat" /> 169 <EmbeddedResource Include="Data\els19.dat" /> 170 <EmbeddedResource Include="Data\esc128.dat" /> 171 <EmbeddedResource Include="Data\esc16a.dat" /> 172 <EmbeddedResource Include="Data\esc16b.dat" /> 173 <EmbeddedResource Include="Data\esc16c.dat" /> 174 <EmbeddedResource Include="Data\esc16d.dat" /> 175 <EmbeddedResource Include="Data\esc16e.dat" /> 176 <EmbeddedResource Include="Data\esc16f.dat" /> 177 <EmbeddedResource Include="Data\esc16g.dat" /> 178 <EmbeddedResource Include="Data\esc16h.dat" /> 179 <EmbeddedResource Include="Data\esc16i.dat" /> 180 <EmbeddedResource Include="Data\esc16j.dat" /> 181 <EmbeddedResource Include="Data\esc32a.dat" /> 182 <EmbeddedResource Include="Data\esc32b.dat" /> 183 <EmbeddedResource Include="Data\esc32c.dat" /> 184 <EmbeddedResource Include="Data\esc32d.dat" /> 185 <EmbeddedResource Include="Data\esc32e.dat" /> 186 <EmbeddedResource Include="Data\esc32f.dat" /> 187 <EmbeddedResource Include="Data\esc32g.dat" /> 188 <EmbeddedResource Include="Data\esc32h.dat" /> 189 <EmbeddedResource Include="Data\esc64a.dat" /> 190 <EmbeddedResource Include="Data\had12.dat" /> 191 <EmbeddedResource Include="Data\had14.dat" /> 192 <EmbeddedResource Include="Data\had16.dat" /> 193 <EmbeddedResource Include="Data\had18.dat" /> 194 <EmbeddedResource Include="Data\had20.dat" /> 195 <EmbeddedResource Include="Data\kra30a.dat" /> 196 <EmbeddedResource Include="Data\kra30b.dat" /> 197 <EmbeddedResource Include="Data\kra32.dat" /> 198 <EmbeddedResource Include="Data\lipa20a.dat" /> 199 <EmbeddedResource Include="Data\lipa20b.dat" /> 200 <EmbeddedResource Include="Data\lipa30a.dat" /> 201 <EmbeddedResource Include="Data\lipa30b.dat" /> 202 <EmbeddedResource Include="Data\lipa40a.dat" /> 203 <EmbeddedResource Include="Data\lipa40b.dat" /> 204 <EmbeddedResource Include="Data\lipa50a.dat" /> 205 <EmbeddedResource Include="Data\lipa50b.dat" /> 206 <EmbeddedResource Include="Data\lipa60a.dat" /> 207 <EmbeddedResource Include="Data\lipa60b.dat" /> 208 <EmbeddedResource Include="Data\lipa70a.dat" /> 209 <EmbeddedResource Include="Data\lipa70b.dat" /> 210 <EmbeddedResource Include="Data\lipa80a.dat" /> 211 <EmbeddedResource Include="Data\lipa80b.dat" /> 212 <EmbeddedResource Include="Data\lipa90a.dat" /> 213 <EmbeddedResource Include="Data\lipa90b.dat" /> 214 <EmbeddedResource Include="Data\nug12.dat" /> 215 <EmbeddedResource Include="Data\nug14.dat" /> 216 <EmbeddedResource Include="Data\nug15.dat" /> 217 <EmbeddedResource Include="Data\nug16a.dat" /> 218 <EmbeddedResource Include="Data\nug16b.dat" /> 219 <EmbeddedResource Include="Data\nug17.dat" /> 220 <EmbeddedResource Include="Data\nug18.dat" /> 221 <EmbeddedResource Include="Data\nug20.dat" /> 222 <EmbeddedResource Include="Data\nug21.dat" /> 223 <EmbeddedResource Include="Data\nug22.dat" /> 224 <EmbeddedResource Include="Data\nug24.dat" /> 225 <EmbeddedResource Include="Data\nug25.dat" /> 226 <EmbeddedResource Include="Data\nug27.dat" /> 227 <EmbeddedResource Include="Data\nug28.dat" /> 228 <EmbeddedResource Include="Data\nug30.dat" /> 229 <EmbeddedResource Include="Data\rou12.dat" /> 230 <EmbeddedResource Include="Data\rou15.dat" /> 231 <EmbeddedResource Include="Data\rou20.dat" /> 232 <EmbeddedResource Include="Data\scr12.dat" /> 233 <EmbeddedResource Include="Data\scr15.dat" /> 234 <EmbeddedResource Include="Data\scr20.dat" /> 235 <EmbeddedResource Include="Data\sko100a.dat" /> 236 <EmbeddedResource Include="Data\sko100b.dat" /> 237 <EmbeddedResource Include="Data\sko100c.dat" /> 238 <EmbeddedResource Include="Data\sko100d.dat" /> 239 <EmbeddedResource Include="Data\sko100e.dat" /> 240 <EmbeddedResource Include="Data\sko100f.dat" /> 241 <EmbeddedResource Include="Data\sko42.dat" /> 242 <EmbeddedResource Include="Data\sko49.dat" /> 243 <EmbeddedResource Include="Data\sko56.dat" /> 244 <EmbeddedResource Include="Data\sko64.dat" /> 245 <EmbeddedResource Include="Data\sko72.dat" /> 246 <EmbeddedResource Include="Data\sko81.dat" /> 247 <EmbeddedResource Include="Data\sko90.dat" /> 248 <EmbeddedResource Include="Data\ste36a.dat" /> 249 <EmbeddedResource Include="Data\ste36b.dat" /> 250 <EmbeddedResource Include="Data\ste36c.dat" /> 251 <EmbeddedResource Include="Data\tai100a.dat" /> 252 <EmbeddedResource Include="Data\tai100b.dat" /> 253 <EmbeddedResource Include="Data\tai10a.dat" /> 254 <EmbeddedResource Include="Data\tai10b.dat" /> 255 <EmbeddedResource Include="Data\tai12a.dat" /> 256 <EmbeddedResource Include="Data\tai12b.dat" /> 257 <EmbeddedResource Include="Data\tai150b.dat" /> 258 <EmbeddedResource Include="Data\tai15a.dat" /> 259 <EmbeddedResource Include="Data\tai15b.dat" /> 260 <EmbeddedResource Include="Data\tai17a.dat" /> 261 <EmbeddedResource Include="Data\tai20a.dat" /> 262 <EmbeddedResource Include="Data\tai20b.dat" /> 263 <EmbeddedResource Include="Data\tai256c.dat" /> 264 <EmbeddedResource Include="Data\tai25a.dat" /> 265 <EmbeddedResource Include="Data\tai25b.dat" /> 266 <EmbeddedResource Include="Data\tai30a.dat" /> 267 <EmbeddedResource Include="Data\tai30b.dat" /> 268 <EmbeddedResource Include="Data\tai35a.dat" /> 269 <EmbeddedResource Include="Data\tai35b.dat" /> 270 <EmbeddedResource Include="Data\tai40a.dat" /> 271 <EmbeddedResource Include="Data\tai40b.dat" /> 272 <EmbeddedResource Include="Data\tai50a.dat" /> 273 <EmbeddedResource Include="Data\tai50b.dat" /> 274 <EmbeddedResource Include="Data\tai60a.dat" /> 275 <EmbeddedResource Include="Data\tai60b.dat" /> 276 <EmbeddedResource Include="Data\tai64c.dat" /> 277 <EmbeddedResource Include="Data\tai80a.dat" /> 278 <EmbeddedResource Include="Data\tai80b.dat" /> 279 <EmbeddedResource Include="Data\tho150.dat" /> 280 <EmbeddedResource Include="Data\tho30.dat" /> 281 <EmbeddedResource Include="Data\tho40.dat" /> 282 <EmbeddedResource Include="Data\wil100.dat" /> 283 <EmbeddedResource Include="Data\wil50.dat" /> 146 284 <None Include="Plugin.cs.frame" /> 147 285 <Compile Include="Plugin.cs" /> … … 152 290 <None Include="HeuristicLab.snk" /> 153 291 </ItemGroup> 154 <ItemGroup /> 292 <ItemGroup> 293 <EmbeddedResource Include="Data\bur26a.sln" /> 294 <EmbeddedResource Include="Data\bur26b.sln" /> 295 <EmbeddedResource Include="Data\bur26c.sln" /> 296 <EmbeddedResource Include="Data\bur26d.sln" /> 297 <EmbeddedResource Include="Data\bur26e.sln" /> 298 <EmbeddedResource Include="Data\bur26f.sln" /> 299 <EmbeddedResource Include="Data\bur26g.sln" /> 300 <EmbeddedResource Include="Data\bur26h.sln" /> 301 <EmbeddedResource Include="Data\chr12a.sln" /> 302 <EmbeddedResource Include="Data\chr12b.sln" /> 303 <EmbeddedResource Include="Data\chr12c.sln" /> 304 <EmbeddedResource Include="Data\chr15a.sln" /> 305 <EmbeddedResource Include="Data\chr15b.sln" /> 306 <EmbeddedResource Include="Data\chr15c.sln" /> 307 <EmbeddedResource Include="Data\chr18a.sln" /> 308 <EmbeddedResource Include="Data\chr18b.sln" /> 309 <EmbeddedResource Include="Data\chr20a.sln" /> 310 <EmbeddedResource Include="Data\chr20b.sln" /> 311 <EmbeddedResource Include="Data\chr20c.sln" /> 312 <EmbeddedResource Include="Data\chr22a.sln" /> 313 <EmbeddedResource Include="Data\chr22b.sln" /> 314 <EmbeddedResource Include="Data\chr25a.sln" /> 315 <EmbeddedResource Include="Data\els19.sln" /> 316 <EmbeddedResource Include="Data\esc128.sln" /> 317 <EmbeddedResource Include="Data\esc16a.sln" /> 318 <EmbeddedResource Include="Data\esc16b.sln" /> 319 <EmbeddedResource Include="Data\esc16c.sln" /> 320 <EmbeddedResource Include="Data\esc16d.sln" /> 321 <EmbeddedResource Include="Data\esc16e.sln" /> 322 <EmbeddedResource Include="Data\esc16f.sln" /> 323 <EmbeddedResource Include="Data\esc16g.sln" /> 324 <EmbeddedResource Include="Data\esc16h.sln" /> 325 <EmbeddedResource Include="Data\esc16i.sln" /> 326 <EmbeddedResource Include="Data\esc16j.sln" /> 327 <EmbeddedResource Include="Data\esc32e.sln" /> 328 <EmbeddedResource Include="Data\esc32f.sln" /> 329 <EmbeddedResource Include="Data\esc32g.sln" /> 330 <EmbeddedResource Include="Data\had12.sln" /> 331 <EmbeddedResource Include="Data\had14.sln" /> 332 <EmbeddedResource Include="Data\had16.sln" /> 333 <EmbeddedResource Include="Data\had18.sln" /> 334 <EmbeddedResource Include="Data\had20.sln" /> 335 <EmbeddedResource Include="Data\kra30a.sln" /> 336 <EmbeddedResource Include="Data\kra30b.sln" /> 337 <EmbeddedResource Include="Data\kra32.sln" /> 338 <EmbeddedResource Include="Data\lipa20a.sln" /> 339 <EmbeddedResource Include="Data\lipa20b.sln" /> 340 <EmbeddedResource Include="Data\lipa30a.sln" /> 341 <EmbeddedResource Include="Data\lipa30b.sln" /> 342 <EmbeddedResource Include="Data\lipa40a.sln" /> 343 <EmbeddedResource Include="Data\lipa40b.sln" /> 344 <EmbeddedResource Include="Data\lipa50a.sln" /> 345 <EmbeddedResource Include="Data\lipa50b.sln" /> 346 <EmbeddedResource Include="Data\lipa60a.sln" /> 347 <EmbeddedResource Include="Data\lipa60b.sln" /> 348 <EmbeddedResource Include="Data\lipa70a.sln" /> 349 <EmbeddedResource Include="Data\lipa70b.sln" /> 350 <EmbeddedResource Include="Data\lipa80a.sln" /> 351 <EmbeddedResource Include="Data\lipa80b.sln" /> 352 <EmbeddedResource Include="Data\lipa90a.sln" /> 353 <EmbeddedResource Include="Data\lipa90b.sln" /> 354 <EmbeddedResource Include="Data\nug12.sln" /> 355 <EmbeddedResource Include="Data\nug14.sln" /> 356 <EmbeddedResource Include="Data\nug15.sln" /> 357 <EmbeddedResource Include="Data\nug16a.sln" /> 358 <EmbeddedResource Include="Data\nug16b.sln" /> 359 <EmbeddedResource Include="Data\nug17.sln" /> 360 <EmbeddedResource Include="Data\nug18.sln" /> 361 <EmbeddedResource Include="Data\nug20.sln" /> 362 <EmbeddedResource Include="Data\nug21.sln" /> 363 <EmbeddedResource Include="Data\nug22.sln" /> 364 <EmbeddedResource Include="Data\nug24.sln" /> 365 <EmbeddedResource Include="Data\nug25.sln" /> 366 <EmbeddedResource Include="Data\nug27.sln" /> 367 <EmbeddedResource Include="Data\nug28.sln" /> 368 <EmbeddedResource Include="Data\nug30.sln" /> 369 <EmbeddedResource Include="Data\rou12.sln" /> 370 <EmbeddedResource Include="Data\rou15.sln" /> 371 <EmbeddedResource Include="Data\rou20.sln" /> 372 <EmbeddedResource Include="Data\scr12.sln" /> 373 <EmbeddedResource Include="Data\scr15.sln" /> 374 <EmbeddedResource Include="Data\scr20.sln" /> 375 <EmbeddedResource Include="Data\sko100a.sln" /> 376 <EmbeddedResource Include="Data\sko100b.sln" /> 377 <EmbeddedResource Include="Data\sko100c.sln" /> 378 <EmbeddedResource Include="Data\sko100d.sln" /> 379 <EmbeddedResource Include="Data\sko100e.sln" /> 380 <EmbeddedResource Include="Data\sko100f.sln" /> 381 <EmbeddedResource Include="Data\sko81.sln" /> 382 <EmbeddedResource Include="Data\sko90.sln" /> 383 <EmbeddedResource Include="Data\ste36a.sln" /> 384 <EmbeddedResource Include="Data\ste36b.sln" /> 385 <EmbeddedResource Include="Data\ste36c.sln" /> 386 <EmbeddedResource Include="Data\tai100b.sln" /> 387 <EmbeddedResource Include="Data\tai12a.sln" /> 388 <EmbeddedResource Include="Data\tai12b.sln" /> 389 <EmbeddedResource Include="Data\tai150b.sln" /> 390 <EmbeddedResource Include="Data\tai15a.sln" /> 391 <EmbeddedResource Include="Data\tai15b.sln" /> 392 <EmbeddedResource Include="Data\tai17a.sln" /> 393 <EmbeddedResource Include="Data\tai20a.sln" /> 394 <EmbeddedResource Include="Data\tai20b.sln" /> 395 <EmbeddedResource Include="Data\tai256c.sln" /> 396 <EmbeddedResource Include="Data\tai25b.sln" /> 397 <EmbeddedResource Include="Data\tai30b.sln" /> 398 <EmbeddedResource Include="Data\tai35b.sln" /> 399 <EmbeddedResource Include="Data\tai40b.sln" /> 400 <EmbeddedResource Include="Data\tai50b.sln" /> 401 <EmbeddedResource Include="Data\tai60a.sln" /> 402 <EmbeddedResource Include="Data\tai60b.sln" /> 403 <EmbeddedResource Include="Data\tai64c.sln" /> 404 <EmbeddedResource Include="Data\tai80a.sln" /> 405 <EmbeddedResource Include="Data\tai80b.sln" /> 406 <EmbeddedResource Include="Data\tho150.sln" /> 407 <EmbeddedResource Include="Data\tho30.sln" /> 408 <EmbeddedResource Include="Data\wil100.sln" /> 409 </ItemGroup> 155 410 <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> 156 411 <PropertyGroup> -
branches/QAP/HeuristicLab.Problems.QuadraticAssignment/3.3/Interfaces/IQAPEvaluator.cs
r5558 r5562 27 27 namespace HeuristicLab.Problems.QuadraticAssignment { 28 28 public interface IQAPEvaluator : ISingleObjectiveEvaluator { 29 publicILookupParameter<Permutation> PermutationParameter { get; }30 publicILookupParameter<BoolValue> UseDistanceMatrixParameter { get; }31 publicILookupParameter<DoubleMatrix> DistanceMatrixParameter { get; }32 publicILookupParameter<DoubleMatrix> CoordinatesParameter { get; }33 publicILookupParameter<DoubleMatrix> WeightsParameter { get; }29 ILookupParameter<Permutation> PermutationParameter { get; } 30 ILookupParameter<BoolValue> UseDistanceMatrixParameter { get; } 31 ILookupParameter<DoubleMatrix> DistanceMatrixParameter { get; } 32 ILookupParameter<DoubleMatrix> CoordinatesParameter { get; } 33 ILookupParameter<DoubleMatrix> WeightsParameter { get; } 34 34 } 35 35 } -
branches/QAP/HeuristicLab.Problems.QuadraticAssignment/3.3/Plugin.cs.frame
r5558 r5562 35 35 [PluginDependency("HeuristicLab.Parameters", "3.3.3")] 36 36 [PluginDependency("HeuristicLab.Persistence", "3.3.3")] 37 public class HeuristicLabProblemsQuadraticAssignmentPlugin : PluginBase { 38 } 37 public class HeuristicLabProblemsQuadraticAssignmentPlugin : PluginBase { } 39 38 } -
branches/QAP/HeuristicLab.Problems.QuadraticAssignment/3.3/QuadraticAssignmentProblem.cs
r5558 r5562 21 21 22 22 using System; 23 using System.Collections.Generic;24 23 using System.Drawing; 24 using System.IO; 25 25 using System.Linq; 26 using System.Reflection; 26 27 using HeuristicLab.Common; 27 28 using HeuristicLab.Core; … … 31 32 using HeuristicLab.Parameters; 32 33 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 34 using HeuristicLab.PluginInfrastructure; 33 35 34 36 namespace HeuristicLab.Problems.QuadraticAssignment { … … 42 44 43 45 #region Parameter Properties 44 public ValueParameter<IPermutationCreator> SolutionCreatorParameter {45 get { return (ValueParameter<IPermutationCreator>)Parameters["SolutionCreator"]; }46 }47 IParameter IProblem.SolutionCreatorParameter {48 get { return SolutionCreatorParameter; }49 }50 public ValueParameter<IQAPEvaluator> EvaluatorParameter {51 get { return (ValueParameter<IQAPEvaluator>)Parameters["Evaluator"]; }52 }53 IParameter IProblem.EvaluatorParameter {54 get { return EvaluatorParameter; }55 }56 46 public ValueParameter<Permutation> BestKnownSolutionParameter { 57 47 get { return (ValueParameter<Permutation>)Parameters["BestKnownSolution"]; } … … 73 63 74 64 #region Properties 75 public IPermutationCreator SolutionCreator {76 get { return SolutionCreatorParameter.Value; }77 set { SolutionCreatorParameter.Value = value; }78 }79 ISolutionCreator IProblem.SolutionCreator {80 get { return SolutionCreatorParameter.Value; }81 }82 public IQAPEvaluator Evaluator {83 get { return EvaluatorParameter.Value; }84 set { EvaluatorParameter.Value = value; }85 }86 ISingleObjectiveEvaluator ISingleObjectiveProblem.Evaluator {87 get { return EvaluatorParameter.Value; }88 }89 IEvaluator IProblem.Evaluator {90 get { return EvaluatorParameter.Value; }91 }92 65 public Permutation BestKnownSolution { 93 66 get { return BestKnownSolutionParameter.Value; } 94 67 set { BestKnownSolutionParameter.Value = value; } 95 68 } 96 97 69 public DoubleMatrix Coordinates { 98 70 get { return CoordinatesParameter.Value; } … … 111 83 set { UseDistanceMatrixParameter.Value = value; } 112 84 } 113 114 public IEnumerable<IOperator> Operators { 115 get { return operators; } 116 } 117 #endregion 118 119 [Storable] 120 private List<IOperator> operators; 85 #endregion 121 86 122 87 [StorableConstructor] 123 88 private QuadraticAssignmentProblem(bool deserializing) : base(deserializing) { } 124 pr otectedQuadraticAssignmentProblem(QuadraticAssignmentProblem original, Cloner cloner)89 private QuadraticAssignmentProblem(QuadraticAssignmentProblem original, Cloner cloner) 125 90 : base(original, cloner) { 126 this.operators = original.operators.Select(x => (IOperator)cloner.Clone(x)).ToList();127 91 AttachEventHandlers(); 128 92 } … … 131 95 RandomPermutationCreator solutionCreator = new RandomPermutationCreator(); 132 96 solutionCreator.LengthParameter.Value = new IntValue(5); 133 97 solutionCreator.PermutationParameter.ActualName = "Assignment"; 134 98 QAPEvaluator evaluator = new QAPEvaluator(); 135 99 … … 178 142 179 143 #region Events 180 public event EventHandler SolutionCreatorChanged; 181 private void OnSolutionCreatorChanged() { 182 EventHandler handler = SolutionCreatorChanged; 183 if (handler != null) handler(this, EventArgs.Empty); 184 } 185 public event EventHandler EvaluatorChanged; 186 private void OnEvaluatorChanged() { 187 EventHandler handler = EvaluatorChanged; 188 if (handler != null) handler(this, EventArgs.Empty); 189 } 190 public event EventHandler OperatorsChanged; 191 private void OnOperatorsChanged() { 192 EventHandler handler = OperatorsChanged; 193 if (handler != null) handler(this, EventArgs.Empty); 194 } 195 public event EventHandler Reset; 196 private void OnReset() { 197 EventHandler handler = Reset; 198 if (handler != null) handler(this, EventArgs.Empty); 199 } 200 201 // TODO: Add your event handlers here 144 protected override void OnSolutionCreatorChanged() { 145 SolutionCreator.PermutationParameter.ActualNameChanged += new EventHandler(SolutionCreator_PermutationParameter_ActualNameChanged); 146 ParameterizeSolutionCreator(); 147 ParameterizeEvaluator(); 148 ParameterizeOperators(); 149 base.OnSolutionCreatorChanged(); 150 } 151 protected override void OnEvaluatorChanged() { 152 ParameterizeEvaluator(); 153 ParameterizeOperators(); 154 base.OnEvaluatorChanged(); 155 } 156 157 private void SolutionCreator_PermutationParameter_ActualNameChanged(object sender, EventArgs e) { 158 ParameterizeEvaluator(); 159 ParameterizeOperators(); 160 } 161 private void WeightsParameter_ValueChanged(object sender, EventArgs e) { 162 Weights.RowsChanged += new EventHandler(Weights_RowsChanged); 163 ParameterizeSolutionCreator(); 164 ParameterizeEvaluator(); 165 ParameterizeOperators(); 166 } 167 private void Weights_RowsChanged(object sender, EventArgs e) { 168 ParameterizeSolutionCreator(); 169 ParameterizeEvaluator(); 170 ParameterizeOperators(); 171 } 202 172 #endregion 203 173 … … 209 179 210 180 private void AttachEventHandlers() { 211 // TODO: Add event handlers to the parameters here 181 WeightsParameter.ValueChanged += new EventHandler(WeightsParameter_ValueChanged); 182 Weights.RowsChanged += new EventHandler(Weights_RowsChanged); 183 SolutionCreator.PermutationParameter.ActualNameChanged += new EventHandler(SolutionCreator_PermutationParameter_ActualNameChanged); 212 184 } 213 185 214 186 private void InitializeOperators() { 215 operators = new List<IOperator>(); 216 // TODO: Add custom problem analyzer to the list 217 // TODO: Add operators from the representation either by direct instantiation, or by using ApplicationManager.Manger.GetInstances<T>().Cast<IOperator>() 187 Operators.AddRange(ApplicationManager.Manager.GetInstances<IPermutationOperator>()); 218 188 } 219 189 private void ParameterizeSolutionCreator() { 220 190 SolutionCreator.PermutationTypeParameter.Value = new PermutationType(PermutationTypes.Absolute); 221 if (UseDistanceMatrix.Value) { 222 SolutionCreator.LengthParameter.Value = new IntValue(DistanceMatrix.Rows); 223 } else { 224 SolutionCreator.LengthParameter.Value = new IntValue(Coordinates.Rows); 225 } 191 SolutionCreator.LengthParameter.Value = new IntValue(Weights.Rows); 226 192 } 227 193 private void ParameterizeEvaluator() { … … 232 198 Evaluator.WeightsParameter.ActualName = WeightsParameter.Name; 233 199 } 234 #endregion 200 private void ParameterizeOperators() { 201 foreach (IPermutationCrossover op in Operators.OfType<IPermutationCrossover>()) { 202 op.ParentsParameter.ActualName = SolutionCreator.PermutationParameter.ActualName; 203 op.ChildParameter.ActualName = SolutionCreator.PermutationParameter.ActualName; 204 } 205 foreach (IPermutationManipulator op in Operators.OfType<IPermutationManipulator>()) { 206 op.PermutationParameter.ActualName = SolutionCreator.PermutationParameter.ActualName; 207 } 208 foreach (IPermutationMoveOperator op in Operators.OfType<IPermutationMoveOperator>()) { 209 op.PermutationParameter.ActualName = SolutionCreator.PermutationParameter.ActualName; 210 } 211 string inversionMove = Operators.OfType<IMoveGenerator>().OfType<IPermutationInversionMoveOperator>().First().InversionMoveParameter.ActualName; 212 foreach (IPermutationInversionMoveOperator op in Operators.OfType<IPermutationInversionMoveOperator>()) 213 op.InversionMoveParameter.ActualName = inversionMove; 214 string translocationMove = Operators.OfType<IMoveGenerator>().OfType<IPermutationTranslocationMoveOperator>().First().TranslocationMoveParameter.ActualName; 215 foreach (IPermutationTranslocationMoveOperator op in Operators.OfType<IPermutationTranslocationMoveOperator>()) 216 op.TranslocationMoveParameter.ActualName = translocationMove; 217 } 218 #endregion 219 220 public void ImportFromQAPLib(string filename) { 221 QAPLIBParser parser = new QAPLIBParser(); 222 parser.Parse(filename); 223 DistanceMatrix = new DoubleMatrix(parser.Distances); 224 Weights = new DoubleMatrix(parser.Weights); 225 UseDistanceMatrix.Value = true; 226 Name = "Quadratic Assignment Problem (imported from " + Path.GetFileNameWithoutExtension(filename) + ")"; 227 Description = "Imported problem data using QAPLIBParser " + Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyFileVersionAttribute), true).Cast<AssemblyFileVersionAttribute>().FirstOrDefault().Version + "."; 228 OnReset(); 229 } 235 230 } 236 231 }
Note: See TracChangeset
for help on using the changeset viewer.