Changeset 15504 for branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/SolutionCreators
- Timestamp:
- 12/10/17 22:11:10 (7 years ago)
- Location:
- branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/SolutionCreators
- Files:
-
- 1 deleted
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/SolutionCreators/GQAPSolutionCreator.cs
r7523 r15504 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 2Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2017 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 31 31 [Item("GQAPSolutionCreator", "Base class for solution creators of the Generalized Quadratic Assignment Problem.")] 32 32 [StorableClass] 33 public abstract class GQAPSolutionCreator : SingleSuccessorOperator, I DemandsAwareGQAPOperator, ICapacitiesAwareGQAPOperator, IGQAPSolutionCreator {33 public abstract class GQAPSolutionCreator : SingleSuccessorOperator, IProblemInstanceAwareGQAPOperator, IGQAPSolutionCreator { 34 34 35 35 #region Parameter Descriptions … … 37 37 #endregion 38 38 39 public ILookupParameter<IntegerVector> AssignmentParameter {40 get { return (ILookupParameter<IntegerVector>)Parameters[" Assignment"]; }39 public ILookupParameter<IntegerVector> IntegerVectorParameter { 40 get { return (ILookupParameter<IntegerVector>)Parameters["IntegerVector"]; } 41 41 } 42 public ILookupParameter< DoubleArray> DemandsParameter {43 get { return (ILookupParameter< DoubleArray>)Parameters["Demands"]; }42 public ILookupParameter<GQAPInstance> ProblemInstanceParameter { 43 get { return (ILookupParameter<GQAPInstance>)Parameters["ProblemInstance"]; } 44 44 } 45 public ILookupParameter<DoubleArray> CapacitiesParameter { 46 get { return (ILookupParameter<DoubleArray>)Parameters["Capacities"]; } 45 public IValueLookupParameter<IntValue> LengthParameter { 46 get { return (IValueLookupParameter<IntValue>)Parameters["Length"]; } 47 } 48 public IValueLookupParameter<IntMatrix> BoundsParameter { 49 get { return (IValueLookupParameter<IntMatrix>)Parameters["Bounds"]; } 47 50 } 48 51 … … 53 56 public GQAPSolutionCreator() 54 57 : base() { 55 Parameters.Add(new LookupParameter<IntegerVector>("Assignment", AssignmentDescription)); 56 Parameters.Add(new LookupParameter<DoubleArray>("Demands", GeneralizedQuadraticAssignmentProblem.DemandsDescription)); 57 Parameters.Add(new LookupParameter<DoubleArray>("Capacities", GeneralizedQuadraticAssignmentProblem.CapacitiesDescription)); 58 Parameters.Add(new LookupParameter<IntegerVector>("IntegerVector", AssignmentDescription)); 59 Parameters.Add(new LookupParameter<GQAPInstance>("ProblemInstance", GQAP.ProblemInstanceDescription)); 60 Parameters.Add(new ValueLookupParameter<IntValue>("Length", "The length of the vector.") { Hidden = true }); 61 Parameters.Add(new ValueLookupParameter<IntMatrix>("Bounds", "") { Hidden = true }); 58 62 } 59 63 60 64 public override IOperation Apply() { 61 AssignmentParameter.ActualValue = CreateSolution(DemandsParameter.ActualValue, CapacitiesParameter.ActualValue);65 IntegerVectorParameter.ActualValue = CreateSolution(ProblemInstanceParameter.ActualValue); 62 66 return base.Apply(); 63 67 } 64 68 65 protected abstract IntegerVector CreateSolution( DoubleArray demands, DoubleArray capacities);69 protected abstract IntegerVector CreateSolution(GQAPInstance problemInstance); 66 70 } 67 71 } -
branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/SolutionCreators/GQAPStochasticSolutionCreator.cs
r7523 r15504 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 2Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2017 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 22 22 using HeuristicLab.Common; 23 23 using HeuristicLab.Core; 24 using HeuristicLab.Data;25 24 using HeuristicLab.Encodings.IntegerVectorEncoding; 26 25 using HeuristicLab.Optimization; … … 46 45 } 47 46 48 protected sealed override IntegerVector CreateSolution( DoubleArray demands, DoubleArray capacities) {49 return CreateRandomSolution(RandomParameter.ActualValue, demands, capacities);47 protected sealed override IntegerVector CreateSolution(GQAPInstance problemInstance) { 48 return CreateRandomSolution(RandomParameter.ActualValue, problemInstance); 50 49 } 51 50 52 protected abstract IntegerVector CreateRandomSolution(IRandom random, DoubleArray demands, DoubleArray capacities);51 protected abstract IntegerVector CreateRandomSolution(IRandom random, GQAPInstance problemInstance); 53 52 } 54 53 } -
branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/SolutionCreators/GreedyRandomizedSolutionCreator.cs
r7970 r15504 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 2Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2017 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 35 35 [Item("GreedyRandomizedSolutionCreator", "Creates a solution according to the procedure described in Mateus, G., Resende, M., and Silva, R. 2011. GRASP with path-relinking for the generalized quadratic assignment problem. Journal of Heuristics 17, Springer Netherlands, pp. 527-565.")] 36 36 [StorableClass] 37 public class GreedyRandomizedSolutionCreator : GQAPStochasticSolutionCreator, 38 IEvaluatorAwareGQAPOperator { 37 public class GreedyRandomizedSolutionCreator : GQAPStochasticSolutionCreator { 39 38 40 39 public IValueLookupParameter<IntValue> MaximumTriesParameter { … … 43 42 public IValueLookupParameter<BoolValue> CreateMostFeasibleSolutionParameter { 44 43 get { return (IValueLookupParameter<BoolValue>)Parameters["CreateMostFeasibleSolution"]; } 45 }46 public IValueLookupParameter<IGQAPEvaluator> EvaluatorParameter {47 get { return (IValueLookupParameter<IGQAPEvaluator>)Parameters["Evaluator"]; }48 44 } 49 45 … … 56 52 Parameters.Add(new ValueLookupParameter<IntValue>("MaximumTries", "The maximum number of tries to create a feasible solution after which an exception is thrown. If it is set to 0 or a negative value there will be an infinite number of attempts.", new IntValue(100000))); 57 53 Parameters.Add(new ValueLookupParameter<BoolValue>("CreateMostFeasibleSolution", "If this is set to true the operator will always succeed, and outputs the solution with the least violation instead of throwing an exception.", new BoolValue(false))); 58 Parameters.Add(new ValueLookupParameter<IGQAPEvaluator>("Evaluator", "The evaluator that is used to evaluate GQAP solutions."));59 54 } 60 55 … … 63 58 } 64 59 65 public static IntegerVector CreateSolution(IRandom random, DoubleArray demands, DoubleArray capacities, 66 IGQAPEvaluator evaluator, 60 public static IntegerVector CreateSolution(IRandom random, GQAPInstance problemInstance, 67 61 int maximumTries, bool createMostFeasibleSolution, CancellationToken cancelToken) { 62 var demands = problemInstance.Demands; 63 var capacities = problemInstance.Capacities; 68 64 int tries = 0; 69 65 var assignment = new Dictionary<int, int>(demands.Length); … … 125 121 slack[l] -= demands[f]; 126 122 } 127 double violation = evaluator.EvaluateOverbooking(slack, capacities);123 double violation = slack.Select(x => x < 0 ? -x : 0).Sum(); 128 124 if (violation < minViolation) { 129 125 bestAssignment = assignment; … … 139 135 } 140 136 141 protected override IntegerVector CreateRandomSolution(IRandom random, DoubleArray demands, DoubleArray capacities) { 142 return CreateSolution(random, demands, capacities, 143 EvaluatorParameter.ActualValue, 137 protected override IntegerVector CreateRandomSolution(IRandom random, GQAPInstance problemInstance) { 138 return CreateSolution(random, problemInstance, 144 139 MaximumTriesParameter.ActualValue.Value, 145 140 CreateMostFeasibleSolutionParameter.ActualValue.Value, -
branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/SolutionCreators/RandomButFeasibleSolutionCreator.cs
r7970 r15504 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 2Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2017 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 35 35 [Item("RandomButFeasibleSolutionCreator", "Creates a random, but feasible solution to the Generalized Quadratic Assignment Problem.")] 36 36 [StorableClass] 37 public class RandomFeasibleSolutionCreator : GQAPStochasticSolutionCreator, 38 IEvaluatorAwareGQAPOperator { 37 public class RandomFeasibleSolutionCreator : GQAPStochasticSolutionCreator { 39 38 40 39 public IValueLookupParameter<IntValue> MaximumTriesParameter { … … 43 42 public IValueLookupParameter<BoolValue> CreateMostFeasibleSolutionParameter { 44 43 get { return (IValueLookupParameter<BoolValue>)Parameters["CreateMostFeasibleSolution"]; } 45 }46 public IValueLookupParameter<IGQAPEvaluator> EvaluatorParameter {47 get { return (IValueLookupParameter<IGQAPEvaluator>)Parameters["Evaluator"]; }48 44 } 49 45 … … 55 51 Parameters.Add(new ValueLookupParameter<IntValue>("MaximumTries", "The maximum number of tries to create a feasible solution after which an exception is thrown. If it is set to 0 or a negative value there will be an infinite number of attempts.", new IntValue(100000))); 56 52 Parameters.Add(new ValueLookupParameter<BoolValue>("CreateMostFeasibleSolution", "If this is set to true the operator will always succeed, and outputs the solution with the least violation instead of throwing an exception.", new BoolValue(false))); 57 Parameters.Add(new ValueLookupParameter<IGQAPEvaluator>("Evaluator", "The evaluator that is used to evaluate GQAP solutions."));58 53 } 59 54 … … 62 57 } 63 58 64 public static IntegerVector CreateSolution(IRandom random, DoubleArray demands, 65 DoubleArray capacities, IGQAPEvaluator evaluator, 59 public static IntegerVector CreateSolution(IRandom random, GQAPInstance problemInstance, 66 60 int maximumTries, bool createMostFeasibleSolution, CancellationToken cancel) { 61 var capacities = problemInstance.Capacities; 62 var demands = problemInstance.Demands; 67 63 IntegerVector result = null; 68 64 bool isFeasible = false; … … 87 83 slack[assignment[equipment]] -= demands[equipment]; 88 84 } 89 double violation = evaluator.EvaluateOverbooking(slack, capacities);85 double violation = slack.Select(x => x < 0 ? -x : 0).Sum(); 90 86 isFeasible = violation == 0; 91 87 if (isFeasible || violation < minViolation) { … … 97 93 } 98 94 99 protected override IntegerVector CreateRandomSolution(IRandom random, DoubleArray demands, DoubleArray capacities) { 100 return CreateSolution(random, demands, capacities, 101 EvaluatorParameter.ActualValue, 95 protected override IntegerVector CreateRandomSolution(IRandom random, GQAPInstance problemInstance) { 96 return CreateSolution(random, problemInstance, 102 97 MaximumTriesParameter.ActualValue.Value, 103 98 CreateMostFeasibleSolutionParameter.ActualValue.Value, -
branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/SolutionCreators/SlackMinimizationSolutionCreator.cs
r7970 r15504 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 2Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2017 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 35 35 [Item("SlackMinimizationSolutionCreator", "A heuristic that creates a solution to the Generalized Quadratic Assignment Problem by minimizing the amount of slack.")] 36 36 [StorableClass] 37 public class SlackMinimizationSolutionCreator : GQAPStochasticSolutionCreator, 38 IEvaluatorAwareGQAPOperator { 37 public class SlackMinimizationSolutionCreator : GQAPStochasticSolutionCreator { 39 38 40 39 public IValueLookupParameter<IntValue> MaximumTriesParameter { … … 50 49 get { return (IValueLookupParameter<IntValue>)Parameters["RandomWalkLength"]; } 51 50 } 52 public IValueLookupParameter<IGQAPEvaluator> EvaluatorParameter {53 get { return (IValueLookupParameter<IGQAPEvaluator>)Parameters["Evaluator"]; }54 }55 51 56 52 [StorableConstructor] … … 63 59 Parameters.Add(new ValueLookupParameter<IntValue>("Depth", "How deep the algorithm should look forward.", new IntValue(3))); 64 60 Parameters.Add(new ValueLookupParameter<IntValue>("RandomWalkLength", "The length of the random walk in the feasible region that is used to diversify the found assignments.", new IntValue(10))); 65 Parameters.Add(new ValueLookupParameter<IGQAPEvaluator>("Evaluator", "The evaluator that is used to evaluate GQAP solutions."));66 61 } 67 62 … … 70 65 } 71 66 72 [StorableHook(HookType.AfterDeserialization)] 73 private void AfterDeserialization() { 74 if (!Parameters.ContainsKey("Depth")) { 75 Parameters.Add(new ValueLookupParameter<IntValue>("Depth", "How deep the algorithm should look forward.", new IntValue(3))); 76 } 77 if (!Parameters.ContainsKey("RandomWalkLength")) { 78 Parameters.Add(new ValueLookupParameter<IntValue>("RandomWalkLength", "The length of the random walk in the feasible region that is used to diversify the found assignments.", new IntValue(10))); 79 } 80 } 67 public static IntegerVector CreateSolution(IRandom random, GQAPInstance problemInstance, 68 int depth, int maximumTries, bool createMostFeasibleSolution, int randomWalkLength, CancellationToken cancel) { 69 var capacities = problemInstance.Capacities; 70 var demands = problemInstance.Demands; 81 71 82 public static IntegerVector CreateSolution(IRandom random, DoubleArray demands,83 DoubleArray capacities, IGQAPEvaluator evaluator,84 int depth, int maximumTries, bool createMostFeasibleSolution, int randomWalkLength, CancellationToken cancel) {85 72 IntegerVector result = null; 86 73 bool isFeasible = false; … … 125 112 } 126 113 } else RandomFeasibleWalk(random, assignment, demands, slack, randomWalkLength); 127 double violation = evaluator.EvaluateOverbooking(slack, capacities);114 double violation = slack.Select(x => x < 0 ? -x : 0).Sum(); 128 115 isFeasible = violation == 0; 129 116 if (isFeasible || violation < minViolation) { … … 182 169 } 183 170 184 protected override IntegerVector CreateRandomSolution(IRandom random, DoubleArray demands, DoubleArray capacities) { 185 return CreateSolution(random, demands, capacities, 186 EvaluatorParameter.ActualValue, 171 protected override IntegerVector CreateRandomSolution(IRandom random, GQAPInstance problemInstance) { 172 return CreateSolution(random, problemInstance, 187 173 DepthParameter.ActualValue.Value, 188 174 MaximumTriesParameter.ActualValue.Value,
Note: See TracChangeset
for help on using the changeset viewer.