Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/31/10 14:26:45 (15 years ago)
Author:
gkronber
Message:

Extracted view for artificial ant problem into a separate plugin/project. #952 (Artificial Ant Problem for 3.3)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Problems.ArtificialAnt/3.3/ArtificialAntProblem.cs

    r3238 r3239  
    4242    }
    4343
     44    #region constant for default world (Santa Fe)
     45    private readonly bool[,] santaFeAntTrail = new bool[,] {
     46      {false, true, true, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false},
     47      {false, false, false, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false},
     48      {false, false, false, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true, true, true, false, false, false, false},
     49      {false, false, false, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true, false, false, false, false, true, false, false},
     50      {false, false, false, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true, false, false, false, false, true, false, false},
     51      {false, false, false, true, true, true, true, false, true, true, true, true, true, false, false, false, false, false, false, false, false, true, true, false, false, false, false, false, false, false, false, false},
     52      {false, false, false, false, false, false, false, false, false, false, false, false, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true, false, false},
     53      {false, false, false, false, false, false, false, false, false, false, false, false, true, false, false, false, false, false, false, false, true, false, false, false, false, false, false, false, false, false, false, false},
     54      {false, false, false, false, false, false, false, false, false, false, false, false, true, false, false, false, false, false, false, false, true, false, false, false, false, false, false, false, false, false, false, false},
     55      {false, false, false, false, false, false, false, false, false, false, false, false, true, false, false, false, false, false, false, false, true, false, false, false, false, false, false, false, false, true, false, false},
     56      {false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true, false, false, false, false, false, false, false, false, false, false, false},
     57      {false, false, false, false, false, false, false, false, false, false, false, false, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false},
     58      {false, false, false, false, false, false, false, false, false, false, false, false, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true, false, false},
     59      {false, false, false, false, false, false, false, false, false, false, false, false, true, false, false, false, false, false, false, false, true, false, false, false, false, false, false, false, false, false, false, false},
     60      {false, false, false, false, false, false, false, false, false, false, false, false, true, false, false, false, false, false, false, false, true, false, false, false, false, false, true, true, true, false, false, false},
     61      {false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true, false, false, false, false, false, true, false, false, false, false, false, false, false, false},
     62      {false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false},
     63      {false, false, false, false, false, false, false, false, false, false, false, false, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false},
     64      {false, false, false, false, false, false, false, false, false, false, false, false, true, false, false, false, true, false, false, false, false, false, false, false, true, false, false, false, false, false, false, false},
     65      {false, false, false, false, false, false, false, false, false, false, false, false, true, false, false, false, true, false, false, false, false, false, false, false, false, false, false, true, false, false, false, false},
     66      {false, false, false, false, false, false, false, false, false, false, false, false, true, false, false, false, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false},
     67      {false, false, false, false, false, false, false, false, false, false, false, false, true, false, false, false, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false},
     68      {false, false, false, false, false, false, false, false, false, false, false, false, true, false, false, false, false, false, false, false, false, false, false, false, false, false, true, false, false, false, false, false},
     69      {false, false, false, false, false, false, false, false, false, false, false, false, true, false, false, false, false, false, false, false, false, false, false, true, false, false, false, false, false, false, false, false},
     70      {false, false, false, true, true, false, false, true, true, true, true, true, false, false, false, false, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false},
     71      {false, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false},
     72      {false, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false},
     73      {false, true, false, false, false, false, false, false, true, true, true, true, true, true, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false},
     74      {false, true, false, false, false, false, false, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false},
     75      {false, false, false, false, false, false, false, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false},
     76      {false, false, true, true, true, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false },
     77      {false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false }
     78    };
     79    #endregion
     80
    4481    #region Parameter Properties
    4582    public ValueParameter<BoolValue> MaximizationParameter {
     
    70107      get { return (ValueParameter<IntValue>)Parameters["MaxExpressionDepth"]; }
    71108    }
     109    public ValueParameter<BoolMatrix> WorldParameter {
     110      get { return (ValueParameter<BoolMatrix>)Parameters["World"]; }
     111    }
     112    public ValueParameter<IntValue> MaxTimeStepsParameter {
     113      get { return (ValueParameter<IntValue>)Parameters["MaxTimeSteps"]; }
     114    }
    72115
    73116    public OptionalValueParameter<IAntTrailVisualizer> VisualizerParameter {
     
    86129
    87130    #region Properties
     131    public BoolMatrix World {
     132      get { return WorldParameter.Value; }
     133      set { WorldParameter.Value = value; }
     134    }
     135    public IntValue MaxTimeSteps {
     136      get { return MaxTimeStepsParameter.Value; }
     137      set { MaxTimeStepsParameter.Value = value; }
     138    }
     139    public IntValue MaxExpressionLength {
     140      get { return MaxExpressionLengthParameter.Value; }
     141      set { MaxExpressionLengthParameter.Value = value; }
     142    }
     143    public IntValue MaxExpressionDepth {
     144      get { return MaxExpressionDepthParameter.Value; }
     145      set { MaxExpressionDepthParameter.Value = value; }
     146    }
    88147    public SymbolicExpressionTreeCreator SolutionCreator {
    89148      get { return SolutionCreatorParameter.Value; }
     
    116175      get { return BestKnownQualityParameter.Value; }
    117176    }
    118     private List<IOperator> operators;
     177    private List<ISymbolicExpressionTreeOperator> operators;
    119178    public IEnumerable<IOperator> Operators {
    120       get { return operators; }
     179      get { return operators.Cast<IOperator>(); }
    121180    }
    122181    #endregion
     
    128187      ArtificialAntExpressionGrammar grammar = new ArtificialAntExpressionGrammar();
    129188      BestAntTrailVisualizer visualizer = new BestAntTrailVisualizer();
    130 
     189      BoolMatrix world = new BoolMatrix(santaFeAntTrail);
    131190      Parameters.Add(new ValueParameter<BoolValue>("Maximization", "Set to true as the Artificial Ant Problem is a maximization problem.", new BoolValue(true)));
    132191      Parameters.Add(new ValueParameter<SymbolicExpressionTreeCreator>("SolutionCreator", "The operator which should be used to create new artificial ant solutions.", creator));
     
    136195      Parameters.Add(new ValueParameter<IntValue>("MaxExpressionLength", "Maximal length of the expression to control the artificial ant.", new IntValue(100)));
    137196      Parameters.Add(new ValueParameter<IntValue>("MaxExpressionDepth", "Maximal depth of the expression to control the artificial ant.", new IntValue(10)));
     197      Parameters.Add(new ValueParameter<BoolMatrix>("World", "The world for the artificial ant with scattered food items.", world));
     198      Parameters.Add(new ValueParameter<IntValue>("MaxTimeSteps", "The number of time steps the artificial ant has available to collect all food items.", new IntValue(600)));
    138199      Parameters.Add(new ValueParameter<IAntTrailVisualizer>("Visualizer", "The operator which should be used to visualize artificial ant solutions.", visualizer));
    139200
     
    159220    public event EventHandler SolutionCreatorChanged;
    160221    private void OnSolutionCreatorChanged() {
    161       if (SolutionCreatorChanged != null)
    162         SolutionCreatorChanged(this, EventArgs.Empty);
     222      var changed = SolutionCreatorChanged;
     223      if (changed != null)
     224        changed(this, EventArgs.Empty);
    163225    }
    164226    public event EventHandler EvaluatorChanged;
    165227    private void OnEvaluatorChanged() {
    166       if (EvaluatorChanged != null)
    167         EvaluatorChanged(this, EventArgs.Empty);
     228      var changed = EvaluatorChanged;
     229      if (changed != null)
     230        changed(this, EventArgs.Empty);
    168231    }
    169232    public event EventHandler VisualizerChanged;
    170233    private void OnVisualizerChanged() {
    171       if (VisualizerChanged != null)
    172         VisualizerChanged(this, EventArgs.Empty);
     234      var changed = VisualizerChanged;
     235      if (changed != null)
     236        changed(this, EventArgs.Empty);
    173237    }
    174238
    175239    public event EventHandler OperatorsChanged;
    176240    private void OnOperatorsChanged() {
    177       if (OperatorsChanged != null)
    178         OperatorsChanged(this, EventArgs.Empty);
     241      var changed = OperatorsChanged;
     242      if (changed != null)
     243        changed(this, EventArgs.Empty);
    179244    }
    180245
     
    183248      ParameterizeSolutionCreator();
    184249      ParameterizeEvaluator();
     250      ParameterizeVisualizer();
    185251      ParameterizeOperators();
    186252      OnSolutionCreatorChanged();
     
    188254    private void SolutionCreator_SymbolicExpressionTreeParameter_ActualNameChanged(object sender, EventArgs e) {
    189255      ParameterizeEvaluator();
     256      ParameterizeVisualizer();
    190257      ParameterizeOperators();
    191258    }
    192259    private void EvaluatorParameter_ValueChanged(object sender, EventArgs e) {
     260      Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
    193261      ParameterizeEvaluator();
     262      ParameterizeVisualizer();
    194263      OnEvaluatorChanged();
    195264    }
     265
     266    private void VisualizerParameter_ValueChanged(object sender, EventArgs e) {
     267      ParameterizeVisualizer();
     268      OnVisualizerChanged();
     269    }
     270
     271    private void Evaluator_QualityParameter_ActualNameChanged(object sender, EventArgs e) {
     272      ParameterizeVisualizer();
     273    }
     274
    196275    #endregion
    197276
     
    203282      SolutionCreator.SymbolicExpressionTreeParameter.ActualNameChanged += new EventHandler(SolutionCreator_SymbolicExpressionTreeParameter_ActualNameChanged);
    204283      EvaluatorParameter.ValueChanged += new EventHandler(EvaluatorParameter_ValueChanged);
    205     }
     284      Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
     285      VisualizerParameter.ValueChanged += new EventHandler(VisualizerParameter_ValueChanged);
     286    }
     287
     288    private void InitializeOperators() {
     289      operators = new List<ISymbolicExpressionTreeOperator>();
     290      operators.AddRange(ApplicationManager.Manager.GetInstances<ISymbolicExpressionTreeOperator>());
     291      ParameterizeOperators();
     292    }
     293
    206294    private void ParameterizeSolutionCreator() {
    207295      SolutionCreator.SymbolicExpressionGrammarParameter.ActualName = ArtificialAntExpressionGrammarParameter.Name;
     296      SolutionCreator.MaxTreeHeightParameter.ActualName = MaxExpressionDepthParameter.Name;
     297      SolutionCreator.MaxTreeSizeParameter.ActualName = MaxExpressionLengthParameter.Name;
    208298    }
    209299    private void ParameterizeEvaluator() {
    210300      Evaluator.SymbolicExpressionTreeParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName;
    211     }
    212     private void InitializeOperators() {
    213       operators = new List<IOperator>();
    214       operators.Add(Evaluator);
    215       operators.Add(SolutionCreator);
    216       operators.Add(new SubtreeCrossover());
    217       ParameterizeOperators();
     301      Evaluator.MaxTimeStepsParameter.ActualName = MaxTimeStepsParameter.Name;
     302      Evaluator.WorldParameter.ActualName = WorldParameter.Name;
     303    }
     304    private void ParameterizeVisualizer() {
     305      if (Visualizer != null) {
     306        Visualizer.QualityParameter.ActualName = Evaluator.QualityParameter.ActualName;
     307        var antTrailVisualizer = Visualizer as IAntTrailVisualizer;
     308        if (antTrailVisualizer != null) {
     309          antTrailVisualizer.SymbolicExpressionTreeParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName;
     310          antTrailVisualizer.WorldParameter.ActualName = WorldParameter.Name;
     311          antTrailVisualizer.MaxTimeStepsParameter.ActualName = MaxTimeStepsParameter.Name;
     312        }
     313      }
    218314    }
    219315
    220316    private void ParameterizeOperators() {
    221       foreach (ProbabilisticTreeCreator op in Operators.OfType<ProbabilisticTreeCreator>()) {
     317      foreach (ISymbolicExpressionTreeOperator op in Operators.OfType<ISymbolicExpressionTreeOperator>()) {
    222318        op.MaxTreeHeightParameter.ActualName = MaxExpressionDepthParameter.Name;
    223319        op.MaxTreeSizeParameter.ActualName = MaxExpressionLengthParameter.Name;
     
    226322      foreach (Evaluator op in Operators.OfType<Evaluator>()) {
    227323        op.SymbolicExpressionTreeParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName;
     324        op.MaxTimeStepsParameter.ActualName = MaxTimeStepsParameter.Name;
     325        op.WorldParameter.ActualName = WorldParameter.Name;
    228326      }
    229327      foreach (SymbolicExpressionTreeCrossover op in Operators.OfType<SymbolicExpressionTreeCrossover>()) {
    230         op.MaxTreeHeightParameter.ActualName = MaxExpressionDepthParameter.Name;
    231         op.MaxTreeSizeParameter.ActualName = MaxExpressionLengthParameter.Name;
    232         op.SymbolicExpressionGrammarParameter.ActualName = ArtificialAntExpressionGrammarParameter.Name;
    233328        op.ParentsParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName;
    234329        op.ChildParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName;
    235330      }
    236331    }
    237     private void ParameterizeVisualizer() {
    238       if (Visualizer != null) {
    239         Visualizer.QualityParameter.ActualName = Evaluator.QualityParameter.ActualName;
    240         if (Visualizer is IAntTrailVisualizer)
    241           ((IAntTrailVisualizer)Visualizer).SymbolicExpressionTreeParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName;
    242       }
    243     }
     332
    244333
    245334    #endregion
Note: See TracChangeset for help on using the changeset viewer.