Changeset 15504 for branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/SolutionCreators/RandomButFeasibleSolutionCreator.cs
- Timestamp:
- 12/10/17 22:11:10 (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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,
Note: See TracChangeset
for help on using the changeset viewer.