- Timestamp:
- 04/19/10 21:13:35 (15 years ago)
- Location:
- trunk/sources
- Files:
-
- 3 added
- 1 deleted
- 15 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Common.Resources/3.2/HeuristicLabCommonResourcesPlugin.cs.frame
r2790 r3418 25 25 using HeuristicLab.PluginInfrastructure; 26 26 27 namespace HeuristicLab.Comm unication.Data{27 namespace HeuristicLab.Common.Resources { 28 28 [Plugin("HeuristicLab.Common.Resources", "3.2.0.$WCREV$")] 29 29 [PluginFile("HeuristicLab.Common.Resources-3.2.dll", PluginFileType.Assembly)] -
trunk/sources/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/HeuristicLab.Encodings.BinaryVectorEncoding-3.3.csproj
r3384 r3418 135 135 <Name>HeuristicLab.Operators-3.3</Name> 136 136 </ProjectReference> 137 <ProjectReference Include="..\..\HeuristicLab.Optimization.Operators\3.3\HeuristicLab.Optimization.Operators-3.3.csproj"> 138 <Project>{25087811-F74C-4128-BC86-8324271DA13E}</Project> 139 <Name>HeuristicLab.Optimization.Operators-3.3</Name> 140 </ProjectReference> 137 141 <ProjectReference Include="..\..\HeuristicLab.Optimization\3.3\HeuristicLab.Optimization-3.3.csproj"> 138 142 <Project>{14AB8D24-25BC-400C-A846-4627AA945192}</Project> -
trunk/sources/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/HeuristicLabEncodingsBinaryVectorEncodingPlugin.cs.frame
r3384 r3418 34 34 [PluginDependency("HeuristicLab.Operators", "3.3")] 35 35 [PluginDependency("HeuristicLab.Optimization", "3.3")] 36 [PluginDependency("HeuristicLab.Optimization.Operators", "3.3")] 36 37 [PluginDependency("HeuristicLab.Parameters", "3.3")] 37 38 [PluginDependency("HeuristicLab.Persistence", "3.3")] -
trunk/sources/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/Moves/OneBitflipMove/OneBitflipMoveTabuMaker.cs
r3376 r3418 26 26 using HeuristicLab.Operators; 27 27 using HeuristicLab.Optimization; 28 using HeuristicLab.Optimization.Operators; 28 29 using HeuristicLab.Parameters; 29 30 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; -
trunk/sources/HeuristicLab.Encodings.PermutationEncoding/3.3/HeuristicLab.Encodings.PermutationEncoding-3.3.csproj
r3384 r3418 91 91 <Compile Include="Crossovers\OrderCrossover2.cs" /> 92 92 <Compile Include="Crossovers\PartiallyMatchedCrossover.cs" /> 93 <Compile Include="Crossovers\PermutationMultiCrossover.cs" /> 93 94 <Compile Include="Crossovers\PositionBasedCrossover.cs" /> 94 95 <Compile Include="HeuristicLabEncodingsPermutationEncodingPlugin.cs" /> … … 169 170 <Name>HeuristicLab.Operators-3.3</Name> 170 171 </ProjectReference> 172 <ProjectReference Include="..\..\HeuristicLab.Optimization.Operators\3.3\HeuristicLab.Optimization.Operators-3.3.csproj"> 173 <Project>{25087811-F74C-4128-BC86-8324271DA13E}</Project> 174 <Name>HeuristicLab.Optimization.Operators-3.3</Name> 175 </ProjectReference> 171 176 <ProjectReference Include="..\..\HeuristicLab.Optimization\3.3\HeuristicLab.Optimization-3.3.csproj"> 172 177 <Project>{14AB8D24-25BC-400C-A846-4627AA945192}</Project> -
trunk/sources/HeuristicLab.Encodings.PermutationEncoding/3.3/HeuristicLabEncodingsPermutationEncodingPlugin.cs.frame
r3384 r3418 34 34 [PluginDependency("HeuristicLab.Operators", "3.3")] 35 35 [PluginDependency("HeuristicLab.Optimization", "3.3")] 36 [PluginDependency("HeuristicLab.Optimization.Operators", "3.3")] 36 37 [PluginDependency("HeuristicLab.Parameters", "3.3")] 37 38 [PluginDependency("HeuristicLab.Persistence", "3.3")] -
trunk/sources/HeuristicLab.Encodings.PermutationEncoding/3.3/Moves/ThreeOpt/TranslocationMoveTabuMaker.cs
r3376 r3418 26 26 using HeuristicLab.Operators; 27 27 using HeuristicLab.Optimization; 28 using HeuristicLab.Optimization.Operators; 28 29 using HeuristicLab.Parameters; 29 30 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; -
trunk/sources/HeuristicLab.Encodings.PermutationEncoding/3.3/Moves/TwoOpt/InversionMoveTabuMaker.cs
r3376 r3418 26 26 using HeuristicLab.Operators; 27 27 using HeuristicLab.Optimization; 28 using HeuristicLab.Optimization.Operators; 28 29 using HeuristicLab.Parameters; 29 30 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; -
trunk/sources/HeuristicLab.Encodings.RealVectorEncoding/3.3/HeuristicLab.Encodings.RealVectorEncoding-3.3.csproj
r3384 r3418 157 157 <Name>HeuristicLab.Operators-3.3</Name> 158 158 </ProjectReference> 159 <ProjectReference Include="..\..\HeuristicLab.Optimization.Operators\3.3\HeuristicLab.Optimization.Operators-3.3.csproj"> 160 <Project>{25087811-F74C-4128-BC86-8324271DA13E}</Project> 161 <Name>HeuristicLab.Optimization.Operators-3.3</Name> 162 </ProjectReference> 159 163 <ProjectReference Include="..\..\HeuristicLab.Optimization\3.3\HeuristicLab.Optimization-3.3.csproj"> 160 164 <Project>{14AB8D24-25BC-400C-A846-4627AA945192}</Project> -
trunk/sources/HeuristicLab.Encodings.RealVectorEncoding/3.3/HeuristicLabEncodingsRealVectorEncodingPlugin.cs.frame
r3384 r3418 34 34 [PluginDependency("HeuristicLab.Operators", "3.3")] 35 35 [PluginDependency("HeuristicLab.Optimization", "3.3")] 36 [PluginDependency("HeuristicLab.Optimization.Operators", "3.3")] 36 37 [PluginDependency("HeuristicLab.Parameters", "3.3")] 37 38 [PluginDependency("HeuristicLab.Persistence", "3.3")] -
trunk/sources/HeuristicLab.Encodings.RealVectorEncoding/3.3/Moves/AdditiveMoveTabuMaker.cs
r3376 r3418 26 26 using HeuristicLab.Operators; 27 27 using HeuristicLab.Optimization; 28 using HeuristicLab.Optimization.Operators; 28 29 using HeuristicLab.Parameters; 29 30 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; -
trunk/sources/HeuristicLab.Operators/3.3/HeuristicLab.Operators-3.3.csproj
r3407 r3418 97 97 <Compile Include="ScopeCleaner.cs" /> 98 98 <Compile Include="StochasticBranch.cs" /> 99 <Compile Include="StochasticMultiBranch.cs" /> 99 100 <Compile Include="SubScopesCreator.cs" /> 100 101 <Compile Include="SubScopesMixer.cs" /> -
trunk/sources/HeuristicLab.Operators/3.3/StochasticMultiBranch.cs
r1530 r3418 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-20 08Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 22 22 using System; 23 23 using System.Collections.Generic; 24 using System.Text; 24 using System.Collections.ObjectModel; 25 using System.Linq; 26 using HeuristicLab.Collections; 27 using HeuristicLab.Common; 25 28 using HeuristicLab.Core; 26 29 using HeuristicLab.Data; 30 using HeuristicLab.Parameters; 31 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 27 32 28 33 namespace HeuristicLab.Operators { … … 30 35 /// Branch of operators that have different probabilities to get executed. 31 36 /// </summary> 32 public class StochasticMultiBranch : OperatorBase { 33 ///<inheritdoc select="summary"/> 34 public override string Description { 35 get { return @"TODO\r\nOperator description still missing ..."; } 37 [Item("StochasticMultiBranch", "Branch of operators that have different probabilities to get executed.")] 38 [StorableClass] 39 public class StochasticMultiBranch : MultiOperator<IOperator> { 40 public ValueLookupParameter<DoubleArray> ProbabilitiesParameter { 41 get { return (ValueLookupParameter<DoubleArray>)Parameters["Probabilities"]; } 42 } 43 public ILookupParameter<IRandom> RandomParameter { 44 get { return (ILookupParameter<IRandom>)Parameters["Random"]; } 36 45 } 37 46 47 public DoubleArray Probabilities { 48 get { return ProbabilitiesParameter.Value; } 49 set { ProbabilitiesParameter.Value = value; } 50 } 51 52 [StorableConstructor] 53 public StochasticMultiBranch(bool deserializing) : base() { } 38 54 /// <summary> 39 /// Initializes a new instance of <see cref="StochasticMultiBranch"/> with two variable infos55 /// Initializes a new instance of <see cref="StochasticMultiBranch"/> with two parameters 40 56 /// (<c>Probabilities</c> and <c>Random</c>). 41 57 /// </summary> 42 58 public StochasticMultiBranch() 43 59 : base() { 44 AddVariableInfo(new VariableInfo("Probabilities", "The probabilities, that define how likely each suboperator/graph is executed. This array must sum to 1", typeof(DoubleArrayData), VariableKind.In)); 45 AddVariableInfo(new VariableInfo("Random", "The pseudo random-generator, used for any random-decision.", typeof(IRandom), VariableKind.In)); 60 Parameters.Add(new ValueLookupParameter<DoubleArray>("Probabilities", "The array of relative probabilities for each operator.", new DoubleArray())); 61 Parameters.Add(new LookupParameter<IRandom>("Random", "The random number generator to use.")); 62 Initialize(); 63 } 64 65 [StorableHook(HookType.AfterDeserialization)] 66 private void Initialize() { 67 Operators.ItemsAdded += new CollectionItemsChangedEventHandler<IndexedItem<IOperator>>(Operators_ItemsAdded); 68 Operators.ItemsRemoved += new CollectionItemsChangedEventHandler<IndexedItem<IOperator>>(Operators_ItemsRemoved); 69 Operators.ItemsMoved += new CollectionItemsChangedEventHandler<IndexedItem<IOperator>>(Operators_ItemsMoved); 70 } 71 72 void Operators_ItemsMoved(object sender, CollectionItemsChangedEventArgs<IndexedItem<IOperator>> e) { 73 if (Probabilities != null) { 74 DoubleArray oldProb = (DoubleArray)Probabilities.Clone(); 75 foreach (IndexedItem<IOperator> old in e.OldItems) { 76 foreach (IndexedItem<IOperator> item in e.Items) { 77 if (old.Value == item.Value && item.Index < Probabilities.Length && old.Index < oldProb.Length) 78 Probabilities[item.Index] = oldProb[old.Index]; 79 } 80 } 81 } 82 } 83 84 void Operators_ItemsRemoved(object sender, CollectionItemsChangedEventArgs<IndexedItem<IOperator>> e) { 85 if (Probabilities != null && Probabilities.Length > Operators.Count) { 86 List<double> probs = new List<double>(Probabilities.Cast<DoubleValue>().Select(x => x.Value)); 87 var sorted = e.Items.OrderByDescending(x => x.Index); 88 foreach (IndexedItem<IOperator> item in sorted) 89 if (probs.Count > item.Index) probs.RemoveAt(item.Index); 90 Probabilities = new DoubleArray(probs.ToArray()); 91 } 92 } 93 94 private void Operators_ItemsAdded(object sender, HeuristicLab.Collections.CollectionItemsChangedEventArgs<IndexedItem<IOperator>> e) { 95 if (Probabilities != null && Probabilities.Length < Operators.Count) { 96 DoubleArray probs = new DoubleArray(Operators.Count); 97 double avg = 0; 98 if (Probabilities.Length > 0) { 99 for (int i = 0; i < Probabilities.Length; i++) 100 avg += Probabilities[i]; 101 avg /= (double)Probabilities.Length; 102 } else avg = 1; 103 104 var added = e.Items.OrderBy(x => x.Index).ToList(); 105 int insertCount = 0; 106 for (int i = 0; i < Operators.Count; i++) { 107 if (insertCount < added.Count && i == added[insertCount].Index) { 108 probs[i] = avg; 109 insertCount++; 110 } else if (i - insertCount < Probabilities.Length) { 111 probs[i] = Probabilities[i - insertCount]; 112 } else probs[i] = avg; 113 } 114 Probabilities = probs; 115 } 46 116 } 47 117 48 118 /// <summary> 49 /// Applies an operator of the branches to the specified <paramref name="scope"/>with a119 /// Applies an operator of the branches to the current scope with a 50 120 /// specific probability. 51 121 /// </summary> 52 122 /// <exception cref="InvalidOperationException">Thrown when the list of probabilites does not 53 /// match the number of operators or if there was another problem with the list of probabilities.</exception> 54 /// <param name="scope">The scope to apply the operators on.</param> 55 /// <returns>A new <see cref="AtomicOperation"/> with a specific operator, depending 56 /// on its probability, applied on the given <paramref name="scope"/>.</returns> 57 public override IOperation Apply(IScope scope) { 58 IRandom random = GetVariableValue<IRandom>("Random", scope, true); 59 DoubleArrayData probabilities = GetVariableValue<DoubleArrayData>("Probabilities", scope, true); 60 if(probabilities.Data.Length != SubOperators.Count) { 123 /// match the number of operators.</exception> 124 /// <returns>A new operation with the operator that was selected followed by the current operator's successor.</returns> 125 public override IOperation Apply() { 126 IRandom random = RandomParameter.ActualValue; 127 DoubleArray probabilities = ProbabilitiesParameter.ActualValue; 128 if(probabilities.Length != Operators.Count) { 61 129 throw new InvalidOperationException("StochasticMultiBranch: The list of probabilities has to match the number of operators"); 62 130 } 63 131 double sum = 0; 64 for each(double prob in probabilities.Data) {65 sum +=prob;132 for (int i = 0; i < Operators.Count; i++) { 133 sum += probabilities[i]; 66 134 } 67 double r = random.NextDouble() *sum;135 double r = random.NextDouble() * sum; 68 136 sum = 0; 69 137 IOperator successor = null; 70 for(int i = 0; i < SubOperators.Count; i++) {71 sum += probabilities .Data[i];138 for(int i = 0; i < Operators.Count; i++) { 139 sum += probabilities[i]; 72 140 if(sum > r) { 73 successor = SubOperators[i];141 successor = Operators[i]; 74 142 break; 75 143 } 76 144 } 77 if(successor == null) { 78 throw new InvalidOperationException("StochasticMultiBranch: There was a problem with the list of probabilities"); 145 OperationCollection next = new OperationCollection(base.Apply()); 146 if (successor != null) { 147 next.Insert(0, ExecutionContext.CreateOperation(successor)); 79 148 } 80 return ne w AtomicOperation(successor, scope);149 return next; 81 150 } 82 151 } -
trunk/sources/HeuristicLab.Optimization.Operators/3.3/HeuristicLab.Optimization.Operators-3.3.csproj
r3413 r3418 93 93 <Compile Include="QualityComparator.cs" /> 94 94 <Compile Include="SolutionsCreator.cs" /> 95 <Compile Include="MultiCrossover.cs" /> 96 <Compile Include="TabuMaker.cs" /> 95 97 <Compile Include="UnidirectionalRingMigrator.cs" /> 96 98 <Compile Include="WeightedParentsQualityComparator.cs" /> -
trunk/sources/HeuristicLab.Optimization/3.3/HeuristicLab.Optimization-3.3.csproj
r3384 r3418 131 131 <Compile Include="Interfaces\ITabuMaker.cs" /> 132 132 <Compile Include="Result.cs" /> 133 <Compile Include="TabuMaker.cs" />134 133 <Compile Include="UserDefinedAlgorithm.cs" /> 135 134 <Compile Include="EngineAlgorithm.cs" /> … … 162 161 <Project>{BBAB9DF5-5EF3-4BA8-ADE9-B36E82114937}</Project> 163 162 <Name>HeuristicLab.Data-3.3</Name> 164 </ProjectReference>165 <ProjectReference Include="..\..\HeuristicLab.Operators\3.3\HeuristicLab.Operators-3.3.csproj">166 <Project>{23DA7FF4-D5B8-41B6-AA96-F0561D24F3EE}</Project>167 <Name>HeuristicLab.Operators-3.3</Name>168 163 </ProjectReference> 169 164 <ProjectReference Include="..\..\HeuristicLab.Parameters\3.3\HeuristicLab.Parameters-3.3.csproj">
Note: See TracChangeset
for help on using the changeset viewer.