Changeset 7852


Ignore:
Timestamp:
05/21/12 13:46:48 (7 years ago)
Author:
svonolfe
Message:

Moved parameters from the ProblemInstance to the Problem (#1177)

Location:
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/General/Moves/VRPMoveMaker.cs

    r6607 r7852  
    6363
    6464    private void UpdateMoveEvaluation() {
    65       IVRPEvaluator evaluator = ProblemInstance.EvaluatorParameter.Value;
     65      IVRPEvaluator evaluator = ProblemInstance.SolutionEvaluator;
    6666      ICollection<IParameter> addedParameters = new List<IParameter>();
    6767     
  • branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Interfaces/IVRPProblemInstance.cs

    r6854 r7852  
    3131namespace HeuristicLab.Problems.VehicleRouting.Interfaces {
    3232  public interface IVRPProblemInstance: IItem {
    33     IValueParameter<IVRPEvaluator> EvaluatorParameter { get; }
     33    IVRPEvaluator SolutionEvaluator { get; }
    3434    IVRPEvaluator MoveEvaluator { get; }
    35     IValueParameter<IVRPCreator> SolutionCreatorParameter { get; }
    36     IValueParameter<DoubleValue> BestKnownQualityParameter { get; }
    37     IValueParameter<VRPSolution> BestKnownSolutionParameter { get; }
    3835    IEnumerable<IOperator> Operators { get; }
     36
     37    event EventHandler EvaluationChanged;
    3938
    4039    DoubleMatrix Coordinates { get; }
  • branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/ProblemInstances/MultiDepotVRP/MDCVRP/MDCVRPProblemInstance.cs

    r6851 r7852  
    119119    #region Event handlers
    120120    void CapacityParameter_ValueChanged(object sender, EventArgs e) {
    121       BestKnownSolution = null;
     121      EvalBestKnownSolution();
    122122    }
    123123    void OverloadPenaltyParameter_ValueChanged(object sender, EventArgs e) {
  • branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/ProblemInstances/SingleDepotVRP/CVRP/CVRPProblemInstance.cs

    r6711 r7852  
    121121    void CapacityParameter_ValueChanged(object sender, EventArgs e) {
    122122      CapacityParameter.Value.ValueChanged += new EventHandler(Capacity_ValueChanged);
    123       BestKnownSolution = null;
     123      EvalBestKnownSolution();
    124124    }
    125125    void Capacity_ValueChanged(object sender, EventArgs e) {
    126       BestKnownSolution = null;
     126      EvalBestKnownSolution();
    127127    }
    128128    void OverloadPenaltyParameter_ValueChanged(object sender, EventArgs e) {
  • branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/ProblemInstances/VRPProblemInstance.cs

    r7543 r7852  
    3838  [StorableClass]
    3939  public abstract class VRPProblemInstance : ParameterizedNamedItem, IVRPProblemInstance, IStatefulItem {
    40     public IValueParameter<IVRPEvaluator> EvaluatorParameter {
    41       get { return (ValueParameter<IVRPEvaluator>)Parameters["Evaluator"]; }
    42     }
    43 
    4440    IVRPEvaluator moveEvaluator;
    4541
    4642    public IVRPEvaluator MoveEvaluator {
    4743      get {
    48         if (EvaluatorParameter.Value == null)
     44        if (evaluator == null)
    4945          return null;
    5046        else {
    5147          if (moveEvaluator == null) {
    52             moveEvaluator = EvaluatorParameter.Value.Clone() as IVRPEvaluator;
     48            moveEvaluator = evaluator.Clone() as IVRPEvaluator;
    5349
    5450            foreach (IParameter parameter in moveEvaluator.Parameters) {
     
    6864    }
    6965
    70     public IValueParameter<IVRPCreator> SolutionCreatorParameter {
    71       get { return (ValueParameter<IVRPCreator>)Parameters["SolutionCreator"]; }
    72     }
    73 
    7466    protected abstract IEnumerable<IOperator> GetOperators();
    7567    protected abstract IEnumerable<IOperator> GetAnalyzers();
     
    10496    }
    10597
    106     protected OptionalValueParameter<DoubleValue> BestKnownQualityParameter {
    107       get { return (OptionalValueParameter<DoubleValue>)Parameters["BestKnownQuality"]; }
    108     }
    109     protected OptionalValueParameter<VRPSolution> BestKnownSolutionParameter {
    110       get { return (OptionalValueParameter<VRPSolution>)Parameters["BestKnownSolution"]; }
    111     }
    112 
    113     IValueParameter<DoubleValue> IVRPProblemInstance.BestKnownQualityParameter {
    114       get { return BestKnownQualityParameter; }
    115     }
    116 
    117     IValueParameter<VRPSolution> IVRPProblemInstance.BestKnownSolutionParameter {
    118       get { return BestKnownSolutionParameter; }
    119     }
    120 
    12198    public DoubleMatrix Coordinates {
    12299      get { return CoordinatesParameter.Value; }
     
    151128      get { return DistanceFactorParameter.Value; }
    152129      set { DistanceFactorParameter.Value = value; }
    153     }
    154 
    155     public DoubleValue BestKnownQuality {
    156       get { return BestKnownQualityParameter.Value; }
    157       set { BestKnownQualityParameter.Value = value; }
    158     }
    159     public VRPSolution BestKnownSolution {
    160       get { return BestKnownSolutionParameter.Value; }
    161       set { BestKnownSolutionParameter.Value = value; }
    162130    }
    163131
     
    205173    private IVRPEvaluator evaluator = null;
    206174
     175    public IVRPEvaluator SolutionEvaluator {
     176      get {       
     177        return evaluator;
     178      }
     179    }
     180
    207181    public virtual double GetDistance(int start, int end, IVRPEncoding solution) {
    208182      double distance = 0.0;
     
    259233    }
    260234
     235
     236    public event EventHandler EvaluationChanged;
     237
    261238    protected void EvalBestKnownSolution() {
    262       if (BestKnownSolution != null) {
    263         //call evaluator
    264         BestKnownQuality = new DoubleValue(Evaluate(BestKnownSolution.Solution).Quality);
    265         BestKnownSolution.Quality = BestKnownQuality;
    266       } else {
    267         BestKnownQuality = null;
    268       }
     239      EventHandler tmp = EvaluationChanged;
     240      if (tmp != null)
     241        tmp(this, null);
    269242    }
    270243
     
    286259      Parameters.Add(new ValueParameter<DoubleValue>("EvalDistanceFactor", "The distance factor considered in the evaluation.", new DoubleValue(1)));
    287260
    288       Parameters.Add(new ValueParameter<IVRPCreator>("SolutionCreator", "The operator which should be used to create new VRP solutions.", Creator));
    289       Parameters.Add(new ValueParameter<IVRPEvaluator>("Evaluator", "The operator which should be used to evaluate VRP solutions.", Evaluator));
    290 
    291       Parameters.Add(new OptionalValueParameter<DoubleValue>("BestKnownQuality", "The quality of the best known solution of this VRP instance."));
    292       Parameters.Add(new OptionalValueParameter<VRPSolution>("BestKnownSolution", "The best known solution of this VRP instance."));
    293 
     261      evaluator = Evaluator;
    294262      AttachEventHandlers();
    295263    }
     
    297265    protected VRPProblemInstance(VRPProblemInstance original, Cloner cloner)
    298266      : base(original, cloner) {
    299         AttachEventHandlers();
     267      evaluator = Evaluator; 
     268      AttachEventHandlers();
    300269    }
    301270
    302271    [StorableHook(HookType.AfterDeserialization)]
    303272    private void AfterDeserializationHook() {
     273      evaluator = Evaluator;
    304274      AttachEventHandlers();
    305275    }
    306276
    307277    private void AttachEventHandlers() {
    308       evaluator = EvaluatorParameter.Value;
    309       EvaluatorParameter.ValueChanged += new EventHandler(EvaluatorParameter_ValueChanged);
    310       BestKnownSolutionParameter.ValueChanged += new EventHandler(BestKnownSolutionParameter_ValueChanged);
    311278      DistanceFactorParameter.ValueChanged += new EventHandler(DistanceFactorParameter_ValueChanged);
    312279      DistanceFactorParameter.Value.ValueChanged += new EventHandler(DistanceFactor_ValueChanged);
     
    329296
    330297    #region Event handlers
    331     void EvaluatorParameter_ValueChanged(object sender, EventArgs e) {
    332       moveEvaluator = null;
    333       evaluator = EvaluatorParameter.Value;
    334     }
    335 
    336     void BestKnownSolutionParameter_ValueChanged(object sender, EventArgs e) {
    337       EvalBestKnownSolution();
    338     }
    339298    void DistanceFactorParameter_ValueChanged(object sender, EventArgs e) {
    340299      DistanceFactorParameter.Value.ValueChanged += new EventHandler(DistanceFactor_ValueChanged);
  • branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/VehicleRoutingProblem.cs

    r7203 r7852  
    9292    }
    9393
     94    public DoubleValue BestKnownQuality {
     95      get { return BestKnownQualityParameter.Value; }
     96      set { BestKnownQualityParameter.Value = value; }
     97    }
     98
    9499    public ISingleObjectiveEvaluator Evaluator {
    95       get { return ProblemInstance.EvaluatorParameter.Value; }
     100      get { return EvaluatorParameter.Value; }
    96101    }
    97102
     
    101106
    102107    public ISolutionCreator SolutionCreator {
    103       get { return ProblemInstance.SolutionCreatorParameter.Value; }
     108      get { return SolutionCreatorParameter.Value; }
    104109    }
    105110
     
    121126      Parameters.Add(new OptionalValueParameter<VRPSolution>("BestKnownSolution", "The best known solution of this VRP instance."));
    122127
     128      Parameters.Add(new ConstrainedValueParameter<IVRPCreator>("SolutionCreator", "The operator which should be used to create new VRP solutions."));
     129      Parameters.Add(new ValueParameter<IVRPEvaluator>("Evaluator", "The operator which should be used to evaluate VRP solutions."));
     130
     131      EvaluatorParameter.Hidden = true;
     132
    123133      operators = new List<IOperator>();
    124134
     
    175185
    176186    private void AttachProblemInstanceEventHandlers() {
    177       if (Parameters.ContainsKey("Evaluator"))
    178         Parameters.Remove("Evaluator");
    179 
    180       if (Parameters.ContainsKey("SolutionCreator"))
    181         Parameters.Remove("SolutionCreator");
    182 
    183       if (Parameters.ContainsKey("BestKnownSolution"))
    184         Parameters.Remove("BestKnownSolution");
    185 
    186       if (Parameters.ContainsKey("BestKnownQuality"))
    187         Parameters.Remove("BestKnownQuality");
    188 
     187      var solutionCreatorParameter = SolutionCreatorParameter as ConstrainedValueParameter<IVRPCreator>;
     188      solutionCreatorParameter.ValidValues.Clear();
    189189
    190190      if (ProblemInstance != null) {
    191         ProblemInstance.SolutionCreatorParameter.ValueChanged += new EventHandler(SolutionCreatorParameter_ValueChanged);
    192         ProblemInstance.EvaluatorParameter.ValueChanged += new EventHandler(EvaluatorParameter_ValueChanged);
    193         Parameters.Add(ProblemInstance.EvaluatorParameter);
    194         Parameters.Add(ProblemInstance.SolutionCreatorParameter);
    195 
    196         Parameters.Add(ProblemInstance.BestKnownQualityParameter);
    197         Parameters.Add(ProblemInstance.BestKnownSolutionParameter);
     191        EvaluatorParameter.Value = ProblemInstance.SolutionEvaluator;
     192        foreach (IVRPCreator creator in ProblemInstance.Operators.Where(o => o is IVRPCreator)) {
     193          solutionCreatorParameter.ValidValues.Add(creator);
     194        }
     195        ProblemInstance.EvaluationChanged += new EventHandler(ProblemInstance_EvaluationChanged);
     196      }     
     197    }
     198
     199    void ProblemInstance_EvaluationChanged(object sender, EventArgs e) {
     200      if (BestKnownSolution != null) {
     201        //call evaluator
     202        BestKnownQuality = new DoubleValue(ProblemInstance.Evaluate(BestKnownSolution.Solution).Quality);
     203        BestKnownSolution.Quality = BestKnownQuality;
     204      } else {
     205        BestKnownQuality = null;
    198206      }
    199207    }
     
    260268      parser.Parse();
    261269
     270      this.Name = parser.ProblemName;
    262271      MDCVRPTWProblemInstance problem = new MDCVRPTWProblemInstance();
    263272
     
    291300      parser.Parse();
    292301
     302      this.Name = parser.ProblemName;
    293303      CVRPPDTWProblemInstance problem = new CVRPPDTWProblemInstance();
    294304
     
    444454      else {
    445455        VRPSolution solution = new VRPSolution(ProblemInstance, encoding, new DoubleValue(0));
    446         ProblemInstance.BestKnownSolutionParameter.Value = solution;
     456        BestKnownSolutionParameter.Value = solution;
    447457      }
    448458    }
Note: See TracChangeset for help on using the changeset viewer.