Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
06/24/12 17:57:51 (12 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/HeuristicLab.Problems.LinearAssignment/3.3
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • 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.