Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Core/3.3/Collections/DirectedGraph/Arc.cs @ 11241

Last change on this file since 11241 was 11241, checked in by mkommend, 10 years ago

#2223: Copied directed graph implented in bottom up tree distance branch into the trunk.

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.Persistence.Default.CompositeSerializers.Storable;
25
26namespace HeuristicLab.Core {
27  /// <summary>
28  /// An arc that can have a weight, a label, and a data object for holding additional info
29  /// </summary>
30  [StorableClass]
31  public class Arc : Item, IArc {
32    [Storable]
33    public IVertex Source { get; private set; }
34
35    [Storable]
36    public IVertex Target { get; private set; }
37
38    [Storable]
39    protected string label;
40    public string Label {
41      get { return label; }
42      set {
43        if (label.Equals(value)) return;
44        label = value;
45        OnChanged(this, EventArgs.Empty);
46      }
47    }
48
49    [Storable]
50    protected double weight;
51    public double Weight {
52      get { return weight; }
53      set {
54        if (weight.Equals(value)) return;
55        weight = value;
56        OnChanged(this, EventArgs.Empty);
57      }
58    }
59
60    [Storable]
61    protected IDeepCloneable data;
62    public IDeepCloneable Data {
63      get { return data; }
64      set {
65        if (data == value) return;
66        data = value;
67        OnChanged(this, EventArgs.Empty);
68      }
69    }
70
71    [StorableConstructor]
72    public Arc(bool deserializing) : base(deserializing) { }
73
74    public Arc(IVertex source, IVertex target) {
75      Source = source;
76      Target = target;
77    }
78
79    protected Arc(Arc original, Cloner cloner)
80      : base(original, cloner) {
81      Source = cloner.Clone(original.Source);
82      Target = cloner.Clone(original.Target);
83      label = original.Label;
84      weight = original.Weight;
85      data = cloner.Clone(data);
86    }
87    public override IDeepCloneable Clone(Cloner cloner) { return new Arc(this, cloner); }
88
89    public event EventHandler Changed;
90    protected virtual void OnChanged(object sender, EventArgs args) {
91      var changed = Changed;
92      if (changed != null)
93        changed(sender, args);
94    }
95  }
96
97  [StorableClass]
98  public class Arc<T> : Arc, IArc<T> where T : class,IItem {
99    public Arc(bool deserializing)
100      : base(deserializing) {
101    }
102
103    public Arc(IVertex source, IVertex target)
104      : base(source, target) {
105    }
106
107    protected Arc(Arc original, Cloner cloner)
108      : base(original, cloner) {
109    }
110
111    new public IVertex<T> Source {
112      get { return (IVertex<T>)base.Source; }
113    }
114    new public IVertex<T> Target {
115      get { return (IVertex<T>)base.Target; }
116    }
117  }
118}
Note: See TracBrowser for help on using the repository browser.