[3238] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
| 3 | * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
| 4 | *
|
---|
| 5 | * This file is part of HeuristicLab.
|
---|
| 6 | *
|
---|
| 7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
| 8 | * it under the terms of the GNU General Public License as published by
|
---|
| 9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
| 10 | * (at your option) any later version.
|
---|
| 11 | *
|
---|
| 12 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 15 | * GNU General Public License for more details.
|
---|
| 16 | *
|
---|
| 17 | * You should have received a copy of the GNU General Public License
|
---|
| 18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
| 19 | */
|
---|
| 20 | #endregion
|
---|
| 21 |
|
---|
| 22 | using System;
|
---|
| 23 | using HeuristicLab.Common;
|
---|
| 24 | using HeuristicLab.Core;
|
---|
| 25 | using HeuristicLab.Data;
|
---|
| 26 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
| 27 | using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
|
---|
[3710] | 28 | using System.Drawing;
|
---|
[3238] | 29 |
|
---|
| 30 | namespace HeuristicLab.Problems.ArtificialAnt {
|
---|
| 31 | /// <summary>
|
---|
| 32 | /// Represents a trail of an artificial ant which can be visualized in the GUI.
|
---|
| 33 | /// </summary>
|
---|
| 34 | [Item("AntTrail", "Represents a trail of an artificial ant which can be visualized in the GUI.")]
|
---|
| 35 | [StorableClass]
|
---|
| 36 | public sealed class AntTrail : Item {
|
---|
[3710] | 37 | public override Image ItemImage {
|
---|
| 38 | get { return HeuristicLab.Common.Resources.VS2008ImageLibrary.Image; }
|
---|
| 39 | }
|
---|
[3317] | 40 | [Storable]
|
---|
[3238] | 41 | private SymbolicExpressionTree expression;
|
---|
| 42 | public SymbolicExpressionTree SymbolicExpressionTree {
|
---|
| 43 | get { return expression; }
|
---|
| 44 | set {
|
---|
| 45 | if (expression != value) {
|
---|
| 46 | //if (expression != null) DeregisterSymbolicExpressionTreeEvents();
|
---|
| 47 | expression = value;
|
---|
| 48 | //if (expression != null) RegisterSymbolicExpressionTreeEvents();
|
---|
| 49 | OnSymbolicExpressionTreeChanged();
|
---|
| 50 | }
|
---|
| 51 | }
|
---|
| 52 | }
|
---|
| 53 |
|
---|
[3317] | 54 | [Storable]
|
---|
[3239] | 55 | private BoolMatrix world;
|
---|
| 56 | public BoolMatrix World {
|
---|
| 57 | get { return world; }
|
---|
| 58 | set {
|
---|
| 59 | if (world != value) {
|
---|
| 60 | if (world != null) DeregisterWorldEvents();
|
---|
| 61 | world = value;
|
---|
| 62 | if (world != null) RegisterWorldEvents();
|
---|
| 63 | OnWorldChanged();
|
---|
| 64 | }
|
---|
| 65 | }
|
---|
| 66 | }
|
---|
[3317] | 67 | [Storable]
|
---|
[3239] | 68 | private IntValue maxTimeSteps;
|
---|
| 69 | public IntValue MaxTimeSteps {
|
---|
| 70 | get { return maxTimeSteps; }
|
---|
| 71 | set {
|
---|
| 72 | if (maxTimeSteps != value) {
|
---|
| 73 | if (maxTimeSteps != value) {
|
---|
| 74 | if (maxTimeSteps != null) DeregisterMaxTimeStepsEvents();
|
---|
| 75 | maxTimeSteps = value;
|
---|
| 76 | if (maxTimeSteps != null) RegisterMaxTimeStepsEvents();
|
---|
| 77 | OnWorldChanged();
|
---|
| 78 | }
|
---|
| 79 | }
|
---|
| 80 | }
|
---|
| 81 | }
|
---|
| 82 |
|
---|
[3238] | 83 | public AntTrail() : base() { }
|
---|
[3239] | 84 | public AntTrail(BoolMatrix world, SymbolicExpressionTree expression, IntValue maxTimeSteps)
|
---|
[3238] | 85 | : this() {
|
---|
[3317] | 86 | this.world = world;
|
---|
| 87 | this.expression = expression;
|
---|
| 88 | this.maxTimeSteps = maxTimeSteps;
|
---|
| 89 | Initialize();
|
---|
[3238] | 90 | }
|
---|
[3317] | 91 | [StorableConstructor]
|
---|
| 92 | private AntTrail(bool deserializing) : base(deserializing) { }
|
---|
[3238] | 93 |
|
---|
[3317] | 94 | [StorableHook(HookType.AfterDeserialization)]
|
---|
| 95 | private void Initialize() {
|
---|
| 96 | //if (expression != null) RegisterSymbolicExpressionTreeEvents();
|
---|
| 97 | if (world != null) RegisterWorldEvents();
|
---|
| 98 | if (maxTimeSteps != null) RegisterMaxTimeStepsEvents();
|
---|
| 99 | }
|
---|
| 100 |
|
---|
[3238] | 101 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
| 102 | AntTrail clone = new AntTrail();
|
---|
| 103 | cloner.RegisterClonedObject(this, clone);
|
---|
| 104 | clone.expression = (SymbolicExpressionTree)cloner.Clone(expression);
|
---|
[3239] | 105 | clone.world = (BoolMatrix)cloner.Clone(world);
|
---|
| 106 | clone.maxTimeSteps = (IntValue)cloner.Clone(maxTimeSteps);
|
---|
[3317] | 107 | clone.Initialize();
|
---|
[3238] | 108 | return clone;
|
---|
| 109 | }
|
---|
| 110 |
|
---|
[3239] | 111 | #region Events
|
---|
[3238] | 112 | public event EventHandler SymbolicExpressionTreeChanged;
|
---|
| 113 | private void OnSymbolicExpressionTreeChanged() {
|
---|
[3239] | 114 | var changed = SymbolicExpressionTreeChanged;
|
---|
| 115 | if (changed != null)
|
---|
| 116 | changed(this, EventArgs.Empty);
|
---|
[3238] | 117 | }
|
---|
[3239] | 118 | public event EventHandler WorldChanged;
|
---|
| 119 | private void OnWorldChanged() {
|
---|
| 120 | var changed = WorldChanged;
|
---|
| 121 | if (changed != null)
|
---|
| 122 | changed(this, EventArgs.Empty);
|
---|
| 123 | }
|
---|
| 124 | public event EventHandler MaxTimeStepsChanged;
|
---|
| 125 | private void OnMaxTimeStepsChanged() {
|
---|
| 126 | var changed = MaxTimeStepsChanged;
|
---|
| 127 | if (changed != null)
|
---|
| 128 | changed(this, EventArgs.Empty);
|
---|
| 129 | }
|
---|
[3238] | 130 |
|
---|
| 131 | //private void RegisterSymbolicExpressionTreeEvents() {
|
---|
| 132 | // SymbolicExpressionTree.ItemChanged += new EventHandler<EventArgs<int>>(SymbolicExpressionTree_ItemChanged);
|
---|
| 133 | // SymbolicExpressionTree.Reset += new EventHandler(SymbolicExpressionTree_Reset);
|
---|
| 134 | //}
|
---|
| 135 | //private void DeregisterSymbolicExpressionTreeEvents() {
|
---|
| 136 | // SymbolicExpressionTree.ItemChanged -= new EventHandler<EventArgs<int>>(SymbolicExpressionTree_ItemChanged);
|
---|
| 137 | // SymbolicExpressionTree.Reset -= new EventHandler(SymbolicExpressionTree_Reset);
|
---|
| 138 | //}
|
---|
| 139 |
|
---|
[3239] | 140 | private void RegisterWorldEvents() {
|
---|
| 141 | World.ItemChanged += new EventHandler<EventArgs<int, int>>(World_ItemChanged);
|
---|
| 142 | World.Reset += new EventHandler(World_Reset);
|
---|
| 143 | }
|
---|
| 144 | private void DeregisterWorldEvents() {
|
---|
| 145 | World.ItemChanged -= new EventHandler<EventArgs<int, int>>(World_ItemChanged);
|
---|
| 146 | World.Reset -= new EventHandler(World_Reset);
|
---|
| 147 | }
|
---|
| 148 | private void RegisterMaxTimeStepsEvents() {
|
---|
| 149 | MaxTimeSteps.ValueChanged += new EventHandler(MaxTimeSteps_ValueChanged);
|
---|
| 150 | }
|
---|
| 151 | private void DeregisterMaxTimeStepsEvents() {
|
---|
| 152 | MaxTimeSteps.ValueChanged -= new EventHandler(MaxTimeSteps_ValueChanged);
|
---|
| 153 | }
|
---|
| 154 |
|
---|
| 155 | void MaxTimeSteps_ValueChanged(object sender, EventArgs e) {
|
---|
| 156 | OnMaxTimeStepsChanged();
|
---|
| 157 | }
|
---|
| 158 | private void World_ItemChanged(object sender, EventArgs<int, int> e) {
|
---|
| 159 | OnWorldChanged();
|
---|
| 160 | }
|
---|
| 161 | private void World_Reset(object sender, EventArgs e) {
|
---|
| 162 | OnWorldChanged();
|
---|
| 163 | }
|
---|
| 164 | #endregion
|
---|
[3238] | 165 | }
|
---|
| 166 | }
|
---|