[3238] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[12012] | 3 | * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[3238] | 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;
|
---|
[4068] | 26 | using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
|
---|
[3238] | 27 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
| 28 |
|
---|
| 29 | namespace HeuristicLab.Problems.ArtificialAnt {
|
---|
| 30 | /// <summary>
|
---|
| 31 | /// Represents a trail of an artificial ant which can be visualized in the GUI.
|
---|
| 32 | /// </summary>
|
---|
| 33 | [Item("AntTrail", "Represents a trail of an artificial ant which can be visualized in the GUI.")]
|
---|
| 34 | [StorableClass]
|
---|
| 35 | public sealed class AntTrail : Item {
|
---|
[13656] | 36 |
|
---|
[3317] | 37 | [Storable]
|
---|
[3238] | 38 | private SymbolicExpressionTree expression;
|
---|
[13656] | 39 | public SymbolicExpressionTree SymbolicExpressionTree
|
---|
| 40 | {
|
---|
[3238] | 41 | get { return expression; }
|
---|
[13656] | 42 | set
|
---|
| 43 | {
|
---|
[3238] | 44 | if (expression != value) {
|
---|
| 45 | //if (expression != null) DeregisterSymbolicExpressionTreeEvents();
|
---|
| 46 | expression = value;
|
---|
| 47 | //if (expression != null) RegisterSymbolicExpressionTreeEvents();
|
---|
| 48 | OnSymbolicExpressionTreeChanged();
|
---|
| 49 | }
|
---|
| 50 | }
|
---|
| 51 | }
|
---|
| 52 |
|
---|
[3317] | 53 | [Storable]
|
---|
[3239] | 54 | private BoolMatrix world;
|
---|
[13656] | 55 | public BoolMatrix World
|
---|
| 56 | {
|
---|
[3239] | 57 | get { return world; }
|
---|
[13656] | 58 | set
|
---|
| 59 | {
|
---|
[3239] | 60 | if (world != value) {
|
---|
| 61 | if (world != null) DeregisterWorldEvents();
|
---|
| 62 | world = value;
|
---|
| 63 | if (world != null) RegisterWorldEvents();
|
---|
| 64 | OnWorldChanged();
|
---|
| 65 | }
|
---|
| 66 | }
|
---|
| 67 | }
|
---|
[3317] | 68 | [Storable]
|
---|
[3239] | 69 | private IntValue maxTimeSteps;
|
---|
[13656] | 70 | public IntValue MaxTimeSteps
|
---|
| 71 | {
|
---|
[3239] | 72 | get { return maxTimeSteps; }
|
---|
[13656] | 73 | set
|
---|
| 74 | {
|
---|
[3239] | 75 | if (maxTimeSteps != value) {
|
---|
| 76 | if (maxTimeSteps != value) {
|
---|
| 77 | if (maxTimeSteps != null) DeregisterMaxTimeStepsEvents();
|
---|
| 78 | maxTimeSteps = value;
|
---|
| 79 | if (maxTimeSteps != null) RegisterMaxTimeStepsEvents();
|
---|
| 80 | OnWorldChanged();
|
---|
| 81 | }
|
---|
| 82 | }
|
---|
| 83 | }
|
---|
| 84 | }
|
---|
| 85 |
|
---|
[3238] | 86 | public AntTrail() : base() { }
|
---|
[3239] | 87 | public AntTrail(BoolMatrix world, SymbolicExpressionTree expression, IntValue maxTimeSteps)
|
---|
[3238] | 88 | : this() {
|
---|
[3317] | 89 | this.world = world;
|
---|
| 90 | this.expression = expression;
|
---|
| 91 | this.maxTimeSteps = maxTimeSteps;
|
---|
| 92 | Initialize();
|
---|
[3238] | 93 | }
|
---|
[4722] | 94 |
|
---|
[3317] | 95 | [StorableConstructor]
|
---|
| 96 | private AntTrail(bool deserializing) : base(deserializing) { }
|
---|
[4722] | 97 | [StorableHook(HookType.AfterDeserialization)]
|
---|
| 98 | private void AfterDeserialization() {
|
---|
| 99 | Initialize();
|
---|
| 100 | }
|
---|
| 101 | private AntTrail(AntTrail original, Cloner cloner)
|
---|
| 102 | : base(original, cloner) {
|
---|
| 103 | expression = cloner.Clone(original.expression);
|
---|
| 104 | world = cloner.Clone(original.world);
|
---|
| 105 | maxTimeSteps = cloner.Clone(original.maxTimeSteps);
|
---|
| 106 | Initialize();
|
---|
| 107 | }
|
---|
| 108 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
| 109 | return new AntTrail(this, cloner);
|
---|
| 110 | }
|
---|
[3238] | 111 |
|
---|
[3317] | 112 | private void Initialize() {
|
---|
| 113 | //if (expression != null) RegisterSymbolicExpressionTreeEvents();
|
---|
| 114 | if (world != null) RegisterWorldEvents();
|
---|
| 115 | if (maxTimeSteps != null) RegisterMaxTimeStepsEvents();
|
---|
| 116 | }
|
---|
| 117 |
|
---|
[3239] | 118 | #region Events
|
---|
[3238] | 119 | public event EventHandler SymbolicExpressionTreeChanged;
|
---|
| 120 | private void OnSymbolicExpressionTreeChanged() {
|
---|
[3239] | 121 | var changed = SymbolicExpressionTreeChanged;
|
---|
[4722] | 122 | if (changed != null) changed(this, EventArgs.Empty);
|
---|
[3238] | 123 | }
|
---|
[3239] | 124 | public event EventHandler WorldChanged;
|
---|
| 125 | private void OnWorldChanged() {
|
---|
| 126 | var changed = WorldChanged;
|
---|
[4722] | 127 | if (changed != null) changed(this, EventArgs.Empty);
|
---|
[3239] | 128 | }
|
---|
| 129 | public event EventHandler MaxTimeStepsChanged;
|
---|
| 130 | private void OnMaxTimeStepsChanged() {
|
---|
| 131 | var changed = MaxTimeStepsChanged;
|
---|
[4722] | 132 | if (changed != null) changed(this, EventArgs.Empty);
|
---|
[3239] | 133 | }
|
---|
[3238] | 134 |
|
---|
| 135 | //private void RegisterSymbolicExpressionTreeEvents() {
|
---|
| 136 | // SymbolicExpressionTree.ItemChanged += new EventHandler<EventArgs<int>>(SymbolicExpressionTree_ItemChanged);
|
---|
| 137 | // SymbolicExpressionTree.Reset += new EventHandler(SymbolicExpressionTree_Reset);
|
---|
| 138 | //}
|
---|
| 139 | //private void DeregisterSymbolicExpressionTreeEvents() {
|
---|
| 140 | // SymbolicExpressionTree.ItemChanged -= new EventHandler<EventArgs<int>>(SymbolicExpressionTree_ItemChanged);
|
---|
| 141 | // SymbolicExpressionTree.Reset -= new EventHandler(SymbolicExpressionTree_Reset);
|
---|
| 142 | //}
|
---|
| 143 |
|
---|
[3239] | 144 | private void RegisterWorldEvents() {
|
---|
| 145 | World.ItemChanged += new EventHandler<EventArgs<int, int>>(World_ItemChanged);
|
---|
| 146 | World.Reset += new EventHandler(World_Reset);
|
---|
| 147 | }
|
---|
| 148 | private void DeregisterWorldEvents() {
|
---|
| 149 | World.ItemChanged -= new EventHandler<EventArgs<int, int>>(World_ItemChanged);
|
---|
| 150 | World.Reset -= new EventHandler(World_Reset);
|
---|
| 151 | }
|
---|
| 152 | private void RegisterMaxTimeStepsEvents() {
|
---|
| 153 | MaxTimeSteps.ValueChanged += new EventHandler(MaxTimeSteps_ValueChanged);
|
---|
| 154 | }
|
---|
| 155 | private void DeregisterMaxTimeStepsEvents() {
|
---|
| 156 | MaxTimeSteps.ValueChanged -= new EventHandler(MaxTimeSteps_ValueChanged);
|
---|
| 157 | }
|
---|
| 158 |
|
---|
| 159 | void MaxTimeSteps_ValueChanged(object sender, EventArgs e) {
|
---|
| 160 | OnMaxTimeStepsChanged();
|
---|
| 161 | }
|
---|
| 162 | private void World_ItemChanged(object sender, EventArgs<int, int> e) {
|
---|
| 163 | OnWorldChanged();
|
---|
| 164 | }
|
---|
| 165 | private void World_Reset(object sender, EventArgs e) {
|
---|
| 166 | OnWorldChanged();
|
---|
| 167 | }
|
---|
| 168 | #endregion
|
---|
[3238] | 169 | }
|
---|
| 170 | }
|
---|