Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
05/05/10 00:09:10 (14 years ago)
Author:
mkommend
Message:

updated Constraints (ticket #996)

Location:
trunk/sources/HeuristicLab.Core/3.3/Constraints
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Core/3.3/Constraints/ComparisonConstraint.cs

    r3602 r3613  
    4444
    4545    public override IEnumerable<ConstraintOperation> AllowedConstraintOperations {
    46       get { return new ConstraintOperation[6] { ConstraintOperation.Equal, ConstraintOperation.NotEqual, ConstraintOperation.Lesser, ConstraintOperation.LesserOrEqual, ConstraintOperation.Greater, ConstraintOperation.GreaterOrEqual }; }
     46      get { return new ConstraintOperation[6] { ConstraintOperation.Lesser, ConstraintOperation.LesserOrEqual, ConstraintOperation.Equal, ConstraintOperation.GreaterOrEqual, ConstraintOperation.Greater, ConstraintOperation.NotEqual }; }
    4747    }
    4848
  • trunk/sources/HeuristicLab.Core/3.3/Constraints/Constraint.cs

    r3605 r3613  
    3232    protected Constraint() {
    3333      this.Active = false;
     34      if (AllowedConstraintOperations != null && AllowedConstraintOperations.Count() != 0)
     35        this.ConstraintOperation = AllowedConstraintOperations.ElementAt(0);
    3436    }
    3537    [StorableConstructor]
     
    6567    public IItem ConstrainedValue {
    6668      get { return this.constrainedValue; }
    67       protected set {
     69      set {
    6870        if (value == null)
    6971          throw new ArgumentNullException("Constraint value cannot be null.");
    7072        if (this.constrainedValue != value) {
    7173          this.constrainedValue = value;
     74          this.OnConstrainedValueChanged();
    7275          this.OnToStringChanged();
    7376        }
     
    138141      EventHandler handler = ActiveChanged;
    139142      if (handler != null)
    140         ActiveChanged(this, EventArgs.Empty);
     143        handler(this, EventArgs.Empty);
     144    }
     145
     146    public event EventHandler ConstrainedValueChanged;
     147    protected virtual void OnConstrainedValueChanged() {
     148      EventHandler handler = ConstrainedValueChanged;
     149      if (handler != null)
     150        handler(this, EventArgs.Empty);
    141151    }
    142152
     
    145155      EventHandler handler = ConstraintDataChanged;
    146156      if (handler != null)
    147         ActiveChanged(this, EventArgs.Empty);
     157        handler(this, EventArgs.Empty);
    148158    }
    149159
     
    152162      EventHandler handler = ConstraintOperationChanged;
    153163      if (handler != null)
    154         ActiveChanged(this, EventArgs.Empty);
     164        handler(this, EventArgs.Empty);
    155165    }
    156166    #endregion
     
    158168    #region overriden item methods
    159169    public override string ToString() {
    160       IItem constrainedValue = GetConstrainedMember();
     170      IItem constrainedMember = GetConstrainedMember();
    161171      string s = string.Empty;
    162       if (constrainedValue != null)
    163         s += constrainedValue.ToString();
    164       else
    165         return "Could not determine constraint value.";
    166 
    167       s += " " + ConstraintOperation.ToString() + " ";
     172      if (constrainedMember != null)
     173        s += constrainedMember.ToString() + " ";
     174
     175      if (constraintOperation != null)
     176        s += ConstraintOperation.ToString() + " ";
    168177
    169178      if (constraintData != null)
     
    178187    public override IDeepCloneable Clone(HeuristicLab.Common.Cloner cloner) {
    179188      Constraint clone = (Constraint)base.Clone(cloner);
    180       clone.constrainedValue = (IItem)cloner.Clone(this.constrainedValue);
     189      clone.constrainedValue = null;  //mkommend: intentional set to null and must be reset in the clone
    181190
    182191      IItem constraintDataItem = this.constraintData as IItem;
  • trunk/sources/HeuristicLab.Core/3.3/Constraints/IConstraint.cs

    r3602 r3613  
    2626
    2727namespace HeuristicLab.Core {
    28   public interface IConstraint: IItem{
     28  public interface IConstraint : IItem {
    2929    bool Active { get; set; }
    30     IItem ConstrainedValue { get;}
     30    IItem ConstrainedValue { get; set; }
    3131    ConstraintOperation ConstraintOperation { get; set; }
    3232    IEnumerable<ConstraintOperation> AllowedConstraintOperations { get; }
     
    3636
    3737    event EventHandler ActiveChanged;
     38    event EventHandler ConstrainedValueChanged;
    3839    event EventHandler ConstraintDataChanged;
    3940    event EventHandler ConstraintOperationChanged;
Note: See TracChangeset for help on using the changeset viewer.