Free cookie consent management tool by TermsFeed Policy Generator

Changeset 4770 for branches


Ignore:
Timestamp:
11/11/10 14:03:24 (14 years ago)
Author:
abeham
Message:

#1258

  • worked on parameter binding
Location:
branches/ParameterBinding
Files:
2 added
2 deleted
4 edited

Legend:

Unmodified
Added
Removed
  • branches/ParameterBinding/HeuristicLab.Core/3.3/ParameterizedNamedItem.cs

    r4757 r4770  
    3434    [Storable]
    3535    private List<IParameterBinding> parameterBindingList;
    36     // eventuelly this should be made public and exposed in a view so that the algorithm designer can add bindings in the GUI
    37     protected List<IParameterBinding> ParameterBindingList {
     36    public List<IParameterBinding> ParameterBindingList {
    3837      get { return parameterBindingList; }
    3938    }
     
    105104      }
    106105    }
     106
     107    [StorableHook(HookType.AfterDeserialization)]
     108    private void AfterDeserialization() {
     109      //BackwardsCompatibility3.3
     110      #region Remove this code when going to 3.4
     111      if (parameterBindingList == null)
     112        parameterBindingList = new List<IParameterBinding>();
     113      #endregion
     114    }
    107115  }
    108116}
  • branches/ParameterBinding/HeuristicLab.Parameters/3.3/HeuristicLab.Parameters-3.3.csproj

    r4758 r4770  
    111111    <None Include="HeuristicLabParametersPlugin.cs.frame" />
    112112    <Compile Include="ConstrainedValueParameter.cs" />
    113     <Compile Include="ParameterSecondLevelValueBinding.cs" />
     113    <Compile Include="ParameterSecondLevelNameBinding.cs" />
    114114    <Compile Include="ParameterValueBinding.cs" />
    115115    <Compile Include="OptionalConstrainedValueParameter.cs" />
    116     <Compile Include="ParameterActualNameBinding.cs" />
     116    <Compile Include="ParameterNameBinding.cs" />
    117117    <Compile Include="ScopeTreeLookupParameter.cs" />
    118118    <Compile Include="ValueParameter.cs" />
  • branches/ParameterBinding/HeuristicLab.Parameters/3.3/ParameterValueBinding.cs

    r4757 r4770  
    1111  public class ParameterValueBinding : IParameterBinding {
    1212    [Storable]
    13     private IValueParameter recipient;
    14     public IValueParameter Recipient {
    15       get { return recipient; }
     13    private IValueParameter target;
     14    public IValueParameter Target {
     15      get { return target; }
    1616    }
    1717    [Storable]
    18     private IValueParameter donor;
    19     public IValueParameter Donor {
    20       get { return donor; }
     18    private IValueParameter source;
     19    public IValueParameter Source {
     20      get { return source; }
    2121    }
    2222
     
    2424    protected ParameterValueBinding(bool deserializing) { }
    2525    protected ParameterValueBinding(ParameterValueBinding original, Cloner cloner) {
    26       this.donor = cloner.Clone(donor);
    27       this.recipient = cloner.Clone(recipient);
     26      this.source = cloner.Clone(source);
     27      this.target = cloner.Clone(target);
    2828      RegisterEventHandlers();
    2929    }
    30     public ParameterValueBinding(IValueParameter recipient, IValueParameter donor) {
    31       if (recipient == null) throw new ArgumentNullException("destination");
    32       if (donor == null) throw new ArgumentNullException("source");
    33       this.recipient = recipient;
    34       this.donor = donor;
    35       RegisterEventHandlers();
     30    public ParameterValueBinding(IValueParameter target, IValueParameter source) {
     31      if (target == null) throw new ArgumentNullException("destination");
     32      if (source == null) throw new ArgumentNullException("source");
     33      this.target = target;
     34      this.source = source;
    3635    }
    3736
    38     public override IDeepCloneable Clone(Cloner cloner) {
     37    public object Clone() {
     38      return Clone(new Cloner());
     39    }
     40
     41    public virtual IDeepCloneable Clone(Cloner cloner) {
    3942      return new ParameterValueBinding(this, cloner);
    4043    }
     
    4245    public void Bind() {
    4346      RegisterEventHandlers();
     47      ExecuteBinding();
    4448    }
    4549
     
    5458
    5559    private void RegisterEventHandlers() {
    56       donor.ValueChanged += new EventHandler(source_ValueChanged);
     60      source.ValueChanged += new EventHandler(source_ValueChanged);
    5761    }
    5862
    5963    private void DeregisterEventHandlers() {
    60       donor.ValueChanged -= new EventHandler(source_ValueChanged);
     64      source.ValueChanged -= new EventHandler(source_ValueChanged);
    6165    }
    62    
    6366
    6467    private void source_ValueChanged(object sender, EventArgs e) {
    65       recipient.Value = (IItem)donor.Value.Clone();
     68      ExecuteBinding();
     69    }
     70
     71    private void ExecuteBinding() {
     72      target.Value = (IItem)source.Value.Clone();
    6673    }
    6774  }
  • branches/ParameterBinding/HeuristicLab.Problems.TravelingSalesman/3.3/TravelingSalesmanProblem.cs

    r4757 r4770  
    239239      ParameterizeAnalyzers();
    240240    }
     241    private void MoveGenerator_InversionMoveParameter_ActualNameChanged(object sender, EventArgs e) {
     242      string name = ((ILookupParameter<InversionMove>)sender).ActualName;
     243      foreach (IPermutationInversionMoveOperator op in Operators.OfType<IPermutationInversionMoveOperator>()) {
     244        op.InversionMoveParameter.ActualName = name;
     245      }
     246    }
    241247    private void MoveGenerator_TranslocationMoveParameter_ActualNameChanged(object sender, EventArgs e) {
    242248      string name = ((ILookupParameter<TranslocationMove>)sender).ActualName;
     
    279285    }
    280286    private void InitializeMoveGenerators() {
    281       foreach (IPermutationInversionMoveOperator moveGen in Operators.OfType<IMoveGenerator>().OfType<IPermutationInversionMoveOperator>()) {
    282         foreach (IPermutationInversionMoveOperator moveOp in Operators.Where(x => ! (x is IMoveGenerator)).OfType<IPermutationInversionMoveOperator>()) {
    283           ParameterActualNameBinding binding = new ParameterActualNameBinding(
    284             moveGen.InversionMoveParameter,
    285             moveOp.InversionMoveParameter);
    286           ParameterBindingList.Add(binding);
    287           binding.Bind();
     287      foreach (IPermutationInversionMoveOperator op in Operators.OfType<IPermutationInversionMoveOperator>()) {
     288        if (op is IMoveGenerator) {
     289          op.InversionMoveParameter.ActualNameChanged += new EventHandler(MoveGenerator_InversionMoveParameter_ActualNameChanged);
    288290        }
    289291      }
    290       foreach (IPermutationTranslocationMoveOperator moveGen in Operators.OfType<IMoveGenerator>().OfType<IPermutationTranslocationMoveOperator>()) {
    291         foreach (IPermutationTranslocationMoveOperator moveOp in Operators.Where(x => !(x is IMoveGenerator)).OfType<IPermutationTranslocationMoveOperator>()) {
    292           ParameterActualNameBinding binding = new ParameterActualNameBinding(
    293             moveGen.TranslocationMoveParameter,
    294             moveOp.TranslocationMoveParameter);
    295           ParameterBindingList.Add(binding);
    296           binding.Bind();
     292      foreach (IPermutationTranslocationMoveOperator op in Operators.OfType<IPermutationTranslocationMoveOperator>()) {
     293        if (op is IMoveGenerator) {
     294          op.TranslocationMoveParameter.ActualNameChanged += new EventHandler(MoveGenerator_TranslocationMoveParameter_ActualNameChanged);
    297295        }
    298296      }
     
    312310    }
    313311    private void ParameterizeEvaluator() {
    314       ParameterSecondLevelActualNameBinding binding = new ParameterSecondLevelActualNameBinding(
    315         SolutionCreatorParameter, EvaluatorParameter,
    316         "PermutationParameter", "PermutationParameter"
    317         );
    318       ParameterBindingList.Add(binding);
    319       binding.Bind();
    320 
    321312      if (Evaluator is ITSPPathEvaluator)
    322313        ((ITSPPathEvaluator)Evaluator).PermutationParameter.ActualName = SolutionCreator.PermutationParameter.ActualName;
     
    330321    private void ParameterizeAnalyzers() {
    331322      if (BestTSPSolutionAnalyzer != null) {
     323        #region Using First Level Bindings
     324        BestTSPSolutionAnalyzer.ParameterBindingList.Add(new ParameterNameBinding(
     325          BestTSPSolutionAnalyzer.QualityParameter,
     326          Evaluator.QualityParameter
     327          ));
     328        BestTSPSolutionAnalyzer.ParameterBindingList.Add(new ParameterNameBinding(
     329          BestTSPSolutionAnalyzer.CoordinatesParameter,
     330          CoordinatesParameter
     331          ));
     332        BestTSPSolutionAnalyzer.ParameterBindingList.Add(new ParameterNameBinding(
     333          BestTSPSolutionAnalyzer.PermutationParameter,
     334          SolutionCreator.PermutationParameter
     335          ));
     336        BestTSPSolutionAnalyzer.ParameterBindingList.Add(new ParameterNameBinding(
     337          BestTSPSolutionAnalyzer.BestKnownQualityParameter,
     338          BestKnownQualityParameter
     339          ));
     340        BestTSPSolutionAnalyzer.ParameterBindingList.Add(new ParameterNameBinding(
     341          BestTSPSolutionAnalyzer.BestKnownSolutionParameter,
     342          BestKnownSolutionParameter
     343          ));
     344        BestTSPSolutionAnalyzer.ParameterBindingList.Add(new ParameterNameBinding(
     345          BestTSPSolutionAnalyzer.MaximizationParameter,
     346          MaximizationParameter
     347          ));
     348        #endregion
     349        #region Using Second Level Bindings
     350        BestTSPSolutionAnalyzer.ParameterBindingList.Add(new ParameterSecondLevelNameBinding(
     351          BestTSPSolutionAnalyzer.QualityParameter,
     352          EvaluatorParameter, "QualityParameter"
     353          ));
     354        BestTSPSolutionAnalyzer.ParameterBindingList.Add(new ParameterSecondLevelNameBinding(
     355           BestTSPSolutionAnalyzer.PermutationParameter,
     356           SolutionCreatorParameter, "PermutationParameter"
     357           ));
     358        #endregion
     359        #region Old
    332360        BestTSPSolutionAnalyzer.QualityParameter.ActualName = Evaluator.QualityParameter.ActualName;
    333361        BestTSPSolutionAnalyzer.CoordinatesParameter.ActualName = CoordinatesParameter.Name;
     
    337365        BestTSPSolutionAnalyzer.BestKnownSolutionParameter.ActualName = BestKnownSolutionParameter.Name;
    338366        BestTSPSolutionAnalyzer.MaximizationParameter.ActualName = MaximizationParameter.Name;
     367        #endregion
    339368      }
    340369
Note: See TracChangeset for help on using the changeset viewer.