Free cookie consent management tool by TermsFeed Policy Generator

source: branches/OptimizationNetworks/HeuristicLab.Networks/3.3/### obsolete/MultiplierNode.cs @ 13799

Last change on this file since 13799 was 11526, checked in by swagner, 10 years ago

#2205: Worked on optimization networks

File size: 2.9 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 HeuristicLab.Common;
23using HeuristicLab.Core;
24using HeuristicLab.Data;
25using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
26using System;
27
28namespace HeuristicLab.Optimization.Networks {
29  [Item("MultiplierNode", "A node for multiplying integer values.")]
30  [StorableClass]
31  public class MultiplierNode : Node {
32    protected static readonly string MultiplierPortName = "Multiplier";
33    protected static readonly string ValuePortName = "Value";
34
35    public IInputPort<IntValue> MultiplierPort {
36      get { return (IInputPort<IntValue>)Ports[MultiplierPortName]; }
37    }
38    public IInputOutputPort<IntValue, IntValue> ValuePort {
39      get { return (IInputOutputPort<IntValue, IntValue>)Ports[ValuePortName]; }
40    }
41
42    [StorableConstructor]
43    protected MultiplierNode(bool deserializing) : base(deserializing) { }
44    protected MultiplierNode(MultiplierNode original, Cloner cloner) : base(original, cloner) { }
45    public MultiplierNode()
46      : base("MultiplierNode") {
47      Initialize();
48    }
49    public MultiplierNode(string name)
50      : base(name) {
51      Initialize();
52    }
53    public MultiplierNode(string name, string description)
54      : base(name, description) {
55      Initialize();
56    }
57
58    public override IDeepCloneable Clone(Cloner cloner) {
59      return new MultiplierNode(this, cloner);
60    }
61
62    protected virtual void Initialize() {
63      Ports.Add(new InputPort<IntValue>(MultiplierPortName));
64      Ports.Add(new InputOutputPort<IntValue, IntValue>(ValuePortName));
65      RegisterPortEvents();
66    }
67
68    protected virtual void RegisterPortEvents() {
69      ValuePort.ValueReceived += ValuePort_ValueReceived;
70    }
71
72    protected virtual void ValuePort_ValueReceived(object sender, OutputInputPortEventArgs<IntValue, IntValue> e) {
73      if (MultiplierPort.Value == null) throw new InvalidOperationException("Multiplier is null");
74      if (e.Value != null) {
75        e.Result = new IntValue(e.Value.Value * MultiplierPort.Value.Value);
76      }
77    }
78  }
79}
Note: See TracBrowser for help on using the repository browser.