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