Free cookie consent management tool by TermsFeed Policy Generator

Changeset 17718


Ignore:
Timestamp:
08/05/20 05:46:07 (4 years ago)
Author:
abeham
Message:

#2521: completed port of VRP (needs testing though)

Location:
branches/2521_ProblemRefactoring
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • branches/2521_ProblemRefactoring/HeuristicLab.Collections/3.3/ObservableCollection.cs

    r17461 r17718  
    103103        if (list.Capacity != capacity)
    104104          OnPropertyChanged("Capacity");
    105         OnPropertyChanged("Item[]");
    106         OnPropertyChanged("Count");
    107       }
     105        OnPropertyChanged("Count");
     106      }
     107    }
     108
     109    /// <summary>
     110    /// Performs a Clear and an AddRange, but does not fire separate events for those operations
     111    /// </summary>
     112    /// <param name="collection"></param>
     113    public void Replace(IEnumerable<T> collection) {
     114      List<T> oldItems = null;
     115      if (list.Any()) oldItems = new List<T>(list);
     116      else oldItems = new List<T>();
     117
     118      int oldCapacity = list.Capacity;
     119      list.Clear();
     120      list.AddRange(collection);
     121
     122      List<T> items = null;
     123      if (list.Any()) items = new List<T>(list);
     124      else items = new List<T>();
     125
     126      OnCollectionReset(items, oldItems);
     127      if (oldCapacity != list.Capacity) OnPropertyChanged("Capacity");
     128      if (oldItems.Count != items.Count) OnPropertyChanged("Count");
    108129    }
    109130
  • branches/2521_ProblemRefactoring/HeuristicLab.Collections/3.3/ObservableSet.cs

    r17226 r17718  
    128128        OnItemsRemoved(items);
    129129      }
     130    }
     131
     132    /// <summary>
     133    /// Performs a Clear and an Add, but does not fire separate events for those operations
     134    /// </summary>
     135    /// <param name="other"></param>
     136    public void Replace(IEnumerable<T> other) {
     137      List<T> oldItems = null;
     138      if (set.Any()) oldItems = new List<T>(set);
     139      else oldItems = new List<T>();
     140
     141      set.Clear();
     142      set.UnionWith(other);
     143
     144      List<T> items = null;
     145      if (set.Any()) items = new List<T>(set);
     146      else items = new List<T>();
     147
     148      OnCollectionReset(items, oldItems);
     149      if (oldItems.Count != items.Count) OnPropertyChanged("Count");
    130150    }
    131151
  • branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/BasicProblems/Encoding.cs

    r17699 r17718  
    8282    }
    8383
     84    protected void ReplaceOperators(IEnumerable<IOperator> operators) {
     85      encodingOperators.Replace(operators);
     86    }
     87
    8488    public void ConfigureOperator(IItem @operator) { ConfigureOperators(new[] { @operator }); }
    8589    public virtual void ConfigureOperators(IEnumerable<IItem> operators) {
  • branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/Results/ResultParameter.cs

    r17715 r17718  
    121121      if (result.Value != null && resultValue == null)
    122122        throw new InvalidOperationException(string.Format("Type mismatch. Result \"{0}\" does not contain a \"{1}\".", ActualName, typeof(T).GetPrettyName()));
    123 
     123      else if (result.Value == null && DefaultValue != null) {
     124        result.Value = resultValue = (T)DefaultValue.Clone();
     125      }
    124126      return resultValue;
    125127    }
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Alba/AlbaEncoding.cs

    r17714 r17718  
    2727using HeuristicLab.Core;
    2828using HeuristicLab.PluginInfrastructure;
     29using HeuristicLab.Problems.VehicleRouting.Encodings.General;
    2930using HeuristicLab.Problems.VehicleRouting.Interfaces;
    3031
     
    5657          typeof (IAlbaOperator),
    5758          typeof (IVRPCreator),
    58           typeof (IMultiVRPOperator)
     59          typeof (IMultiVRPOperator),
     60          typeof (IMultiVRPMoveOperator)
    5961      };
    6062    }
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/GVR/GVREncoding.cs

    r17714 r17718  
    2727using HeuristicLab.Core;
    2828using HeuristicLab.PluginInfrastructure;
     29using HeuristicLab.Problems.VehicleRouting.Encodings.General;
    2930using HeuristicLab.Problems.VehicleRouting.Interfaces;
    3031
     
    5657          typeof (IGVROperator),
    5758          typeof (IVRPCreator),
    58           typeof (IMultiVRPOperator)
     59          typeof (IMultiVRPOperator),
     60          typeof (IMultiVRPMoveOperator)
    5961      };
    6062    }
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Potvin/PotvinEncoding.cs

    r17714 r17718  
    2727using HeuristicLab.Core;
    2828using HeuristicLab.PluginInfrastructure;
     29using HeuristicLab.Problems.VehicleRouting.Encodings.General;
    2930using HeuristicLab.Problems.VehicleRouting.Interfaces;
    3031
     
    5657          typeof (IPotvinOperator),
    5758          typeof (IVRPCreator),
    58           typeof (IMultiVRPOperator)
     59          typeof (IMultiVRPOperator),
     60          typeof (IMultiVRPMoveOperator)
    5961      };
    6062    }
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Prins/PrinsEncoding.cs

    r17714 r17718  
    2727using HeuristicLab.Core;
    2828using HeuristicLab.PluginInfrastructure;
     29using HeuristicLab.Problems.VehicleRouting.Encodings.General;
    2930using HeuristicLab.Problems.VehicleRouting.Interfaces;
    3031
     
    5657          typeof (IPrinsOperator),
    5758          typeof (IVRPCreator),
    58           typeof (IMultiVRPOperator)
     59          typeof (IMultiVRPOperator),
     60          typeof (IMultiVRPMoveOperator)
    5961      };
    6062    }
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/VRPEncoding.cs

    r17711 r17718  
    3939    public void FilterOperators(IVRPProblemInstance instance) {
    4040      DiscoverOperators();
    41       var operators = instance.FilterOperators(Operators);
    42       foreach (var op in Operators.Except(operators).ToList()) {
    43         RemoveOperator(op);
     41      var operators = instance.FilterOperators(Operators).ToList();
     42      foreach (var op in operators.OfType<IMultiVRPOperator>().ToList()) {
     43        var subOps = instance.FilterOperators(op.Operators).ToList();
     44        if (subOps.Count == 0) operators.Remove(op);
     45        else {
     46          foreach (var dm in op.Operators.Except(subOps).ToList())
     47            op.RemoveOperator(dm);
     48        }
    4449      }
     50      ReplaceOperators(operators);
    4551    }
    4652
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Zhu/ZhuEncoding.cs

    r17714 r17718  
    2727using HeuristicLab.Core;
    2828using HeuristicLab.PluginInfrastructure;
     29using HeuristicLab.Problems.VehicleRouting.Encodings.General;
    2930using HeuristicLab.Problems.VehicleRouting.Interfaces;
    3031
     
    5657          typeof (IZhuOperator),
    5758          typeof (IVRPCreator),
    58           typeof (IMultiVRPOperator)
     59          typeof (IMultiVRPOperator),
     60          typeof (IMultiVRPMoveOperator)
    5961      };
    6062    }
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.VehicleRouting/3.4/VehicleRoutingProblem.cs

    r17717 r17718  
    204204      Encoding.FilterOperators(ProblemInstance);
    205205
    206       var newOps = new List<IItem>();
    207       var operatorTypes = new HashSet<Type>(Operators.Select(x => x.GetType()));
     206      var newOps = ProblemInstance.FilterOperators(Operators.OfType<IOperator>())
     207        .Union(Operators.Where(x => !(x is IOperator) || x.GetType().Namespace.StartsWith("HeuristicLab.Optimization")))
     208        .ToList();
     209      var operatorTypes = new HashSet<Type>(newOps.Select(x => x.GetType()));
    208210      if (operatorTypes.Add(typeof(VRPSimilarityCalculator)))
    209211        newOps.Add(new VRPSimilarityCalculator());
     
    214216
    215217      var assembly = typeof(VehicleRoutingProblem).Assembly;
    216       var operators = ApplicationManager.Manager.GetTypes(new[] { typeof(IAnalyzer) }, assembly, true, false, false)
     218      var analyzers = ApplicationManager.Manager.GetTypes(new[] { typeof(IAnalyzer) }, assembly, true, false, false)
    217219        .Where(x => operatorTypes.Add(x)).Select(t => (IOperator)Activator.CreateInstance(t)).ToList();
    218       newOps.AddRange(ProblemInstance.FilterOperators(operators));
    219 
    220       Operators.AddRange(newOps);
     220      newOps.AddRange(ProblemInstance.FilterOperators(analyzers));
     221     
     222      Operators.Replace(newOps);
    221223    }
    222224
Note: See TracChangeset for help on using the changeset viewer.