Changeset 6693 for trunk/sources/HeuristicLab.Optimization
- Timestamp:
- 09/01/11 15:51:30 (13 years ago)
- Location:
- trunk/sources/HeuristicLab.Optimization/3.3
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Optimization/3.3/RunCollection.cs
r5445 r6693 51 51 52 52 constraints = new RunCollectionConstraintCollection(original.constraints.Select(x => cloner.Clone(x))); 53 modifiers = new CheckedItemList<IRunCollectionModifier>(original.modifiers.Select(cloner.Clone)); 53 54 foreach (IRunCollectionConstraint constraint in constraints) 54 55 constraint.ConstrainedValue = this; … … 67 68 dataTypes = new Dictionary<string, HashSet<Type>>(); 68 69 constraints = new RunCollectionConstraintCollection(); 70 modifiers = new CheckedItemList<IRunCollectionModifier>(); 69 71 RegisterConstraintsEvents(); 70 72 } … … 83 85 get { return constraints; } 84 86 } 87 88 [Storable] 89 private CheckedItemList<IRunCollectionModifier> modifiers; 90 public CheckedItemList<IRunCollectionModifier> Modifiers { 91 get { return modifiers; } 92 } 93 85 94 86 95 private bool updateOfRunsInProgress; … … 98 107 private void AfterDeserialization() { 99 108 if (constraints == null) constraints = new RunCollectionConstraintCollection(); 109 if (modifiers == null) modifiers = new CheckedItemList<IRunCollectionModifier>(); 100 110 RegisterConstraintsEvents(); 101 111 RegisterConstraintEvents(constraints); … … 393 403 } 394 404 #endregion 405 406 #region Modification 407 public void Modify() { 408 UpdateOfRunsInProgress = true; 409 var runs = this.ToList(); 410 var selectedRuns = runs.Where(r => r.Visible).ToList(); 411 int nSelected = selectedRuns.Count; 412 if (nSelected > 0) { 413 foreach (var modifier in Modifiers.CheckedItems) 414 modifier.Value.Modify(selectedRuns); 415 if (nSelected != selectedRuns.Count || HaveDifferentOrder(selectedRuns, runs.Where(r => r.Visible))) { 416 Clear(); 417 AddRange(ReplaceVisibleRuns(runs, selectedRuns)); 418 } else if (runs.Count > 0) { 419 OnCollectionReset(this, runs); 420 } 421 } 422 UpdateOfRunsInProgress = false; 423 } 424 425 private static IEnumerable<IRun> ReplaceVisibleRuns(IEnumerable<IRun> runs, IEnumerable<IRun> visibleRuns) { 426 var newRuns = new List<IRun>(); 427 var runIt = runs.GetEnumerator(); 428 var visibleRunIt = visibleRuns.GetEnumerator(); 429 while (runIt.MoveNext()) { 430 if (runIt.Current != null && !runIt.Current.Visible) 431 newRuns.Add(runIt.Current); 432 else if (visibleRunIt.MoveNext()) 433 newRuns.Add(visibleRunIt.Current); 434 } 435 while (visibleRunIt.MoveNext()) 436 newRuns.Add(visibleRunIt.Current); 437 return newRuns; 438 } 439 440 private static bool HaveDifferentOrder(IEnumerable<IRun> l1, IEnumerable<IRun> l2) { 441 return l1.Zip(l2, (r1, r2) => r1 != r2).Any(); 442 } 443 #endregion 395 444 } 396 445 } -
trunk/sources/HeuristicLab.Optimization/3.3/RunCollectionModificationEvaluator.cs
r6677 r6693 48 48 #endregion 49 49 50 [StorableHook(HookType.AfterDeserialization)] 51 private void AfterDeserialization() { 52 if (RunCollection != null && RunCollection.Modifiers != null) { 53 RunCollection.Modifiers.AddRange(Modifiers); 54 foreach (var modifier in RunCollection.Modifiers) { 55 RunCollection.Modifiers.SetItemCheckedState(modifier, Modifiers.ItemChecked(modifier)); 56 } 57 Modifiers.Clear(); 58 } 59 } 60 50 61 public void Evaluate() { 51 62 RunCollection.UpdateOfRunsInProgress = true; 52 var runs = RunCollection.Select((r, i) => new { Run = r, r.Visible, Index = i}).ToList();63 var runs = RunCollection.Select((r, i) => new { Run = r, r.Visible, Index = i }).ToList(); 53 64 var visibleRuns = runs.Where(r => r.Visible).Select(r => r.Run).ToList(); 54 65 int n = visibleRuns.Count; … … 73 84 RunCollection.AddRange(newRuns); 74 85 } else if (runs.Count > 0) { // force update 75 var run = (IRun) 86 var run = (IRun)runs[0].Run.Clone(); 76 87 RunCollection.Add(run); 77 88 RunCollection.Remove(run);
Note: See TracChangeset
for help on using the changeset viewer.