- Timestamp:
- 09/01/11 15:51:30 (13 years ago)
- File:
-
- 1 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 }
Note: See TracChangeset
for help on using the changeset viewer.