- Timestamp:
- 07/15/17 14:25:44 (7 years ago)
- Location:
- branches/PerformanceComparison/HeuristicLab.Optimization
- Files:
-
- 2 deleted
- 10 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/PerformanceComparison/HeuristicLab.Optimization
- Property svn:mergeinfo changed
-
branches/PerformanceComparison/HeuristicLab.Optimization/3.3/BasicProblems/Individuals/Individual.cs
r14600 r15256 21 21 22 22 using System; 23 using System.Collections.Generic; 24 using System.Linq; 23 25 using HeuristicLab.Core; 24 26 … … 27 29 protected IEncoding Encoding { get; private set; } 28 30 protected IScope Scope { get; private set; } 29 30 31 public string Name { get { return Encoding.Name; } } 31 32 … … 35 36 } 36 37 37 public abstract IItem this[string name] { get; set; } 38 public IItem this[string name] { 39 get { return ExtractScopeValue(name, Scope); } 40 set { SetScopeValue(name, Scope, value); } 41 } 42 43 public IEnumerable<KeyValuePair<string, IItem>> Values { 44 get { return Scope.Variables.Select(v => new KeyValuePair<string, IItem>(v.Name, v.Value)); } 45 } 38 46 public abstract TEncoding GetEncoding<TEncoding>() where TEncoding : class, IEncoding; 39 47 40 public Individual Copy() { 41 return CopyToScope(new Scope()); 48 public abstract Individual Copy(); 49 internal void CopyToScope(IScope scope) { 50 foreach (var val in Values) 51 SetScopeValue(val.Key, scope, val.Value); 42 52 } 43 53 44 public abstract Individual CopyToScope(IScope scope); 45 46 protected static IItem ExtractScopeValue(string name, IScope scope) { 54 private static IItem ExtractScopeValue(string name, IScope scope) { 55 if (scope == null) throw new ArgumentNullException("scope"); 47 56 if (!scope.Variables.ContainsKey(name)) throw new ArgumentException(string.Format(" {0} cannot be found in the provided scope.", name)); 48 57 var value = scope.Variables[name].Value; … … 51 60 } 52 61 53 protected static void SetScopeValue(string name, IScope scope, IItem value) { 62 private static void SetScopeValue(string name, IScope scope, IItem value) { 63 if (scope == null) throw new ArgumentNullException("scope"); 54 64 if (value == null) throw new ArgumentNullException("value"); 65 55 66 if (!scope.Variables.ContainsKey(name)) scope.Variables.Add(new Variable(name, value)); 56 67 else scope.Variables[name].Value = value; -
branches/PerformanceComparison/HeuristicLab.Optimization/3.3/BasicProblems/Individuals/MultiEncodingIndividual.cs
r14600 r15256 32 32 } 33 33 34 private readonly IEnumerable<Individual> individuals; 34 public MultiEncodingIndividual(MultiEncoding encoding, IScope scope) 35 : base(encoding, scope) { } 35 36 36 public MultiEncodingIndividual(MultiEncoding encoding, IScope scope) 37 : base(encoding, scope) { 38 individuals = encoding.Encodings.Select(e => e.GetIndividual(scope)).ToArray(); 37 private MultiEncodingIndividual(MultiEncodingIndividual copy) : base(copy.Encoding, new Scope()) { 38 copy.CopyToScope(Scope); 39 39 } 40 41 private MultiEncodingIndividual(MultiEncoding encoding, IScope scope, IEnumerable<Individual> individuals) 42 : base(encoding, scope) { 43 this.individuals = individuals; 44 } 45 46 47 public override IItem this[string name] { 48 get { 49 var individual = individuals.SingleOrDefault(i => i.Name == name); 50 if (individual == null) throw new ArgumentException(string.Format("{0} is not part of the specified encoding.", name)); 51 return individual[name]; 52 } 53 set { 54 var individual = individuals.SingleOrDefault(i => i.Name == name); 55 if (individual == null) throw new ArgumentException(string.Format("{0} is not part of the specified encoding.", name)); 56 individual[name] = value; 57 } 40 public override Individual Copy() { 41 return new MultiEncodingIndividual(this); 58 42 } 59 43 … … 62 46 try { 63 47 encoding = (TEncoding)Encoding.Encodings.SingleOrDefault(e => e is TEncoding); 64 } catch (InvalidOperationException) { 48 } 49 catch (InvalidOperationException) { 65 50 throw new InvalidOperationException(string.Format("The individual uses multiple {0} .", typeof(TEncoding).GetPrettyName())); 66 51 } … … 68 53 return encoding; 69 54 } 70 71 public override Individual CopyToScope(IScope scope) {72 var copies = individuals.Select(i => i.CopyToScope(scope)).ToArray();73 return new MultiEncodingIndividual(Encoding, scope, copies);74 }75 55 } 76 56 } -
branches/PerformanceComparison/HeuristicLab.Optimization/3.3/BasicProblems/Individuals/SingleEncodingIndividual.cs
r14600 r15256 32 32 } 33 33 34 public override IItem this[string name] { 35 get { 36 if (Name != name) throw new ArgumentException(string.Format("{0} is not part of the individual.", name)); 37 return ExtractScopeValue(Name, Scope); 38 } 39 set { 40 if (Name != name) throw new ArgumentException(string.Format("{0} is not part of the individual.", name)); 41 SetScopeValue(Name, Scope, value); 42 } 34 private SingleEncodingIndividual(SingleEncodingIndividual copy) : base(copy.Encoding, new Scope()) { 35 copy.CopyToScope(Scope); 36 } 37 public override Individual Copy() { 38 return new SingleEncodingIndividual(this); 43 39 } 44 40 … … 48 44 return encoding; 49 45 } 50 51 public override Individual CopyToScope(IScope scope) {52 SetScopeValue(Name, scope, (IItem)this[Name].Clone());53 return new SingleEncodingIndividual(Encoding, scope);54 }55 46 } 56 47 -
branches/PerformanceComparison/HeuristicLab.Optimization/3.3/BasicProblems/MultiObjectiveBasicProblem.cs
r14600 r15256 20 20 #endregion 21 21 22 using System; 23 using System.Collections.Generic; 22 24 using System.Linq; 23 25 using HeuristicLab.Common; … … 57 59 public abstract double[] Evaluate(Individual individual, IRandom random); 58 60 public virtual void Analyze(Individual[] individuals, double[][] qualities, ResultCollection results, IRandom random) { } 59 61 60 62 protected override void OnOperatorsChanged() { 61 63 base.OnOperatorsChanged(); … … 74 76 if (encoding != null && encoding.Operators.Any(x => x is ISingleObjectiveOperator && !(x is IMultiObjectiveOperator))) 75 77 encoding.Operators = encoding.Operators.Where(x => !(x is ISingleObjectiveOperator) || x is IMultiObjectiveOperator).ToList(); 78 79 foreach (var multiOp in Encoding.Operators.OfType<IMultiOperator>()) { 80 foreach (var soOp in multiOp.Operators.Where(x => x is ISingleObjectiveOperator).ToList()) { 81 multiOp.RemoveOperator(soOp); 82 } 83 } 76 84 } 77 85 -
branches/PerformanceComparison/HeuristicLab.Optimization/3.3/BasicProblems/SingleObjectiveBasicProblem.cs
r14600 r15256 20 20 #endregion 21 21 22 using System; 22 23 using System.Collections.Generic; 23 24 using System.Linq; … … 84 85 } 85 86 87 protected Tuple<Individual, double> GetBestIndividual(Individual[] individuals, double[] qualities) { 88 return GetBestIndividual(individuals, qualities, Maximization); 89 } 90 public static Tuple<Individual, double> GetBestIndividual(Individual[] individuals, double[] qualities, bool maximization) { 91 var zipped = individuals.Zip(qualities, (i, q) => new { Individual = i, Quality = q }); 92 var best = (maximization ? zipped.OrderByDescending(z => z.Quality) : zipped.OrderBy(z => z.Quality)).First(); 93 return Tuple.Create(best.Individual, best.Quality); 94 } 95 86 96 protected override void OnOperatorsChanged() { 87 97 base.OnOperatorsChanged(); … … 100 110 if (encoding.Operators.Any(x => x is IMultiObjectiveOperator && !(x is ISingleObjectiveOperator))) 101 111 encoding.Operators = encoding.Operators.Where(x => !(x is IMultiObjectiveOperator) || x is ISingleObjectiveOperator).ToList(); 112 113 foreach (var multiOp in Encoding.Operators.OfType<IMultiOperator>()) { 114 foreach (var moOp in multiOp.Operators.Where(x => x is IMultiObjectiveOperator).ToList()) { 115 multiOp.RemoveOperator(moOp); 116 } 117 } 102 118 } 103 119 -
branches/PerformanceComparison/HeuristicLab.Optimization/3.3/HeuristicLab.Optimization-3.3.csproj
r14776 r15256 201 201 <Compile Include="Interfaces\ILocalImprovementAlgorithmOperator.cs" /> 202 202 <Compile Include="Interfaces\IMultiObjectiveOperator.cs" /> 203 <Compile Include="MultiObjective\DominationCalculator.cs" /> 203 204 <Compile Include="Interfaces\IPreexistingSolutionCreator.cs" /> 204 205 <Compile Include="Interfaces\ISolutionModel.cs" /> … … 240 241 <Compile Include="Interfaces\IDiscreteDoubleMatrixModifier.cs" /> 241 242 <Compile Include="Algorithms\HeuristicOptimizationEngineAlgorithm.cs" /> 242 <Compile Include="Interfaces\IGlobalParticleUpdater.cs" />243 243 <Compile Include="Interfaces\ILocalImprovementOperator.cs" /> 244 <Compile Include="Interfaces\ILocalParticleUpdater.cs" />245 244 <Compile Include="Algorithms\HeuristicOptimizationAlgorithm.cs" /> 246 245 <Compile Include="Interfaces\IMultiNeighborhoodShakingOperator.cs" /> -
branches/PerformanceComparison/HeuristicLab.Optimization/3.3/Interfaces/IParticleCreator.cs
r14600 r15256 27 27 /// </summary> 28 28 public interface IParticleCreator : ISolutionCreator { 29 ILookupParameter<ISolutionCreator> SolutionCreatorParameter { get; } 29 30 } 30 31 } -
branches/PerformanceComparison/HeuristicLab.Optimization/3.3/Problems/SingleObjectiveHeuristicOptimizationProblem.cs
- Property svn:mergeinfo changed
-
branches/PerformanceComparison/HeuristicLab.Optimization/3.3/Results/ResultCollection.cs
r12764 r15256 75 75 } 76 76 77 public void AddOrUpdateResult(string name, IItem value) { 78 IResult res; 79 if (!TryGetValue(name, out res)) { 80 res = new Result(name, value); 81 Add(res); 82 } else res.Value = value; 83 } 77 84 } 78 85 }
Note: See TracChangeset
for help on using the changeset viewer.