Changeset 8006


Ignore:
Timestamp:
06/14/12 10:46:19 (7 years ago)
Author:
svonolfe
Message:

Derived VRP from Problem base class (#1177)

Location:
trunk/sources/HeuristicLab.Problems.VehicleRouting/3.4
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Problems.VehicleRouting/3.4/Interfaces/IVRPProblemInstance.cs

    r7852 r8006  
    3131namespace HeuristicLab.Problems.VehicleRouting.Interfaces {
    3232  public interface IVRPProblemInstance: IItem {
    33     IVRPEvaluator SolutionEvaluator { get; }
     33    IVRPEvaluator SolutionEvaluator { get; set; }
    3434    IVRPEvaluator MoveEvaluator { get; }
    3535    IEnumerable<IOperator> Operators { get; }
  • trunk/sources/HeuristicLab.Problems.VehicleRouting/3.4/ProblemInstances/VRPProblemInstance.cs

    r7934 r8006  
    174174        return evaluator;
    175175      }
     176
     177      set {
     178        moveEvaluator = null;
     179        evaluator = value;
     180        EvalBestKnownSolution();
     181      }
    176182    }
    177183
  • trunk/sources/HeuristicLab.Problems.VehicleRouting/3.4/VehicleRoutingProblem.cs

    r7999 r8006  
    4141  [Creatable("Problems")]
    4242  [StorableClass]
    43   public sealed class VehicleRoutingProblem : ParameterizedNamedItem, ISingleObjectiveHeuristicOptimizationProblem, IStorableContent, IProblemInstanceConsumer<IVRPData> {
     43  public sealed class VehicleRoutingProblem : Problem, ISingleObjectiveHeuristicOptimizationProblem, IStorableContent, IProblemInstanceConsumer<IVRPData> {
    4444    public string Filename { get; set; }
    4545
     
    107107    public ISolutionCreator SolutionCreator {
    108108      get { return SolutionCreatorParameter.Value; }
    109     }
    110 
    111     [Storable]
    112     private List<IItem> operators;
    113 
    114     public IEnumerable<IItem> Operators {
    115       get { return operators; }
    116109    }
    117110    #endregion
     
    131124      EvaluatorParameter.Hidden = true;
    132125
    133       operators = new List<IItem>();
    134 
    135126      InitializeRandomVRPInstance();
    136127      InitializeOperators();
     
    147138    private VehicleRoutingProblem(VehicleRoutingProblem original, Cloner cloner)
    148139      : base(original, cloner) {
    149       this.operators = original.operators.Select(x => (IItem)cloner.Clone(x)).ToList();
    150140      this.AttachEventHandlers();
    151141    }
     
    162152      if (handler != null) handler(this, EventArgs.Empty);
    163153    }
    164     public event EventHandler OperatorsChanged;
    165     private void OnOperatorsChanged() {
    166       EventHandler handler = OperatorsChanged;
    167       if (handler != null) handler(this, EventArgs.Empty);
    168     }
    169     public event EventHandler Reset;
    170     private void OnReset() {
    171       EventHandler handler = Reset;
    172       if (handler != null) handler(this, EventArgs.Empty);
    173     }
    174154    #endregion
    175155
     
    181161    }
    182162
     163    [Storable(Name = "operators", AllowOneWay = true)]
     164    private List<IOperator> StorableOperators {
     165      set { Operators.AddRange(value); }
     166    }
     167
    183168    private void AttachEventHandlers() {
    184169      ProblemInstanceParameter.ValueChanged += new EventHandler(ProblemInstanceParameter_ValueChanged);
    185170      BestKnownSolutionParameter.ValueChanged += new EventHandler(BestKnownSolutionParameter_ValueChanged);
     171      EvaluatorParameter.ValueChanged += new EventHandler(EvaluatorParameter_ValueChanged);
     172      SolutionCreatorParameter.ValueChanged += new EventHandler(SolutionCreatorParameter_ValueChanged);
    186173    }
    187174
     
    193180        EvaluatorParameter.Value = ProblemInstance.SolutionEvaluator;
    194181        IVRPCreator defaultCreator = null;
    195         foreach (IVRPCreator creator in operators.Where(o => o is IVRPCreator)) {
     182        foreach (IVRPCreator creator in Operators.Where(o => o is IVRPCreator)) {
    196183          solutionCreatorParameter.ValidValues.Add(creator);
    197184          if (creator is Encodings.Alba.RandomCreator)
     
    220207
    221208    void ProblemInstance_EvaluationChanged(object sender, EventArgs e) {
     209      EvaluatorParameter.Value = ProblemInstance.SolutionEvaluator;
    222210      EvalBestKnownSolution();
    223211    }
     
    245233
    246234    private void SolutionCreatorParameter_ValueChanged(object sender, EventArgs e) {
    247       ParameterizeSolutionCreator();
    248 
    249235      OnSolutionCreatorChanged();
    250236    }
    251237    private void EvaluatorParameter_ValueChanged(object sender, EventArgs e) {
     238      if (ProblemInstance != null)
     239        ProblemInstance.SolutionEvaluator = EvaluatorParameter.Value;
    252240      OnEvaluatorChanged();
    253241    }
    254242
    255243    private void InitializeOperators() {
    256       operators = new List<IItem>();
     244      Operators.Clear();
    257245
    258246      if (ProblemInstance != null) {
    259         operators.AddRange(
     247        Operators.AddRange(
    260248        ProblemInstance.Operators.Concat(
    261249          ApplicationManager.Manager.GetInstances<IGeneralVRPOperator>().Cast<IOperator>()).OrderBy(op => op.Name));
     
    263251
    264252      ParameterizeOperators();
    265     }
    266 
    267     private void ParameterizeSolutionCreator() {
    268       if (SolutionCreator is IMultiVRPOperator) {
    269         (SolutionCreator as IMultiVRPOperator).SetOperators(Operators.OfType<IOperator>());
    270       }
    271253    }
    272254
Note: See TracChangeset for help on using the changeset viewer.