Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
06/06/12 04:29:56 (13 years ago)
Author:
abeham
Message:

#1614: restructured architecture to allow for different evaluator with different penalty strategies

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  
    3535  [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.")]
    3636  [StorableClass]
    37   public class GreedyRandomizedSolutionCreator : GQAPStochasticSolutionCreator {
     37  public class GreedyRandomizedSolutionCreator : GQAPStochasticSolutionCreator,
     38    IEvaluatorAwareGQAPOperator {
    3839
    3940    public IValueLookupParameter<IntValue> MaximumTriesParameter {
     
    4243    public IValueLookupParameter<BoolValue> CreateMostFeasibleSolutionParameter {
    4344      get { return (IValueLookupParameter<BoolValue>)Parameters["CreateMostFeasibleSolution"]; }
     45    }
     46    public IValueLookupParameter<IGQAPEvaluator> EvaluatorParameter {
     47      get { return (IValueLookupParameter<IGQAPEvaluator>)Parameters["Evaluator"]; }
    4448    }
    4549
     
    5256      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)));
    5357      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."));
    5459    }
    5560
     
    5863    }
    5964
    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) {
    6168      int tries = 0;
    6269      var assignment = new Dictionary<int, int>(demands.Length);
     
    118125            slack[l] -= demands[f];
    119126          }
    120           double violation = GQAPEvaluator.EvaluateOverbooking(slack, capacities);
     127          double violation = evaluator.EvaluateOverbooking(slack, capacities);
    121128          if (violation < minViolation) {
    122129            bestAssignment = assignment;
     
    134141    protected override IntegerVector CreateRandomSolution(IRandom random, DoubleArray demands, DoubleArray capacities) {
    135142      return CreateSolution(random, demands, capacities,
     143        EvaluatorParameter.ActualValue,
    136144        MaximumTriesParameter.ActualValue.Value,
    137145        CreateMostFeasibleSolutionParameter.ActualValue.Value,
  • branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/SolutionCreators/RandomButFeasibleSolutionCreator.cs

    r7813 r7970  
    3535  [Item("RandomButFeasibleSolutionCreator", "Creates a random, but feasible solution to the Generalized Quadratic Assignment Problem.")]
    3636  [StorableClass]
    37   public class RandomFeasibleSolutionCreator : GQAPStochasticSolutionCreator {
     37  public class RandomFeasibleSolutionCreator : GQAPStochasticSolutionCreator,
     38    IEvaluatorAwareGQAPOperator {
    3839
    3940    public IValueLookupParameter<IntValue> MaximumTriesParameter {
     
    4243    public IValueLookupParameter<BoolValue> CreateMostFeasibleSolutionParameter {
    4344      get { return (IValueLookupParameter<BoolValue>)Parameters["CreateMostFeasibleSolution"]; }
     45    }
     46    public IValueLookupParameter<IGQAPEvaluator> EvaluatorParameter {
     47      get { return (IValueLookupParameter<IGQAPEvaluator>)Parameters["Evaluator"]; }
    4448    }
    4549
     
    5155      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)));
    5256      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."));
    5358    }
    5459
     
    5762    }
    5863
    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) {
    6067      IntegerVector result = null;
    6168      bool isFeasible = false;
     
    8087          slack[assignment[equipment]] -= demands[equipment];
    8188        }
    82         double violation = GQAPEvaluator.EvaluateOverbooking(slack, capacities);
     89        double violation = evaluator.EvaluateOverbooking(slack, capacities);
    8390        isFeasible = violation == 0;
    8491        if (isFeasible || violation < minViolation) {
     
    9299    protected override IntegerVector CreateRandomSolution(IRandom random, DoubleArray demands, DoubleArray capacities) {
    93100      return CreateSolution(random, demands, capacities,
     101        EvaluatorParameter.ActualValue,
    94102        MaximumTriesParameter.ActualValue.Value,
    95103        CreateMostFeasibleSolutionParameter.ActualValue.Value,
  • branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/SolutionCreators/SlackMinimizationSolutionCreator.cs

    r7813 r7970  
    3535  [Item("SlackMinimizationSolutionCreator", "A heuristic that creates a solution to the Generalized Quadratic Assignment Problem by minimizing the amount of slack.")]
    3636  [StorableClass]
    37   public class SlackMinimizationSolutionCreator : GQAPStochasticSolutionCreator {
     37  public class SlackMinimizationSolutionCreator : GQAPStochasticSolutionCreator,
     38    IEvaluatorAwareGQAPOperator {
    3839
    3940    public IValueLookupParameter<IntValue> MaximumTriesParameter {
     
    4950      get { return (IValueLookupParameter<IntValue>)Parameters["RandomWalkLength"]; }
    5051    }
     52    public IValueLookupParameter<IGQAPEvaluator> EvaluatorParameter {
     53      get { return (IValueLookupParameter<IGQAPEvaluator>)Parameters["Evaluator"]; }
     54    }
    5155
    5256    [StorableConstructor]
     
    5963      Parameters.Add(new ValueLookupParameter<IntValue>("Depth", "How deep the algorithm should look forward.", new IntValue(3)));
    6064      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."));
    6166    }
    6267
     
    7580    }
    7681
    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) {
    7885      IntegerVector result = null;
    7986      bool isFeasible = false;
     
    118125          }
    119126        } else RandomFeasibleWalk(random, assignment, demands, slack, randomWalkLength);
    120         double violation = GQAPEvaluator.EvaluateOverbooking(slack, capacities);
     127        double violation = evaluator.EvaluateOverbooking(slack, capacities);
    121128        isFeasible = violation == 0;
    122129        if (isFeasible || violation < minViolation) {
     
    177184    protected override IntegerVector CreateRandomSolution(IRandom random, DoubleArray demands, DoubleArray capacities) {
    178185      return CreateSolution(random, demands, capacities,
     186        EvaluatorParameter.ActualValue,
    179187        DepthParameter.ActualValue.Value,
    180188        MaximumTriesParameter.ActualValue.Value,
Note: See TracChangeset for help on using the changeset viewer.