Changeset 637 for trunk/sources
- Timestamp:
- 10/08/08 12:39:51 (16 years ago)
- Location:
- trunk/sources/HeuristicLab.SimOpt
- Files:
-
- 1 added
- 16 deleted
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.SimOpt/HeuristicLab.SimOpt.csproj
r590 r637 50 50 </ItemGroup> 51 51 <ItemGroup> 52 <Compile Include="DefaultInitializer.cs" /> 53 <Compile Include="DefaultManipulator.cs" /> 54 <Compile Include="NormalDoubleManipulator.cs" /> 55 <Compile Include="NormalIntManipulator.cs" /> 56 <Compile Include="PermutationParameterCyclicCrossover.cs" /> 57 <Compile Include="PermutationParameterOrderCrossover.cs" /> 58 <Compile Include="PermutationParameterPartiallyMatchedCrossover.cs" /> 59 <Compile Include="SimOptCrossoverBase.cs" /> 52 <Compile Include="SimOptCrossoverPreparator.cs" /> 60 53 <Compile Include="SimOptSequentialSubOperatorProcessor.cs" /> 61 54 <Compile Include="SimOptSquentialSubOperatorCrossover.cs" /> 62 <Compile Include="Swap2PermutationManipulator.cs" />63 <Compile Include="RandomDoubleInitializer.cs" />64 <Compile Include="RandomPermutationInitializer.cs" />65 <Compile Include="SimOptInitializationOperatorBase.cs" />66 <Compile Include="SimOptManipulationOperatorBase.cs" />67 55 <Compile Include="DoubleParameterBoundConstraint.cs" /> 68 56 <Compile Include="DoubleParameterBoundConstraintView.cs"> … … 87 75 </Compile> 88 76 <Compile Include="SimOptSinglePointCrossover.cs" /> 89 <Compile Include="TranslocationPermutationAdaptiveManipulator.cs" />90 <Compile Include="TranslocationPermutationManipulator.cs">91 <SubType>Code</SubType>92 </Compile>93 <Compile Include="UniformIntInitializer.cs" />94 77 </ItemGroup> 95 78 <ItemGroup> … … 127 110 <Name>HeuristicLab.Operators</Name> 128 111 </ProjectReference> 129 <ProjectReference Include="..\HeuristicLab.Permutation\HeuristicLab.Permutation.csproj">130 <Project>{55FDCFB3-3E8C-4FB0-837C-0CF06BEDED39}</Project>131 <Name>HeuristicLab.Permutation</Name>132 </ProjectReference>133 112 <ProjectReference Include="..\HeuristicLab.PluginInfrastructure\HeuristicLab.PluginInfrastructure.csproj"> 134 113 <Project>{94186A6A-5176-4402-AE83-886557B53CCA}</Project> 135 114 <Name>HeuristicLab.PluginInfrastructure</Name> 136 115 </ProjectReference> 137 <ProjectReference Include="..\HeuristicLab. Random\HeuristicLab.Random.csproj">138 <Project>{ 47019A74-F7F7-482E-83AA-D3F4F777E879}</Project>139 <Name>HeuristicLab. Random</Name>116 <ProjectReference Include="..\HeuristicLab.Selection\HeuristicLab.Selection.csproj"> 117 <Project>{F7CF0571-25CB-43D5-8443-0843A1E2861A}</Project> 118 <Name>HeuristicLab.Selection</Name> 140 119 </ProjectReference> 141 120 </ItemGroup> -
trunk/sources/HeuristicLab.SimOpt/HeuristicLabSimOptPlugin.cs
r591 r637 32 32 [Dependency(Dependency = "HeuristicLab.Data-3.2")] 33 33 [Dependency(Dependency = "HeuristicLab.Operators-3.2")] 34 [Dependency(Dependency = "HeuristicLab.Random-3.2")]35 34 [Dependency(Dependency = "HeuristicLab.Constraints-3.2")] 36 35 [Dependency(Dependency = "HeuristicLab.Evolutionary-3.2")] 37 [Dependency(Dependency = "HeuristicLab. Permutation-3.2")]36 [Dependency(Dependency = "HeuristicLab.Selection-3.2")] 38 37 public class HeuristicLabSimOptPlugin : PluginBase { 39 38 } -
trunk/sources/HeuristicLab.SimOpt/SimOptDiscreteMultiCrossover.cs
r591 r637 26 26 using HeuristicLab.Data; 27 27 using HeuristicLab.Operators; 28 using HeuristicLab.Random;29 28 using HeuristicLab.Evolutionary; 30 29 -
trunk/sources/HeuristicLab.SimOpt/SimOptParameterExtractor.cs
r591 r637 31 31 public class SimOptParameterExtractor : OperatorBase { 32 32 public override string Description { 33 get { return @" Injects the contents of a ConstrainedItemList into the scope"; }33 get { return @"Appends each parameter as subscope to the current scope."; } 34 34 } 35 35 36 36 public SimOptParameterExtractor() 37 37 : base() { 38 AddVariableInfo(new VariableInfo("Items", "The ConstrainedItemList to be extracted", typeof(ConstrainedItemList), VariableKind.In)); 38 AddVariableInfo(new VariableInfo("Items", "The ConstrainedItemList to be extracted", typeof(ConstrainedItemList), VariableKind.In | VariableKind.Deleted)); 39 AddVariableInfo(new VariableInfo("DeleteItems", "Whether or not to remove items from the current scope", typeof(BoolData), VariableKind.In)); 40 AddVariable(new Variable("DeleteItems", new BoolData(false))); 41 GetVariableInfo("DeleteItems").Local = true; 39 42 } 40 43 41 44 public override IOperation Apply(IScope scope) { 42 45 ConstrainedItemList cil = GetVariableValue<ConstrainedItemList>("Items", scope, false); 46 bool delete = GetVariableValue<BoolData>("DeleteItems", scope, true).Data; 43 47 for (int i = 0; i < cil.Count; i++) { 44 IVariable var = scope.GetVariable(((Variable)cil[i]).Name); 45 if (var == null) scope.AddVariable((IVariable)cil[i].Clone()); 46 else var.Value = (IItem)((Variable)cil[i]).Value.Clone(); 48 IScope tmp = new Scope(scope.Name + "_Param" + i.ToString()); 49 try { 50 scope.AddVariable(cil[i].Clone() as Variable); 51 } catch (InvalidCastException ice) { 52 throw new InvalidCastException("Parameters in the constrained item list have to be encapsulated in a variable!\r\n\r\n" + ice.Message); 53 } 54 scope.AddSubScope(tmp); 55 } 56 if (delete) { 57 IVariableInfo info = GetVariableInfo("Items"); 58 if (info.Local) RemoveVariable(info.ActualName); 59 else scope.RemoveVariable(info.ActualName); 47 60 } 48 61 return null; -
trunk/sources/HeuristicLab.SimOpt/SimOptParameterPacker.cs
r591 r637 31 31 public class SimOptParameterPacker : OperatorBase { 32 32 public override string Description { 33 get { return @"Updates a ConstrainedItemList with the variables in the scope and removes them afterwards."; } 33 get { return @"Takes the parameters in the subscope and creates or a updates a parameter vector. The order of the subscopes is assumed to be the same as the parameters appear in the vector. 34 If the parameter vector could not be updated due to a constraint violation, the first suboperator is returned as the next operation."; } 34 35 } 35 36 36 37 public SimOptParameterPacker() 37 38 : base() { 38 AddVariableInfo(new VariableInfo("Items", "The ConstrainedItemList to be updated", typeof(ConstrainedItemList), VariableKind.In | VariableKind.Out)); 39 AddVariableInfo(new VariableInfo("Items", "The ConstrainedItemList to be updated or created", typeof(ConstrainedItemList), VariableKind.New | VariableKind.In | VariableKind.Out)); 40 AddVariableInfo(new VariableInfo("DeleteParameters", "Whether or not the subscopes containing the parameters should be removed afterwards", typeof(BoolData), VariableKind.In)); 41 AddVariable(new Variable("DeleteParameters", new BoolData(true))); 42 GetVariableInfo("DeleteParameters").Local = true; 39 43 } 40 44 41 45 public override IOperation Apply(IScope scope) { 42 ConstrainedItemList cil = GetVariableValue<ConstrainedItemList>("Items", scope, false); 43 for (int i = 0; i < cil.Count; i++) { 44 IVariable var = scope.GetVariable(((Variable)cil[i]).Name); 45 if (var == null) throw new InvalidOperationException("ERROR in SimOptParameterPacker: Cannot find variable " + ((Variable)cil[i]).Name + " in scope"); 46 else { 47 ((Variable)cil[i]).Value = (IItem)var.Value.Clone(); 48 scope.RemoveVariable(var.Name); 46 // ----- FETCH THE PARAMETER VECTOR ----- // 47 bool updateVector = true; 48 ConstrainedItemList cil; 49 try { 50 cil = GetVariableValue<ConstrainedItemList>("Items", scope, false); 51 } catch (ArgumentException) { 52 updateVector = false; 53 // the parameter vector is fetched from a higher scope and added locally 54 cil = GetVariableValue<ConstrainedItemList>("Items", scope, true); 55 } 56 ConstrainedItemList tempcil = (ConstrainedItemList)cil.Clone(); 57 bool delete = GetVariableValue<BoolData>("DeleteParameters", scope, true).Data; 58 59 ICollection<IConstraint> violatedConstraints; 60 61 tempcil.BeginCombinedOperation(); 62 // ----- FETCH PARAMETERS AND UPDATE TEMPORARY VECTOR ----- // 63 for (int i = 0; i < scope.SubScopes.Count; i++) { 64 IVariable var = scope.SubScopes[i].GetVariable(((IVariable)tempcil[i]).Name); 65 if (var == null) throw new ArgumentNullException(scope.SubScopes[i].Name, "Could not find parameter " + ((IVariable)tempcil[i]).Name + " in this scope"); 66 tempcil.TrySetAt(i, var, out violatedConstraints); 67 } 68 69 // ----- CONSTRAINT HANDLING ----- // 70 IVariableInfo info = GetVariableInfo("Items"); 71 bool error = tempcil.EndCombinedOperation(out violatedConstraints); 72 if (!error) { 73 if (!updateVector) { 74 if (info.Local) AddVariable(new Variable(info.ActualName, tempcil)); 75 else scope.AddVariable(new Variable(scope.TranslateName("Items"), tempcil)); 76 } else { 77 if (info.Local) GetVariable(info.ActualName).Value = tempcil; 78 else scope.GetVariable(scope.TranslateName("Items")).Value = tempcil; 49 79 } 80 } else if (!updateVector) { // in case there was an error and the parameter vector is not in the current scope, add it 81 if (info.Local) AddVariable(new Variable(info.ActualName, cil)); 82 else scope.AddVariable(new Variable(scope.TranslateName("Items"), cil)); 50 83 } 51 return null; 84 85 // ----- DELETE SUBSCOPES ----- // 86 if (delete) { 87 scope.SubScopes.Clear(); 88 } 89 90 if (error) return new AtomicOperation(SubOperators[0], scope); 91 else return null; 52 92 } 53 93 } -
trunk/sources/HeuristicLab.SimOpt/SimOptSequentialSubOperatorProcessor.cs
r591 r637 26 26 using HeuristicLab.Core; 27 27 using HeuristicLab.Data; 28 using HeuristicLab.Operators; 28 29 29 30 namespace HeuristicLab.SimOpt { … … 31 32 public override string Description { 32 33 get { 33 return @"Applies its suboperators on the parameter vector one for each index, afterwards it checks if the parameter vector satisfies all the constraints. If not it restores the old parameter vector and tries again until a maximum amount of tries (default: 100) has been reached."; 34 return @"This operator encapsulates the functionality of processing the parameters of a simulation parameter vector. It works as follows: 35 1. The parameters are extracted [SimOptParameterExtractor] 36 2. The parameters are processed [SequentialSubScopeProcessor which applies the SubOperators of this operator on each parameter] 37 3. The parameters are updated again [SimOptParameterPacker] 38 39 Should the packing fail due to constraint violations, the operator will retry as often as specified in the variable MaximumTries."; 34 40 } 35 41 } … … 42 48 GetVariableInfo("MaximumTries").Local = true; 43 49 AddVariable(new Variable("MaximumTries", new IntData(100))); 44 AddVariable(new Variable("Tries", new IntData( 0)));50 AddVariable(new Variable("Tries", new IntData(1))); 45 51 } 46 52 47 53 public override IOperation Apply(IScope scope) { 48 ConstrainedItemList parameterVector = GetVariableValue<ConstrainedItemList>("Items", scope, false, false); 49 // Mode: The parameter vector does not yet exist in the current scope 50 if (parameterVector == null) { // the parameter does not yet exist in the current scope 51 parameterVector = GetVariableValue<ConstrainedItemList>("Items", scope, true); // search for it 52 parameterVector = (ConstrainedItemList)parameterVector.Clone(); // clone it 53 scope.AddVariable(new Variable(scope.TranslateName("Items"), parameterVector)); // and add it to the current scope 54 55 int tries = (GetVariable("Tries").Value as IntData).Data; 56 int maxTries = GetVariableValue<IntData>("MaximumTries", scope, true).Data; 57 58 IVariableInfo itemsInfo = GetVariableInfo("Items"); 59 SimOptParameterExtractor extractor = new SimOptParameterExtractor(); 60 extractor.GetVariableInfo("Items").ActualName = itemsInfo.ActualName; 61 62 SequentialSubScopesProcessor sssp = new SequentialSubScopesProcessor(); 63 foreach (IOperator op in SubOperators) 64 sssp.AddSubOperator(op); 65 66 SimOptParameterPacker packer = new SimOptParameterPacker(); 67 packer.GetVariableInfo("Items").ActualName = itemsInfo.ActualName; 68 if (tries < maxTries) { 69 SimOptSequentialSubOperatorProcessor sssop = (SimOptSequentialSubOperatorProcessor)this.Clone(); 70 (sssop.GetVariable("Tries").Value as IntData).Data = tries + 1; 71 packer.AddSubOperator(this); 54 72 } 55 // Mode: The parameter vector is marked for manipulation/initialization (constraint check is suspended) 56 if (parameterVector.ConstraintCheckSuspended) { 57 ICollection<IConstraint> violatedConstraints; 58 if (parameterVector.EndCombinedOperation(out violatedConstraints)) { 59 ((IntData)GetVariable("Tries").Value).Data = 0; 60 GetVariable("ItemsBackup").Value = new NullData(); 61 return null; // manipulation/initialization was successful 62 } else { // restore old vector 63 int maximumTries = GetVariableValue<IntData>("MaximumTries", scope, true).Data; 64 IntData tries = (GetVariable("Tries").Value as IntData); 65 if (tries.Data >= maximumTries) throw new InvalidOperationException("ERROR: no valid solution in " + maximumTries.ToString() + " tries"); 66 parameterVector = (ConstrainedItemList)GetVariable("ItemsBackup").Value; 67 scope.GetVariable(scope.TranslateName("Items")).Value = parameterVector; 68 ((IntData)GetVariable("Tries").Value).Data++; 69 } 70 } 71 // perform the sub operators in sequential order on the indices of the parameter vector 72 GetVariable("ItemsBackup").Value = (ConstrainedItemList)parameterVector.Clone(); 73 CompositeOperation co = new CompositeOperation(); 74 for (int i = 0; i < SubOperators.Count; i++) { 75 if (SubOperators[i].GetVariable("Index") != null) { 76 SubOperators[i].GetVariable("Index").Value = new IntData(i); 77 } 78 if (SubOperators[i].GetVariableInfo("Items") != null) { 79 SubOperators[i].GetVariableInfo("Items").ActualName = GetVariableInfo("Items").ActualName; 80 } 81 } 82 for (int i = 0; i < SubOperators.Count; i++) 83 co.AddOperation(new AtomicOperation(SubOperators[i], scope)); 84 // add self to check if the manipulation/initialization did not violate any constraints 85 co.AddOperation(new AtomicOperation(this, scope)); 86 parameterVector.BeginCombinedOperation(); 87 return co; 73 74 CompositeOperation operation = new CompositeOperation(); 75 operation.AddOperation(new AtomicOperation(extractor, scope)); 76 operation.AddOperation(new AtomicOperation(sssp, scope)); 77 operation.AddOperation(new AtomicOperation(packer, scope)); 78 79 return operation; 88 80 } 89 81 } -
trunk/sources/HeuristicLab.SimOpt/SimOptSinglePointCrossover.cs
r591 r637 26 26 using HeuristicLab.Data; 27 27 using HeuristicLab.Operators; 28 using HeuristicLab.Random;29 28 using HeuristicLab.Evolutionary; 30 29 -
trunk/sources/HeuristicLab.SimOpt/SimOptSquentialSubOperatorCrossover.cs
r591 r637 24 24 using System.Linq; 25 25 using System.Text; 26 using System.Xml; 26 27 using HeuristicLab.Core; 27 28 using HeuristicLab.Data; 28 using HeuristicLab.Evolutionary; 29 using HeuristicLab.Operators; 30 using HeuristicLab.Selection; 29 31 30 32 namespace HeuristicLab.SimOpt { 31 33 public class SimOptSquentialSubOperatorCrossover : OperatorBase { 34 private UniformSequentialSubScopesProcessor usssp, usssp2, usssp3, usssp4; 35 private SequentialSubScopesProcessor sssp; 36 private SimOptParameterExtractor extractor; 37 private SimOptParameterPacker packer; 38 private SimOptCrossoverPreparator preparator; 39 private MergingReducer merger; 40 private bool uptodate; 41 32 42 public override string Description { 33 get { return @"Takes the parameter vector of two items and on each index applies the respectively indexed suboperator"; } 43 get { 44 return @"This operator encapsulates the functionality of crossing the parameters of a simulation parameter vector. It works as follows: 45 1. The parameters of all parents are extracted [UniformSequentialSubScopeProcessor which applies a SimOptParameterExtractor] 46 2. The parents are prepared for crossing by grouping the respective parameters [SimOptCrossoverPreparator] 47 3. The parameters are crossed [UniformSequentialSubScopeProcessor which applies SequentialSubScopeProcessor which applies the SubOperators of this operator on each parameter group (except for the last one)] 48 4. Assigning the crossed parameters to the respective children [MergingReducer] 49 5. Update the parameters [UniformSequentialSubScopeProcessor which applies SimOptParameterPacker] 50 51 Should the packing fail due to constraint violations, the operator will execute the last of its suboperators."; 52 } 34 53 } 35 54 … … 38 57 AddVariableInfo(new VariableInfo("Items", "The parameter vector", typeof(ConstrainedItemList), VariableKind.In | VariableKind.New)); 39 58 AddVariableInfo(new VariableInfo("Parents", "The number of parents per child", typeof(IntData), VariableKind.In)); 59 uptodate = false; 40 60 } 41 61 42 62 public override IOperation Apply(IScope scope) { 43 int parents = GetVariableValue<IntData>("Parents", scope, true).Data; 63 string itemsActualName = GetVariableInfo("Items").ActualName; 64 string parentsActualName = GetVariableInfo("Parents").ActualName; 65 int parameters = SubOperators.Count - 1; 44 66 45 int subScopesCount = scope.SubScopes.Count; 46 if (subScopesCount < parents || (subScopesCount % parents) != 0) 47 throw new InvalidOperationException("Size of mating pool is not a multiple (>1) of the number of parents per child"); 48 int children = subScopesCount / parents; 67 if (!uptodate) { 68 usssp = new UniformSequentialSubScopesProcessor(); 69 extractor = new SimOptParameterExtractor(); 70 usssp.AddSubOperator(extractor); 71 72 preparator = new SimOptCrossoverPreparator(); 73 74 usssp2 = new UniformSequentialSubScopesProcessor(); 75 sssp = new SequentialSubScopesProcessor(); 76 for (int i = 0; i < parameters; i++) { 77 sssp.AddSubOperator(SubOperators[i]); 78 } 79 usssp2.AddSubOperator(sssp); 80 81 usssp3 = new UniformSequentialSubScopesProcessor(); 82 merger = new MergingReducer(); 83 usssp3.AddSubOperator(merger); 84 85 usssp4 = new UniformSequentialSubScopesProcessor(); 86 packer = new SimOptParameterPacker(); 87 packer.AddSubOperator(SubOperators[SubOperators.Count - 1]); 88 usssp4.AddSubOperator(packer); 89 uptodate = true; 90 } 91 // Setting the actual names is necessary as the operator does not know if they've changed 92 extractor.GetVariableInfo("Items").ActualName = itemsActualName; 93 preparator.GetVariableInfo("Parents").ActualName = parentsActualName; 94 packer.GetVariableInfo("Items").ActualName = itemsActualName; 49 95 50 96 CompositeOperation co = new CompositeOperation(); 51 for (int i = 0; i < SubOperators.Count; i++) { 52 if (SubOperators[i].GetVariable("Index") != null) { 53 SubOperators[i].GetVariable("Index").Value = new IntData(i); 54 } 55 if (SubOperators[i].GetVariableInfo("Items") != null) { 56 SubOperators[i].GetVariableInfo("Items").ActualName = GetVariableInfo("Items").ActualName; 57 } 58 } 59 for (int i = 0; i < children; i++) { 60 IScope child = (IScope)scope.SubScopes[0].Clone(); 61 for (int j = 0; j < parents; j++) { 62 IScope parent = scope.SubScopes[0]; 63 child.AddSubScope(parent); 64 scope.RemoveSubScope(parent); 65 } 66 scope.AddSubScope(child); 67 for (int n = 0 ; n < SubOperators.Count ; n++) 68 co.AddOperation(new AtomicOperation(SubOperators[n], child)); 69 co.AddOperation(new AtomicOperation(new Operators.SubScopesRemover(), child)); 70 } 97 co.AddOperation(new AtomicOperation(usssp, scope)); 98 co.AddOperation(new AtomicOperation(preparator, scope)); 99 co.AddOperation(new AtomicOperation(usssp2, scope)); 100 co.AddOperation(new AtomicOperation(usssp3, scope)); 101 co.AddOperation(new AtomicOperation(usssp4, scope)); 71 102 return co; 103 } 104 105 protected override void OnSubOperatorAdded(IOperator subOperator, int index) { 106 base.OnSubOperatorAdded(subOperator, index); 107 uptodate = false; 108 } 109 110 protected override void OnSubOperatorRemoved(IOperator subOperator, int index) { 111 base.OnSubOperatorRemoved(subOperator, index); 112 uptodate = false; 113 } 114 115 public override void Populate(XmlNode node, IDictionary<Guid, IStorable> restoredObjects) { 116 base.Populate(node, restoredObjects); 117 uptodate = false; 72 118 } 73 119 }
Note: See TracChangeset
for help on using the changeset viewer.