Free cookie consent management tool by TermsFeed Policy Generator

source: branches/DynamicVehicleRouting/HeuristicLab.PDPSimulation/3.3/Optimizers/LocalUpdate/TreePriorityDispatching.cs @ 13231

Last change on this file since 13231 was 8808, checked in by svonolfe, 12 years ago

Added symbolic tree dispatching and metaoptimization (#1955)

File size: 2.5 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Diagnostics;
4using System.Linq;
5using HeuristicLab.Common;
6using HeuristicLab.Core;
7using HeuristicLab.Encodings.RealVectorEncoding;
8using HeuristicLab.Parameters;
9using HeuristicLab.PDPSimulation.DomainModel;
10using HeuristicLab.PDPSimulation.Operators;
11using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
12using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
13using HeuristicLab.Problems.DataAnalysis.Symbolic;
14using HeuristicLab.Problems.DataAnalysis;
15
16namespace HeuristicLab.PDPSimulation {
17  [Item("TreePriorityDispatching", "")]
18  [StorableClass]
19  public class TreePriorityDispatching : PriorityDispatching {
20    public IValueLookupParameter<ISymbolicExpressionTree> SymbolicExpressionTreeParameter {
21      get { return (IValueLookupParameter<ISymbolicExpressionTree>)Parameters["SymbolicExpressionTree"]; }
22    }
23
24    public IValueLookupParameter<ISymbolicDataAnalysisExpressionTreeInterpreter> SymbolicDataAnalysisTreeInterpreterParameter {
25      get { return (IValueLookupParameter<ISymbolicDataAnalysisExpressionTreeInterpreter>)Parameters["SymbolicExpressionTreeInterpreter"]; }
26    }
27
28    [StorableConstructor]
29    protected TreePriorityDispatching(bool deserializing) : base(deserializing) { }
30    protected TreePriorityDispatching(PriorityDispatching original, Cloner cloner) : base(original, cloner) { }
31    public TreePriorityDispatching() {
32      Parameters.Add(new ValueLookupParameter<ISymbolicExpressionTree>("SymbolicExpressionTree", "The symbolic data analysis solution encoded as a symbolic expression tree."));
33      Parameters.Add(new ValueLookupParameter<ISymbolicDataAnalysisExpressionTreeInterpreter>("SymbolicExpressionTreeInterpreter", "The interpreter that should be used to calculate the output values of the symbolic data analysis tree."));
34    }
35
36    public override IDeepCloneable Clone(Cloner cloner) {
37      return new TreePriorityDispatching(this, cloner);
38    }
39
40    protected override double CalculatePriority(IDictionary<string, double> variables) {
41      var tree = SymbolicExpressionTreeParameter.Value;
42      var interpreter = SymbolicDataAnalysisTreeInterpreterParameter.Value;
43
44      Dataset ds = new Dataset(variables.Keys, variables.Values.Select(v => new List<double>(new double[] { v })));
45
46      List<int> rows = new List<int>();
47      rows.Add(0);
48
49      double prio = interpreter.GetSymbolicExpressionTreeValues(tree, ds, rows).First();
50
51      return prio;
52    }
53  }
54}
Note: See TracBrowser for help on using the repository browser.