Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
12/10/17 22:11:10 (6 years ago)
Author:
abeham
Message:

#1614: refactored code

  • change problem to derive from basic problem
  • using a combined instance class instead of individual parameters
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/SolutionCreators/RandomButFeasibleSolutionCreator.cs

    r7970 r15504  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2017 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    3535  [Item("RandomButFeasibleSolutionCreator", "Creates a random, but feasible solution to the Generalized Quadratic Assignment Problem.")]
    3636  [StorableClass]
    37   public class RandomFeasibleSolutionCreator : GQAPStochasticSolutionCreator,
    38     IEvaluatorAwareGQAPOperator {
     37  public class RandomFeasibleSolutionCreator : GQAPStochasticSolutionCreator {
    3938
    4039    public IValueLookupParameter<IntValue> MaximumTriesParameter {
     
    4342    public IValueLookupParameter<BoolValue> CreateMostFeasibleSolutionParameter {
    4443      get { return (IValueLookupParameter<BoolValue>)Parameters["CreateMostFeasibleSolution"]; }
    45     }
    46     public IValueLookupParameter<IGQAPEvaluator> EvaluatorParameter {
    47       get { return (IValueLookupParameter<IGQAPEvaluator>)Parameters["Evaluator"]; }
    4844    }
    4945
     
    5551      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)));
    5652      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."));
    5853    }
    5954
     
    6257    }
    6358
    64     public static IntegerVector CreateSolution(IRandom random, DoubleArray demands,
    65       DoubleArray capacities, IGQAPEvaluator evaluator,
     59    public static IntegerVector CreateSolution(IRandom random, GQAPInstance problemInstance,
    6660      int maximumTries, bool createMostFeasibleSolution, CancellationToken cancel) {
     61      var capacities = problemInstance.Capacities;
     62      var demands = problemInstance.Demands;
    6763      IntegerVector result = null;
    6864      bool isFeasible = false;
     
    8783          slack[assignment[equipment]] -= demands[equipment];
    8884        }
    89         double violation = evaluator.EvaluateOverbooking(slack, capacities);
     85        double violation = slack.Select(x => x < 0 ? -x : 0).Sum();
    9086        isFeasible = violation == 0;
    9187        if (isFeasible || violation < minViolation) {
     
    9793    }
    9894
    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,
    10297        MaximumTriesParameter.ActualValue.Value,
    10398        CreateMostFeasibleSolutionParameter.ActualValue.Value,
Note: See TracChangeset for help on using the changeset viewer.