Free cookie consent management tool by TermsFeed Policy Generator

Changeset 7311


Ignore:
Timestamp:
01/11/12 09:16:27 (13 years ago)
Author:
abeham
Message:

#1614

  • updated GQAP
Location:
branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3
Files:
5 edited

Legend:

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

    • Property svn:ignore
      •  

        old new  
        11Plugin.cs
        22obj
         3bin
  • branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Analyzers/BestGQAPSolutionAnalyzer.cs

    r6956 r7311  
    3737  [StorableClass]
    3838  public sealed class BestGQAPSolutionAnalyzer : SingleSuccessorOperator, IAnalyzer {
     39
     40    public bool EnabledByDefault {
     41      get { return true; }
     42    }
     43
    3944    public LookupParameter<BoolValue> MaximizationParameter {
    4045      get { return (LookupParameter<BoolValue>)Parameters["Maximization"]; }
     
    6469      get { return (LookupParameter<IntegerVector>)Parameters["BestKnownSolution"]; }
    6570    }
     71    public ILookupParameter<StringArray> EquipmentNamesParameter {
     72      get { return (ILookupParameter<StringArray>)Parameters["EquipmentNames"]; }
     73    }
     74    public ILookupParameter<StringArray> LocationNamesParameter {
     75      get { return (ILookupParameter<StringArray>)Parameters["LocationNames"]; }
     76    }
    6677
    6778    [StorableConstructor]
     
    8293      Parameters.Add(new LookupParameter<DoubleValue>("BestKnownQuality", "The quality of the best known solution of this GQAP instance."));
    8394      Parameters.Add(new LookupParameter<IntegerVector>("BestKnownSolution", "The best known solution of this GQAP instance."));
     95      Parameters.Add(new LookupParameter<StringArray>("EquipmentNames", "A list of names that describes the equipments."));
     96      Parameters.Add(new LookupParameter<StringArray>("LocationNames", "A list of names that describes the locations."));
     97    }
     98
     99    [StorableHook(HookType.AfterDeserialization)]
     100    private void AfterDeserializationHook() {
     101      // BackwardsCompatibility3.3
     102      #region Backwards compatible code, remove with 3.4
     103      if (!Parameters.ContainsKey("EquipmentNames"))
     104        Parameters.Add(new LookupParameter<StringArray>("EquipmentNames", "Optional: A list of names that describes the equipments."));
     105      if (!Parameters.ContainsKey("LocationNames"))
     106        Parameters.Add(new LookupParameter<StringArray>("LocationNames", "Optional: A list of names that describes the locations."));
     107      #endregion
    84108    }
    85109
     
    107131      GQAPAssignment assignment = BestSolutionParameter.ActualValue;
    108132      if (assignment == null) {
    109         assignment = new GQAPAssignment(weights, (IntegerVector)assignments[i].Clone(), new DoubleValue(qualities[i].Value));
     133        StringArray equipmentNames = EquipmentNamesParameter.ActualValue;
     134        StringArray locationNames = LocationNamesParameter.ActualValue;
     135        assignment = new GQAPAssignment(weights, (IntegerVector)assignments[i].Clone(), new DoubleValue(qualities[i].Value), equipmentNames, locationNames);
    110136        assignment.Distances = distances;
    111137        BestSolutionParameter.ActualValue = assignment;
  • branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Evaluators/GQAPEvaluator.cs

    r6956 r7311  
    2020#endregion
    2121
     22using System;
    2223using System.Linq;
    2324using HeuristicLab.Common;
     
    9899      double infeasibility = 0;
    99100
     101      if (weights.Rows != weights.Columns || distances.Rows != distances.Columns
     102        || weights.Rows != installCosts.Rows || distances.Rows != installCosts.Columns
     103        || demands.Length != weights.Rows || capacities.Length != distances.Rows)
     104        throw new InvalidOperationException("ERROR: The problem configuration is not valid! Check the sizes of the weights (NxN), distances (MxM) and installation costs (NxM) matrices as well as the length of the demand (N) and capacities (M) vectors.");
     105
    100106      int len = assignment.Length;
    101107      for (int i = 0; i < len; i++) {
  • branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/GQAPAssignment.cs

    r6956 r7311  
    7676    }
    7777
     78    [Storable]
     79    private StringArray equipmentNames;
     80    public StringArray EquipmentNames {
     81      get { return equipmentNames; }
     82      set {
     83        bool changed = (equipmentNames != value);
     84        equipmentNames = value;
     85        if (changed) OnPropertyChanged("EquipmentNames");
     86      }
     87    }
     88
     89    [Storable]
     90    private StringArray locationNames;
     91    public StringArray LocationNames {
     92      get { return locationNames; }
     93      set {
     94        bool changed = (locationNames != value);
     95        locationNames = value;
     96        if (changed) OnPropertyChanged("LocationNames");
     97      }
     98    }
     99
    78100    [StorableConstructor]
    79101    private GQAPAssignment(bool deserializing) : base(deserializing) { }
     
    84106      assignment = cloner.Clone(original.assignment);
    85107      quality = cloner.Clone(original.quality);
     108      equipmentNames = cloner.Clone(original.equipmentNames);
     109      locationNames = cloner.Clone(original.locationNames);
    86110    }
    87111    public GQAPAssignment(DoubleMatrix weights, IntegerVector assignment) {
     
    92116      : this(weights, assignment) {
    93117      this.quality = quality;
     118    }
     119    public GQAPAssignment(DoubleMatrix weights, IntegerVector assignment, DoubleValue quality, StringArray equipmentNames, StringArray locationNames)
     120      : this(weights, assignment, quality) {
     121      this.equipmentNames = equipmentNames;
     122      this.locationNames = locationNames;
    94123    }
    95124
  • branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/GeneralizedQuadraticAssignmentProblem.cs

    r6956 r7311  
    2020#endregion
    2121
     22using System;
    2223using System.Drawing;
    2324using System.Linq;
     
    3536  [Creatable("Problems")]
    3637  [StorableClass]
    37   public sealed class GeneralizedQuadraticAssignmentProblem : SingleObjectiveHeuristicOptimizationProblem<IGQAPEvaluator, IIntegerVectorCreator> {
     38  public sealed class GeneralizedQuadraticAssignmentProblem : SingleObjectiveHeuristicOptimizationProblem<IGQAPEvaluator, IIntegerVectorCreator>, IStorableContent {
    3839    public override Image ItemImage {
    3940      get { return HeuristicLab.Common.Resources.VSImageLibrary.Type; }
    4041    }
     42
     43    public string Filename { get; set; }
    4144
    4245    #region Parameter Properties
     
    6265      get { return (OptionalValueParameter<IItem>)Parameters["BestKnownSolution"]; }
    6366    }
    64 
    6567    #endregion
    6668
     
    9092      set { CapacitiesParameter.Value = value; }
    9193    }
    92 
    9394    #endregion
    9495
     
    116117      Parameters.Add(new ValueParameter<DoubleArray>("Capacities", "The capacities vector describes the available space at the locations.", new DoubleArray()));
    117118      Parameters.Add(new OptionalValueParameter<IItem>("BestKnownSolution", "The best known solution (if available)", null));
     119      Parameters.Add(new OptionalValueParameter<StringArray>("EquipmentNames", "Optional: A list of names that describes the equipments.", null, false));
     120      Parameters.Add(new OptionalValueParameter<StringArray>("LocationNames", "Optional: A list of names that describes the locations.", null, false));
    118121
    119122      WeightsParameter.ReactOnValueToStringChangedAndValueItemImageChanged = false;
     
    133136      Distances[0, 2] = Distances[2, 0] = 2;
    134137
    135       InstallationCosts = new DoubleMatrix(3, 3);
     138      InstallationCosts = new DoubleMatrix(5, 3);
    136139
    137140      TransportationCosts = 1;
     
    143146      Capacities[0] = 4; Capacities[1] = 1; Capacities[2] = 4;
    144147
    145       ParameterizeSolutionCreator();
    146       ParameterizeEvaluator();
     148      Parameterize();
    147149
    148150      InitializeOperators();
     
    155157
    156158    #region Events
    157     // TODO: Add your event handlers here
     159    protected override void OnOperatorsChanged() {
     160      base.OnOperatorsChanged();
     161      Parameterize();
     162    }
     163    protected override void OnEvaluatorChanged() {
     164      base.OnEvaluatorChanged();
     165      Parameterize();
     166      Evaluator.QualityParameter.ActualNameChanged += new System.EventHandler(Evaluator_QualityParameter_ActualNameChanged);
     167    }
     168    protected override void OnSolutionCreatorChanged() {
     169      base.OnSolutionCreatorChanged();
     170      Parameterize();
     171      SolutionCreator.IntegerVectorParameter.ActualNameChanged += new EventHandler(SolutionCreator_IntegerVectorParameter_ActualNameChanged);
     172    }
     173
     174    private void Evaluator_QualityParameter_ActualNameChanged(object sender, EventArgs e) {
     175      Parameterize();
     176    }
     177    private void SolutionCreator_IntegerVectorParameter_ActualNameChanged(object sender, EventArgs e) {
     178      Parameterize();
     179    }
    158180    #endregion
    159181
     
    161183    [StorableHook(HookType.AfterDeserialization)]
    162184    private void AfterDeserializationHook() {
     185      // BackwardsCompatibility3.3
     186      #region Backwards compatible code, remove with 3.4
     187      if (!Parameters.ContainsKey("EquipmentNames"))
     188        Parameters.Add(new OptionalValueParameter<StringArray>("EquipmentNames", "Optional: A list of names that describes the equipments.", null, false));
     189      if (!Parameters.ContainsKey("LocationNames"))
     190        Parameters.Add(new OptionalValueParameter<StringArray>("LocationNames", "Optional: A list of names that describes the locations.", null, false));
     191      #endregion
    163192      AttachEventHandlers();
    164193    }
    165194
    166195    private void AttachEventHandlers() {
    167       // TODO: Add event handlers to the parameters here
     196      Evaluator.QualityParameter.ActualNameChanged += new System.EventHandler(Evaluator_QualityParameter_ActualNameChanged);
     197      SolutionCreator.IntegerVectorParameter.ActualNameChanged += new EventHandler(SolutionCreator_IntegerVectorParameter_ActualNameChanged);
    168198    }
    169199
     
    172202      Operators.RemoveAll(x => x is ISingleObjectiveMoveEvaluator);
    173203      Operators.Add(new BestGQAPSolutionAnalyzer());
    174       ParameterizeAnalyzers();
    175       ParameterizeOperators();
    176     }
    177     private void ParameterizeAnalyzers() {
     204      Parameterize();
     205    }
     206
     207    private void Parameterize() {
     208      Evaluator.WeightsParameter.ActualName = WeightsParameter.Name;
     209      Evaluator.DistancesParameter.ActualName = DistancesParameter.Name;
     210      Evaluator.InstallationCostsParameter.ActualName = InstallationCostsParameter.Name;
     211      Evaluator.TransportationCostsParameter.ActualName = TransportationCostsParameter.Name;
     212      Evaluator.DemandsParameter.ActualName = DemandsParameter.Name;
     213      Evaluator.CapacitiesParameter.ActualName = CapacitiesParameter.Name;
     214      Evaluator.AssignmentParameter.ActualName = "Assignment";
     215
     216      SolutionCreator.LengthParameter.Value = new IntValue(Demands.Length);
     217      SolutionCreator.MinimumParameter.Value = new IntValue(0);
     218      SolutionCreator.MaximumParameter.Value = new IntValue(Capacities.Length);
     219      SolutionCreator.IntegerVectorParameter.ActualName = "Assignment";
     220
     221      foreach (IIntegerVectorCrossover op in Operators.OfType<IIntegerVectorCrossover>()) {
     222        op.ParentsParameter.ActualName = SolutionCreator.IntegerVectorParameter.ActualName;
     223        op.ChildParameter.ActualName = SolutionCreator.IntegerVectorParameter.ActualName;
     224      }
     225      foreach (IIntegerVectorManipulator op in Operators.OfType<IIntegerVectorManipulator>()) {
     226        op.IntegerVectorParameter.ActualName = SolutionCreator.IntegerVectorParameter.ActualName;
     227      }
     228
    178229      if (BestSolutionAnalyzer != null) {
    179230        BestSolutionAnalyzer.QualityParameter.ActualName = Evaluator.QualityParameter.ActualName;
     
    186237      }
    187238    }
    188     private void ParameterizeOperators() {
    189       foreach (IIntegerVectorCrossover op in Operators.OfType<IIntegerVectorCrossover>()) {
    190         op.ParentsParameter.ActualName = SolutionCreator.IntegerVectorParameter.ActualName;
    191         op.ChildParameter.ActualName = SolutionCreator.IntegerVectorParameter.ActualName;
    192       }
    193       foreach (IIntegerVectorManipulator op in Operators.OfType<IIntegerVectorManipulator>()) {
    194         op.IntegerVectorParameter.ActualName = SolutionCreator.IntegerVectorParameter.ActualName;
    195       }
    196     }
    197     private void ParameterizeSolutionCreator() {
    198       SolutionCreator.LengthParameter.Value = new IntValue(Demands.Length);
    199       SolutionCreator.MinimumParameter.Value = new IntValue(0);
    200       SolutionCreator.MaximumParameter.Value = new IntValue(Capacities.Length);
    201       SolutionCreator.IntegerVectorParameter.ActualName = "Assignment";
    202     }
    203     private void ParameterizeEvaluator() {
    204       Evaluator.WeightsParameter.ActualName = WeightsParameter.Name;
    205       Evaluator.DistancesParameter.ActualName = DistancesParameter.Name;
    206       Evaluator.InstallationCostsParameter.ActualName = InstallationCostsParameter.Name;
    207       Evaluator.TransportationCostsParameter.ActualName = TransportationCostsParameter.Name;
    208       Evaluator.DemandsParameter.ActualName = DemandsParameter.Name;
    209       Evaluator.CapacitiesParameter.ActualName = CapacitiesParameter.Name;
    210       Evaluator.AssignmentParameter.ActualName = "Assignment";
    211     }
    212239    #endregion
    213240  }
Note: See TracChangeset for help on using the changeset viewer.