- Timestamp:
- 09/15/14 10:23:34 (10 years ago)
- Location:
- branches/SimSharp/HeuristicLab.Problems.Programmable/3.3
- Files:
-
- 4 added
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/SimSharp/HeuristicLab.Problems.Programmable/3.3/Datastructures/IntegerParameterConfiguration.cs
r10856 r11363 74 74 if (min.Count != max.Count) throw new ArgumentException("min must be of the same length as max", "min"); 75 75 if (step != null && min.Count != step.Count) throw new ArgumentException("step must be of the same length as min or null", "step"); 76 if (min.Zip(max, (mi, ma) => mi >= ma).Any( )) throw new ArgumentException("min must be less than max in each dimension", "min");76 if (min.Zip(max, (mi, ma) => mi >= ma).Any(x => x)) throw new ArgumentException("min must be less than max in each dimension", "min"); 77 77 this.length = new IntValue(length); 78 78 bounds = new IntMatrix(min.Count, step != null ? 3 : 2); -
branches/SimSharp/HeuristicLab.Problems.Programmable/3.3/Datastructures/ParameterVector.cs
r10850 r11363 22 22 using System.Collections.Generic; 23 23 using System.Linq; 24 using HeuristicLab.Common; 24 25 using HeuristicLab.Encodings.BinaryVectorEncoding; 25 26 using HeuristicLab.Encodings.IntegerVectorEncoding; … … 28 29 29 30 namespace HeuristicLab.Problems.Programmable { 30 public class ParameterVector{31 pr otectedDictionary<string, BinaryVector> BinaryParameters;32 pr otectedDictionary<string, IntegerVector> IntegerParameters;33 pr otectedDictionary<string, RealVector> RealParameters;34 pr otectedDictionary<string, Permutation> PermutationParameters;31 public sealed class ParameterVector : IDeepCloneable { 32 private Dictionary<string, BinaryVector> BinaryParameters; 33 private Dictionary<string, IntegerVector> IntegerParameters; 34 private Dictionary<string, RealVector> RealParameters; 35 private Dictionary<string, Permutation> PermutationParameters; 35 36 36 37 public ParameterVector(IEnumerable<KeyValuePair<string, BinaryVector>> binaryVectors = null, … … 42 43 if (realVectors != null) RealParameters = realVectors.ToDictionary(x => x.Key, x => x.Value); 43 44 if (permutations != null) PermutationParameters = permutations.ToDictionary(x => x.Key, x => x.Value); 45 } 46 private ParameterVector(ParameterVector original, Cloner cloner) { 47 cloner.RegisterClonedObject(original, this); 48 if (original.BinaryParameters != null) { 49 BinaryParameters = new Dictionary<string, BinaryVector>(original.BinaryParameters.Comparer); 50 foreach (var param in original.BinaryParameters) 51 BinaryParameters[param.Key] = cloner.Clone(param.Value); 52 } 53 if (original.IntegerParameters != null) { 54 IntegerParameters = new Dictionary<string, IntegerVector>(original.IntegerParameters.Comparer); 55 foreach (var param in original.IntegerParameters) 56 IntegerParameters[param.Key] = cloner.Clone(param.Value); 57 } 58 if (original.RealParameters != null) { 59 RealParameters = new Dictionary<string, RealVector>(original.RealParameters.Comparer); 60 foreach (var param in original.RealParameters) 61 RealParameters[param.Key] = cloner.Clone(param.Value); 62 } 63 if (original.PermutationParameters != null) { 64 PermutationParameters = new Dictionary<string, Permutation>(original.PermutationParameters.Comparer); 65 foreach (var param in original.PermutationParameters) 66 PermutationParameters[param.Key] = cloner.Clone(param.Value); 67 } 68 } 69 70 public object Clone() { 71 return Clone(new Cloner()); 72 } 73 74 public IDeepCloneable Clone(Cloner cloner) { 75 return new ParameterVector(this, cloner); 44 76 } 45 77 … … 53 85 54 86 public IEnumerable<string> BinaryNames { 55 get { return BinaryParameters .Keys; }87 get { return BinaryParameters != null ? BinaryParameters.Keys : Enumerable.Empty<string>(); } 56 88 } 57 89 … … 65 97 66 98 public IEnumerable<string> IntegerNames { 67 get { return IntegerParameters .Keys; }99 get { return IntegerParameters != null ? IntegerParameters.Keys : Enumerable.Empty<string>(); } 68 100 } 69 101 … … 77 109 78 110 public IEnumerable<string> RealNames { 79 get { return RealParameters .Keys; }111 get { return RealParameters != null ? RealParameters.Keys : Enumerable.Empty<string>(); } 80 112 } 81 113 … … 85 117 86 118 public IEnumerable<string> PermutationNames { 87 get { return PermutationParameters .Keys; }119 get { return PermutationParameters != null ? PermutationParameters.Keys : Enumerable.Empty<string>(); } 88 120 } 89 121 } -
branches/SimSharp/HeuristicLab.Problems.Programmable/3.3/Datastructures/RealParameterConfiguration.cs
r10856 r11363 71 71 if (min.Count == 0) throw new ArgumentException("Bounds must be given for the real parameters."); 72 72 if (min.Count != max.Count) throw new ArgumentException("min must be of the same length as max", "min"); 73 if (min.Zip(max, (mi, ma) => mi >= ma).Any( )) throw new ArgumentException("min must be less than max in each dimension", "min");73 if (min.Zip(max, (mi, ma) => mi >= ma).Any(x => x)) throw new ArgumentException("min must be less than max in each dimension", "min"); 74 74 this.length = new IntValue(length); 75 75 bounds = new DoubleMatrix(min.Count, 2); -
branches/SimSharp/HeuristicLab.Problems.Programmable/3.3/HeuristicLab.Problems.Programmable-3.3.csproj
r10856 r11363 121 121 <Private>False</Private> 122 122 </Reference> 123 <Reference Include="SimSharp, Version=3.0.3.0, Culture=neutral, PublicKeyToken=4222a9c6c8b27052, processorArchitecture=MSIL">124 <SpecificVersion>False</SpecificVersion>125 <HintPath>..\..\..\..\trunk\sources\bin\SimSharp.dll</HintPath>126 <Private>False</Private>127 </Reference>128 123 <Reference Include="System" /> 129 124 <Reference Include="System.Core" /> … … 143 138 <Compile Include="Datastructures\ParameterConfiguration.cs" /> 144 139 <Compile Include="Datastructures\ParameterVector.cs" /> 140 <Compile Include="Interfaces\IParameterVectorMoveOperator.cs" /> 145 141 <Compile Include="Interfaces\ISingleObjectiveProgrammableProblemEvaluator.cs" /> 146 142 <Compile Include="Operators\ParameterVectorManipulator.cs" /> 147 143 <Compile Include="Operators\ParameterVectorCrossover.cs" /> 144 <Compile Include="Operators\ParameterVectorMoveEvaluator.cs" /> 145 <Compile Include="Operators\ParameterVectorMoveGenerator.cs" /> 146 <Compile Include="Operators\ParameterVectorMoveMaker.cs" /> 148 147 <Compile Include="Operators\SingleObjectiveEvaluator.cs" /> 149 148 <Compile Include="Operators\ParameterVectorCreater.cs" /> -
branches/SimSharp/HeuristicLab.Problems.Programmable/3.3/Interfaces/ISingleObjectiveProblemDefinition.cs
r10856 r11363 20 20 #endregion 21 21 22 using System.Collections.Generic; 22 23 using HeuristicLab.Core; 23 24 … … 26 27 bool IsMaximizationProblem { get; } 27 28 double Evaluate(IRandom random, ParameterVector vector); 29 IEnumerable<ParameterVector> GetNeighbors(IRandom random, ParameterVector vector); 28 30 } 29 31 } -
branches/SimSharp/HeuristicLab.Problems.Programmable/3.3/SingleObjectiveProgrammableProblem.cs
r10856 r11363 138 138 UpdateMultiVectorEncodingOperators(solutionCreators, configuration); 139 139 } 140 UpdateMoveOperators(); 140 141 } 141 142 … … 597 598 } 598 599 600 protected virtual void UpdateMoveOperators() { 601 Operators.RemoveAll(x => x is IParameterVectorMoveOperator); 602 var generator = new ParameterVectorMoveGenerator(); 603 generator.ConfigurationParameter.ActualName = ConfigurationParameter.Name; 604 generator.ScriptParameter.ActualName = ScriptParameter.Name; 605 606 var evaluator = new ParameterVectorMoveEvaluator(); 607 evaluator.ConfigurationParameter.ActualName = ConfigurationParameter.Name; 608 evaluator.QualityParameter.ActualName = Evaluator.QualityParameter.ActualName; 609 evaluator.ScriptParameter.ActualName = ScriptParameter.Name; 610 611 var maker = new ParameterVectorMoveMaker(); 612 maker.ConfigurationParameter.ActualName = ConfigurationParameter.Name; 613 maker.MoveQualityParameter.ActualName = evaluator.MoveQualityParameter.ActualName; 614 maker.QualityParameter.ActualName = Evaluator.QualityParameter.ActualName; 615 616 Operators.AddRange(new IItem[] { generator, evaluator, maker }); 617 } 618 599 619 // ReSharper disable RedundantNameQualifier 600 620 protected virtual IBinaryVectorCrossover GetDefaultBinaryCrossover(string paramName, Configuration config) { -
branches/SimSharp/HeuristicLab.Problems.Programmable/3.3/SingleObjectiveScript.cs
r10856 r11363 34 34 protected SingleObjectiveScript(SingleObjectiveScript original, Cloner cloner) 35 35 : base(original, cloner) { } 36 public SingleObjectiveScript() { } 36 37 public SingleObjectiveScript() { 38 Code = CodeTemplate; 39 } 37 40 38 41 public override IDeepCloneable Clone(Cloner cloner) { … … 78 81 } 79 82 83 public IEnumerable<ParameterVector> GetNeighbors(IRandom random, ParameterVector vector) { 84 // Create new vectors, based on the given one that represent small changes 85 // This method is only called from move-based algorithms (LocalSearch, SimulatedAnnealing, etc.) 86 while (true) { 87 var neighbor = (ParameterVector)vector.Clone(); 88 //e.g. make a bit flip in a binary parameter 89 //var bIndex = random.Next(neighbor.Binary(""b"").Length); 90 //neighbor.Binary(""b"")[bIndex] = !neighbor.Binary(""b"")[bIndex]; 91 yield return neighbor; 92 } 93 } 94 80 95 // implement further classes and methods 81 96 }";
Note: See TracChangeset
for help on using the changeset viewer.