Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/DirectedGraph/Arc.cs @ 11233

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

#1772: Worked towards integrating the new graph api with the tracking operators.

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