Free cookie consent management tool by TermsFeed Policy Generator

Changeset 3139 for trunk/sources


Ignore:
Timestamp:
03/20/10 06:18:48 (15 years ago)
Author:
swagner
Message:

Finished first version of TSP tour visualization (#924).

Location:
trunk/sources
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Algorithms.SGA/3.3/SGA.cs

    r3107 r3139  
    191191      UpdateMutators();
    192192      Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
     193      if (Problem.Visualizer != null) Problem.Visualizer.VisualizationParameter.ActualNameChanged += new EventHandler(Visualizer_VisualizationParameter_ActualNameChanged);
    193194      base.OnProblemChanged();
    194195    }
     196
    195197    protected override void Problem_SolutionCreatorChanged(object sender, EventArgs e) {
    196198      ParameterizeStochasticOperator(Problem.SolutionCreator);
     
    209211      ParameterizeStochasticOperator(Problem.Visualizer);
    210212      ParameterizeSGAMainLoop();
     213      if (Problem.Visualizer != null) Problem.Visualizer.VisualizationParameter.ActualNameChanged += new EventHandler(Visualizer_VisualizationParameter_ActualNameChanged);
    211214      base.Problem_VisualizerChanged(sender, e);
    212215    }
     
    234237      ParameterizeSGAMainLoop();
    235238      ParameterizeSelectors();
     239    }
     240    private void Visualizer_VisualizationParameter_ActualNameChanged(object sender, EventArgs e) {
     241      ParameterizeSGAMainLoop();
    236242    }
    237243    #endregion
     
    246252      ElitesParameter.ValueChanged += new EventHandler(ElitesParameter_ValueChanged);
    247253      Elites.ValueChanged += new EventHandler(Elites_ValueChanged);
    248       if (Problem != null)
     254      if (Problem != null) {
     255        UpdateCrossovers();
     256        UpdateMutators();
    249257        Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
     258        if (Problem.Visualizer != null) Problem.Visualizer.VisualizationParameter.ActualNameChanged += new EventHandler(Visualizer_VisualizationParameter_ActualNameChanged);
     259      }
    250260    }
    251261
     
    260270      SGAMainLoop.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
    261271      SGAMainLoop.VisualizerParameter.ActualName = Problem.VisualizerParameter.Name;
    262       SGAMainLoop.VisualizationParameter.ActualName = Problem.Visualizer.VisualizationParameter.ActualName;
     272      if (Problem.Visualizer != null)
     273        SGAMainLoop.VisualizationParameter.ActualName = Problem.Visualizer.VisualizationParameter.ActualName;
    263274    }
    264275    private void ParameterizeStochasticOperator(IOperator op) {
  • trunk/sources/HeuristicLab.Operators/3.3/ResultsCollector.cs

    r3095 r3139  
    4545      IVariable var;
    4646      foreach (IParameter param in CollectedValues) {
    47         results.TryGetValue(param.Name, out var);
    48         if (var != null)
    49           var.Value = (IItem)param.ActualValue;
    50         else
    51           results.Add(new Variable(param.Name, param.Description, param.ActualValue));
     47        IItem value = param.ActualValue;
     48        if (value != null) {
     49          results.TryGetValue(param.Name, out var);
     50          if (var != null)
     51            var.Value = value;
     52          else
     53            results.Add(new Variable(param.Name, param.Description, value));
     54        }
    5255      }
    5356      return base.Apply();
  • trunk/sources/HeuristicLab.Problems.TSP.Views/3.3/PathTSPTourView.cs

    r3107 r3139  
    8383          DoubleMatrix coordinates = Content.Coordinates;
    8484          Permutation permutation = Content.Permutation;
     85          Bitmap bitmap = new Bitmap(pictureBox.Width, pictureBox.Height);
    8586
    86           double xMin = double.MaxValue, yMin = double.MaxValue, xMax = double.MinValue, yMax = double.MinValue;
    87           for (int i = 0; i < coordinates.Rows; i++) {
    88             if (xMin > coordinates[i, 0]) xMin = coordinates[i, 0];
    89             if (yMin > coordinates[i, 1]) yMin = coordinates[i, 1];
    90             if (xMax < coordinates[i, 0]) xMax = coordinates[i, 0];
    91             if (yMax < coordinates[i, 1]) yMax = coordinates[i, 1];
     87          if (coordinates != null) {
     88            double xMin = double.MaxValue, yMin = double.MaxValue, xMax = double.MinValue, yMax = double.MinValue;
     89            for (int i = 0; i < coordinates.Rows; i++) {
     90              if (xMin > coordinates[i, 0]) xMin = coordinates[i, 0];
     91              if (yMin > coordinates[i, 1]) yMin = coordinates[i, 1];
     92              if (xMax < coordinates[i, 0]) xMax = coordinates[i, 0];
     93              if (yMax < coordinates[i, 1]) yMax = coordinates[i, 1];
     94            }
     95
     96            int border = 20;
     97            double xStep = (pictureBox.Width - 2 * border) / (xMax - xMin);
     98            double yStep = (pictureBox.Height - 2 * border) / (yMax - yMin);
     99
     100            Point[] points = new Point[coordinates.Rows];
     101            if (permutation == null) {
     102              for (int i = 0; i < coordinates.Rows; i++)
     103                points[i] = new Point(border + ((int)((coordinates[i, 0] - xMin) * xStep)),
     104                                      border + ((int)((coordinates[i, 1] - yMin) * yStep)));
     105            } else {
     106              for (int i = 0; i < coordinates.Rows; i++)
     107                points[i] = new Point(border + ((int)((coordinates[permutation[i], 0] - xMin) * xStep)),
     108                                      border + ((int)((coordinates[permutation[i], 1] - yMin) * yStep)));
     109            }
     110
     111            Graphics graphics = Graphics.FromImage(bitmap);
     112            if (permutation != null) graphics.DrawPolygon(Pens.Black, points);
     113            for (int i = 0; i < points.Length; i++)
     114              graphics.FillRectangle(Brushes.Red, points[i].X - 2, points[i].Y - 2, 6, 6);
     115            graphics.Dispose();
    92116          }
    93 
    94           int border = 20;
    95           double xStep = (pictureBox.Width - 2 * border) / (xMax - xMin);
    96           double yStep = (pictureBox.Height - 2 * border) / (yMax - yMin);
    97 
    98           Point[] points = new Point[coordinates.Rows];
    99           for (int i = 0; i < coordinates.Rows; i++)
    100             points[i] = new Point(border + ((int)((coordinates[permutation[i], 0] - xMin) * xStep)),
    101                                   border + ((int)((coordinates[permutation[i], 1] - yMin) * yStep)));
    102 
    103           Bitmap bitmap = new Bitmap(pictureBox.Width, pictureBox.Height);
    104           Graphics graphics = Graphics.FromImage(bitmap);
    105           graphics.DrawPolygon(Pens.Black, points);
    106           for (int i = 0; i < points.Length; i++)
    107             graphics.FillRectangle(Brushes.Blue, points[i].X - 1, points[i].Y - 1, 4, 4);
    108           graphics.Dispose();
    109117          pictureBox.Image = bitmap;
    110118        }
  • trunk/sources/HeuristicLab.Problems.TSP/3.3/PathTSPTour.cs

    r3133 r3139  
    3939      get { return coordinates; }
    4040      set {
    41         if (value == null) throw new ArgumentNullException();
    4241        if (coordinates != value) {
    4342          if (coordinates != null) DeregisterCoordinatesEvents();
     
    5352      get { return permutation; }
    5453      set {
    55         if (value == null) throw new ArgumentNullException();
    5654        if (permutation != value) {
    5755          if (permutation != null) DeregisterPermutationEvents();
     
    6361    }
    6462
    65     private PathTSPTour() : base() { }
    66     public PathTSPTour(DoubleMatrix coordinates, Permutation permutation)
     63    public PathTSPTour() : base() { }
     64    public PathTSPTour(DoubleMatrix coordinates)
    6765      : base() {
    6866      Coordinates = coordinates;
     67    }
     68    public PathTSPTour(DoubleMatrix coordinates, Permutation permutation)
     69      : this(coordinates) {
    6970      Permutation = permutation;
    7071    }
  • trunk/sources/HeuristicLab.Problems.TSP/3.3/TSP.cs

    r3107 r3139  
    218218    }
    219219    private void EvaluatorParameter_ValueChanged(object sender, EventArgs e) {
     220      Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
    220221      ParameterizeEvaluator();
    221222      ParameterizeVisualizer();
    222223      ClearDistanceMatrix();
    223224      OnEvaluatorChanged();
     225    }
     226    private void Evaluator_QualityParameter_ActualNameChanged(object sender, EventArgs e) {
     227      ParameterizeVisualizer();
    224228    }
    225229    private void VisualizerParameter_ValueChanged(object sender, EventArgs e) {
     
    251255      SolutionCreator.PermutationParameter.ActualNameChanged += new EventHandler(SolutionCreator_PermutationParameter_ActualNameChanged);
    252256      EvaluatorParameter.ValueChanged += new EventHandler(EvaluatorParameter_ValueChanged);
     257      Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
    253258      VisualizerParameter.ValueChanged += new EventHandler(VisualizerParameter_ValueChanged);
    254259    }
     260
    255261    private void InitializeOperators() {
    256262      operators = new List<IPermutationOperator>();
     
    287293    }
    288294    private void ParameterizeVisualizer() {
    289       Visualizer.QualityParameter.ActualName = Evaluator.QualityParameter.ActualName;
    290       if (Visualizer is ICoordinatesTSPSolutionsVisualizer)
    291         ((ICoordinatesTSPSolutionsVisualizer)Visualizer).CoordinatesParameter.ActualName = CoordinatesParameter.Name;
    292       if (Visualizer is IPathCoordinatesTSPSolutionsVisualizer)
    293         ((IPathCoordinatesTSPSolutionsVisualizer)Visualizer).PermutationParameter.ActualName = SolutionCreator.PermutationParameter.ActualName;
     295      if (Visualizer != null) {
     296        Visualizer.QualityParameter.ActualName = Evaluator.QualityParameter.ActualName;
     297        if (Visualizer is ICoordinatesTSPSolutionsVisualizer)
     298          ((ICoordinatesTSPSolutionsVisualizer)Visualizer).CoordinatesParameter.ActualName = CoordinatesParameter.Name;
     299        if (Visualizer is IPathCoordinatesTSPSolutionsVisualizer)
     300          ((IPathCoordinatesTSPSolutionsVisualizer)Visualizer).PermutationParameter.ActualName = SolutionCreator.PermutationParameter.ActualName;
     301      }
    294302    }
    295303    private void ParameterizeOperators() {
Note: See TracChangeset for help on using the changeset viewer.