Changeset 11109 for stable/HeuristicLab.Problems.LinearAssignment/3.3/LinearAssignmentProblemSolver.cs
- Timestamp:
- 07/07/14 14:20:04 (10 years ago)
- Location:
- stable
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
stable
- Property svn:mergeinfo changed
/trunk/sources merged: 11087,11097
- Property svn:mergeinfo changed
-
stable/HeuristicLab.Problems.LinearAssignment/3.3/LinearAssignmentProblemSolver.cs
r9456 r11109 34 34 private const int UNASSIGNED = -1; 35 35 36 public IValueLookupParameter<BoolValue> MaximizationParameter { 37 get { return (IValueLookupParameter<BoolValue>)Parameters["Maximization"]; } 38 } 36 39 public ILookupParameter<DoubleMatrix> CostsParameter { 37 40 get { return (ILookupParameter<DoubleMatrix>)Parameters["Costs"]; } … … 49 52 public LinearAssignmentProblemSolver() 50 53 : base() { 54 Parameters.Add(new ValueLookupParameter<BoolValue>("Maximization", "Whether the costs should be maximized or minimized.")); 51 55 Parameters.Add(new LookupParameter<DoubleMatrix>("Costs", LinearAssignmentProblem.CostsDescription)); 52 56 Parameters.Add(new LookupParameter<Permutation>("Assignment", "The assignment solution to create.")); … … 58 62 } 59 63 64 [StorableHook(HookType.AfterDeserialization)] 65 private void AfterDeserialization() { 66 // BackwardsCompatibility3.3 67 #region Backwards compatible code, remove with 3.4 68 if (!Parameters.ContainsKey("Maximization")) 69 Parameters.Add(new ValueLookupParameter<BoolValue>("Maximization", "Whether the costs should be maximized or minimized.")); 70 #endregion 71 } 72 60 73 public override IOperation Apply() { 61 74 var costs = CostsParameter.ActualValue; 75 var maximization = MaximizationParameter.ActualValue.Value; 76 if (maximization) { 77 costs = (DoubleMatrix)costs.Clone(); 78 for (int i = 0; i < costs.Rows; i++) 79 for (int j = 0; j < costs.Rows; j++) 80 costs[i, j] = -costs[i, j]; 81 } 62 82 double quality; 63 83 var solution = Solve(costs, out quality); 64 84 65 85 AssignmentParameter.ActualValue = new Permutation(PermutationTypes.Absolute, solution); 86 if (maximization) quality = -quality; 66 87 QualityParameter.ActualValue = new DoubleValue(quality); 67 88
Note: See TracChangeset
for help on using the changeset viewer.