- Timestamp:
- 03/31/10 14:26:45 (15 years ago)
- Location:
- trunk/sources
- Files:
-
- 8 added
- 16 edited
- 4 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab 3.3.sln
r3230 r3239 80 80 {BF7D9494-A586-457B-8DF9-ED599F9E6A71} = {BF7D9494-A586-457B-8DF9-ED599F9E6A71} 81 81 {DE12659F-87C4-48E6-B2E3-4E73DD95A540} = {DE12659F-87C4-48E6-B2E3-4E73DD95A540} 82 {30DD3DA2-CA57-49DD-A5BA-50CEF19DB45F} = {30DD3DA2-CA57-49DD-A5BA-50CEF19DB45F} 82 83 {F5C0ECAC-EDBA-4024-872A-1F74AFCB20B4} = {F5C0ECAC-EDBA-4024-872A-1F74AFCB20B4} 83 84 {DBECB8B0-B166-4133-BAF1-ED67C3FD7FCA} = {DBECB8B0-B166-4133-BAF1-ED67C3FD7FCA} … … 229 230 EndProject 230 231 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HeuristicLab.Problems.ArtificialAnt-3.3", "HeuristicLab.Problems.ArtificialAnt\3.3\HeuristicLab.Problems.ArtificialAnt-3.3.csproj", "{F5C0ECAC-EDBA-4024-872A-1F74AFCB20B4}" 232 EndProject 233 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HeuristicLab.Problems.ArtificialAnt.Views-3.3", "HeuristicLab.Problems.ArtificialAnt.Views\3.3\HeuristicLab.Problems.ArtificialAnt.Views-3.3.csproj", "{30DD3DA2-CA57-49DD-A5BA-50CEF19DB45F}" 231 234 EndProject 232 235 Global … … 1282 1285 {F5C0ECAC-EDBA-4024-872A-1F74AFCB20B4}.Services|x64.ActiveCfg = Release|x64 1283 1286 {F5C0ECAC-EDBA-4024-872A-1F74AFCB20B4}.Services|x86.ActiveCfg = Release|x86 1287 {30DD3DA2-CA57-49DD-A5BA-50CEF19DB45F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 1288 {30DD3DA2-CA57-49DD-A5BA-50CEF19DB45F}.Debug|Any CPU.Build.0 = Debug|Any CPU 1289 {30DD3DA2-CA57-49DD-A5BA-50CEF19DB45F}.Debug|x64.ActiveCfg = Debug|x64 1290 {30DD3DA2-CA57-49DD-A5BA-50CEF19DB45F}.Debug|x64.Build.0 = Debug|x64 1291 {30DD3DA2-CA57-49DD-A5BA-50CEF19DB45F}.Debug|x86.ActiveCfg = Debug|x86 1292 {30DD3DA2-CA57-49DD-A5BA-50CEF19DB45F}.Debug|x86.Build.0 = Debug|x86 1293 {30DD3DA2-CA57-49DD-A5BA-50CEF19DB45F}.Release|Any CPU.ActiveCfg = Release|Any CPU 1294 {30DD3DA2-CA57-49DD-A5BA-50CEF19DB45F}.Release|Any CPU.Build.0 = Release|Any CPU 1295 {30DD3DA2-CA57-49DD-A5BA-50CEF19DB45F}.Release|x64.ActiveCfg = Release|x64 1296 {30DD3DA2-CA57-49DD-A5BA-50CEF19DB45F}.Release|x64.Build.0 = Release|x64 1297 {30DD3DA2-CA57-49DD-A5BA-50CEF19DB45F}.Release|x86.ActiveCfg = Release|x86 1298 {30DD3DA2-CA57-49DD-A5BA-50CEF19DB45F}.Release|x86.Build.0 = Release|x86 1299 {30DD3DA2-CA57-49DD-A5BA-50CEF19DB45F}.Services|Any CPU.ActiveCfg = Release|Any CPU 1300 {30DD3DA2-CA57-49DD-A5BA-50CEF19DB45F}.Services|x64.ActiveCfg = Release|x64 1301 {30DD3DA2-CA57-49DD-A5BA-50CEF19DB45F}.Services|x86.ActiveCfg = Release|x86 1284 1302 EndGlobalSection 1285 1303 GlobalSection(SolutionProperties) = preSolution -
trunk/sources/HeuristicLab 3.3/Files.txt
r3223 r3239 42 42 HeuristicLab.PluginAdministrator\3.3:HeuristicLab.PluginAdministrator-3.3.dll 43 43 HeuristicLab.Problems.ArtificialAnt\3.3:HeuristicLab.Problems.ArtificialAnt-3.3.dll 44 HeuristicLab.Problems.ArtificialAnt.Views\3.3:HeuristicLab.Problems.ArtificialAnt.Views-3.3.dll 44 45 HeuristicLab.Problems.Knapsack\3.3:HeuristicLab.Problems.Knapsack-3.3.dll 45 46 HeuristicLab.Problems.Knapsack.Views\3.3:HeuristicLab.Problems.Knapsack.Views-3.3.dll -
trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Creators/ProbabilisticTreeCreator.cs
r3237 r3239 32 32 [Item("ProbabilisticTreeCreator", "An operator that creates new symbolic expression trees with uniformly distributed size")] 33 33 public class ProbabilisticTreeCreator : SymbolicExpressionTreeCreator { 34 private const int MAX_TRIES = 100;35 34 public ProbabilisticTreeCreator() 36 35 : base() { … … 48 47 int treeSize = random.Next(allowedMinSize, allowedMaxSize); 49 48 SymbolicExpressionTree tree = new SymbolicExpressionTree(); 50 int tries = 0;51 49 do { 52 50 try { 53 tree.Root = PTC2(random, grammar, grammar.StartSymbol, treeSize+1, maxTreeHeight+1); 54 //// determine possible root symbols to create a tree of the target size 55 //var possibleRootSymbols = from symbol in grammar.AllowedSymbols(grammar.StartSymbol, 0) 56 // where treeSize <= grammar.MaximalExpressionLength(symbol) 57 // where treeSize >= grammar.MinimalExpressionLength(symbol) 58 // select symbol; 59 //Symbol rootSymbol = SelectRandomSymbol(random, possibleRootSymbols); 60 //tree.Root = PTC2(random, grammar, rootSymbol, treeSize, maxTreeHeight); 51 tree.Root = PTC2(random, grammar, grammar.StartSymbol, treeSize + 1, maxTreeHeight + 1); 61 52 } 62 53 catch (ArgumentException) { 63 54 // try a different size 64 55 treeSize = random.Next(allowedMinSize, allowedMaxSize); 65 tries = 0;66 }67 if (tries++ >= MAX_TRIES) {68 // try a different size69 treeSize = random.Next(allowedMinSize, allowedMaxSize);70 tries = 0;71 56 } 72 57 } while (tree.Root == null || tree.Size > maxTreeSize || tree.Height > maxTreeHeight); … … 191 176 return tree; 192 177 } 193 194 //private bool IsRecursiveExpansionPossible(Symbol symbol) {195 // return FindCycle(function, new Stack<IFunction>());196 //}197 198 //private Dictionary<IFunction, bool> inCycle = new Dictionary<IFunction, bool>();199 //private bool FindCycle(IFunction function, Stack<IFunction> functionChain) {200 // if (inCycle.ContainsKey(function)) {201 // return inCycle[function];202 // } else if (IsTerminal(function)) {203 // inCycle[function] = false;204 // return false;205 // } else if (functionChain.Contains(function)) {206 // inCycle[function] = true;207 // return true;208 // } else {209 // functionChain.Push(function);210 // bool result = false;211 // // all slot indexes212 // for (int i = 0; i < function.MaxSubTrees; i++) {213 // foreach (IFunction subFunction in GetAllowedSubFunctions(function, i)) {214 // result |= FindCycle(subFunction, functionChain);215 // }216 // }217 218 // functionChain.Pop();219 // inCycle[function] = result;220 // return result;221 // }222 //}223 224 178 } 225 179 } -
trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding-3.3.csproj
r3237 r3239 87 87 <Compile Include="Creators\ProbabilisticTreeCreator.cs" /> 88 88 <Compile Include="HeuristicLabEncodingsSymbolicExpressionTreeEncodingPlugin.cs" /> 89 <Compile Include="Interfaces\ISymbolicExpressionTreeOperator.cs" /> 89 90 <Compile Include="SymbolicExpressionGrammar.cs" /> 90 91 <Compile Include="SymbolicExpressionTreeCreator.cs" /> -
trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/SymbolicExpressionTreeCreator.cs
r3223 r3239 33 33 [Item("SymbolicExpressionTreeCreator", "A base class for operators creating symbolic expression trees.")] 34 34 [StorableClass] 35 public abstract class SymbolicExpressionTreeCreator : SingleSuccessorOperator, ISolutionCreator, IStochasticOperator {35 public abstract class SymbolicExpressionTreeCreator : SingleSuccessorOperator, ISolutionCreator, IStochasticOperator, ISymbolicExpressionTreeOperator { 36 36 private const string RandomParameterName = "Random"; 37 37 private const string SymbolicExpressionTreeParameterName = "SymbolicExpressionTree"; -
trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/SymbolicExpressionTreeCrossover.cs
r3237 r3239 35 35 [Item("SymbolicExpressionTreeCrossover", "A base class for operators that perform a crossover of symbolic expression trees.")] 36 36 [StorableClass] 37 public abstract class SymbolicExpressionTreeCrossover : SingleSuccessorOperator, ICrossover, IStochasticOperator {37 public abstract class SymbolicExpressionTreeCrossover : SingleSuccessorOperator, ICrossover, IStochasticOperator, ISymbolicExpressionTreeOperator { 38 38 public override bool CanChangeName { 39 39 get { return false; } -
trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/SymbolicExpressionTreeManipulator.cs
r3223 r3239 33 33 [Item("RealVectorManipulator", "A base class for operators that manipulate real-valued vectors.")] 34 34 [StorableClass] 35 public abstract class RealVectorManipulator : SingleSuccessorOperator, IRealVectorManipulator, IStochasticOperator {35 public abstract class RealVectorManipulator : SingleSuccessorOperator, IRealVectorManipulator, IStochasticOperator, ISymbolicExpressionTreeOperator { 36 36 public override bool CanChangeName { 37 37 get { return false; } -
trunk/sources/HeuristicLab.Problems.ArtificialAnt.Views/3.3/AntTrailView.Designer.cs
r3238 r3239 20 20 #endregion 21 21 22 namespace HeuristicLab.Problems.ArtificialAnt {22 namespace HeuristicLab.Problems.ArtificialAnt.Views { 23 23 partial class AntTrailView { 24 24 /// <summary> … … 45 45 /// </summary> 46 46 private void InitializeComponent() { 47 this.components = new System.ComponentModel.Container(); 47 48 this.pictureBox = new System.Windows.Forms.PictureBox(); 49 this.playButton = new System.Windows.Forms.Button(); 50 this.animationTimer = new System.Windows.Forms.Timer(this.components); 48 51 ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit(); 49 52 this.SuspendLayout(); … … 58 61 this.pictureBox.Location = new System.Drawing.Point(0, 0); 59 62 this.pictureBox.Name = "pictureBox"; 60 this.pictureBox.Size = new System.Drawing.Size(392, 310);63 this.pictureBox.Size = new System.Drawing.Size(392, 275); 61 64 this.pictureBox.TabIndex = 0; 62 65 this.pictureBox.TabStop = false; 63 66 this.pictureBox.SizeChanged += new System.EventHandler(this.pictureBox_SizeChanged); 64 67 // 65 // PathTSPTourView 68 // playButton 69 // 70 this.playButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); 71 this.playButton.Location = new System.Drawing.Point(4, 281); 72 this.playButton.Name = "playButton"; 73 this.playButton.Size = new System.Drawing.Size(75, 23); 74 this.playButton.TabIndex = 1; 75 this.playButton.Text = "Play"; 76 this.playButton.UseVisualStyleBackColor = true; 77 this.playButton.Click += new System.EventHandler(this.playButton_Click); 78 // 79 // animationTimer 80 // 81 this.animationTimer.Interval = 15; 82 this.animationTimer.Tick += new System.EventHandler(this.animationTimer_Tick); 83 // 84 // AntTrailView 66 85 // 67 86 this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); 68 87 this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 88 this.Controls.Add(this.playButton); 69 89 this.Controls.Add(this.pictureBox); 70 this.Name = " PathTSPTourView";90 this.Name = "AntTrailView"; 71 91 this.Size = new System.Drawing.Size(392, 310); 92 this.EnabledChanged += new System.EventHandler(this.AntTrailView_EnabledChanged); 72 93 ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit(); 73 94 this.ResumeLayout(false); … … 78 99 79 100 private System.Windows.Forms.PictureBox pictureBox; 101 private System.Windows.Forms.Button playButton; 102 private System.Windows.Forms.Timer animationTimer; 80 103 81 104 -
trunk/sources/HeuristicLab.Problems.ArtificialAnt.Views/3.3/AntTrailView.cs
r3238 r3239 29 29 using System.Collections.Generic; 30 30 31 namespace HeuristicLab.Problems.ArtificialAnt {31 namespace HeuristicLab.Problems.ArtificialAnt.Views { 32 32 [View("AntTrail View")] 33 33 [Content(typeof(AntTrail), true)] 34 34 public sealed partial class AntTrailView : ItemView { 35 private const int N_FOOD_ITEMS = 89;36 private const int WORLD_WIDTH = 32;37 private const int WORLD_HEIGHT = 32;38 private const int FOOD = 1;39 private const int EMPTY = 0;40 private int[] SANTA_FE_TRAIL = new int[] {41 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 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 private const int MAX_TIME_STEPS = 600;76 77 private int[] trail;78 private int currentLocation;79 private int currentDirection;80 Stack<SymbolicExpressionTreeNode> nodeStack;81 82 35 public new AntTrail Content { 83 36 get { return (AntTrail)base.Content; } … … 87 40 public AntTrailView() { 88 41 InitializeComponent(); 89 ResetTrailInterpreter();90 42 } 91 43 … … 115 67 } 116 68 117 private void ResetTrailInterpreter() {118 nodeStack = new Stack<SymbolicExpressionTreeNode>();119 currentLocation = 0;120 currentDirection = 0;121 trail = new int[WORLD_HEIGHT * WORLD_WIDTH];122 Array.Copy(SANTA_FE_TRAIL, trail, SANTA_FE_TRAIL.Length);123 }124 125 126 69 private void GenerateImage() { 70 playButton.Enabled = this.Enabled; 71 animationTimer.Stop(); 127 72 if ((pictureBox.Width > 0) && (pictureBox.Height > 0)) { 128 73 if (Content == null) { 129 74 pictureBox.Image = null; 75 playButton.Enabled = false; 130 76 } else { 131 ResetTrailInterpreter(); 77 var nodeStack = new Stack<SymbolicExpressionTreeNode>(); 78 int rows = Content.World.Rows; 79 int columns = Content.World.Columns; 132 80 SymbolicExpressionTree expression = Content.SymbolicExpressionTree; 133 81 134 Bitmap bitmap = new Bitmap(pictureBox.Width, pictureBox.Height); 135 using (Graphics graphics = Graphics.FromImage(bitmap)) { 136 int cellHeight = pictureBox.Height / WORLD_HEIGHT; 137 int cellWidth = pictureBox.Width / WORLD_WIDTH; 138 // draw world 139 for (int i = 0; i < WORLD_HEIGHT; i++) { 140 graphics.DrawLine(Pens.Black, 0, i * cellHeight, pictureBox.Width, i * cellHeight); 82 DrawWorld(); 83 using (Graphics graphics = Graphics.FromImage(pictureBox.Image)) { 84 float cellHeight = pictureBox.Height / (float)rows; 85 float cellWidth = pictureBox.Width / (float)columns; 86 87 AntInterpreter interpreter = new AntInterpreter(); 88 interpreter.MaxTimeSteps = Content.MaxTimeSteps.Value; 89 interpreter.Expression = Content.SymbolicExpressionTree; 90 interpreter.World = Content.World; 91 int currentAntLocationColumn; 92 int currentAntLocationRow; 93 // draw initial ant 94 interpreter.AntLocation(out currentAntLocationRow, out currentAntLocationColumn); 95 DrawAnt(graphics, currentAntLocationRow, currentAntLocationColumn, interpreter.AntDirection, cellWidth, cellHeight); 96 // interpret ant code and draw trail 97 while (interpreter.ElapsedTime < interpreter.MaxTimeSteps) { 98 interpreter.Step(); 99 interpreter.AntLocation(out currentAntLocationRow, out currentAntLocationColumn); 100 DrawAnt(graphics, currentAntLocationRow, currentAntLocationColumn, interpreter.AntDirection, cellWidth, cellHeight); 141 101 } 142 for (int j = 0; j < WORLD_WIDTH; j++) { 143 graphics.DrawLine(Pens.Black, j * cellWidth, 0, j * cellWidth, pictureBox.Height); 144 } 145 for (int i = 0; i < WORLD_HEIGHT; i++) { 146 for (int j = 0; j < WORLD_WIDTH; j++) { 147 if (trail[i * WORLD_HEIGHT + j] == FOOD) graphics.FillEllipse(Brushes.LightBlue, j * cellWidth, i * cellHeight, cellWidth, cellHeight); 148 } 149 } 150 // step ant and draw trail 151 nodeStack.Clear(); 152 int step = 0; 153 while (step < MAX_TIME_STEPS) { 154 // expression evaluated completly => start at root again 155 if (nodeStack.Count == 0) 156 nodeStack.Push(expression.Root.SubTrees[0]); 157 158 var currentNode = nodeStack.Pop(); 159 if (currentNode.Symbol is Left) { 160 currentDirection = (currentDirection + 3) % 4; 161 step++; 162 } else if (currentNode.Symbol is Right) { 163 currentDirection = (currentDirection + 1) % 4; 164 step++; 165 } else if (currentNode.Symbol is Move) { 166 currentLocation = NextField(); 167 trail[currentLocation] = EMPTY; 168 float currentCellX = currentLocation % WORLD_WIDTH; 169 float currentCellY = currentLocation / WORLD_HEIGHT; 170 graphics.FillRectangle(Brushes.Brown, 171 currentCellX * cellWidth + cellWidth * 0.25f, currentCellY * cellHeight + cellHeight * 0.25f, 172 cellWidth * 0.5f, cellHeight * 0.5f); 173 step++; 174 } else if (currentNode.Symbol is IfFoodAhead) { 175 if (trail[NextField()] == FOOD) { 176 nodeStack.Push(currentNode.SubTrees[0]); 177 } else { 178 nodeStack.Push(currentNode.SubTrees[1]); 179 } 180 } else if (currentNode.Symbol is Prog2) { 181 nodeStack.Push(currentNode.SubTrees[1]); 182 nodeStack.Push(currentNode.SubTrees[0]); 183 } else if (currentNode.Symbol is Prog3) { 184 nodeStack.Push(currentNode.SubTrees[2]); 185 nodeStack.Push(currentNode.SubTrees[1]); 186 nodeStack.Push(currentNode.SubTrees[0]); 187 } else { 188 throw new InvalidOperationException(currentNode.Symbol.ToString()); 189 } 190 191 192 } 193 } 194 pictureBox.Image = bitmap; 195 } 196 } 197 } 198 199 private int NextField() { 200 int currentLocationX = currentLocation % WORLD_WIDTH; 201 int currentLocationY = currentLocation / WORLD_HEIGHT; 202 203 switch (currentDirection) { 204 case 0: 205 currentLocationX = (currentLocationX + 1) % WORLD_WIDTH; // EAST 206 break; 207 case 1: 208 currentLocationY = (currentLocationY + 1) % WORLD_HEIGHT; // SOUTH 209 break; 210 case 2: 211 currentLocationX = (currentLocationX + WORLD_WIDTH - 1) % WORLD_WIDTH; // WEST 212 break; 213 case 3: 214 currentLocationY = (currentLocationY + WORLD_HEIGHT - 1) % WORLD_HEIGHT; // NORTH 215 break; 216 default: 217 throw new InvalidOperationException(); 218 } 219 return currentLocationY * WORLD_WIDTH + currentLocationX; 102 } 103 pictureBox.Refresh(); 104 } 105 } 106 } 107 108 private void DrawWorld() { 109 int rows = Content.World.Rows; 110 int columns = Content.World.Columns; 111 Bitmap bitmap = new Bitmap(pictureBox.Width, pictureBox.Height); 112 using (Graphics graphics = Graphics.FromImage(bitmap)) { 113 float cellHeight = pictureBox.Height / (float)rows; 114 float cellWidth = pictureBox.Width / (float)columns; 115 // draw world 116 for (int i = 0; i < rows; i++) { 117 graphics.DrawLine(Pens.Black, 0, i * cellHeight, pictureBox.Width, i * cellHeight); 118 } 119 for (int j = 0; j < columns; j++) { 120 graphics.DrawLine(Pens.Black, j * cellWidth, 0, j * cellWidth, pictureBox.Height); 121 } 122 for (int i = 0; i < rows; i++) { 123 for (int j = 0; j < columns; j++) { 124 if (Content.World[i, j]) 125 graphics.FillEllipse(Brushes.LightBlue, j * cellWidth, i * cellHeight, cellWidth, cellHeight); 126 } 127 } 128 pictureBox.Image = bitmap; 129 } 130 } 131 132 private void DrawAnt(Graphics g, int row, int column, int direction, float cellWidth, float cellHeight) { 133 //g.FillRectangle(Brushes.White, column * cellWidth, row * cellHeight, 134 // cellWidth, cellHeight); 135 // draw ant body 136 g.FillRectangle(Brushes.Brown, 137 column * cellWidth + cellWidth * 0.25f, row * cellHeight + cellHeight * 0.25f, 138 cellWidth * 0.5f, cellHeight * 0.5f); 139 // show ant direction 140 float centerX = column * cellWidth + cellWidth * 0.5f; 141 float centerY = row * cellHeight + cellHeight * 0.5f; 142 float directionX = centerX; 143 float directionY = centerY; 144 switch (direction) { 145 case 0: { // EAST 146 directionX = centerX + cellWidth * 0.5f; 147 break; 148 } 149 case 1: { // SOUTH 150 directionY = directionY + cellHeight * 0.5f; 151 break; 152 } 153 case 2: { // WEST 154 directionX = centerX - cellWidth * 0.5f; 155 break; 156 } 157 case 3: { // NORTH 158 directionY = directionY - cellHeight * 0.5f; 159 break; 160 } 161 default: throw new InvalidOperationException(); 162 } 163 g.DrawLine(Pens.Brown, centerX, centerY, directionX, directionY); 220 164 } 221 165 … … 230 174 GenerateImage(); 231 175 } 176 177 #region animation 178 private AntInterpreter animationInterpreter; 179 private void playButton_Click(object sender, EventArgs e) { 180 playButton.Enabled = false; 181 int rows = Content.World.Rows; 182 int columns = Content.World.Columns; 183 SymbolicExpressionTree expression = Content.SymbolicExpressionTree; 184 var nodeStack = new Stack<SymbolicExpressionTreeNode>(); 185 186 animationInterpreter = new AntInterpreter(); 187 animationInterpreter.MaxTimeSteps = Content.MaxTimeSteps.Value; 188 animationInterpreter.Expression = Content.SymbolicExpressionTree; 189 animationInterpreter.World = Content.World; 190 191 DrawWorld(); 192 using (Graphics graphics = Graphics.FromImage(pictureBox.Image)) { 193 float cellHeight = pictureBox.Height / (float)Content.World.Rows; 194 float cellWidth = pictureBox.Width / (float)Content.World.Columns; 195 // draw initial ant 196 int currentAntLocationColumn; 197 int currentAntLocationRow; 198 animationInterpreter.AntLocation(out currentAntLocationRow, out currentAntLocationColumn); 199 DrawAnt(graphics, currentAntLocationRow, currentAntLocationColumn, animationInterpreter.AntDirection, cellWidth, cellHeight); 200 pictureBox.Refresh(); 201 } 202 203 animationTimer.Start(); 204 } 205 206 private void animationTimer_Tick(object sender, EventArgs e) { 207 using (Graphics graphics = Graphics.FromImage(pictureBox.Image)) { 208 float cellHeight = pictureBox.Height / (float)Content.World.Rows; 209 float cellWidth = pictureBox.Width / (float)Content.World.Columns; 210 int currentAntLocationColumn; 211 int currentAntLocationRow; 212 // interpret ant code and draw trail 213 animationInterpreter.Step(); 214 animationInterpreter.AntLocation(out currentAntLocationRow, out currentAntLocationColumn); 215 DrawAnt(graphics, currentAntLocationRow, currentAntLocationColumn, animationInterpreter.AntDirection, cellWidth, cellHeight); 216 pictureBox.Refresh(); 217 if (animationInterpreter.ElapsedTime < animationInterpreter.MaxTimeSteps) { 218 animationTimer.Start(); 219 } else { 220 animationTimer.Stop(); 221 playButton.Enabled = this.Enabled; 222 } 223 } 224 } 225 #endregion 226 227 private void AntTrailView_EnabledChanged(object sender, EventArgs e) { 228 if (this.Enabled) playButton.Enabled = true; 229 else playButton.Enabled = false; 230 } 232 231 } 233 232 } -
trunk/sources/HeuristicLab.Problems.ArtificialAnt.Views/3.3/ArtificialAntProblemView.Designer.cs
r3238 r3239 1 namespace HeuristicLab.Problems.ArtificialAnt {1 namespace HeuristicLab.Problems.ArtificialAnt.Views { 2 2 partial class ArtificialAntProblemView { 3 3 /// <summary> -
trunk/sources/HeuristicLab.Problems.ArtificialAnt.Views/3.3/ArtificialAntProblemView.cs
r3238 r3239 9 9 using HeuristicLab.MainForm; 10 10 11 namespace HeuristicLab.Problems.ArtificialAnt {11 namespace HeuristicLab.Problems.ArtificialAnt.Views { 12 12 [View("ArtificialAntProblem View")] 13 13 [Content(typeof(ArtificialAntProblem), true)] -
trunk/sources/HeuristicLab.Problems.ArtificialAnt/3.3/AntInterpreter.cs
r3238 r3239 22 22 using System; 23 23 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 24 using HeuristicLab.Data; 25 using System.Collections.Generic; 24 26 25 27 namespace HeuristicLab.Problems.ArtificialAnt { 26 internal class AntInterpreter { 27 private const int N_FOOD_ITEMS = 89; 28 private const int WORLD_WIDTH = 32; 29 private const int WORLD_HEIGHT = 32; 30 private const int FOOD = 1; 31 private const int EMPTY = 0; 32 private int[] SANTA_FE_TRAIL = new int[] { 33 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 34 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 35 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 36 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 37 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 38 0, 0, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 39 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 40 0, 0, 0, 0, 0, 0, 0, 0, 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 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 62 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 63 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 64 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 65 }; 66 67 private int[] trail; 68 69 public int ElapsedTime { get; set; } 28 public class AntInterpreter { 70 29 public int MaxTimeSteps { get; set; } 71 30 public int FoodEaten { get; set; } 72 private int currentDirection; 73 private int currentLocation; 74 75 public AntInterpreter() { 76 currentLocation = 0; 77 currentDirection = 0; 78 FoodEaten = 0; 79 trail = new int[WORLD_HEIGHT * WORLD_WIDTH]; 80 Array.Copy(SANTA_FE_TRAIL, trail, SANTA_FE_TRAIL.Length); 81 } 82 83 internal void Run(SymbolicExpressionTree tree) { 84 while (FoodEaten < N_FOOD_ITEMS && ElapsedTime < MaxTimeSteps) { 85 Step(tree.Root.SubTrees[0]); 31 private BoolMatrix world; 32 public BoolMatrix World { 33 get { return world; } 34 set { 35 // create a clone of the world because the ant will remove the food items it can find. 36 world = (BoolMatrix)value.Clone(); 37 CountFoodItems(); 86 38 } 87 39 } 88 40 89 internal void Step(SymbolicExpressionTreeNode currentNode) { 41 private SymbolicExpressionTree expression; 42 public SymbolicExpressionTree Expression { 43 get { return expression; } 44 set { 45 expression = value; 46 } 47 } 48 public int ElapsedTime { get; set; } 49 private int currentDirection; 50 private int currentAntLocationRow; 51 private int currentAntLocationColumn; 52 private int nFoodItems; 53 private Stack<SymbolicExpressionTreeNode> nodeStack = new Stack<SymbolicExpressionTreeNode>(); 54 55 private void CountFoodItems() { 56 nFoodItems = 0; 57 for (int i = 0; i < World.Rows; i++) { 58 for (int j = 0; j < World.Columns; j++) { 59 if (World[i, j]) nFoodItems++; 60 } 61 } 62 } 63 64 public void AntLocation(out int row, out int column) { 65 row = currentAntLocationRow; 66 column = currentAntLocationColumn; 67 } 68 69 public int AntDirection { 70 get { return currentDirection; } 71 } 72 73 public void Run() { 74 while (ElapsedTime < MaxTimeSteps && FoodEaten < nFoodItems) { 75 Step(); 76 } 77 } 78 79 public void Step() { 80 // expression evaluated completly => start at root again 81 if (nodeStack.Count == 0) 82 nodeStack.Push(Expression.Root.SubTrees[0]); 83 var currentNode = nodeStack.Pop(); 90 84 if (currentNode.Symbol is Left) { 91 if (ElapsedTime >= MaxTimeSteps || FoodEaten >= N_FOOD_ITEMS) return;92 85 currentDirection = (currentDirection + 3) % 4; 93 86 ElapsedTime++; 94 87 } else if (currentNode.Symbol is Right) { 95 if (ElapsedTime >= MaxTimeSteps || FoodEaten >= N_FOOD_ITEMS) return;96 88 currentDirection = (currentDirection + 1) % 4; 97 89 ElapsedTime++; 98 90 } else if (currentNode.Symbol is Move) { 99 if (ElapsedTime >= MaxTimeSteps || FoodEaten >= N_FOOD_ITEMS) return;100 currentLocation = NextField();101 FoodEaten += trail[currentLocation];102 trail[currentLocation] = EMPTY;91 MoveAntForward(); 92 if (World[currentAntLocationRow, currentAntLocationColumn]) 93 FoodEaten++; 94 World[currentAntLocationRow, currentAntLocationColumn] = false; 103 95 ElapsedTime++; 104 96 } else if (currentNode.Symbol is IfFoodAhead) { 105 if (trail[NextField()] == FOOD) { 106 Step(currentNode.SubTrees[0]); 97 int nextAntLocationRow; 98 int nextAntLocationColumn; 99 NextField(out nextAntLocationRow, out nextAntLocationColumn); 100 if (World[nextAntLocationRow, nextAntLocationColumn]) { 101 nodeStack.Push(currentNode.SubTrees[0]); 107 102 } else { 108 Step(currentNode.SubTrees[1]);103 nodeStack.Push(currentNode.SubTrees[1]); 109 104 } 110 105 } else if (currentNode.Symbol is Prog2) { 111 Step(currentNode.SubTrees[0]);112 Step(currentNode.SubTrees[1]);106 nodeStack.Push(currentNode.SubTrees[1]); 107 nodeStack.Push(currentNode.SubTrees[0]); 113 108 return; 114 109 } else if (currentNode.Symbol is Prog3) { 115 Step(currentNode.SubTrees[0]);116 Step(currentNode.SubTrees[1]);117 Step(currentNode.SubTrees[2]);110 nodeStack.Push(currentNode.SubTrees[2]); 111 nodeStack.Push(currentNode.SubTrees[1]); 112 nodeStack.Push(currentNode.SubTrees[0]); 118 113 return; 119 } else 114 } else { 120 115 throw new InvalidOperationException(currentNode.Symbol.ToString()); 121 116 } 122 117 } 123 118 124 private int NextField() {125 int currentLocationX = currentLocation % WORLD_WIDTH;126 int currentLocationY = currentLocation / WORLD_HEIGHT;119 private void MoveAntForward() { 120 NextField(out currentAntLocationRow, out currentAntLocationColumn); 121 } 127 122 123 private void NextField(out int nextAntLocationRow, out int nextAntLocationColumn) { 128 124 switch (currentDirection) { 129 125 case 0: 130 currentLocationX = (currentLocationX + 1) % WORLD_WIDTH; // EAST 126 nextAntLocationColumn = (currentAntLocationColumn + 1) % World.Columns; // EAST 127 nextAntLocationRow = currentAntLocationRow; 131 128 break; 132 129 case 1: 133 currentLocationY = (currentLocationY + 1) % WORLD_HEIGHT; // SOUTH 130 nextAntLocationRow = (currentAntLocationRow + 1) % World.Rows; // SOUTH 131 nextAntLocationColumn = currentAntLocationColumn; 134 132 break; 135 133 case 2: 136 currentLocationX = (currentLocationX + WORLD_WIDTH - 1) % WORLD_WIDTH; // WEST 134 nextAntLocationColumn = (currentAntLocationColumn + World.Columns - 1) % World.Columns; // WEST 135 nextAntLocationRow = currentAntLocationRow; 137 136 break; 138 137 case 3: 139 currentLocationY = (currentLocationY + WORLD_HEIGHT - 1) % WORLD_HEIGHT; // NORTH 138 nextAntLocationRow = (currentAntLocationRow + World.Rows - 1) % World.Rows; // NORTH 139 nextAntLocationColumn = currentAntLocationColumn; 140 140 break; 141 141 default: 142 142 throw new InvalidOperationException(); 143 143 } 144 return currentLocationY * WORLD_WIDTH + currentLocationX;145 144 } 146 145 } -
trunk/sources/HeuristicLab.Problems.ArtificialAnt/3.3/AntTrail.cs
r3238 r3239 48 48 } 49 49 50 private BoolMatrix world; 51 [Storable] 52 public BoolMatrix World { 53 get { return world; } 54 set { 55 if (world != value) { 56 if (world != null) DeregisterWorldEvents(); 57 world = value; 58 if (world != null) RegisterWorldEvents(); 59 OnWorldChanged(); 60 } 61 } 62 } 63 private IntValue maxTimeSteps; 64 [Storable] 65 public IntValue MaxTimeSteps { 66 get { return maxTimeSteps; } 67 set { 68 if (maxTimeSteps != value) { 69 if (maxTimeSteps != value) { 70 if (maxTimeSteps != null) DeregisterMaxTimeStepsEvents(); 71 maxTimeSteps = value; 72 if (maxTimeSteps != null) RegisterMaxTimeStepsEvents(); 73 OnWorldChanged(); 74 } 75 } 76 } 77 } 78 50 79 public AntTrail() : base() { } 51 public AntTrail( SymbolicExpressionTree expression)80 public AntTrail(BoolMatrix world, SymbolicExpressionTree expression, IntValue maxTimeSteps) 52 81 : this() { 82 World = world; 53 83 SymbolicExpressionTree = expression; 84 MaxTimeSteps = maxTimeSteps; 54 85 } 55 86 … … 58 89 cloner.RegisterClonedObject(this, clone); 59 90 clone.expression = (SymbolicExpressionTree)cloner.Clone(expression); 91 clone.world = (BoolMatrix)cloner.Clone(world); 92 clone.maxTimeSteps = (IntValue)cloner.Clone(maxTimeSteps); 60 93 return clone; 61 94 } 62 95 63 //#region Events96 #region Events 64 97 public event EventHandler SymbolicExpressionTreeChanged; 65 98 private void OnSymbolicExpressionTreeChanged() { 66 if (SymbolicExpressionTreeChanged != null) 67 SymbolicExpressionTreeChanged(this, EventArgs.Empty); 99 var changed = SymbolicExpressionTreeChanged; 100 if (changed != null) 101 changed(this, EventArgs.Empty); 102 } 103 public event EventHandler WorldChanged; 104 private void OnWorldChanged() { 105 var changed = WorldChanged; 106 if (changed != null) 107 changed(this, EventArgs.Empty); 108 } 109 public event EventHandler MaxTimeStepsChanged; 110 private void OnMaxTimeStepsChanged() { 111 var changed = MaxTimeStepsChanged; 112 if (changed != null) 113 changed(this, EventArgs.Empty); 68 114 } 69 115 … … 77 123 //} 78 124 79 //private void SymbolicExpressionTree_ItemChanged(object sender, EventArgs<int> e) { 80 // OnSymbolicExpressionTreeChanged(); 81 //} 82 //private void SymbolicExpressionTree_Reset(object sender, EventArgs e) { 83 // OnSymbolicExpressionTreeChanged(); 84 //} 85 //#endregion 125 private void RegisterWorldEvents() { 126 World.ItemChanged += new EventHandler<EventArgs<int, int>>(World_ItemChanged); 127 World.Reset += new EventHandler(World_Reset); 128 } 129 private void DeregisterWorldEvents() { 130 World.ItemChanged -= new EventHandler<EventArgs<int, int>>(World_ItemChanged); 131 World.Reset -= new EventHandler(World_Reset); 132 } 133 private void RegisterMaxTimeStepsEvents() { 134 MaxTimeSteps.ValueChanged += new EventHandler(MaxTimeSteps_ValueChanged); 135 } 136 private void DeregisterMaxTimeStepsEvents() { 137 MaxTimeSteps.ValueChanged -= new EventHandler(MaxTimeSteps_ValueChanged); 138 } 139 140 void MaxTimeSteps_ValueChanged(object sender, EventArgs e) { 141 OnMaxTimeStepsChanged(); 142 } 143 private void World_ItemChanged(object sender, EventArgs<int, int> e) { 144 OnWorldChanged(); 145 } 146 private void World_Reset(object sender, EventArgs e) { 147 OnWorldChanged(); 148 } 149 #endregion 86 150 } 87 151 } -
trunk/sources/HeuristicLab.Problems.ArtificialAnt/3.3/ArtificialAntProblem.cs
r3238 r3239 42 42 } 43 43 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 44 81 #region Parameter Properties 45 82 public ValueParameter<BoolValue> MaximizationParameter { … … 70 107 get { return (ValueParameter<IntValue>)Parameters["MaxExpressionDepth"]; } 71 108 } 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 } 72 115 73 116 public OptionalValueParameter<IAntTrailVisualizer> VisualizerParameter { … … 86 129 87 130 #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 } 88 147 public SymbolicExpressionTreeCreator SolutionCreator { 89 148 get { return SolutionCreatorParameter.Value; } … … 116 175 get { return BestKnownQualityParameter.Value; } 117 176 } 118 private List<I Operator> operators;177 private List<ISymbolicExpressionTreeOperator> operators; 119 178 public IEnumerable<IOperator> Operators { 120 get { return operators ; }179 get { return operators.Cast<IOperator>(); } 121 180 } 122 181 #endregion … … 128 187 ArtificialAntExpressionGrammar grammar = new ArtificialAntExpressionGrammar(); 129 188 BestAntTrailVisualizer visualizer = new BestAntTrailVisualizer(); 130 189 BoolMatrix world = new BoolMatrix(santaFeAntTrail); 131 190 Parameters.Add(new ValueParameter<BoolValue>("Maximization", "Set to true as the Artificial Ant Problem is a maximization problem.", new BoolValue(true))); 132 191 Parameters.Add(new ValueParameter<SymbolicExpressionTreeCreator>("SolutionCreator", "The operator which should be used to create new artificial ant solutions.", creator)); … … 136 195 Parameters.Add(new ValueParameter<IntValue>("MaxExpressionLength", "Maximal length of the expression to control the artificial ant.", new IntValue(100))); 137 196 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))); 138 199 Parameters.Add(new ValueParameter<IAntTrailVisualizer>("Visualizer", "The operator which should be used to visualize artificial ant solutions.", visualizer)); 139 200 … … 159 220 public event EventHandler SolutionCreatorChanged; 160 221 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); 163 225 } 164 226 public event EventHandler EvaluatorChanged; 165 227 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); 168 231 } 169 232 public event EventHandler VisualizerChanged; 170 233 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); 173 237 } 174 238 175 239 public event EventHandler OperatorsChanged; 176 240 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); 179 244 } 180 245 … … 183 248 ParameterizeSolutionCreator(); 184 249 ParameterizeEvaluator(); 250 ParameterizeVisualizer(); 185 251 ParameterizeOperators(); 186 252 OnSolutionCreatorChanged(); … … 188 254 private void SolutionCreator_SymbolicExpressionTreeParameter_ActualNameChanged(object sender, EventArgs e) { 189 255 ParameterizeEvaluator(); 256 ParameterizeVisualizer(); 190 257 ParameterizeOperators(); 191 258 } 192 259 private void EvaluatorParameter_ValueChanged(object sender, EventArgs e) { 260 Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged); 193 261 ParameterizeEvaluator(); 262 ParameterizeVisualizer(); 194 263 OnEvaluatorChanged(); 195 264 } 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 196 275 #endregion 197 276 … … 203 282 SolutionCreator.SymbolicExpressionTreeParameter.ActualNameChanged += new EventHandler(SolutionCreator_SymbolicExpressionTreeParameter_ActualNameChanged); 204 283 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 206 294 private void ParameterizeSolutionCreator() { 207 295 SolutionCreator.SymbolicExpressionGrammarParameter.ActualName = ArtificialAntExpressionGrammarParameter.Name; 296 SolutionCreator.MaxTreeHeightParameter.ActualName = MaxExpressionDepthParameter.Name; 297 SolutionCreator.MaxTreeSizeParameter.ActualName = MaxExpressionLengthParameter.Name; 208 298 } 209 299 private void ParameterizeEvaluator() { 210 300 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 } 218 314 } 219 315 220 316 private void ParameterizeOperators() { 221 foreach ( ProbabilisticTreeCreator op in Operators.OfType<ProbabilisticTreeCreator>()) {317 foreach (ISymbolicExpressionTreeOperator op in Operators.OfType<ISymbolicExpressionTreeOperator>()) { 222 318 op.MaxTreeHeightParameter.ActualName = MaxExpressionDepthParameter.Name; 223 319 op.MaxTreeSizeParameter.ActualName = MaxExpressionLengthParameter.Name; … … 226 322 foreach (Evaluator op in Operators.OfType<Evaluator>()) { 227 323 op.SymbolicExpressionTreeParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName; 324 op.MaxTimeStepsParameter.ActualName = MaxTimeStepsParameter.Name; 325 op.WorldParameter.ActualName = WorldParameter.Name; 228 326 } 229 327 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;233 328 op.ParentsParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName; 234 329 op.ChildParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName; 235 330 } 236 331 } 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 244 333 245 334 #endregion -
trunk/sources/HeuristicLab.Problems.ArtificialAnt/3.3/BestAntTrailVisualizer.cs
r3238 r3239 36 36 [StorableClass] 37 37 public sealed class BestAntTrailVisualizer : SingleSuccessorOperator, IAntTrailVisualizer { 38 public ILookupParameter<BoolMatrix> WorldParameter { 39 get { return (ILookupParameter<BoolMatrix>)Parameters["World"]; } 40 } 38 41 public ILookupParameter<ItemArray<SymbolicExpressionTree>> SymbolicExpressionTreeParameter { 39 42 get { return (ILookupParameter<ItemArray<SymbolicExpressionTree>>)Parameters["SymbolicExpressionTree"]; } … … 42 45 get { return (ILookupParameter<ItemArray<DoubleValue>>)Parameters["Quality"]; } 43 46 } 47 public ILookupParameter<IntValue> MaxTimeStepsParameter { 48 get { return (ILookupParameter<IntValue>)Parameters["MaxTimeSteps"]; } 49 } 50 44 51 public ILookupParameter<AntTrail> AntTrailParameter { 45 52 get { return (ILookupParameter<AntTrail>)Parameters["AntTrail"]; } … … 51 58 public BestAntTrailVisualizer() 52 59 : base() { 53 Parameters.Add(new LookupParameter< DoubleMatrix>("Coordinates", "The x- and y-Coordinates of the cities."));60 Parameters.Add(new LookupParameter<BoolMatrix>("World", "The world with food items for the artificial ant.")); 54 61 Parameters.Add(new SubScopesLookupParameter<SymbolicExpressionTree>("SymbolicExpressionTree", "The artificial ant solutions from which the best solution should be visualized.")); 55 62 Parameters.Add(new SubScopesLookupParameter<DoubleValue>("Quality", "The qualities of the artificial ant solutions which should be visualized.")); 56 63 Parameters.Add(new LookupParameter<AntTrail>("AntTrail", "The visual representation of the best ant trail.")); 64 Parameters.Add(new LookupParameter<IntValue>("MaxTimeSteps", "The maximal time steps that the artificial ant has available to collect all food items.")); 57 65 } 58 66 … … 60 68 ItemArray<SymbolicExpressionTree> expressions = SymbolicExpressionTreeParameter.ActualValue; 61 69 ItemArray<DoubleValue> qualities = QualityParameter.ActualValue; 70 BoolMatrix world = WorldParameter.ActualValue; 71 IntValue maxTimeSteps = MaxTimeStepsParameter.ActualValue; 62 72 63 73 int i = qualities.Select((x, index) => new { index, x.Value }).OrderBy(x => -x.Value).First().index; 64 74 65 75 AntTrail antTrail = AntTrailParameter.ActualValue; 66 if (antTrail == null) AntTrailParameter.ActualValue = new AntTrail( expressions[i]);76 if (antTrail == null) AntTrailParameter.ActualValue = new AntTrail(world, expressions[i], maxTimeSteps); 67 77 else { 78 antTrail.World = world; 68 79 antTrail.SymbolicExpressionTree = expressions[i]; 80 antTrail.MaxTimeSteps = maxTimeSteps; 69 81 } 70 82 return base.Apply(); -
trunk/sources/HeuristicLab.Problems.ArtificialAnt/3.3/Evaluator.cs
r3223 r3239 40 40 get { return (ILookupParameter<SymbolicExpressionTree>)Parameters["SymbolicExpressionTree"]; } 41 41 } 42 public ILookupParameter<BoolMatrix> WorldParameter { 43 get { return (ILookupParameter<BoolMatrix>)Parameters["World"]; } 44 } 45 public ILookupParameter<IntValue> MaxTimeStepsParameter { 46 get { return (ILookupParameter<IntValue>)Parameters["MaxTimeSteps"]; } 47 } 48 42 49 public Evaluator() 43 50 : base() { 44 51 Parameters.Add(new LookupParameter<DoubleValue>("Quality", "The quality of the evaluated artificial ant solution.")); 45 52 Parameters.Add(new LookupParameter<SymbolicExpressionTree>("SymbolicExpressionTree", "The artificial ant solution encoded as a symbolic expression tree that should be evaluated")); 53 Parameters.Add(new LookupParameter<BoolMatrix>("World", "The world for the artificial ant with scattered food items.")); 54 Parameters.Add(new LookupParameter<IntValue>("MaxTimeSteps", "The maximal number of time steps that the artificial ant should be simulated.")); 46 55 } 47 56 48 57 public sealed override IOperation Apply() { 58 SymbolicExpressionTree expression = SymbolicExpressionTreeParameter.ActualValue; 59 BoolMatrix world = WorldParameter.ActualValue; 60 IntValue maxTimeSteps = MaxTimeStepsParameter.ActualValue; 49 61 50 SymbolicExpressionTree solution = SymbolicExpressionTreeParameter.ActualValue;51 62 AntInterpreter interpreter = new AntInterpreter(); 52 interpreter.MaxTimeSteps = 600; 53 interpreter.Run(solution); 63 interpreter.MaxTimeSteps = maxTimeSteps.Value; 64 interpreter.World = world; 65 interpreter.Expression = expression; 66 interpreter.Run(); 54 67 55 68 QualityParameter.ActualValue = new DoubleValue(interpreter.FoodEaten); -
trunk/sources/HeuristicLab.Problems.ArtificialAnt/3.3/HeuristicLab.Problems.ArtificialAnt-3.3.csproj
r3238 r3239 71 71 </Reference> 72 72 <Reference Include="System.Drawing" /> 73 <Reference Include="System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">74 <SpecificVersion>False</SpecificVersion>75 <HintPath>..\..\..\..\..\..\Windows\Microsoft.NET\Framework\v2.0.50727\System.Windows.Forms.dll</HintPath>76 </Reference>77 73 <Reference Include="System.Xml.Linq"> 78 74 <RequiredTargetFramework>3.5</RequiredTargetFramework> … … 92 88 <Compile Include="ArtificialAntExpressionGrammar.cs" /> 93 89 <Compile Include="ArtificialAntProblem.cs" /> 94 <Compile Include="ArtificialAntProblemView.cs">95 <SubType>UserControl</SubType>96 </Compile>97 <Compile Include="ArtificialAntProblemView.Designer.cs">98 <DependentUpon>ArtificialAntProblemView.cs</DependentUpon>99 </Compile>100 90 <Compile Include="AntTrail.cs" /> 101 <Compile Include="AntTrailView.cs">102 <SubType>UserControl</SubType>103 </Compile>104 <Compile Include="AntTrailView.Designer.cs">105 <DependentUpon>AntTrailView.cs</DependentUpon>106 </Compile>107 91 <Compile Include="Properties\AssemblyInfo.cs" /> 108 92 <Compile Include="Symbols\IfFoodAhead.cs" /> … … 130 114 <Name>HeuristicLab.Common-3.2</Name> 131 115 </ProjectReference> 132 <ProjectReference Include="..\..\HeuristicLab.Core.Views\3.3\HeuristicLab.Core.Views-3.3.csproj">133 <Project>{E226881D-315F-423D-B419-A766FE0D8685}</Project>134 <Name>HeuristicLab.Core.Views-3.3</Name>135 </ProjectReference>136 116 <ProjectReference Include="..\..\HeuristicLab.Core\3.3\HeuristicLab.Core-3.3.csproj"> 137 117 <Project>{C36BD924-A541-4A00-AFA8-41701378DDC5}</Project> … … 146 126 <Name>HeuristicLab.Encodings.SymbolicExpressionTreeEncoding-3.3</Name> 147 127 </ProjectReference> 148 <ProjectReference Include="..\..\HeuristicLab.MainForm.WindowsForms\3.2\HeuristicLab.MainForm.WindowsForms-3.2.csproj">149 <Project>{AB687BBE-1BFE-476B-906D-44237135431D}</Project>150 <Name>HeuristicLab.MainForm.WindowsForms-3.2</Name>151 </ProjectReference>152 <ProjectReference Include="..\..\HeuristicLab.MainForm\3.2\HeuristicLab.MainForm-3.2.csproj">153 <Project>{3BD61258-31DA-4B09-89C0-4F71FEF5F05A}</Project>154 <Name>HeuristicLab.MainForm-3.2</Name>155 </ProjectReference>156 128 <ProjectReference Include="..\..\HeuristicLab.Operators\3.3\HeuristicLab.Operators-3.3.csproj"> 157 129 <Project>{23DA7FF4-D5B8-41B6-AA96-F0561D24F3EE}</Project> 158 130 <Name>HeuristicLab.Operators-3.3</Name> 159 </ProjectReference>160 <ProjectReference Include="..\..\HeuristicLab.Optimization.Views\3.3\HeuristicLab.Optimization.Views-3.3.csproj">161 <Project>{662B4B15-8F4D-4AE5-B3EB-D91C215F5AF2}</Project>162 <Name>HeuristicLab.Optimization.Views-3.3</Name>163 131 </ProjectReference> 164 132 <ProjectReference Include="..\..\HeuristicLab.Optimization\3.3\HeuristicLab.Optimization-3.3.csproj"> -
trunk/sources/HeuristicLab.Problems.ArtificialAnt/3.3/HeuristicLabProblemsArtificialAntPlugin.cs.frame
r3223 r3239 33 33 [PluginDependency("HeuristicLab.Data", "3.3.0.0")] 34 34 [PluginDependency("HeuristicLab.Encodings.SymbolicExpressionTreeEncoding","3.3.0.0")] 35 [PluginDependency("HeuristicLab.Operators", "3.3.0.0")] 35 36 [PluginDependency("HeuristicLab.Optimization", "3.3.0.0")] 36 [PluginDependency("HeuristicLab.Operators", "3.3.0.0")]37 37 [PluginDependency("HeuristicLab.Parameters", "3.3.0.0")] 38 38 [PluginDependency("HeuristicLab.Persistence", "3.3.0.0")] -
trunk/sources/HeuristicLab.Problems.ArtificialAnt/3.3/IAntTrailVisualizer.cs
r3238 r3239 24 24 using HeuristicLab.Optimization; 25 25 using HeuristicLab.Core; 26 using HeuristicLab.Data; 26 27 27 28 namespace HeuristicLab.Problems.ArtificialAnt { 28 29 public interface IAntTrailVisualizer : ISolutionsVisualizer, ISingleObjectiveSolutionsVisualizer { 29 30 ILookupParameter<ItemArray<SymbolicExpressionTree>> SymbolicExpressionTreeParameter { get; } 31 ILookupParameter<BoolMatrix> WorldParameter { get; } 32 ILookupParameter<IntValue> MaxTimeStepsParameter { get; } 30 33 } 31 34 } -
trunk/sources/HeuristicLab.Problems.TravelingSalesman/3.3/PathTSPTour.cs
r3158 r3239 82 82 public event EventHandler CoordinatesChanged; 83 83 private void OnCoordinatesChanged() { 84 if (CoordinatesChanged != null) 85 CoordinatesChanged(this, EventArgs.Empty); 84 var changed = CoordinatesChanged; 85 if (changed != null) 86 changed(this, EventArgs.Empty); 86 87 } 87 88 public event EventHandler PermutationChanged; 88 89 private void OnPermutationChanged() { 89 if (PermutationChanged != null) 90 PermutationChanged(this, EventArgs.Empty); 90 var changed = PermutationChanged; 91 if (changed != null) 92 changed(this, EventArgs.Empty); 91 93 } 92 94
Note: See TracChangeset
for help on using the changeset viewer.