Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/23/11 09:28:34 (14 years ago)
Author:
abeham
Message:

#1330

  • Adapted QAP to new problem base class structure
  • Fixed a bug in a view
  • Merged changes from Optimization plugin into branch
Location:
branches/QAP/HeuristicLab.Optimization/3.3
Files:
4 deleted
6 edited
8 copied

Legend:

Unmodified
Added
Removed
  • branches/QAP/HeuristicLab.Optimization/3.3

  • branches/QAP/HeuristicLab.Optimization/3.3/Algorithm.cs

    r5445 r5811  
    224224    public virtual void CollectResultValues(IDictionary<string, IItem> values) {
    225225      values.Add("Execution Time", new TimeSpanValue(ExecutionTime));
    226       foreach (IResult result in Results)
    227         values.Add(result.Name, result.Value);
     226      CollectResultsRecursively("", Results, values);
     227    }
     228
     229    private void CollectResultsRecursively(string path, ResultCollection results, IDictionary<string, IItem> values) {
     230      foreach (IResult result in results) {
     231        values.Add(path + result.Name, result.Value);
     232        ResultCollection childCollection = result.Value as ResultCollection;
     233        if (childCollection != null) {
     234          CollectResultsRecursively(path + result.Name + ".", childCollection, values);
     235        }
     236      }
    228237    }
    229238
     
    283292
    284293    protected virtual void DeregisterProblemEvents() {
    285       problem.SolutionCreatorChanged -= new EventHandler(Problem_SolutionCreatorChanged);
    286       problem.EvaluatorChanged -= new EventHandler(Problem_EvaluatorChanged);
    287294      problem.OperatorsChanged -= new EventHandler(Problem_OperatorsChanged);
    288295      problem.Reset -= new EventHandler(Problem_Reset);
    289296    }
    290297    protected virtual void RegisterProblemEvents() {
    291       problem.SolutionCreatorChanged += new EventHandler(Problem_SolutionCreatorChanged);
    292       problem.EvaluatorChanged += new EventHandler(Problem_EvaluatorChanged);
    293298      problem.OperatorsChanged += new EventHandler(Problem_OperatorsChanged);
    294299      problem.Reset += new EventHandler(Problem_Reset);
    295300    }
    296     protected virtual void Problem_SolutionCreatorChanged(object sender, EventArgs e) { }
    297     protected virtual void Problem_EvaluatorChanged(object sender, EventArgs e) { }
    298301    protected virtual void Problem_OperatorsChanged(object sender, EventArgs e) { }
    299302    protected virtual void Problem_Reset(object sender, EventArgs e) {
  • branches/QAP/HeuristicLab.Optimization/3.3/HeuristicLab.Optimization-3.3.csproj

    r5785 r5811  
    142142    <Compile Include="BatchRun.cs" />
    143143    <Compile Include="Interfaces\IDiscreteDoubleMatrixModifier.cs" />
     144    <Compile Include="HeuristicOptimizationEngineAlgorithm.cs" />
    144145    <Compile Include="Interfaces\IGlobalParticleUpdater.cs" />
    145146    <Compile Include="Interfaces\ILocalImprovementOperator.cs" />
    146147    <Compile Include="Interfaces\ILocalParticleUpdater.cs" />
     148    <Compile Include="HeuristicOptimizationAlgorithm.cs" />
     149    <Compile Include="MultiObjectiveHeuristicOptimizationProblem.cs" />
     150    <Compile Include="HeuristicOptimizationProblem.cs" />
     151    <Compile Include="SingleObjectiveHeuristicOptimizationProblem.cs" />
     152    <Compile Include="Interfaces\IHeuristicOptimizationProblem.cs" />
    147153    <Compile Include="Interfaces\IMultiAnalyzer.cs" />
    148154    <Compile Include="Interfaces\IIterationBasedOperator.cs" />
     
    152158    <Compile Include="Interfaces\ITopologyInitializer.cs" />
    153159    <Compile Include="Interfaces\ITopologyUpdater.cs" />
    154     <Compile Include="MultiObjectiveProblem.cs" />
     160    <Compile Include="Interfaces\IMultiObjectiveHeuristicOptimizationProblem.cs" />
     161    <Compile Include="Interfaces\ISingleObjectiveHeuristicOptimizationProblem.cs" />
    155162    <Compile Include="Problem.cs" />
    156163    <Compile Include="RunCollectionConstraints\RunCollectionComparisonConstraint.cs" />
     
    188195    <Compile Include="Interfaces\IReducer.cs" />
    189196    <Compile Include="Interfaces\ISelector.cs" />
    190     <Compile Include="Interfaces\IMultiObjectiveProblem.cs" />
    191197    <Compile Include="Interfaces\IMultiObjectiveEvaluator.cs" />
    192198    <Compile Include="Interfaces\IAlgorithm.cs" />
     
    196202    <Compile Include="Interfaces\IProblem.cs" />
    197203    <Compile Include="Interfaces\ISingleObjectiveEvaluator.cs" />
    198     <Compile Include="Interfaces\ISingleObjectiveProblem.cs" />
    199204    <Compile Include="Interfaces\ISolutionCreator.cs" />
    200205    <Compile Include="Interfaces\IStochasticOperator.cs" />
     
    202207    <Compile Include="Interfaces\ITabuMaker.cs" />
    203208    <Compile Include="Result.cs" />
    204     <Compile Include="SingleObjectiveProblem.cs" />
    205209    <Compile Include="UserDefinedAlgorithm.cs" />
    206210    <Compile Include="EngineAlgorithm.cs" />
  • branches/QAP/HeuristicLab.Optimization/3.3/Interfaces/IProblem.cs

    r5445 r5811  
    2929  /// </summary>
    3030  public interface IProblem : IParameterizedNamedItem {
    31     IParameter SolutionCreatorParameter { get; }
    32     ISolutionCreator SolutionCreator { get; }
    33     IParameter EvaluatorParameter { get; }
    34     IEvaluator Evaluator { get; }
    3531    IEnumerable<IOperator> Operators { get; }
    3632
    37     event EventHandler SolutionCreatorChanged;
    38     event EventHandler EvaluatorChanged;
    3933    event EventHandler OperatorsChanged;
    4034    event EventHandler Reset;
  • branches/QAP/HeuristicLab.Optimization/3.3/Problem.cs

    r5445 r5811  
    2626using HeuristicLab.Common;
    2727using HeuristicLab.Core;
    28 using HeuristicLab.Parameters;
    2928using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    3029
     
    3231  [Item("Problem", "Represents the base class for a problem.")]
    3332  [StorableClass]
    34   public abstract class Problem<T, U> : ParameterizedNamedItem, IProblem
    35     where T : class,IEvaluator
    36     where U : class,ISolutionCreator {
    37     private const string EvaluatorParameterName = "Evaluator";
    38     private const string SolutionCreateParameterName = "SolutionCreator";
    39 
     33  public abstract class Problem : ParameterizedNamedItem, IProblem {
    4034    public override Image ItemImage {
    4135      get { return HeuristicLab.Common.Resources.VSImageLibrary.Type; }
     
    4438    [StorableConstructor]
    4539    protected Problem(bool deserializing) : base(deserializing) { }
    46     protected Problem(Problem<T, U> original, Cloner cloner)
     40    protected Problem(Problem original, Cloner cloner)
    4741      : base(original, cloner) {
    4842      operators = cloner.Clone(original.operators);
     
    5347      : base() {
    5448      operators = new OperatorCollection();
    55       Parameters.Add(new ValueParameter<T>(EvaluatorParameterName, "The operator used to evaluate a solution."));
    56       Parameters.Add(new ValueParameter<U>(SolutionCreateParameterName, "The operator to create a solution."));
    5749      RegisterEventHandlers();
    5850    }
     
    6759      Operators.ItemsRemoved += new CollectionItemsChangedEventHandler<IOperator>(Operators_Changed);
    6860      Operators.CollectionReset += new CollectionItemsChangedEventHandler<IOperator>(Operators_Changed);
    69 
    70       EvaluatorParameter.ValueChanged += new EventHandler(EvaluatorParameter_ValueChanged);
    71       SolutionCreatorParameter.ValueChanged += new EventHandler(SolutionCreatorParameter_ValueChanged);
    7261    }
    7362
     
    8372    }
    8473    IEnumerable<IOperator> IProblem.Operators { get { return operators; } }
    85 
    86     public T Evaluator {
    87       get { return EvaluatorParameter.Value; }
    88       protected set { EvaluatorParameter.Value = value; }
    89     }
    90     public ValueParameter<T> EvaluatorParameter {
    91       get { return (ValueParameter<T>)Parameters[EvaluatorParameterName]; }
    92     }
    93     IEvaluator IProblem.Evaluator { get { return Evaluator; } }
    94     IParameter IProblem.EvaluatorParameter { get { return EvaluatorParameter; } }
    95 
    96     public U SolutionCreator {
    97       get { return SolutionCreatorParameter.Value; }
    98       protected set { SolutionCreatorParameter.Value = value; }
    99     }
    100     public ValueParameter<U> SolutionCreatorParameter {
    101       get { return (ValueParameter<U>)Parameters[SolutionCreateParameterName]; }
    102     }
    103     ISolutionCreator IProblem.SolutionCreator { get { return SolutionCreator; } }
    104     IParameter IProblem.SolutionCreatorParameter { get { return SolutionCreatorParameter; } }
    10574    #endregion
    10675
    10776    #region events
    108     private void EvaluatorParameter_ValueChanged(object sender, EventArgs e) {
    109       OnEvaluatorChanged();
    110     }
    111     public event EventHandler EvaluatorChanged;
    112     protected virtual void OnEvaluatorChanged() {
    113       EventHandler handler = EvaluatorChanged;
    114       if (handler != null)
    115         handler(this, EventArgs.Empty);
    116     }
    117 
    118     private void SolutionCreatorParameter_ValueChanged(object sender, EventArgs e) {
    119       OnSolutionCreatorChanged();
    120     }
    121     public event EventHandler SolutionCreatorChanged;
    122     protected virtual void OnSolutionCreatorChanged() {
    123       EventHandler handler = SolutionCreatorChanged;
    124       if (handler != null)
    125         handler(this, EventArgs.Empty);
    126     }
    127 
    12877    private void Operators_Changed(object sender, EventArgs e) {
    12978      OnOperatorsChanged();
  • branches/QAP/HeuristicLab.Optimization/3.3/SingleObjectiveHeuristicOptimizationProblem.cs

    r5809 r5811  
    4141      : base() {
    4242      Parameters.Add(new ValueParameter<BoolValue>(MaximizationParameterName, "Set to false if the problem should be minimized.", new BoolValue()));
    43       Parameters.Add(new ValueParameter<DoubleValue>(BestKnownQualityParameterName, "The quality of the best known solution of this problem.", new DoubleValue()));
     43      Parameters.Add(new OptionalValueParameter<DoubleValue>(BestKnownQualityParameterName, "The quality of the best known solution of this problem.", new DoubleValue()));
    4444    }
    4545
     
    4747      : base(evaluator, solutionCreator) {
    4848      Parameters.Add(new ValueParameter<BoolValue>(MaximizationParameterName, "Set to false if the problem should be minimized.", new BoolValue()));
    49       Parameters.Add(new ValueParameter<DoubleValue>(BestKnownQualityParameterName, "The quality of the best known solution of this problem.", new DoubleValue()));
     49      Parameters.Add(new OptionalValueParameter<DoubleValue>(BestKnownQualityParameterName, "The quality of the best known solution of this problem.", new DoubleValue()));
    5050    }
    5151
    52     public ValueParameter<BoolValue> MaximizationParameter {
    53       get { return (ValueParameter<BoolValue>)Parameters[MaximizationParameterName]; }
     52    [StorableHook(HookType.AfterDeserialization)]
     53    protected virtual void AfterDeserialization() {
     54      // BackwardsCompatibility3.3
     55      #region Backwards compatible code (remove with 3.4)
     56      if (BestKnownQualityParameter is ValueParameter<DoubleValue>) {
     57        Parameters.Remove(BestKnownQualityParameterName);
     58        Parameters.Add(new OptionalValueParameter<DoubleValue>(BestKnownQualityParameterName, "The quality of the best known solution of this problem."));
     59      }
     60      #endregion
     61    }
     62    public IValueParameter<BoolValue> MaximizationParameter {
     63      get { return (IValueParameter<BoolValue>)Parameters[MaximizationParameterName]; }
    5464    }
    5565    IParameter ISingleObjectiveHeuristicOptimizationProblem.MaximizationParameter {
     
    6171    }
    6272
    63     public ValueParameter<DoubleValue> BestKnownQualityParameter {
    64       get { return (ValueParameter<DoubleValue>)Parameters[BestKnownQualityParameterName]; }
     73    public IValueParameter<DoubleValue> BestKnownQualityParameter {
     74      get { return (IValueParameter<DoubleValue>)Parameters[BestKnownQualityParameterName]; }
    6575    }
    6676    IParameter ISingleObjectiveHeuristicOptimizationProblem.BestKnownQualityParameter {
  • branches/QAP/HeuristicLab.Optimization/3.3/UserDefinedProblem.cs

    r5785 r5811  
    4040  [Creatable("Problems")]
    4141  [StorableClass]
    42   public sealed class UserDefinedProblem : ParameterizedNamedItem, ISingleObjectiveProblem, IStorableContent {
     42  public sealed class UserDefinedProblem : ParameterizedNamedItem, ISingleObjectiveHeuristicOptimizationProblem, IStorableContent {
    4343    public string Filename { get; set; }
    4444
     
    6060      get { return (ValueParameter<BoolValue>)Parameters["Maximization"]; }
    6161    }
    62     IParameter ISingleObjectiveProblem.MaximizationParameter {
     62    IParameter ISingleObjectiveHeuristicOptimizationProblem.MaximizationParameter {
    6363      get { return MaximizationParameter; }
    6464    }
     
    6666      get { return (ValueParameter<ISolutionCreator>)Parameters["SolutionCreator"]; }
    6767    }
    68     IParameter IProblem.SolutionCreatorParameter {
     68    IParameter IHeuristicOptimizationProblem.SolutionCreatorParameter {
    6969      get { return SolutionCreatorParameter; }
    7070    }
    71     IParameter IProblem.EvaluatorParameter {
     71    IParameter IHeuristicOptimizationProblem.EvaluatorParameter {
    7272      get { return EvaluatorParameter; }
    7373    }
     
    7575      get { return (OptionalValueParameter<DoubleValue>)Parameters["BestKnownQuality"]; }
    7676    }
    77     IParameter ISingleObjectiveProblem.BestKnownQualityParameter {
     77    IParameter ISingleObjectiveHeuristicOptimizationProblem.BestKnownQualityParameter {
    7878      get { return BestKnownQualityParameter; }
    7979    }
     
    9595      set { SolutionCreatorParameter.Value = value; }
    9696    }
    97     ISolutionCreator IProblem.SolutionCreator {
     97    ISolutionCreator IHeuristicOptimizationProblem.SolutionCreator {
    9898      get { return SolutionCreatorParameter.Value; }
    9999    }
     
    102102      set { EvaluatorParameter.Value = value; }
    103103    }
    104     ISingleObjectiveEvaluator ISingleObjectiveProblem.Evaluator {
     104    ISingleObjectiveEvaluator ISingleObjectiveHeuristicOptimizationProblem.Evaluator {
    105105      get { return EvaluatorParameter.Value; }
    106106    }
    107     IEvaluator IProblem.Evaluator {
     107    IEvaluator IHeuristicOptimizationProblem.Evaluator {
    108108      get { return EvaluatorParameter.Value; }
    109109    }
Note: See TracChangeset for help on using the changeset viewer.