#region License Information /* HeuristicLab * Copyright (C) 2002-2014 Heuristic and Evolutionary Algorithms Laboratory (HEAL) * * This file is part of HeuristicLab. * * HeuristicLab is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * HeuristicLab is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with HeuristicLab. If not, see . */ #endregion using HeuristicLab.Common; using HeuristicLab.Core; using HeuristicLab.Data; using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; using System; namespace HeuristicLab.Optimization.Networks { [Item("MultiplierNode", "A node for multiplying integer values.")] [StorableClass] public class MultiplierNode : Node { protected static readonly string MultiplierPortName = "Multiplier"; protected static readonly string ValuePortName = "Value"; public IInputPort MultiplierPort { get { return (IInputPort)Ports[MultiplierPortName]; } } public IInputOutputPort ValuePort { get { return (IInputOutputPort)Ports[ValuePortName]; } } [StorableConstructor] protected MultiplierNode(bool deserializing) : base(deserializing) { } protected MultiplierNode(MultiplierNode original, Cloner cloner) : base(original, cloner) { } public MultiplierNode() : base("MultiplierNode") { Initialize(); } public MultiplierNode(string name) : base(name) { Initialize(); } public MultiplierNode(string name, string description) : base(name, description) { Initialize(); } public override IDeepCloneable Clone(Cloner cloner) { return new MultiplierNode(this, cloner); } protected virtual void Initialize() { Ports.Add(new InputPort(MultiplierPortName)); Ports.Add(new InputOutputPort(ValuePortName)); RegisterPortEvents(); } protected virtual void RegisterPortEvents() { ValuePort.ValueReceived += ValuePort_ValueReceived; } protected virtual void ValuePort_ValueReceived(object sender, OutputInputPortEventArgs e) { if (MultiplierPort.Value == null) throw new InvalidOperationException("Multiplier is null"); if (e.Value != null) { e.Result = new IntValue(e.Value.Value * MultiplierPort.Value.Value); } } } }