Changeset 5609
- Timestamp:
- 03/04/11 17:23:40 (14 years ago)
- Location:
- branches/VNS
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/VNS/HeuristicLab.Algorithms.VariableNeighborhoodSearch/3.3/LocalSearchImprovement.cs
r5603 r5609 87 87 : base() { 88 88 loop = new LocalSearchMainLoop(); 89 loop.ResultsParameter.Value = new VariableCollection();90 89 91 90 Parameters.Add(new /*Constrained*/ValueParameter<IMoveGenerator>("MoveGenerator", "The operator used to generate moves to the neighborhood of the current solution.")); … … 143 142 public override IOperation Apply() { 144 143 Scope subScope = new Scope(); 145 subScope.Parent = ExecutionContext.Scope;144 Scope individual = new Scope(); 146 145 147 IAtomicOperation op = ExecutionContext.CreateChildOperation(loop, subScope); 148 op.Operator.Execute((IExecutionContext)op, CancellationToken); 146 foreach (Variable var in ExecutionContext.Scope.Variables) { 147 individual.Variables.Add(var); 148 } 149 subScope.SubScopes.Add(individual); 149 150 150 ExecutionContext.Scope.SubScopes.Remove(subScope); 151 ExecutionContext.Scope.SubScopes.Add(subScope); 152 int index = subScope.Parent.SubScopes.IndexOf(subScope); 151 153 152 return base.Apply(); 154 SubScopesProcessor processor = new SubScopesProcessor(); 155 SubScopesRemover remover = new SubScopesRemover(); 156 157 remover.RemoveAllSubScopes = false; 158 remover.SubScopeIndexParameter.Value = new IntValue(index); 159 160 for (int i = 0; i < index; i++) { 161 processor.Operators.Add(new EmptyOperator()); 162 } 163 164 loop.MoveGeneratorParameter.Value = MoveGeneratorParameter.Value; 165 loop.MoveEvaluatorParameter.Value = MoveEvaluatorParameter.Value; 166 loop.MoveMakerParameter.Value = MoveMakerParameter.Value; 167 loop.MaximumIterationsParameter.Value = MaximumIterationsParameter.Value; 168 169 processor.Operators.Add(loop); 170 processor.Successor = remover; 171 172 IOperation next = base.Apply(); 173 if (next as ExecutionContext != null) { 174 remover.Successor = (next as ExecutionContext).Operator; 175 } 176 177 return ExecutionContext.CreateOperation(processor); 153 178 } 154 179 } -
branches/VNS/HeuristicLab.Algorithms.VariableNeighborhoodSearch/3.3/ShakingOperator.cs
r5603 r5609 65 65 IOperator successor = null; 66 66 67 if (index >= operators.Count || index < 0) {67 if (index >= operators.Count - 1) { 68 68 ContinueParameter.ActualValue = new BoolValue(false); 69 69 } else { 70 70 ContinueParameter.ActualValue = new BoolValue(true); 71 } 72 73 if (index >= 0 && index < operators.Count) { 71 74 successor = operators[index].Value; 72 75 } -
branches/VNS/HeuristicLab.Algorithms.VariableNeighborhoodSearch/3.3/VariableNeighborhoodSearchMainLoop.cs
r5603 r5609 126 126 QualityComparator qualityComparator = new QualityComparator(); 127 127 ConditionalBranch improvesQualityBranch = new ConditionalBranch(); 128 ConditionalBranch improvesQualityBranch2 = new ConditionalBranch(); 128 129 129 130 Assigner bestQualityUpdater = new Assigner(); … … 134 135 Assigner indexResetter = new Assigner(); 135 136 136 SubScopesRemover remover = new SubScopesRemover(); 137 SubScopesRemover remover1 = new SubScopesRemover(); 138 SubScopesRemover remover2 = new SubScopesRemover(); 137 139 Placeholder analyzer2 = new Placeholder(); 138 140 … … 145 147 variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("Iterations", new IntValue(0))); 146 148 variableCreator.CollectedValues.Add(new ValueParameter<DoubleValue>("Index", new DoubleValue(0))); 149 variableCreator.CollectedValues.Add(new ValueParameter<BoolValue>("Continue", new BoolValue(false))); 147 150 variableCreator.CollectedValues.Add(new ValueParameter<DoubleValue>("BestQuality", new DoubleValue(0))); 148 151 … … 183 186 evaluator.OperatorParameter.ActualName = EvaluatorParameter.Name; 184 187 185 qualityComparator.LeftSideParameter.ActualName = "OriginalQuality";186 qualityComparator.RightSideParameter.ActualName = QualityParameter.Name;188 qualityComparator.LeftSideParameter.ActualName = QualityParameter.Name; 189 qualityComparator.RightSideParameter.ActualName = "OriginalQuality"; 187 190 qualityComparator.ResultParameter.ActualName = "IsBetter"; 188 191 189 192 improvesQualityBranch.ConditionParameter.ActualName = "IsBetter"; 193 improvesQualityBranch2.ConditionParameter.ActualName = "IsBetter"; 190 194 191 195 bestQualityUpdater.Name = "Update BestQuality"; … … 194 198 195 199 cleaner.Name = "Clean scope"; 200 cleaner.ClearSubScopesParameter.Value = new BoolValue(false); 196 201 originalRestorer.Name = "Restore original solution"; 197 202 … … 204 209 indexResetter.RightSideParameter.Value = new IntValue(0); 205 210 206 remover .Name = "Remove subscope";211 remover1.Name = remover2.Name = "Remove subscope"; 207 212 208 213 analyzer2.Name = "Analyzer (placeholder)"; … … 253 258 improvesQualityBranch.TrueBranch = bestQualityUpdater; 254 259 improvesQualityBranch.FalseBranch = cleaner; 255 improvesQualityBranch.Successor = remover;256 260 257 261 bestQualityUpdater.Successor = indexResetter; 262 indexResetter.Successor = remover1; 258 263 259 264 cleaner.Successor = originalRestorer; 260 originalRestorer.Successor = indexCounter; 265 originalRestorer.Successor = remover2; 266 remover2.Successor = indexCounter; 261 267 ///////// 262 indexTermination.TrueBranch = null; 263 indexTermination.FalseBranch = iterationInit; 268 indexTermination.TrueBranch = improvesQualityBranch2; 269 indexTermination.FalseBranch = null; 270 271 improvesQualityBranch2.TrueBranch = null; 272 improvesQualityBranch2.FalseBranch = createChild; 264 273 265 274 iterationsCounter.Successor = iterationsComparator; -
branches/VNS/HeuristicLab.Operators/3.3/ScopeCleaner.cs
r5445 r5609 24 24 using HeuristicLab.Parameters; 25 25 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 26 using HeuristicLab.Data; 26 27 27 28 namespace HeuristicLab.Operators { … … 38 39 get { return CurrentScopeParameter.ActualValue; } 39 40 } 41 public ValueParameter<BoolValue> ClearSubScopesParameter { 42 get { return (ValueParameter<BoolValue>)Parameters["ClearSubScopes"]; } 43 } 44 45 [StorableHook(HookType.AfterDeserialization)] 46 private void AfterDeserializationHook() { 47 #region Backwards Compatibility 48 if (!Parameters.ContainsKey("ClearSubScopes")) { 49 Parameters.Add(new ValueParameter<BoolValue>("ClearSubScopes", "Indicates, if the subscopes should be cleared.", new BoolValue(false))); 50 } 51 #endregion 52 } 40 53 41 54 [StorableConstructor] … … 47 60 : base() { 48 61 Parameters.Add(new ScopeParameter("CurrentScope", "The current scope whose variables and sub-scopes should be removed.")); 62 Parameters.Add(new ValueParameter<BoolValue>("ClearSubScopes", "Indicates, if the subscopes should be cleared.", new BoolValue(false))); 49 63 } 50 64 … … 55 69 public override IOperation Apply() { 56 70 CurrentScope.Variables.Clear(); 57 CurrentScope.SubScopes.Clear(); 71 if(ClearSubScopesParameter.Value.Value) 72 CurrentScope.SubScopes.Clear(); 58 73 return base.Apply(); 59 74 }
Note: See TracChangeset
for help on using the changeset viewer.