Пример #1
0
        /// <summary>
        /// Disconnects a specific phased connection between network elements.
        /// </summary>
        /// <param name="elem1">The first element to disconnect.</param>
        /// <param name="phase1">The phase that the connection is currently on, for <paramref name="elem1"/>.</param>
        /// <param name="elem2">The second element to disconnect.</param>
        /// <param name="phase2">The phase that the connection is currently on, for <paramref name="elem2"/>.</param>
        protected static void Disconnect(NetworkElement elem1, int phase1, NetworkElement elem2, int phase2)
        {
            if (!ConnectionExists(elem1, phase1, elem2, phase2))
            {
                return;
            }

            elem1._ConnectedToPhased[phase1].Remove(new NetworkElementConnection(elem2, phase2));
            elem2._ConnectedToPhased[phase2].Remove(new NetworkElementConnection(elem1, phase1));
        }
 /// <summary>
 /// Connects the <see cref="PowerDeliveryElement"/> on the phases in <paramref name="bus1AndLinePhases"/>
 /// to the same phases on <paramref name="bus1"/>, and to the correspondingly-indexed phases <paramref name="bus2Phases"/>
 /// on <paramref name="bus2"/>.
 /// </summary>
 /// <example>
 /// The following code connects the <see cref="PowerDeliveryElement"/> to <paramref name="bus1"/>
 /// and <paramref name="bus2"/>, with the following phasing:
 /// <code>
 /// // key: line phase -> bus1 phase, bus2 phase
 /// // 1 -> 1, 2
 /// // 2 -> 2, 3
 /// // 3 -> 3, 1
 /// myPowerDeliveryElement.Connect(bus1, new[] {1,2,3}, bus2, new[] {2,3,1});
 /// </code></example>
 /// <param name="bus1">The first <see cref="Bus"/> to connect to. Shares common phases with the <see cref="PowerDeliveryElement"/>.</param>
 /// <param name="bus1AndLinePhases">The common phases to connect between the <see cref="PowerDeliveryElement"/> and the <see cref="Bus"/>.</param>
 /// <param name="bus2">The second <see cref="Bus"/> to connect to.</param>
 /// <param name="bus2Phases">Phase connections for <paramref name="bus2"/>.</param>
 public void Connect(Bus bus1, IEnumerable <int> bus1AndLinePhases, Bus bus2, IEnumerable <int> bus2Phases)
 {
     foreach (var phasePair in bus1AndLinePhases.Zip(bus2Phases, (phase1, phase2) => new { Bus1AndLinePhase = phase1, Bus2Phase = phase2 }))
     {
         NetworkElement.ConnectBetween(this,
                                       phasePair.Bus1AndLinePhase,
                                       bus1,
                                       phasePair.Bus1AndLinePhase,
                                       bus2,
                                       phasePair.Bus2Phase
                                       );
     }
 }
Пример #3
0
 /// <summary>
 /// Disconnects two <see cref="NetworkElement"/> from each other across all
 /// phases.
 /// </summary>
 /// <param name="elem1">The first element to disconnect.</param>
 /// <param name="elem2">The second element to disconnect.</param>
 protected static void Disconnect(NetworkElement elem1, NetworkElement elem2)
 {
     foreach (var connections in elem1._ConnectedToPhased.Values)
     {
         foreach (var deleteCon in connections.Where(conn => conn.Element == elem2))
         {
             connections.Remove(deleteCon);
         }
     }
     foreach (var connections in elem2._ConnectedToPhased.Values)
     {
         foreach (var deleteCon in connections.Where(conn => conn.Element == elem1))
         {
             connections.Remove(deleteCon);
         }
     }
 }
Пример #4
0
        /// <summary>
        /// Connects a <see cref="NetworkElement"/> to a single other <see cref="NetworkElement"/>, with a specified phasing.
        /// </summary>
        /// <param name="elem1">The first element to connect.</param>
        /// <param name="phase1">The phase of the first element to connect.</param>
        /// <param name="elem2">The second element to connect.</param>
        /// <param name="phase2">The phase of the second element to connect.</param>
        protected static void Connect(NetworkElement elem1, int phase1, NetworkElement elem2, int phase2)
        {
            if (ConnectionExists(elem1, phase1, elem2, phase2))
            {
                return;
            }

            if (!elem1._ConnectedToPhased.ContainsKey(phase1))
            {
                elem1._ConnectedToPhased[phase1] = new Collection <NetworkElementConnection>();
            }

            elem1._ConnectedToPhased[phase1].Add(new NetworkElementConnection(elem2, phase2));

            if (!elem2._ConnectedToPhased.ContainsKey(phase2))
            {
                elem2._ConnectedToPhased[phase2] = new Collection <NetworkElementConnection>();
            }

            elem2._ConnectedToPhased[phase2].Add(new NetworkElementConnection(elem1, phase1));
        }
Пример #5
0
 /// <summary>
 /// Disconnects two <see cref="NetworkElement"/> from each other across all
 /// phases.
 /// </summary>
 /// <param name="elem1">The first element to disconnect.</param>
 /// <param name="elem2">The second element to disconnect.</param>
 protected static void Disconnect(NetworkElement elem1, NetworkElement elem2)
 {
     foreach (var connections in elem1._ConnectedToPhased.Values)
     {
         foreach (var deleteCon in connections.Where(conn => conn.Element == elem2))
         {
             connections.Remove(deleteCon);
         }
     }
     foreach (var connections in elem2._ConnectedToPhased.Values)
     {
         foreach (var deleteCon in connections.Where(conn => conn.Element == elem1))
         {
             connections.Remove(deleteCon);
         }
     }
 }
Пример #6
0
        /// <summary>
        /// Connects a <see cref="NetworkElement"/> to a single other <see cref="NetworkElement"/>, with a specified phasing.
        /// </summary>
        /// <param name="elem1">The first element to connect.</param>
        /// <param name="phase1">The phase of the first element to connect.</param>
        /// <param name="elem2">The second element to connect.</param>
        /// <param name="phase2">The phase of the second element to connect.</param>
        protected static void Connect(NetworkElement elem1, int phase1, NetworkElement elem2, int phase2)
        {
            if (ConnectionExists(elem1, phase1, elem2, phase2))
                return;

            if (!elem1._ConnectedToPhased.ContainsKey(phase1))
                elem1._ConnectedToPhased[phase1] = new Collection<NetworkElementConnection>();

            elem1._ConnectedToPhased[phase1].Add(new NetworkElementConnection(elem2, phase2));

            if (!elem2._ConnectedToPhased.ContainsKey(phase2))
                elem2._ConnectedToPhased[phase2] = new Collection<NetworkElementConnection>();

            elem2._ConnectedToPhased[phase2].Add(new NetworkElementConnection(elem1, phase1));
        }
Пример #7
0
 /// <summary>
 /// Test if a specific connection between this element and another element on specific phases exists.
 /// </summary>
 /// <param name="thisElemPhase">The phase of this element to check.</param>
 /// <param name="otherElem">The second element to check.</param>
 /// <param name="otherElemPhase">The phase of <paramref name="otherElem"/> to check.</param>
 /// <returns><c>true</c> if the specifically requested connection exists.</returns>
 public bool ConnectionExists(int thisElemPhase, NetworkElement otherElem, int otherElemPhase)
 {
     return ConnectionExists(this, thisElemPhase, otherElem, otherElemPhase);
 }
Пример #8
0
 /// <summary>
 /// Test if a specific connection between elements on specific phases exists.
 /// </summary>
 /// <param name="elem1">The first element to check.</param>
 /// <param name="phase1">The phase of <paramref name="elem1"/> to check.</param>
 /// <param name="elem2">The second element to check.</param>
 /// <param name="phase2">The phase of <paramref name="elem2"/> to check.</param>
 /// <returns><c>true</c> if the specifically requested connection exists.</returns>
 public static bool ConnectionExists(NetworkElement elem1, int phase1, NetworkElement elem2, int phase2)
 {
     return elem1._ConnectedToPhased.ContainsKey(phase1) &&
             elem1._ConnectedToPhased[phase1].Any(conn => conn.Element == elem2 && conn.Phase == phase2);
 }
 public void PairConnectionAssertions(NetworkElement elem1, int phase1, NetworkElement elem2, int phase2)
 {
     Assert.IsTrue(elem1.ConnectionExists(phase1, elem2, phase2));
     Assert.IsTrue(elem2.ConnectionExists(phase2, elem1, phase1));
 }
Пример #10
0
 /// <summary>
 /// Connects the <see cref="NetworkElement"/> between two other <see cref="NetworkElement"/>s, with a specific phasing.
 /// </summary>
 /// <param name="thisElemPhase">The phase that should be connected.</param>
 /// <param name="elem1">The element to connect to this element on one side.</param>
 /// <param name="elem1Phase">The phase of <paramref name="elem1"/> that should be connected.</param>
 /// <param name="elem2">The element to connect to this element on the other side.</param>
 /// <param name="elem2Phase">The phase of <paramref name="elem2"/> that should be connected.</param>
 protected void ConnectBetween(int thisElemPhase, NetworkElement elem1, int elem1Phase, NetworkElement elem2, int elem2Phase)
 {
     Connect(this, thisElemPhase, elem1, elem1Phase);
     Connect(this, thisElemPhase, elem2, elem2Phase);
 }
Пример #11
0
 /// <summary>
 /// Test if a specific connection between this element and another element on specific phases exists.
 /// </summary>
 /// <param name="thisElemPhase">The phase of this element to check.</param>
 /// <param name="otherElem">The second element to check.</param>
 /// <param name="otherElemPhase">The phase of <paramref name="otherElem"/> to check.</param>
 /// <returns><c>true</c> if the specifically requested connection exists.</returns>
 public bool ConnectionExists(int thisElemPhase, NetworkElement otherElem, int otherElemPhase)
 {
     return(ConnectionExists(this, thisElemPhase, otherElem, otherElemPhase));
 }
Пример #12
0
 /// <summary>
 /// Test if a specific connection between elements on specific phases exists.
 /// </summary>
 /// <param name="elem1">The first element to check.</param>
 /// <param name="phase1">The phase of <paramref name="elem1"/> to check.</param>
 /// <param name="elem2">The second element to check.</param>
 /// <param name="phase2">The phase of <paramref name="elem2"/> to check.</param>
 /// <returns><c>true</c> if the specifically requested connection exists.</returns>
 public static bool ConnectionExists(NetworkElement elem1, int phase1, NetworkElement elem2, int phase2)
 {
     return(elem1._ConnectedToPhased.ContainsKey(phase1) &&
            elem1._ConnectedToPhased[phase1].Any(conn => conn.Element == elem2 && conn.Phase == phase2));
 }
Пример #13
0
 /// <summary>
 /// Connects this <see cref="NetworkElement"/> to a single other <see cref="NetworkElement"/>, with a specified phasing.
 /// </summary>
 /// <param name="thisPhase">The phase of this element to connect.</param>
 /// <param name="connectTo">The other element to connect.</param>
 /// <param name="connectToPhase">The phase of the other element to connect.</param>
 protected void Connect(int thisPhase, NetworkElement connectTo, int connectToPhase)
 {
     Connect(this, thisPhase, connectTo, connectToPhase);
 }
Пример #14
0
 /// <summary>
 /// Connects the <see cref="NetworkElement"/> between two other <see cref="NetworkElement"/>s, with a specific phasing.
 /// </summary>
 /// <param name="thisElemPhase">The phase that should be connected.</param>
 /// <param name="elem1">The element to connect to this element on one side.</param>
 /// <param name="elem1Phase">The phase of <paramref name="elem1"/> that should be connected.</param>
 /// <param name="elem2">The element to connect to this element on the other side.</param>
 /// <param name="elem2Phase">The phase of <paramref name="elem2"/> that should be connected.</param>
 protected void ConnectBetween(int thisElemPhase, NetworkElement elem1, int elem1Phase, NetworkElement elem2, int elem2Phase)
 {
     Connect(this, thisElemPhase, elem1, elem1Phase);
     Connect(this, thisElemPhase, elem2, elem2Phase);
 }
Пример #15
0
 /// <summary>
 /// Disconnect this network element from another network element across all phases.
 /// </summary>
 /// <param name="elem">The <see cref="NetworkElement"/> to disconnect from.</param>
 protected void Disconnect(NetworkElement elem)
 {
     Disconnect(this, elem);
 }
Пример #16
0
        /// <summary>
        /// Disconnects a specific phased connection between network elements.
        /// </summary>
        /// <param name="elem1">The first element to disconnect.</param>
        /// <param name="phase1">The phase that the connection is currently on, for <paramref name="elem1"/>.</param>
        /// <param name="elem2">The second element to disconnect.</param>
        /// <param name="phase2">The phase that the connection is currently on, for <paramref name="elem2"/>.</param>
        protected static void Disconnect(NetworkElement elem1, int phase1, NetworkElement elem2, int phase2)
        {
            if (!ConnectionExists(elem1, phase1, elem2, phase2))
                return;

            elem1._ConnectedToPhased[phase1].Remove(new NetworkElementConnection(elem2, phase2));
            elem2._ConnectedToPhased[phase2].Remove(new NetworkElementConnection(elem1, phase1));
        }
Пример #17
0
 /// <summary>
 /// Connects this <see cref="NetworkElement"/> to a single other <see cref="NetworkElement"/>, with a specified phasing.
 /// </summary>
 /// <param name="thisPhase">The phase of this element to connect.</param>
 /// <param name="connectTo">The other element to connect.</param>
 /// <param name="connectToPhase">The phase of the other element to connect.</param>
 protected void Connect(int thisPhase, NetworkElement connectTo, int connectToPhase)
 {
     Connect(this, thisPhase, connectTo, connectToPhase);
 }
Пример #18
0
 /// <summary>
 /// Connects <paramref name="thisPhase"/> of this <see cref="PowerDeliveryElement"/> between
 /// <paramref name="bus1Phase"/> of <paramref name="bus1"/> and <paramref name="bus2Phase"/>
 /// of <paramref name="bus2"/>.
 /// </summary>
 /// <param name="thisPhase">The phase of this element to connect.</param>
 /// <param name="bus1">The <see cref="Bus"/> to connect on one side of this <see cref="PowerDeliveryElement"/>.</param>
 /// <param name="bus1Phase">The phase of <paramref name="bus1"/> to connect to.</param>
 /// <param name="bus2">The <see cref="Bus"/> to connect on the other side of this <see cref="PowerDeliveryElement"/>.</param>
 /// <param name="bus2Phase">The phase of <paramref name="bus2"/> to connect to.</param>
 public void Connect(int thisPhase, Bus bus1, int bus1Phase, Bus bus2, int bus2Phase)
 {
     NetworkElement.ConnectBetween(this, thisPhase, bus1, bus1Phase, bus2, bus2Phase);
 }
Пример #19
0
 /// <summary>
 /// Disconnect this network element from another network element across all phases.
 /// </summary>
 /// <param name="elem">The <see cref="NetworkElement"/> to disconnect from.</param>
 protected void Disconnect(NetworkElement elem)
 {
     Disconnect(this, elem);
 }
Пример #20
0
 public bool ConnectedToElemWithID(NetworkElement thisElem, IEnumerable<NetworkElement> elements, String id)
 {
     return thisElem.ConnectedTo.Contains(elements.Single(x => x.ID == id));
 }
Пример #21
0
 /// <summary>
 /// Creates a new <see cref="NetworkElementConnection"/>.
 /// </summary>
 /// <param name="Element">The <see cref="NetworkElement"/> that this structure represents a connection to.</param>
 /// <param name="Phase">The phase of <see cref="Element"/> that this structure represents a connection to.</param>
 public NetworkElementConnection(NetworkElement Element, int Phase)
 {
     _Element = Element;
     _Phase   = Phase;
 }
 /// <summary>
 /// Creates a new <see cref="NetworkElementConnection"/>.
 /// </summary>
 /// <param name="Element">The <see cref="NetworkElement"/> that this structure represents a connection to.</param>
 /// <param name="Phase">The phase of <see cref="Element"/> that this structure represents a connection to.</param>
 public NetworkElementConnection(NetworkElement Element, int Phase)
 {
     _Element = Element;
     _Phase = Phase;
 }