Changeset 7970 for branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/SolutionCreators
- Timestamp:
- 06/06/12 04:29:56 (13 years ago)
- Location:
- branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/SolutionCreators
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/SolutionCreators/GreedyRandomizedSolutionCreator.cs
r7833 r7970 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 { 37 public class GreedyRandomizedSolutionCreator : GQAPStochasticSolutionCreator, 38 IEvaluatorAwareGQAPOperator { 38 39 39 40 public IValueLookupParameter<IntValue> MaximumTriesParameter { … … 42 43 public IValueLookupParameter<BoolValue> CreateMostFeasibleSolutionParameter { 43 44 get { return (IValueLookupParameter<BoolValue>)Parameters["CreateMostFeasibleSolution"]; } 45 } 46 public IValueLookupParameter<IGQAPEvaluator> EvaluatorParameter { 47 get { return (IValueLookupParameter<IGQAPEvaluator>)Parameters["Evaluator"]; } 44 48 } 45 49 … … 52 56 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))); 53 57 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.")); 54 59 } 55 60 … … 58 63 } 59 64 60 public static IntegerVector CreateSolution(IRandom random, DoubleArray demands, DoubleArray capacities, int maximumTries, bool createMostFeasibleSolution, CancellationToken cancelToken) { 65 public static IntegerVector CreateSolution(IRandom random, DoubleArray demands, DoubleArray capacities, 66 IGQAPEvaluator evaluator, 67 int maximumTries, bool createMostFeasibleSolution, CancellationToken cancelToken) { 61 68 int tries = 0; 62 69 var assignment = new Dictionary<int, int>(demands.Length); … … 118 125 slack[l] -= demands[f]; 119 126 } 120 double violation = GQAPEvaluator.EvaluateOverbooking(slack, capacities);127 double violation = evaluator.EvaluateOverbooking(slack, capacities); 121 128 if (violation < minViolation) { 122 129 bestAssignment = assignment; … … 134 141 protected override IntegerVector CreateRandomSolution(IRandom random, DoubleArray demands, DoubleArray capacities) { 135 142 return CreateSolution(random, demands, capacities, 143 EvaluatorParameter.ActualValue, 136 144 MaximumTriesParameter.ActualValue.Value, 137 145 CreateMostFeasibleSolutionParameter.ActualValue.Value, -
branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/SolutionCreators/RandomButFeasibleSolutionCreator.cs
r7813 r7970 35 35 [Item("RandomButFeasibleSolutionCreator", "Creates a random, but feasible solution to the Generalized Quadratic Assignment Problem.")] 36 36 [StorableClass] 37 public class RandomFeasibleSolutionCreator : GQAPStochasticSolutionCreator { 37 public class RandomFeasibleSolutionCreator : GQAPStochasticSolutionCreator, 38 IEvaluatorAwareGQAPOperator { 38 39 39 40 public IValueLookupParameter<IntValue> MaximumTriesParameter { … … 42 43 public IValueLookupParameter<BoolValue> CreateMostFeasibleSolutionParameter { 43 44 get { return (IValueLookupParameter<BoolValue>)Parameters["CreateMostFeasibleSolution"]; } 45 } 46 public IValueLookupParameter<IGQAPEvaluator> EvaluatorParameter { 47 get { return (IValueLookupParameter<IGQAPEvaluator>)Parameters["Evaluator"]; } 44 48 } 45 49 … … 51 55 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))); 52 56 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.")); 53 58 } 54 59 … … 57 62 } 58 63 59 public static IntegerVector CreateSolution(IRandom random, DoubleArray demands, DoubleArray capacities, int maximumTries, bool createMostFeasibleSolution, CancellationToken cancel) { 64 public static IntegerVector CreateSolution(IRandom random, DoubleArray demands, 65 DoubleArray capacities, IGQAPEvaluator evaluator, 66 int maximumTries, bool createMostFeasibleSolution, CancellationToken cancel) { 60 67 IntegerVector result = null; 61 68 bool isFeasible = false; … … 80 87 slack[assignment[equipment]] -= demands[equipment]; 81 88 } 82 double violation = GQAPEvaluator.EvaluateOverbooking(slack, capacities);89 double violation = evaluator.EvaluateOverbooking(slack, capacities); 83 90 isFeasible = violation == 0; 84 91 if (isFeasible || violation < minViolation) { … … 92 99 protected override IntegerVector CreateRandomSolution(IRandom random, DoubleArray demands, DoubleArray capacities) { 93 100 return CreateSolution(random, demands, capacities, 101 EvaluatorParameter.ActualValue, 94 102 MaximumTriesParameter.ActualValue.Value, 95 103 CreateMostFeasibleSolutionParameter.ActualValue.Value, -
branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/SolutionCreators/SlackMinimizationSolutionCreator.cs
r7813 r7970 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 { 37 public class SlackMinimizationSolutionCreator : GQAPStochasticSolutionCreator, 38 IEvaluatorAwareGQAPOperator { 38 39 39 40 public IValueLookupParameter<IntValue> MaximumTriesParameter { … … 49 50 get { return (IValueLookupParameter<IntValue>)Parameters["RandomWalkLength"]; } 50 51 } 52 public IValueLookupParameter<IGQAPEvaluator> EvaluatorParameter { 53 get { return (IValueLookupParameter<IGQAPEvaluator>)Parameters["Evaluator"]; } 54 } 51 55 52 56 [StorableConstructor] … … 59 63 Parameters.Add(new ValueLookupParameter<IntValue>("Depth", "How deep the algorithm should look forward.", new IntValue(3))); 60 64 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.")); 61 66 } 62 67 … … 75 80 } 76 81 77 public static IntegerVector CreateSolution(IRandom random, DoubleArray demands, DoubleArray capacities, int depth, int maximumTries, bool createMostFeasibleSolution, int randomWalkLength, CancellationToken cancel) { 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) { 78 85 IntegerVector result = null; 79 86 bool isFeasible = false; … … 118 125 } 119 126 } else RandomFeasibleWalk(random, assignment, demands, slack, randomWalkLength); 120 double violation = GQAPEvaluator.EvaluateOverbooking(slack, capacities);127 double violation = evaluator.EvaluateOverbooking(slack, capacities); 121 128 isFeasible = violation == 0; 122 129 if (isFeasible || violation < minViolation) { … … 177 184 protected override IntegerVector CreateRandomSolution(IRandom random, DoubleArray demands, DoubleArray capacities) { 178 185 return CreateSolution(random, demands, capacities, 186 EvaluatorParameter.ActualValue, 179 187 DepthParameter.ActualValue.Value, 180 188 MaximumTriesParameter.ActualValue.Value,
Note: See TracChangeset
for help on using the changeset viewer.