Free cookie consent management tool by TermsFeed Policy Generator

Changeset 8093


Ignore:
Timestamp:
06/24/12 17:57:51 (10 years ago)
Author:
abeham
Message:

#1855:

  • Added possibility to name row and column in matrix (to have more interpretable results)
  • Added a "standard" assignment problem
Location:
trunk/sources
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Problems.LinearAssignment.Views/3.3/LAPAssignmentView.Designer.cs

    r8022 r8093  
    4545    /// </summary>
    4646    private void InitializeComponent() {
    47       this.assignmentView = new HeuristicLab.Data.Views.StringConvertibleArrayView();
    4847      this.qualityView = new HeuristicLab.Data.Views.StringConvertibleValueView();
     48      this.splitContainer = new System.Windows.Forms.SplitContainer();
     49      this.assignmentDataGridView = new System.Windows.Forms.DataGridView();
     50      this.RowsColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
     51      this.Columns = new System.Windows.Forms.DataGridViewTextBoxColumn();
     52      ((System.ComponentModel.ISupportInitialize)(this.splitContainer)).BeginInit();
     53      this.splitContainer.Panel1.SuspendLayout();
     54      this.splitContainer.SuspendLayout();
     55      ((System.ComponentModel.ISupportInitialize)(this.assignmentDataGridView)).BeginInit();
    4956      this.SuspendLayout();
    50       //
    51       // assignmentView
    52       //
    53       this.assignmentView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
    54                   | System.Windows.Forms.AnchorStyles.Left)
    55                   | System.Windows.Forms.AnchorStyles.Right)));
    56       this.assignmentView.Caption = "StringConvertibleArray View";
    57       this.assignmentView.Content = null;
    58       this.assignmentView.Location = new System.Drawing.Point(0, 30);
    59       this.assignmentView.Name = "assignmentView";
    60       this.assignmentView.ReadOnly = true;
    61       this.assignmentView.Size = new System.Drawing.Size(422, 130);
    62       this.assignmentView.TabIndex = 0;
    6357      //
    6458      // qualityView
     
    7266      this.qualityView.Name = "qualityView";
    7367      this.qualityView.ReadOnly = true;
    74       this.qualityView.Size = new System.Drawing.Size(422, 21);
     68      this.qualityView.Size = new System.Drawing.Size(413, 21);
    7569      this.qualityView.TabIndex = 1;
     70      //
     71      // splitContainer
     72      //
     73      this.splitContainer.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
     74                  | System.Windows.Forms.AnchorStyles.Left)
     75                  | System.Windows.Forms.AnchorStyles.Right)));
     76      this.splitContainer.FixedPanel = System.Windows.Forms.FixedPanel.Panel2;
     77      this.splitContainer.Location = new System.Drawing.Point(0, 30);
     78      this.splitContainer.Name = "splitContainer";
     79      //
     80      // splitContainer.Panel1
     81      //
     82      this.splitContainer.Panel1.Controls.Add(this.assignmentDataGridView);
     83      this.splitContainer.Size = new System.Drawing.Size(413, 324);
     84      this.splitContainer.SplitterDistance = 250;
     85      this.splitContainer.TabIndex = 2;
     86      //
     87      // assignmentDataGridView
     88      //
     89      this.assignmentDataGridView.AllowUserToAddRows = false;
     90      this.assignmentDataGridView.AllowUserToDeleteRows = false;
     91      this.assignmentDataGridView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
     92                  | System.Windows.Forms.AnchorStyles.Left)
     93                  | System.Windows.Forms.AnchorStyles.Right)));
     94      this.assignmentDataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
     95      this.assignmentDataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
     96            this.RowsColumn,
     97            this.Columns});
     98      this.assignmentDataGridView.Location = new System.Drawing.Point(3, 3);
     99      this.assignmentDataGridView.Name = "assignmentDataGridView";
     100      this.assignmentDataGridView.ReadOnly = true;
     101      this.assignmentDataGridView.Size = new System.Drawing.Size(244, 318);
     102      this.assignmentDataGridView.TabIndex = 0;
     103      //
     104      // RowsColumn
     105      //
     106      this.RowsColumn.HeaderText = "Rows";
     107      this.RowsColumn.Name = "RowsColumn";
     108      this.RowsColumn.ReadOnly = true;
     109      //
     110      // Columns
     111      //
     112      this.Columns.HeaderText = "Columns";
     113      this.Columns.Name = "Columns";
     114      this.Columns.ReadOnly = true;
    76115      //
    77116      // LAPAssignmentView
     
    79118      this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
    80119      this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
     120      this.Controls.Add(this.splitContainer);
    81121      this.Controls.Add(this.qualityView);
    82       this.Controls.Add(this.assignmentView);
    83122      this.Name = "LAPAssignmentView";
    84       this.Size = new System.Drawing.Size(422, 160);
     123      this.Size = new System.Drawing.Size(413, 354);
     124      this.splitContainer.Panel1.ResumeLayout(false);
     125      ((System.ComponentModel.ISupportInitialize)(this.splitContainer)).EndInit();
     126      this.splitContainer.ResumeLayout(false);
     127      ((System.ComponentModel.ISupportInitialize)(this.assignmentDataGridView)).EndInit();
    85128      this.ResumeLayout(false);
    86129
     
    89132    #endregion
    90133
    91     private Data.Views.StringConvertibleArrayView assignmentView;
    92134    private Data.Views.StringConvertibleValueView qualityView;
     135    private System.Windows.Forms.SplitContainer splitContainer;
     136    private System.Windows.Forms.DataGridView assignmentDataGridView;
     137    private System.Windows.Forms.DataGridViewTextBoxColumn RowsColumn;
     138    private System.Windows.Forms.DataGridViewTextBoxColumn Columns;
    93139  }
    94140}
  • trunk/sources/HeuristicLab.Problems.LinearAssignment.Views/3.3/LAPAssignmentView.cs

    r8022 r8093  
    2020#endregion
    2121
     22using System;
    2223using System.ComponentModel;
    2324using System.Windows.Forms;
     25using HeuristicLab.Common;
    2426using HeuristicLab.Core.Views;
     27using HeuristicLab.Encodings.PermutationEncoding;
    2528using HeuristicLab.MainForm;
    2629using HeuristicLab.MainForm.WindowsForms;
     
    3033  [Content(typeof(LAPAssignment), IsDefaultView = true)]
    3134  public partial class LAPAssignmentView : ItemView {
     35    private ViewHost assignmentViewHost;
     36
    3237    public new LAPAssignment Content {
    3338      get { return (LAPAssignment)base.Content; }
     
    3742    public LAPAssignmentView() {
    3843      InitializeComponent();
     44      assignmentViewHost = new ViewHost();
     45      assignmentViewHost.Dock = DockStyle.Fill;
     46      assignmentViewHost.ViewsLabelVisible = true;
     47      splitContainer.Panel2.Controls.Add(assignmentViewHost);
    3948    }
    4049
     
    4251    protected override void DeregisterContentEvents() {
    4352      Content.PropertyChanged -= new PropertyChangedEventHandler(Content_PropertyChanged);
     53      if (Content.Assignment != null) Content.Assignment.ItemChanged -= new EventHandler<EventArgs<int>>(Assignment_ItemChanged);
     54      if (Content.RowNames != null) Content.RowNames.ItemChanged += new EventHandler<EventArgs<int>>(Names_ItemChanged);
     55      if (Content.ColumnNames != null) Content.ColumnNames.ItemChanged -= new EventHandler<EventArgs<int>>(Names_ItemChanged);
    4456      base.DeregisterContentEvents();
    4557    }
     
    4759      base.RegisterContentEvents();
    4860      Content.PropertyChanged += new PropertyChangedEventHandler(Content_PropertyChanged);
     61      if (Content.Assignment != null) Content.Assignment.ItemChanged += new EventHandler<EventArgs<int>>(Assignment_ItemChanged);
     62      if (Content.RowNames != null) Content.RowNames.ItemChanged += new EventHandler<EventArgs<int>>(Names_ItemChanged);
     63      if (Content.ColumnNames != null) Content.ColumnNames.ItemChanged += new EventHandler<EventArgs<int>>(Names_ItemChanged);
     64    }
     65
     66    private void Assignment_ItemChanged(object sender, EventArgs<int> e) {
     67      if (sender != Content.Assignment)
     68        ((Permutation)sender).ItemChanged -= new EventHandler<EventArgs<int>>(Assignment_ItemChanged);
     69      else UpdateAssignmentMatrix();
     70    }
     71
     72    private void Names_ItemChanged(object sender, EventArgs<int> e) {
     73      UpdateAssignmentMatrix();
    4974    }
    5075    #endregion
     
    5479      if (Content == null) {
    5580        qualityView.Content = null;
    56         assignmentView.Content = null;
     81        assignmentViewHost.Content = null;
     82        assignmentDataGridView.Rows.Clear();
    5783      } else {
    5884        qualityView.Content = Content.Quality;
    59         assignmentView.Content = Content.Assignment;
     85        assignmentViewHost.Content = Content.Assignment;
     86        UpdateAssignmentMatrix();
    6087      }
    6188    }
     
    6390    protected override void SetEnabledStateOfControls() {
    6491      base.SetEnabledStateOfControls();
     92      assignmentDataGridView.Enabled = Content != null;
    6593    }
    6694
     
    7098        case "Quality": qualityView.Content = Content.Quality;
    7199          break;
    72         case "Assignment": assignmentView.Content = Content.Assignment;
     100        case "Assignment":
     101          if (Content.Assignment != null)
     102            Content.Assignment.ItemChanged += new EventHandler<EventArgs<int>>(Assignment_ItemChanged);
     103          assignmentViewHost.Content = Content.Assignment;
     104          UpdateAssignmentMatrix();
     105          break;
     106        case "RowNames":
     107          if (Content.RowNames != null)
     108            Content.RowNames.ItemChanged += new EventHandler<EventArgs<int>>(Names_ItemChanged);
     109          UpdateAssignmentMatrix();
     110          break;
     111        case "ColumnNames":
     112          if (Content.ColumnNames != null)
     113            Content.ColumnNames.ItemChanged += new EventHandler<EventArgs<int>>(Names_ItemChanged);
     114          UpdateAssignmentMatrix();
    73115          break;
    74116        default: break;
     
    76118    }
    77119    #endregion
     120
     121    private void UpdateAssignmentMatrix() {
     122      assignmentDataGridView.Rows.Clear();
     123      if (Content.Assignment != null) {
     124        string rowName, colName;
     125        var rows = new DataGridViewRow[Content.Assignment.Length];
     126        for (int i = 0; i < Content.Assignment.Length; i++) {
     127          if (Content.RowNames != null && Content.RowNames.Length > i)
     128            rowName = Content.RowNames[i];
     129          else rowName = "Row " + (i + 1).ToString();
     130          if (Content.ColumnNames != null && Content.ColumnNames.Length > Content.Assignment[i])
     131            colName = Content.ColumnNames[Content.Assignment[i]];
     132          else colName = "Column " + (Content.Assignment[i] + 1).ToString();
     133          rows[i] = new DataGridViewRow();
     134          rows[i].CreateCells(assignmentDataGridView, new string[] { rowName, colName });
     135        }
     136        assignmentDataGridView.Rows.AddRange(rows);
     137        assignmentDataGridView.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells);
     138      }
     139    }
     140
    78141  }
    79142}
  • trunk/sources/HeuristicLab.Problems.LinearAssignment/3.3/Analyzers/BestLAPSolutionAnalyzer.cs

    r8022 r8093  
    4242      get { return (ILookupParameter<DoubleMatrix>)Parameters["Costs"]; }
    4343    }
     44    public IValueLookupParameter<StringArray> RowNamesParameter {
     45      get { return (IValueLookupParameter<StringArray>)Parameters["RowNames"]; }
     46    }
     47    public IValueLookupParameter<StringArray> ColumnNamesParameter {
     48      get { return (IValueLookupParameter<StringArray>)Parameters["ColumnNames"]; }
     49    }
    4450    public IScopeTreeLookupParameter<Permutation> AssignmentParameter {
    4551      get { return (IScopeTreeLookupParameter<Permutation>)Parameters["Assignment"]; }
     
    7177      Parameters.Add(new LookupParameter<BoolValue>("Maximization", "True if the problem is a maximization problem."));
    7278      Parameters.Add(new LookupParameter<DoubleMatrix>("Costs", LinearAssignmentProblem.CostsDescription));
     79      Parameters.Add(new ValueLookupParameter<StringArray>("RowNames", LinearAssignmentProblem.RowNamesDescription));
     80      Parameters.Add(new ValueLookupParameter<StringArray>("ColumnNames", LinearAssignmentProblem.ColumnNamesDescription));
    7381      Parameters.Add(new ScopeTreeLookupParameter<Permutation>("Assignment", "The LAP solutions from which the best solution should be analyzed."));
    7482      Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Quality", "The qualities of the LAP solutions which should be analyzed."));
     
    8694    public override IOperation Apply() {
    8795      var costs = CostsParameter.ActualValue;
     96      var rowNames = RowNamesParameter.ActualValue;
     97      var columnNames = ColumnNamesParameter.ActualValue;
    8898      var permutations = AssignmentParameter.ActualValue;
    8999      var qualities = QualityParameter.ActualValue;
     
    122132      LAPAssignment assignment = BestSolutionParameter.ActualValue;
    123133      if (assignment == null) {
    124         assignment = new LAPAssignment(costs, (Permutation)permutations[i].Clone(), new DoubleValue(qualities[i].Value));
     134        assignment = new LAPAssignment(costs, rowNames, columnNames, (Permutation)permutations[i].Clone(), new DoubleValue(qualities[i].Value));
    125135        BestSolutionParameter.ActualValue = assignment;
    126136        results.Add(new Result("Best LAP Solution", assignment));
     
    131141          assignment.Assignment = (Permutation)permutations[i].Clone();
    132142          assignment.Quality.Value = qualities[i].Value;
     143          if (rowNames != null)
     144            assignment.RowNames = rowNames;
     145          else assignment.RowNames = null;
     146          if (columnNames != null)
     147            assignment.ColumnNames = columnNames;
     148          else assignment.ColumnNames = null;
    133149        }
    134150      }
  • trunk/sources/HeuristicLab.Problems.LinearAssignment/3.3/HungarianAlgorithm.cs

    r8022 r8093  
    5252      get { return (ValueParameter<MultiAnalyzer>)Parameters["Analyzer"]; }
    5353    }
    54 
    5554    #endregion
    5655
     
    6968    private HungarianAlgorithm(HungarianAlgorithm original, Cloner cloner)
    7069      : base(original, cloner) {
    71       // TODO: clone your private fields here
    7270      AttachEventHandlers();
    7371    }
     
    8684      UpdateAnalyzers();
    8785      AttachEventHandlers();
     86
     87      Problem = new LinearAssignmentProblem();
    8888    }
    8989
  • trunk/sources/HeuristicLab.Problems.LinearAssignment/3.3/LAPAssignment.cs

    r8022 r8093  
    4444
    4545    [Storable]
     46    private StringArray rowNames;
     47    public StringArray RowNames {
     48      get { return rowNames; }
     49      set {
     50        bool changed = (rowNames != value);
     51        rowNames = value;
     52        if (changed) OnPropertyChanged("RowNames");
     53      }
     54    }
     55
     56    [Storable]
     57    private StringArray columnNames;
     58    public StringArray ColumnNames {
     59      get { return columnNames; }
     60      set {
     61        bool changed = (columnNames != value);
     62        columnNames = value;
     63        if (changed) OnPropertyChanged("ColumnNames");
     64      }
     65    }
     66
     67    [Storable]
    4668    private Permutation assignment;
    4769    public Permutation Assignment {
     
    81103      this.quality = quality;
    82104    }
     105    public LAPAssignment(DoubleMatrix costs, StringArray rowNames, StringArray columnNames, Permutation assignment)
     106      : this(costs, assignment) {
     107      this.rowNames = rowNames;
     108      this.columnNames = columnNames;
     109    }
     110    public LAPAssignment(DoubleMatrix costs, StringArray rowNames, StringArray columnNames, Permutation assignment, DoubleValue quality)
     111      : this(costs, rowNames, columnNames, assignment) {
     112      this.quality = quality;
     113    }
    83114
    84115    public override IDeepCloneable Clone(Cloner cloner) {
  • trunk/sources/HeuristicLab.Problems.LinearAssignment/3.3/LinearAssignmentProblem.cs

    r8022 r8093  
    3838  public sealed class LinearAssignmentProblem : SingleObjectiveHeuristicOptimizationProblem<ILAPEvaluator, IPermutationCreator> {
    3939    public static readonly string CostsDescription = "The cost matrix that describes the assignment of rows to columns.";
     40    public static readonly string RowNamesDescription = "The elements represented by the rows of the costs matrix.";
     41    public static readonly string ColumnNamesDescription = "The elements represented by the columns of the costs matrix.";
    4042
    4143    public override Image ItemImage {
     
    5254    public IValueParameter<Permutation> BestKnownSolutionParameter {
    5355      get { return (IValueParameter<Permutation>)Parameters["BestKnownSolution"]; }
     56    }
     57    public IValueParameter<StringArray> RowNamesParameter {
     58      get { return (IValueParameter<StringArray>)Parameters["RowNames"]; }
     59    }
     60    public IValueParameter<StringArray> ColumnNamesParameter {
     61      get { return (IValueParameter<StringArray>)Parameters["ColumnNames"]; }
    5462    }
    5563    #endregion
     
    5967      get { return CostsParameter.Value; }
    6068      set { CostsParameter.Value = value; }
     69    }
     70    public StringArray RowNames {
     71      get { return RowNamesParameter.Value; }
     72      set { RowNamesParameter.Value = value; }
     73    }
     74    public StringArray ColumnNames {
     75      get { return ColumnNamesParameter.Value; }
     76      set { ColumnNamesParameter.Value = value; }
    6177    }
    6278    public ItemSet<Permutation> BestKnownSolutions {
     
    85101      Parameters.Add(new OptionalValueParameter<ItemSet<Permutation>>("BestKnownSolutions", "The list of best known solutions which is updated whenever a new better solution is found or may be the optimal solution if it is known beforehand.", null));
    86102      Parameters.Add(new OptionalValueParameter<Permutation>("BestKnownSolution", "The best known solution which is updated whenever a new better solution is found or may be the optimal solution if it is known beforehand.", null));
    87      
     103      Parameters.Add(new OptionalValueParameter<StringArray>("RowNames", RowNamesDescription));
     104      Parameters.Add(new OptionalValueParameter<StringArray>("ColumnNames", ColumnNamesDescription));
     105
    88106      ((ValueParameter<DoubleMatrix>)CostsParameter).ReactOnValueToStringChangedAndValueItemImageChanged = false;
     107      ((OptionalValueParameter<StringArray>)RowNamesParameter).ReactOnValueToStringChangedAndValueItemImageChanged = false;
     108      ((OptionalValueParameter<StringArray>)ColumnNamesParameter).ReactOnValueToStringChangedAndValueItemImageChanged = false;
     109
     110      RowNames = new StringArray(new string[] { "Human", "Von Neumann machine", "Quantum computer" });
     111      ColumnNames = new StringArray(new string[] { "Find a person's e-mail address", "Compute first 1000 decimals of Pi", "Factorize large integers" });
     112      Costs[0, 0] = 1; Costs[0, 1] = 10; Costs[0, 2] = 100;
     113      Costs[1, 0] = 10; Costs[1, 1] = 1; Costs[1, 2] = 100;
     114      Costs[2, 0] = 100; Costs[2, 1] = 10; Costs[2, 1] = 1;
    89115
    90116      bestLAPSolutionAnalyzer = new BestLAPSolutionAnalyzer();
Note: See TracChangeset for help on using the changeset viewer.