Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.BottomUpTreeDistance/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/DirectedGraph/Arc.cs @ 11238

Last change on this file since 11238 was 11238, checked in by bburlacu, 10 years ago

#2215: Updated interfaces and graph components according to the reviewer comments (IDirectedGraph, DirectedGraph, Vertex, Arc).

File size: 3.3 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2014 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System;
23using HeuristicLab.Common;
24using HeuristicLab.Core;
25using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
26
27namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
28  /// <summary>
29  /// An arc that can have a weight, a label, and a data object for holding additional info
30  /// </summary>
31  [StorableClass]
32  public class Arc : Item, IArc {
33    [Storable]
34    public IVertex Source { get; private set; }
35
36    [Storable]
37    public IVertex Target { get; private set; }
38
39    [Storable]
40    protected string label;
41    public string Label {
42      get { return label; }
43      set {
44        if (label.Equals(value)) return;
45        label = value;
46        OnChanged(this, EventArgs.Empty);
47      }
48    }
49
50    [Storable]
51    protected double weight;
52    public double Weight {
53      get { return weight; }
54      set {
55        if (weight.Equals(value)) return;
56        weight = value;
57        OnChanged(this, EventArgs.Empty);
58      }
59    }
60
61    [Storable]
62    protected object data;
63    public object Data {
64      get { return data; }
65      set {
66        if (data == value) return;
67        data = value;
68        OnChanged(this, EventArgs.Empty);
69      }
70    }
71
72    [StorableConstructor]
73    public Arc(bool deserializing) : base(deserializing) { }
74
75    public Arc(IVertex source, IVertex target) {
76      Source = source;
77      Target = target;
78    }
79
80    protected Arc(Arc original, Cloner cloner)
81      : base(original, cloner) {
82      Source = cloner.Clone(original.Source);
83      Target = cloner.Clone(original.Target);
84      label = original.Label;
85      weight = original.Weight;
86      data = original;
87    }
88
89    public override IDeepCloneable Clone(Cloner cloner) {
90      return new Arc(this, cloner);
91    }
92
93    public event EventHandler Changed;
94    protected virtual void OnChanged(object sender, EventArgs args) {
95      var changed = Changed;
96      if (changed != null)
97        changed(sender, args);
98    }
99  }
100
101  [StorableClass]
102  public class Arc<T> : Arc, IArc<T> where T : class,IItem {
103    public Arc(bool deserializing)
104      : base(deserializing) {
105    }
106
107    public Arc(IVertex source, IVertex target)
108      : base(source, target) {
109    }
110
111    protected Arc(Arc original, Cloner cloner)
112      : base(original, cloner) {
113    }
114
115    new public IVertex<T> Source {
116      get { return (IVertex<T>)base.Source; }
117    }
118    new public IVertex<T> Target {
119      get { return (IVertex<T>)base.Target; }
120    }
121  }
122}
Note: See TracBrowser for help on using the repository browser.