Changeset 10855 for branches/SimSharp/HeuristicLab.Problems.Programmable
- Timestamp:
- 05/14/14 15:58:48 (11 years ago)
- Location:
- branches/SimSharp/HeuristicLab.Problems.Programmable/3.3
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/SimSharp/HeuristicLab.Problems.Programmable/3.3/Datastructures/Configuration.cs
r10850 r10855 58 58 59 59 60 public Configuration AddB oolean(string name, int length) {60 public Configuration AddBinary(string name, int length) { 61 61 if (Parameters.ContainsKey(name)) throw new ArgumentException("name must be unique", "name"); 62 62 Parameters.Add(name, new BinaryParameterConfiguration(length)); -
branches/SimSharp/HeuristicLab.Problems.Programmable/3.3/SingleObjectiveProgrammableProblem.cs
r10850 r10855 137 137 138 138 var solutionCreators = new List<ISolutionCreator>(); 139 foreach (var param etersin configuration.Parameters) {140 var binConfig = param eters.Value as BinaryParameterConfiguration;139 foreach (var param in configuration.Parameters) { 140 var binConfig = param.Value as BinaryParameterConfiguration; 141 141 if (binConfig != null) { 142 var p = new ValueParameter<IntValue>(param eters.Key + "Length", binConfig.Length);142 var p = new ValueParameter<IntValue>(param.Key + "Length", binConfig.Length); 143 143 DynamicConfigurationParameters.Add(p); 144 144 145 145 var creator = new RandomBinaryVectorCreator(); 146 creator.BinaryVectorParameter.ActualName = param eters.Key;146 creator.BinaryVectorParameter.ActualName = param.Key; 147 147 creator.LengthParameter.ActualName = p.Name; 148 148 solutionCreators.Add(creator); 149 149 } 150 var intConfig = param eters.Value as IntegerParameterConfiguration;150 var intConfig = param.Value as IntegerParameterConfiguration; 151 151 if (intConfig != null) { 152 var l = new ValueParameter<IntValue>(param eters.Key + "Length", intConfig.Length);153 var b = new ValueParameter<IntMatrix>(param eters.Key + "Bounds", intConfig.Bounds);152 var l = new ValueParameter<IntValue>(param.Key + "Length", intConfig.Length); 153 var b = new ValueParameter<IntMatrix>(param.Key + "Bounds", intConfig.Bounds); 154 154 DynamicConfigurationParameters.Add(l); 155 155 DynamicConfigurationParameters.Add(b); 156 156 157 157 var creator = new UniformRandomIntegerVectorCreator(); 158 creator.IntegerVectorParameter.ActualName = param eters.Key;158 creator.IntegerVectorParameter.ActualName = param.Key; 159 159 creator.LengthParameter.ActualName = l.Name; 160 160 creator.BoundsParameter.ActualName = b.Name; 161 161 solutionCreators.Add(creator); 162 162 } 163 var realConfig = param eters.Value as RealParameterConfiguration;163 var realConfig = param.Value as RealParameterConfiguration; 164 164 if (realConfig != null) { 165 var l = new ValueParameter<IntValue>(param eters.Key + "Length", realConfig.Length);166 var b = new ValueParameter<DoubleMatrix>(param eters.Key + "Bounds", realConfig.Bounds);165 var l = new ValueParameter<IntValue>(param.Key + "Length", realConfig.Length); 166 var b = new ValueParameter<DoubleMatrix>(param.Key + "Bounds", realConfig.Bounds); 167 167 DynamicConfigurationParameters.Add(l); 168 168 DynamicConfigurationParameters.Add(b); 169 169 170 170 var creator = new UniformRandomRealVectorCreator(); 171 creator.RealVectorParameter.ActualName = param eters.Key;171 creator.RealVectorParameter.ActualName = param.Key; 172 172 creator.LengthParameter.ActualName = l.Name; 173 173 creator.BoundsParameter.ActualName = b.Name; 174 174 solutionCreators.Add(creator); 175 175 } 176 var permConfig = param eters.Value as PermutationParameterConfiguration;176 var permConfig = param.Value as PermutationParameterConfiguration; 177 177 if (permConfig != null) { 178 var l = new ValueParameter<IntValue>(param eters.Key + "Length", permConfig.Length);178 var l = new ValueParameter<IntValue>(param.Key + "Length", permConfig.Length); 179 179 DynamicConfigurationParameters.Add(l); 180 180 181 181 var creator = new RandomPermutationCreator(); 182 creator.PermutationParameter.ActualName = param eters.Key;182 creator.PermutationParameter.ActualName = param.Key; 183 183 creator.LengthParameter.ActualName = l.Name; 184 184 creator.PermutationTypeParameter.Value = permConfig.Type; … … 375 375 } 376 376 } 377 378 // crossover and manipulator for multi-vector encoding 379 if (Operators.OfType<ParameterVectorCrossover>().Any()) { 380 foreach (var oldXo in Operators.OfType<ParameterVectorCrossover>()) { 381 // TODO: compare crossovers for old configuration with new configuration 382 } 383 foreach (var oldM in Operators.OfType<ParameterVectorManipulator>()) { 384 // TODO: compare manipulators for old configuration with new configuration 385 } 386 } else { 387 Operators.RemoveAll(x => x is ICrossover); 388 Operators.RemoveAll(x => x is IManipulator); 389 var crossover = new ParameterVectorCrossover(); 390 var manipulator = new ParameterVectorManipulator(); 391 foreach (var param in configuration.Parameters) { 392 var binConfig = param.Value as BinaryParameterConfiguration; 393 if (binConfig != null) { 394 IBinaryVectorCrossover binXo; 395 if (binConfig.Length.Value > 3) binXo = new Encodings.BinaryVectorEncoding.SinglePointCrossover(); 396 else binXo = new Encodings.BinaryVectorEncoding.UniformCrossover(); 397 binXo.ChildParameter.ActualName = param.Key; 398 binXo.ParentsParameter.ActualName = param.Key; 399 var binM = new Encodings.BinaryVectorEncoding.SomePositionsBitflipManipulator(); 400 binM.BinaryVectorParameter.ActualName = param.Key; 401 binM.MutationProbabilityParameter.Value = new DoubleValue(0.1); 402 crossover.BeforeExecutionOperators.Add(binXo); 403 manipulator.BeforeExecutionOperators.Add(binM); 404 continue; 405 } 406 var intConfig = param.Value as IntegerParameterConfiguration; 407 if (intConfig != null) { 408 var intXo = new Encodings.IntegerVectorEncoding.RoundedBlendAlphaBetaCrossover(); 409 intXo.ChildParameter.ActualName = param.Key; 410 intXo.ParentsParameter.ActualName = param.Key; 411 intXo.BoundsParameter.ActualName = param.Key + "Bounds"; 412 intXo.QualityParameter.ActualName = Evaluator.QualityParameter.ActualName; 413 intXo.MaximizationParameter.ActualName = MaximizationParameter.Name; 414 var intM = new Encodings.IntegerVectorEncoding.UniformSomePositionsManipulator(); 415 intM.IntegerVectorParameter.ActualName = param.Key; 416 intM.BoundsParameter.ActualName = param.Key + "Bounds"; 417 intM.ProbabilityParameter.Value = new DoubleValue(0.1); 418 crossover.BeforeExecutionOperators.Add(intXo); 419 manipulator.BeforeExecutionOperators.Add(intM); 420 continue; 421 } 422 var realConfig = param.Value as RealParameterConfiguration; 423 if (realConfig != null) { 424 var realXo = new Encodings.RealVectorEncoding.BlendAlphaBetaCrossover(); 425 realXo.ChildParameter.ActualName = param.Key; 426 realXo.ParentsParameter.ActualName = param.Key; 427 realXo.BoundsParameter.ActualName = param.Key + "Bounds"; 428 realXo.QualityParameter.ActualName = Evaluator.QualityParameter.ActualName; 429 realXo.MaximizationParameter.ActualName = MaximizationParameter.Name; 430 var realM = new Encodings.RealVectorEncoding.BreederGeneticAlgorithmManipulator(); 431 realM.RealVectorParameter.ActualName = param.Key; 432 realM.BoundsParameter.ActualName = param.Key + "Bounds"; 433 crossover.BeforeExecutionOperators.Add(realXo); 434 manipulator.BeforeExecutionOperators.Add(realM); 435 continue; 436 } 437 var permConfig = param.Value as PermutationParameterConfiguration; 438 if (permConfig != null) { 439 var permXo = new Encodings.PermutationEncoding.PartiallyMatchedCrossover(); 440 permXo.ChildParameter.ActualName = param.Key; 441 permXo.ParentsParameter.ActualName = param.Key; 442 var permM = new Encodings.PermutationEncoding.Swap2Manipulator(); 443 permM.PermutationParameter.ActualName = param.Key; 444 crossover.BeforeExecutionOperators.Add(permXo); 445 manipulator.BeforeExecutionOperators.Add(permM); 446 continue; 447 } 448 throw new InvalidOperationException("Unknown type for parameter " + param.Key); 449 } 450 Operators.Add(crossover); 451 Operators.Add(manipulator); 452 } 377 453 } 378 454 }
Note: See TracChangeset
for help on using the changeset viewer.