Changeset 11813
- Timestamp:
- 01/21/15 11:54:43 (10 years ago)
- Location:
- branches/ProgrammableProblem
- Files:
-
- 7 edited
- 3 moved
Legend:
- Unmodified
- Added
- Removed
-
branches/ProgrammableProblem/HeuristicLab.Optimization
- Property svn:mergeinfo changed
/branches/Classification-Extensions/HeuristicLab.Optimization (added) merged: 11687-11689,11718-11720,11761 /trunk/sources/HeuristicLab.Optimization merged: 11762,11790
- Property svn:mergeinfo changed
-
branches/ProgrammableProblem/HeuristicLab.Problems.Programmable.Views/3.3/HeuristicLab.Problems.Programmable.Views-3.3.csproj
r11753 r11813 40 40 </PropertyGroup> 41 41 <ItemGroup> 42 <Reference Include="HeuristicLab.CodeEditor-3. 3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">42 <Reference Include="HeuristicLab.CodeEditor-3.4, Version=3.4.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL"> 43 43 <SpecificVersion>False</SpecificVersion> 44 <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.CodeEditor-3.3.dll</HintPath> 45 <Private>False</Private> 44 <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.CodeEditor-3.4.dll</HintPath> 46 45 </Reference> 47 46 <Reference Include="HeuristicLab.Collections-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL"> -
branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/HeuristicLab.Problems.Programmable-3.3.csproj
r11768 r11813 148 148 <Compile Include="Interfaces\IEncodingOperator.cs" /> 149 149 <Compile Include="Interfaces\ISingleObjectiveMoveOperator.cs" /> 150 <Compile Include="New\ ProgrammableProblem.cs" />151 <Compile Include="New\MultiObjective ProgrammableProblem.cs" />150 <Compile Include="New\BasicProblem.cs" /> 151 <Compile Include="New\MultiObjectiveBasicProblem.cs" /> 152 152 <Compile Include="New\MultiObjectiveScriptableProblem.cs" /> 153 153 <Compile Include="New\Scripts\Templates\CompiledMultiObjectiveProblemDefinition.cs" /> … … 175 175 <Compile Include="New\Scripts\ProblemDefinitionScript.cs" /> 176 176 <Compile Include="New\OneMaxNew.cs" /> 177 <Compile Include="New\SingleObjective ProgrammableProblem.cs" />177 <Compile Include="New\SingleObjectiveBasicProblem.cs" /> 178 178 <Compile Include="New\SingleObjectiveScriptableProblem.cs" /> 179 179 <Compile Include="New\Scripts\MultiObjectiveProblemDefinitionScript.cs" /> -
branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/Individuals/Individual.cs
r11737 r11813 40 40 41 41 public abstract IItem this[string name] { get; set; } 42 public abstract TEncoding GetEncoding<TEncoding>() where TEncoding : class, IEncoding; 42 43 43 44 public Individual Copy() { … … 62 63 #region extension methods 63 64 public static class IndividualExtensionMethods { 65 public static BinaryVector BinaryVector(this Individual individual) { 66 var encoding = individual.GetEncoding<BinaryEncoding>(); 67 return individual.BinaryVector(encoding.Name); 68 } 64 69 public static BinaryVector BinaryVector(this Individual individual, string name) { 65 70 return (BinaryVector)individual[name]; 71 } 72 73 public static IntegerVector IntegerVector(this Individual individual) { 74 var encoding = individual.GetEncoding<IntegerEncoding>(); 75 return individual.IntegerVector(encoding.Name); 66 76 } 67 77 public static IntegerVector IntegerVector(this Individual individual, string name) { 68 78 return (IntegerVector)individual[name]; 69 79 } 80 81 public static Permutation Permutation(this Individual individual) { 82 var encoding = individual.GetEncoding<PermutationEncoding>(); 83 return individual.Permutation(encoding.Name); 84 } 70 85 public static Permutation Permutation(this Individual individual, string name) { 71 86 return (Permutation)individual[name]; 87 } 88 89 public static RealVector RealVector(this Individual individual) { 90 var encoding = individual.GetEncoding<RealEncoding>(); 91 return individual.RealVector(encoding.Name); 72 92 } 73 93 public static RealVector RealVector(this Individual individual, string name) { -
branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/Individuals/MultiEncodingIndividual.cs
r11737 r11813 23 23 using System.Collections.Generic; 24 24 using System.Linq; 25 using HeuristicLab.Common; 25 26 using HeuristicLab.Core; 26 27 … … 46 47 public override IItem this[string name] { 47 48 get { 48 var individual = individuals. FirstOrDefault(i => i.Name == name);49 var individual = individuals.SingleOrDefault(i => i.Name == name); 49 50 if (individual == null) throw new ArgumentException(string.Format("{0} is not part of the specified encoding.", name)); 50 51 return individual[name]; 51 52 } 52 53 set { 53 var individual = individuals. FirstOrDefault(i => i.Name == name);54 var individual = individuals.SingleOrDefault(i => i.Name == name); 54 55 if (individual == null) throw new ArgumentException(string.Format("{0} is not part of the specified encoding.", name)); 55 56 individual[name] = value; 56 57 } 58 } 59 60 public override TEncoding GetEncoding<TEncoding>() { 61 TEncoding encoding; 62 try { 63 encoding = (TEncoding)Encoding.Encodings.SingleOrDefault(e => e is TEncoding); 64 } 65 catch (InvalidOperationException) { 66 throw new InvalidOperationException(string.Format("The individual uses multiple {0} .", typeof(TEncoding).GetPrettyName())); 67 } 68 if (encoding == null) throw new InvalidOperationException(string.Format("The individual does not use a {0}.", typeof(TEncoding).GetPrettyName())); 69 return encoding; 57 70 } 58 71 -
branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/Individuals/SingleEncodingIndividual.cs
r11619 r11813 21 21 22 22 using System; 23 using HeuristicLab.Common; 23 24 using HeuristicLab.Core; 24 25 … … 42 43 } 43 44 45 public override TEncoding GetEncoding<TEncoding>() { 46 TEncoding encoding = Encoding as TEncoding; 47 if (encoding == null) throw new InvalidOperationException(string.Format("The individual does not use a {0}.", typeof(TEncoding).GetPrettyName())); 48 return encoding; 49 } 50 44 51 internal override Individual Copy(IScope scope) { 45 52 SetScopeValue(Name, scope, (IItem)this[Name].Clone()); -
branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/New/BasicProblem.cs
r11798 r11813 103 103 Parameters.Add(solutionCreatorParam); 104 104 105 //TODO register solution creator changed event 105 //TODO register solution creator changed event, change access modifier to private 106 //((IValueParameter)solutionCreatorParam).ValueChanged += SolutionCreatorParameter_ValueChanged; 106 107 107 108 OnOperatorsChanged(); … … 132 133 133 134 var comparer = new TypeEqualityComparer<IOperator>(); 135 var cloner = new Cloner(); 134 136 var oldOperators = oldEncoding.Operators; 135 137 var newOperators = newEncoding.Operators; 136 138 137 var operators = oldOperators.Intersect(newOperators, comparer); 138 //TODO clone overlapping operators139 140 var operators = oldOperators.Intersect(newOperators, comparer).Select(op => cloner.Clone(op)); 139 141 operators = operators.Union(newOperators, comparer); 140 142 -
branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/New/OneMaxNew.cs
r11797 r11813 21 21 22 22 using System.Linq; 23 using HeuristicLab.Analysis; 23 24 using HeuristicLab.Common; 24 25 using HeuristicLab.Core; 26 using HeuristicLab.Encodings.BinaryVectorEncoding; 27 using HeuristicLab.Optimization; 25 28 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 26 29 … … 37 40 : base() { 38 41 Encoding = new BinaryEncoding("BinaryVector", 10); 42 var bestScopeSolutionAnalyzer = Operators.OfType<BestScopeSolutionAnalyzer>().FirstOrDefault(); 43 if (bestScopeSolutionAnalyzer != null) Operators.Remove(bestScopeSolutionAnalyzer); 39 44 } 40 45 … … 47 52 } 48 53 public override double Evaluate(Individual individual, IRandom random) { 49 return individual.BinaryVector( "BinaryVector").Count(b => b);54 return individual.BinaryVector().Count(b => b); 50 55 } 51 56 52 57 public override void Analyze(Individual[] individuals, double[] qualities, ResultCollection results) { 58 base.Analyze(individuals, qualities, results); 59 var best = individuals.Zip(qualities, (i, q) => new { Individual = i, Quality = q }).OrderByDescending(z => z.Quality).First(); 60 if (!results.ContainsKey("Best Solution")) { 61 results.Add(new Result("Best Solution", typeof(BinaryVector))); 62 } 63 results["Best Solution"].Value = best.Individual.BinaryVector(); 64 } 53 65 } 54 66 }
Note: See TracChangeset
for help on using the changeset viewer.