[10278] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[17181] | 3 | * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[10278] | 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 |
|
---|
[11229] | 22 | using System;
|
---|
[10278] | 23 | using HeuristicLab.Common;
|
---|
[17097] | 24 | using HEAL.Attic;
|
---|
[10267] | 25 |
|
---|
[11241] | 26 | namespace HeuristicLab.Core {
|
---|
[11935] | 27 | [Item("Arc", "A graph arc connecting two graph vertices, that can have a weight, label, and data object for holding additional info")]
|
---|
[17097] | 28 | [StorableType("E91E40A2-FE77-49F0-866E-5127F3C1AC79")]
|
---|
[10267] | 29 | public class Arc : Item, IArc {
|
---|
| 30 | [Storable]
|
---|
[11229] | 31 | public IVertex Source { get; private set; }
|
---|
[10897] | 32 |
|
---|
[10267] | 33 | [Storable]
|
---|
[11229] | 34 | public IVertex Target { get; private set; }
|
---|
[10897] | 35 |
|
---|
[10267] | 36 | [Storable]
|
---|
[11229] | 37 | protected string label;
|
---|
| 38 | public string Label {
|
---|
| 39 | get { return label; }
|
---|
| 40 | set {
|
---|
[13906] | 41 | if (label == value) return;
|
---|
[11229] | 42 | label = value;
|
---|
| 43 | OnChanged(this, EventArgs.Empty);
|
---|
| 44 | }
|
---|
| 45 | }
|
---|
[10897] | 46 |
|
---|
[10267] | 47 | [Storable]
|
---|
[11229] | 48 | protected double weight;
|
---|
| 49 | public double Weight {
|
---|
| 50 | get { return weight; }
|
---|
| 51 | set {
|
---|
[11238] | 52 | if (weight.Equals(value)) return;
|
---|
[11229] | 53 | weight = value;
|
---|
| 54 | OnChanged(this, EventArgs.Empty);
|
---|
| 55 | }
|
---|
| 56 | }
|
---|
[10897] | 57 |
|
---|
[10267] | 58 |
|
---|
| 59 | [StorableConstructor]
|
---|
[17097] | 60 | protected Arc(StorableConstructorFlag _) : base(_) { }
|
---|
[10267] | 61 |
|
---|
[11229] | 62 | public Arc(IVertex source, IVertex target) {
|
---|
| 63 | Source = source;
|
---|
| 64 | Target = target;
|
---|
| 65 | }
|
---|
| 66 |
|
---|
| 67 | protected Arc(Arc original, Cloner cloner)
|
---|
| 68 | : base(original, cloner) {
|
---|
| 69 | Source = cloner.Clone(original.Source);
|
---|
| 70 | Target = cloner.Clone(original.Target);
|
---|
| 71 | label = original.Label;
|
---|
| 72 | weight = original.Weight;
|
---|
| 73 | }
|
---|
[11241] | 74 | public override IDeepCloneable Clone(Cloner cloner) { return new Arc(this, cloner); }
|
---|
[11229] | 75 |
|
---|
[11238] | 76 | public event EventHandler Changed;
|
---|
| 77 | protected virtual void OnChanged(object sender, EventArgs args) {
|
---|
| 78 | var changed = Changed;
|
---|
| 79 | if (changed != null)
|
---|
| 80 | changed(sender, args);
|
---|
| 81 | }
|
---|
[11229] | 82 | }
|
---|
[10267] | 83 |
|
---|
[17097] | 84 | [StorableType("5F06782E-3BD2-4A9D-B030-BE1D6A6B714F")]
|
---|
[13906] | 85 | public class Arc<T> : Arc, IArc<T> where T : class, IDeepCloneable {
|
---|
[11935] | 86 | [Storable]
|
---|
| 87 | protected T data;
|
---|
| 88 | public T Data {
|
---|
| 89 | get { return data; }
|
---|
| 90 | set {
|
---|
| 91 | if (data == value) return;
|
---|
| 92 | data = value;
|
---|
| 93 | OnChanged(this, EventArgs.Empty);
|
---|
| 94 | }
|
---|
| 95 | }
|
---|
| 96 |
|
---|
| 97 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
| 98 | return new Arc<T>(this, cloner);
|
---|
| 99 | }
|
---|
| 100 |
|
---|
| 101 | protected Arc(Arc<T> original, Cloner cloner)
|
---|
| 102 | : base(original, cloner) {
|
---|
| 103 | if (original.Data != null)
|
---|
| 104 | Data = cloner.Clone(original.Data);
|
---|
| 105 | }
|
---|
| 106 |
|
---|
[17097] | 107 | [StorableConstructor]
|
---|
| 108 | public Arc(StorableConstructorFlag _)
|
---|
| 109 | : base(_) {
|
---|
[10888] | 110 | }
|
---|
| 111 |
|
---|
[11229] | 112 | public Arc(IVertex source, IVertex target)
|
---|
| 113 | : base(source, target) {
|
---|
| 114 | }
|
---|
| 115 |
|
---|
[10267] | 116 | protected Arc(Arc original, Cloner cloner)
|
---|
| 117 | : base(original, cloner) {
|
---|
| 118 | }
|
---|
| 119 | }
|
---|
| 120 | }
|
---|