Free cookie consent management tool by TermsFeed Policy Generator

Changeset 3239


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

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

Location:
trunk/sources
Files:
8 added
16 edited
4 moved

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab 3.3.sln

    r3230 r3239  
    8080    {BF7D9494-A586-457B-8DF9-ED599F9E6A71} = {BF7D9494-A586-457B-8DF9-ED599F9E6A71}
    8181    {DE12659F-87C4-48E6-B2E3-4E73DD95A540} = {DE12659F-87C4-48E6-B2E3-4E73DD95A540}
     82    {30DD3DA2-CA57-49DD-A5BA-50CEF19DB45F} = {30DD3DA2-CA57-49DD-A5BA-50CEF19DB45F}
    8283    {F5C0ECAC-EDBA-4024-872A-1F74AFCB20B4} = {F5C0ECAC-EDBA-4024-872A-1F74AFCB20B4}
    8384    {DBECB8B0-B166-4133-BAF1-ED67C3FD7FCA} = {DBECB8B0-B166-4133-BAF1-ED67C3FD7FCA}
     
    229230EndProject
    230231Project("{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}"
     232EndProject
     233Project("{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}"
    231234EndProject
    232235Global
     
    12821285    {F5C0ECAC-EDBA-4024-872A-1F74AFCB20B4}.Services|x64.ActiveCfg = Release|x64
    12831286    {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
    12841302  EndGlobalSection
    12851303  GlobalSection(SolutionProperties) = preSolution
  • trunk/sources/HeuristicLab 3.3/Files.txt

    r3223 r3239  
    4242HeuristicLab.PluginAdministrator\3.3:HeuristicLab.PluginAdministrator-3.3.dll
    4343HeuristicLab.Problems.ArtificialAnt\3.3:HeuristicLab.Problems.ArtificialAnt-3.3.dll
     44HeuristicLab.Problems.ArtificialAnt.Views\3.3:HeuristicLab.Problems.ArtificialAnt.Views-3.3.dll
    4445HeuristicLab.Problems.Knapsack\3.3:HeuristicLab.Problems.Knapsack-3.3.dll
    4546HeuristicLab.Problems.Knapsack.Views\3.3:HeuristicLab.Problems.Knapsack.Views-3.3.dll
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Creators/ProbabilisticTreeCreator.cs

    r3237 r3239  
    3232  [Item("ProbabilisticTreeCreator", "An operator that creates new symbolic expression trees with uniformly distributed size")]
    3333  public class ProbabilisticTreeCreator : SymbolicExpressionTreeCreator {
    34     private const int MAX_TRIES = 100;
    3534    public ProbabilisticTreeCreator()
    3635      : base() {
     
    4847      int treeSize = random.Next(allowedMinSize, allowedMaxSize);
    4948      SymbolicExpressionTree tree = new SymbolicExpressionTree();
    50       int tries = 0;
    5149      do {
    5250        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);
    6152        }
    6253        catch (ArgumentException) {
    6354          // try a different size
    6455          treeSize = random.Next(allowedMinSize, allowedMaxSize);
    65           tries = 0;
    66         }
    67         if (tries++ >= MAX_TRIES) {
    68           // try a different size
    69           treeSize = random.Next(allowedMinSize, allowedMaxSize);
    70           tries = 0;
    7156        }
    7257      } while (tree.Root == null || tree.Size > maxTreeSize || tree.Height > maxTreeHeight);
     
    191176      return tree;
    192177    }
    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 indexes
    212     //    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 
    224178  }
    225179}
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding-3.3.csproj

    r3237 r3239  
    8787    <Compile Include="Creators\ProbabilisticTreeCreator.cs" />
    8888    <Compile Include="HeuristicLabEncodingsSymbolicExpressionTreeEncodingPlugin.cs" />
     89    <Compile Include="Interfaces\ISymbolicExpressionTreeOperator.cs" />
    8990    <Compile Include="SymbolicExpressionGrammar.cs" />
    9091    <Compile Include="SymbolicExpressionTreeCreator.cs" />
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/SymbolicExpressionTreeCreator.cs

    r3223 r3239  
    3333  [Item("SymbolicExpressionTreeCreator", "A base class for operators creating symbolic expression trees.")]
    3434  [StorableClass]
    35   public abstract class SymbolicExpressionTreeCreator : SingleSuccessorOperator, ISolutionCreator, IStochasticOperator {
     35  public abstract class SymbolicExpressionTreeCreator : SingleSuccessorOperator, ISolutionCreator, IStochasticOperator, ISymbolicExpressionTreeOperator {
    3636    private const string RandomParameterName = "Random";
    3737    private const string SymbolicExpressionTreeParameterName = "SymbolicExpressionTree";
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/SymbolicExpressionTreeCrossover.cs

    r3237 r3239  
    3535  [Item("SymbolicExpressionTreeCrossover", "A base class for operators that perform a crossover of symbolic expression trees.")]
    3636  [StorableClass]
    37   public abstract class SymbolicExpressionTreeCrossover : SingleSuccessorOperator, ICrossover, IStochasticOperator {
     37  public abstract class SymbolicExpressionTreeCrossover : SingleSuccessorOperator, ICrossover, IStochasticOperator, ISymbolicExpressionTreeOperator {
    3838    public override bool CanChangeName {
    3939      get { return false; }
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/SymbolicExpressionTreeManipulator.cs

    r3223 r3239  
    3333  [Item("RealVectorManipulator", "A base class for operators that manipulate real-valued vectors.")]
    3434  [StorableClass]
    35   public abstract class RealVectorManipulator : SingleSuccessorOperator, IRealVectorManipulator, IStochasticOperator {
     35  public abstract class RealVectorManipulator : SingleSuccessorOperator, IRealVectorManipulator, IStochasticOperator, ISymbolicExpressionTreeOperator {
    3636    public override bool CanChangeName {
    3737      get { return false; }
  • trunk/sources/HeuristicLab.Problems.ArtificialAnt.Views/3.3/AntTrailView.Designer.cs

    r3238 r3239  
    2020#endregion
    2121
    22 namespace HeuristicLab.Problems.ArtificialAnt {
     22namespace HeuristicLab.Problems.ArtificialAnt.Views {
    2323  partial class AntTrailView {
    2424    /// <summary>
     
    4545    /// </summary>
    4646    private void InitializeComponent() {
     47      this.components = new System.ComponentModel.Container();
    4748      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);
    4851      ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit();
    4952      this.SuspendLayout();
     
    5861      this.pictureBox.Location = new System.Drawing.Point(0, 0);
    5962      this.pictureBox.Name = "pictureBox";
    60       this.pictureBox.Size = new System.Drawing.Size(392, 310);
     63      this.pictureBox.Size = new System.Drawing.Size(392, 275);
    6164      this.pictureBox.TabIndex = 0;
    6265      this.pictureBox.TabStop = false;
    6366      this.pictureBox.SizeChanged += new System.EventHandler(this.pictureBox_SizeChanged);
    6467      //
    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
    6685      //
    6786      this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
    6887      this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
     88      this.Controls.Add(this.playButton);
    6989      this.Controls.Add(this.pictureBox);
    70       this.Name = "PathTSPTourView";
     90      this.Name = "AntTrailView";
    7191      this.Size = new System.Drawing.Size(392, 310);
     92      this.EnabledChanged += new System.EventHandler(this.AntTrailView_EnabledChanged);
    7293      ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit();
    7394      this.ResumeLayout(false);
     
    7899
    79100    private System.Windows.Forms.PictureBox pictureBox;
     101    private System.Windows.Forms.Button playButton;
     102    private System.Windows.Forms.Timer animationTimer;
    80103
    81104
  • trunk/sources/HeuristicLab.Problems.ArtificialAnt.Views/3.3/AntTrailView.cs

    r3238 r3239  
    2929using System.Collections.Generic;
    3030
    31 namespace HeuristicLab.Problems.ArtificialAnt {
     31namespace HeuristicLab.Problems.ArtificialAnt.Views {
    3232  [View("AntTrail View")]
    3333  [Content(typeof(AntTrail), true)]
    3434  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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    42       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,
    43       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,
    44       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,
    45       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,
    46       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,
    47       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,
    48       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    49       0, 0, 0, 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 0, 0, 0, 0, 0, 0,
    70       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,
    71       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,
    72       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,
    73     };
    74 
    75     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 
    8235    public new AntTrail Content {
    8336      get { return (AntTrail)base.Content; }
     
    8740    public AntTrailView() {
    8841      InitializeComponent();
    89       ResetTrailInterpreter();
    9042    }
    9143
     
    11567    }
    11668
    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 
    12669    private void GenerateImage() {
     70      playButton.Enabled = this.Enabled;
     71      animationTimer.Stop();
    12772      if ((pictureBox.Width > 0) && (pictureBox.Height > 0)) {
    12873        if (Content == null) {
    12974          pictureBox.Image = null;
     75          playButton.Enabled = false;
    13076        } else {
    131           ResetTrailInterpreter();
     77          var nodeStack = new Stack<SymbolicExpressionTreeNode>();
     78          int rows = Content.World.Rows;
     79          int columns = Content.World.Columns;
    13280          SymbolicExpressionTree expression = Content.SymbolicExpressionTree;
    13381
    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);
    141101            }
    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);
    220164    }
    221165
     
    230174      GenerateImage();
    231175    }
     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    }
    232231  }
    233232}
  • trunk/sources/HeuristicLab.Problems.ArtificialAnt.Views/3.3/ArtificialAntProblemView.Designer.cs

    r3238 r3239  
    1 namespace HeuristicLab.Problems.ArtificialAnt {
     1namespace HeuristicLab.Problems.ArtificialAnt.Views {
    22  partial class ArtificialAntProblemView {
    33    /// <summary>
  • trunk/sources/HeuristicLab.Problems.ArtificialAnt.Views/3.3/ArtificialAntProblemView.cs

    r3238 r3239  
    99using HeuristicLab.MainForm;
    1010
    11 namespace HeuristicLab.Problems.ArtificialAnt {
     11namespace HeuristicLab.Problems.ArtificialAnt.Views {
    1212  [View("ArtificialAntProblem View")]
    1313  [Content(typeof(ArtificialAntProblem), true)]
  • trunk/sources/HeuristicLab.Problems.ArtificialAnt/3.3/AntInterpreter.cs

    r3238 r3239  
    2222using System;
    2323using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
     24using HeuristicLab.Data;
     25using System.Collections.Generic;
    2426
    2527namespace 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, 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 0, 0, 0, 0, 0, 0, 0,
    55       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, 1, 0, 0, 0, 0, 0,
    56       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0,
    57       0, 0, 0, 1, 1, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    58       0, 1, 0, 0, 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,
    59       0, 1, 0, 0, 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,
    60       0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    61       0, 1, 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,
    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 {
    7029    public int MaxTimeSteps { get; set; }
    7130    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();
    8638      }
    8739    }
    8840
    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();
    9084      if (currentNode.Symbol is Left) {
    91         if (ElapsedTime >= MaxTimeSteps || FoodEaten >= N_FOOD_ITEMS) return;
    9285        currentDirection = (currentDirection + 3) % 4;
    9386        ElapsedTime++;
    9487      } else if (currentNode.Symbol is Right) {
    95         if (ElapsedTime >= MaxTimeSteps || FoodEaten >= N_FOOD_ITEMS) return;
    9688        currentDirection = (currentDirection + 1) % 4;
    9789        ElapsedTime++;
    9890      } 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;
    10395        ElapsedTime++;
    10496      } 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]);
    107102        } else {
    108           Step(currentNode.SubTrees[1]);
     103          nodeStack.Push(currentNode.SubTrees[1]);
    109104        }
    110105      } 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]);
    113108        return;
    114109      } 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]);
    118113        return;
    119       } else  {
     114      } else {
    120115        throw new InvalidOperationException(currentNode.Symbol.ToString());
    121116      }
    122117    }
    123118
    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    }
    127122
     123    private void NextField(out int nextAntLocationRow, out int nextAntLocationColumn) {
    128124      switch (currentDirection) {
    129125        case 0:
    130           currentLocationX = (currentLocationX + 1) % WORLD_WIDTH; // EAST
     126          nextAntLocationColumn = (currentAntLocationColumn + 1) % World.Columns; // EAST
     127          nextAntLocationRow = currentAntLocationRow;
    131128          break;
    132129        case 1:
    133           currentLocationY = (currentLocationY + 1) % WORLD_HEIGHT; // SOUTH
     130          nextAntLocationRow = (currentAntLocationRow + 1) % World.Rows; // SOUTH
     131          nextAntLocationColumn = currentAntLocationColumn;
    134132          break;
    135133        case 2:
    136           currentLocationX = (currentLocationX + WORLD_WIDTH - 1) % WORLD_WIDTH; // WEST
     134          nextAntLocationColumn = (currentAntLocationColumn + World.Columns - 1) % World.Columns; // WEST
     135          nextAntLocationRow = currentAntLocationRow;
    137136          break;
    138137        case 3:
    139           currentLocationY = (currentLocationY + WORLD_HEIGHT - 1) % WORLD_HEIGHT; // NORTH
     138          nextAntLocationRow = (currentAntLocationRow + World.Rows - 1) % World.Rows; // NORTH
     139          nextAntLocationColumn = currentAntLocationColumn;
    140140          break;
    141141        default:
    142142          throw new InvalidOperationException();
    143143      }
    144       return currentLocationY * WORLD_WIDTH + currentLocationX;
    145144    }
    146145  }
  • trunk/sources/HeuristicLab.Problems.ArtificialAnt/3.3/AntTrail.cs

    r3238 r3239  
    4848    }
    4949
     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
    5079    public AntTrail() : base() { }
    51     public AntTrail(SymbolicExpressionTree expression)
     80    public AntTrail(BoolMatrix world, SymbolicExpressionTree expression, IntValue maxTimeSteps)
    5281      : this() {
     82      World = world;
    5383      SymbolicExpressionTree = expression;
     84      MaxTimeSteps = maxTimeSteps;
    5485    }
    5586
     
    5889      cloner.RegisterClonedObject(this, clone);
    5990      clone.expression = (SymbolicExpressionTree)cloner.Clone(expression);
     91      clone.world = (BoolMatrix)cloner.Clone(world);
     92      clone.maxTimeSteps = (IntValue)cloner.Clone(maxTimeSteps);
    6093      return clone;
    6194    }
    6295
    63     //#region Events
     96    #region Events
    6497    public event EventHandler SymbolicExpressionTreeChanged;
    6598    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);
    68114    }
    69115
     
    77123    //}
    78124
    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
    86150  }
    87151}
  • 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
  • trunk/sources/HeuristicLab.Problems.ArtificialAnt/3.3/BestAntTrailVisualizer.cs

    r3238 r3239  
    3636  [StorableClass]
    3737  public sealed class BestAntTrailVisualizer : SingleSuccessorOperator, IAntTrailVisualizer {
     38    public ILookupParameter<BoolMatrix> WorldParameter {
     39      get { return (ILookupParameter<BoolMatrix>)Parameters["World"]; }
     40    }
    3841    public ILookupParameter<ItemArray<SymbolicExpressionTree>> SymbolicExpressionTreeParameter {
    3942      get { return (ILookupParameter<ItemArray<SymbolicExpressionTree>>)Parameters["SymbolicExpressionTree"]; }
     
    4245      get { return (ILookupParameter<ItemArray<DoubleValue>>)Parameters["Quality"]; }
    4346    }
     47    public ILookupParameter<IntValue> MaxTimeStepsParameter {
     48      get { return (ILookupParameter<IntValue>)Parameters["MaxTimeSteps"]; }
     49    }
     50
    4451    public ILookupParameter<AntTrail> AntTrailParameter {
    4552      get { return (ILookupParameter<AntTrail>)Parameters["AntTrail"]; }
     
    5158    public BestAntTrailVisualizer()
    5259      : 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."));
    5461      Parameters.Add(new SubScopesLookupParameter<SymbolicExpressionTree>("SymbolicExpressionTree", "The artificial ant solutions from which the best solution should be visualized."));
    5562      Parameters.Add(new SubScopesLookupParameter<DoubleValue>("Quality", "The qualities of the artificial ant solutions which should be visualized."));
    5663      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."));
    5765    }
    5866
     
    6068      ItemArray<SymbolicExpressionTree> expressions = SymbolicExpressionTreeParameter.ActualValue;
    6169      ItemArray<DoubleValue> qualities = QualityParameter.ActualValue;
     70      BoolMatrix world = WorldParameter.ActualValue;
     71      IntValue maxTimeSteps = MaxTimeStepsParameter.ActualValue;
    6272
    6373      int i = qualities.Select((x, index) => new { index, x.Value }).OrderBy(x => -x.Value).First().index;
    6474
    6575      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);
    6777      else {
     78        antTrail.World = world;
    6879        antTrail.SymbolicExpressionTree = expressions[i];
     80        antTrail.MaxTimeSteps = maxTimeSteps;
    6981      }
    7082      return base.Apply();
  • trunk/sources/HeuristicLab.Problems.ArtificialAnt/3.3/Evaluator.cs

    r3223 r3239  
    4040      get { return (ILookupParameter<SymbolicExpressionTree>)Parameters["SymbolicExpressionTree"]; }
    4141    }
     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
    4249    public Evaluator()
    4350      : base() {
    4451      Parameters.Add(new LookupParameter<DoubleValue>("Quality", "The quality of the evaluated artificial ant solution."));
    4552      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."));
    4655    }
    4756
    4857    public sealed override IOperation Apply() {
     58      SymbolicExpressionTree expression = SymbolicExpressionTreeParameter.ActualValue;
     59      BoolMatrix world = WorldParameter.ActualValue;
     60      IntValue maxTimeSteps = MaxTimeStepsParameter.ActualValue;
    4961
    50       SymbolicExpressionTree solution = SymbolicExpressionTreeParameter.ActualValue;
    5162      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();
    5467
    5568      QualityParameter.ActualValue = new DoubleValue(interpreter.FoodEaten);
  • trunk/sources/HeuristicLab.Problems.ArtificialAnt/3.3/HeuristicLab.Problems.ArtificialAnt-3.3.csproj

    r3238 r3239  
    7171    </Reference>
    7272    <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>
    7773    <Reference Include="System.Xml.Linq">
    7874      <RequiredTargetFramework>3.5</RequiredTargetFramework>
     
    9288    <Compile Include="ArtificialAntExpressionGrammar.cs" />
    9389    <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>
    10090    <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>
    10791    <Compile Include="Properties\AssemblyInfo.cs" />
    10892    <Compile Include="Symbols\IfFoodAhead.cs" />
     
    130114      <Name>HeuristicLab.Common-3.2</Name>
    131115    </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>
    136116    <ProjectReference Include="..\..\HeuristicLab.Core\3.3\HeuristicLab.Core-3.3.csproj">
    137117      <Project>{C36BD924-A541-4A00-AFA8-41701378DDC5}</Project>
     
    146126      <Name>HeuristicLab.Encodings.SymbolicExpressionTreeEncoding-3.3</Name>
    147127    </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>
    156128    <ProjectReference Include="..\..\HeuristicLab.Operators\3.3\HeuristicLab.Operators-3.3.csproj">
    157129      <Project>{23DA7FF4-D5B8-41B6-AA96-F0561D24F3EE}</Project>
    158130      <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>
    163131    </ProjectReference>
    164132    <ProjectReference Include="..\..\HeuristicLab.Optimization\3.3\HeuristicLab.Optimization-3.3.csproj">
  • trunk/sources/HeuristicLab.Problems.ArtificialAnt/3.3/HeuristicLabProblemsArtificialAntPlugin.cs.frame

    r3223 r3239  
    3333  [PluginDependency("HeuristicLab.Data", "3.3.0.0")]
    3434  [PluginDependency("HeuristicLab.Encodings.SymbolicExpressionTreeEncoding","3.3.0.0")]
     35  [PluginDependency("HeuristicLab.Operators", "3.3.0.0")]
    3536  [PluginDependency("HeuristicLab.Optimization", "3.3.0.0")]
    36   [PluginDependency("HeuristicLab.Operators", "3.3.0.0")]
    3737  [PluginDependency("HeuristicLab.Parameters", "3.3.0.0")]
    3838  [PluginDependency("HeuristicLab.Persistence", "3.3.0.0")]
  • trunk/sources/HeuristicLab.Problems.ArtificialAnt/3.3/IAntTrailVisualizer.cs

    r3238 r3239  
    2424using HeuristicLab.Optimization;
    2525using HeuristicLab.Core;
     26using HeuristicLab.Data;
    2627
    2728namespace HeuristicLab.Problems.ArtificialAnt {
    2829  public interface IAntTrailVisualizer : ISolutionsVisualizer, ISingleObjectiveSolutionsVisualizer {
    2930    ILookupParameter<ItemArray<SymbolicExpressionTree>> SymbolicExpressionTreeParameter { get; }
     31    ILookupParameter<BoolMatrix> WorldParameter { get; }
     32    ILookupParameter<IntValue> MaxTimeStepsParameter { get; }
    3033  }
    3134}
  • trunk/sources/HeuristicLab.Problems.TravelingSalesman/3.3/PathTSPTour.cs

    r3158 r3239  
    8282    public event EventHandler CoordinatesChanged;
    8383    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);
    8687    }
    8788    public event EventHandler PermutationChanged;
    8889    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);
    9193    }
    9294
Note: See TracChangeset for help on using the changeset viewer.