1. Introduction
Modern electrical power systems are complex networks of synchronous generators, transmission lines and loads[1]. With the growing size of these systems, and the complexity of their operating conditions, an urgent need arose to solve the issue of their optimal operation, with the aim of increasing the Power System Security, and its adaptation to face emergency events, which is a major concern for the Operator and the Power System Planner[2]. Solving this issue requires finding a mathematical model describing the power system, and then analyzing it to obtain the required parameters. The complexity of the issue increases with the increase in the number of its parameters, and the accuracy of the desired results, which means an increase in the time cost, which is undesirable, especially when the system operator is required to find the optimal solution to the issue of operation at the moment of an emergency, in order to continue providing consumers with electrical power and within the possible operational limits. To reduce the calculation time, it was necessary to transfer the mathematical model to a visual computer program, which performs all that the operator needs, from analyzing potential events, determining the capacity of generating units, and many other calculations, in order to ensure the quality of service from an economic and technical point of view, and to achieve system security, and this is considered a development of a group of previous researches. In 1999, the first computer program operating under the DOS environment was completed by researchers A. Hamza and N. Al-Faqih to analyze the safety of electrical power systems using linear models. Then, in 2001, the two researchers developed the program, adding linear programming technology to modify the generation strategy and decreasing some loads as a preventive measure to remove overloading on cumbersome lines[3]. As for the suggestion of the least expensive generation strategy in operation and the same traditional safe operation level of safety, it was completed by the researcher N. Al-Faqih in 2015. As a follow-up to that work, a visual computer program was designed and implemented by researchers O. Bahbouh and N. Al-Faqih, using the MATLAB environment, which has great capabilities in several engineering fields, including system modeling and simulation[4], and according to the standards adopted in software engineering[5], from analysis and design of the system, to be followed by the implementation stage by writing the script, and then the testing stage, which is one of the most difficult and the most accurate stages related to ensuring the security and reliability of the power system, which made it possible to obtain a software product with standard specifications and high reliability. Many new algorithms and options have also been added[3]. In 2019, the researchers, O. Bahbouh and N. Al-Faqih added an algorithm to find the optimal solution for generating and decreasing loads in the event of one line outage from a selected group of lines. It became possible to identify the most dangerous line in the network when it is interrupted, and simulate all lines graphically and with elegant view, with all data written on the screen. With options for the user to determine the importance of the loads, in addition to the cost of changing the generation on each generator in the network[6]. In this paper, an electric network was studied by analyzing it, simulating all its lines, and studying the effect of changing the power factor on the cost. 1- Power System Operation States:
The theoretical framework that defined the power system operating states was introduced in 1967 by DyLiaccoT.E.[8],[7] and then continued the work of Fink, L.H and Carlsen K. in 1978 in the same framework[9]. These definitions were the main motivation for studying the behavior of the power system, which is governed by a set of nonlinear differential and algebraic equations[10]. The operating states that the power system can go through are described in Figure 1, where it is assumed that the operation of the power system takes place under two types of constraints, which are load constraints and operating constraints[11].
1. Normal State: It is the desired state achieved for loading and operating constraints while working. 2. Alert State: The power system continues to operate within the permissible limits in this case, but it lacks the margins that existed in the normal state. 3. Emergency State: They arise when additional disturbances occur and the system is in an alert state, which means that operating constraints are exceeded. 4. Extreme State: In this case, the loading constraints are not achieved because there is not enough power to the loads, the frequency decreases, and there is often a need for load separation in order to secure the system, and the central control plays an important role in transferring the power system to the normal state. 2- Power System Modeling and Simulation:
With the increasing complexity of engineering systems and the increase in their performance requirements, computer simulation has become the only solution for design engineers to study their designs before adopting or starting to build them. Despite the great advantages of computer simulation, it undoubtedly has limitations, as the answers we get from the simulation process are limited by our ability to model phenomena correctly, and thus obtaining an accurate mathematical description of the system, including all its determinants and conditions affecting it. The research is based on finding the mathematical model on the two linear power flow techniques, and the sensitivity factors for the most important events that the power system may be exposed to, regardless of the number of busbars and their levels of voltage, as a first step, before writing the algorithm for analyzing potential events, so that the safety of any An electric power system, and moving towards designing an integrated visual software system to study, analyze and estimate the safety of the power system, to make the appropriate decision in cases of generation scheduling or generation scheduling and load decreasing.
3- Research importance:
Operating planning for electric power systems requires the design of programs that achieve acceptable operation from an economic and technical point of view[3]. In addition to studying the exposure of the electric power system to events such as line outages, generation outages, or both[6]. The research aims to follow up the development of the computer program presented in previous researches by adding the option of studying the effect of changing the power factor in the electric power system. The research aims to integration of mathematical models and software algorithms, to solve the problems of analyzing the electric power system, by calculating the power flow in the steady state, analyzing possible events to which the power system is exposed, detecting overloaded power system elements and indicating the percentage of load, which gives the operator a prior view of the power system situation in case of faults before they actually occur, and proposes corrective actions that decrease cases of overloading in lines in emergency state, and evaluating the safety of the ability system, and thus reaching an integrated software system that combines what has been reached in previous research[6], [3] into a single software system characterized by flexibility of use and low material requirements. This gives a set of positive effects such as reducing electrical losses, and increasing the safety and reliability of the electric power system. With the possibility of using the completed program in electrical power system simulations by graduate students and specialists. A local visual program for simulating electric power systems and suggesting optimal operating procedures, bypassing the drawbacks of foreign software and having the following features:
1. A simulation program with graphical interfaces, easy to handle and with standard specifications. 2. Flexibility in data entry, output, storage and modification using the graphical method or tables. 3. Calculate the power flow in the steady state. 4. Analyze the potential events that the power system is exposed to. 5. It is invested in the power system safety analysis automatically or selectively for potential events, as it names the overload lines, showing the percentages. 6. Allows the operator to selectively arrange the preference for operating the generation units according to a standard chosen by the operator. 7. The possibility of modifying the architecture of the power system by deleting or adding elements, such as lines and busbars. 8. Searching for optimal solutions for some power system parameters. 4- Mathematical Model:
The mathematical model consists of mathematical equations representing the power system, linear power flow problem, sensitivity factors for line (or transformer) interruption, or power station failure, and transmission line maximum load problem.
1. Linear Load Flow:
This method is based on calculating the actual power flow in the network branches in terms of the longitudinal reactance of the branches xij (lines and transformers), the phase angles of the network nodes θi, and the actual injected power Pi in these nodes. To extract the load flow equations, we adopt a representation of π for a transmission line connecting the busbars i and j as shown in Figure 2.
The power injected into the busbar i is equal to the sum of the powers injected into the lines connected to the busbar i whose number is n:

We impose an optional reference busbar with θr=0. We write equation (2) in matrix form:
![P̃ = [B]θ̃ ⟹θ̃ = [X]P̃ (3) where: n Bii = {∑1 ∶ i ≠ref (4) xij j=1 0 ∶ i = ref](https://americaspg.com/storage/fulltext/1623/7da9433ffc94ad19/eq-4.png)
2. Sensitivity Factors:
We must expect, at every moment, that the electrical power system will suffer malfunctions that may lead to one or more lines being out of service, or one or more generator being disconnected from the network in response to the protection system. The security of the power system requires that the coordination center be provided continuously and in advance with information about outages that cause overloads on the lines, and this requires analyzing a large number of outages, and placing the results at the disposal of the coordination center at the maximum speed. The sensitivity factors based on linear flow power have been widely used to find the solution with an acceptable approximation. These factors give the change in the power transmitted on the lines due to a change in the generation or a change in the structure of the network. There are several types of these factors, including sensitivity factors to generation change and sensitivity factors to interruption of lines[6].
3. Maximum loading of a transmission line:
Estimating the safety of the electrical network requires the discovery of overloaded transmission lines, and this requires calculating the maximum power that the line can transmit. There are two criteria used for this issue: the thermal limit of the line, and the static stability limit[3].
4. Formulation of safe economic coordination constraints:
The new power flow on the line ij after the generation change in the busbar m is given by:
old + gij,m ∗ΔPm (5) When the generation changes in all the busbar, the relationship becomes as follows:

1) Line Flow Constraint:
The new flow must always be less than a maximum flow 𝑃𝑖𝑗 𝑚𝑎𝑥can be the thermal limit of the transmission line or the static stability limit, whichever is less) according to the relation:
𝑚𝑎𝑥 (7) From relation (6), and by separating into two inequalities, we find:

We adopt the change in power ΔPm as decision variables in linear programming. And since the simplex method deals only with positive variables, we suppose that the amount of raising the power Pm on busbar m is ΔPm
+, and the amount of decreasing the power Pm on busbar m is ΔPm
2) Loads Covering Constraint:
The total generation power must always equal the sum of the loads power (neglecting losses):

The algebraic sum of the power changes injected into the network nodes must be equal to zero:

3) Generation Shift Constraint:
Each generator can offer a power Pm such that:
𝑚𝑎𝑥 (13) Since the decision variables suitable for programming are ΔPm
− and not Pm, the constraint of equation (13) becomes:
𝑚𝑖𝑛 (15) where m takes values from 1 to n.
5. Formulate the Objective Function:
Assuming that the generation strategy before the failure occurs achieves the economic coordination of generation, then the deviation from the economic coordination of generation must be as small as possible, that is, the modification in the generation power is minimal, and therefore the objective function is:

Where: Cm is the penalty(cost) of the generation deviation from the economic operation. Note that the line flow constraint is given by equations (8, 9), loads covering constraint is given by equation (12), and the generation modification constraint is given by equations (14, 15). 5- Computerized Simulation Test:
Using the implemented program, we have implemented several computer tests on standard power systems. Below we present the simulation results on a power network consisting of 6-busbar system. Figure 3 shows a 6-Busbar System drawn using the implemented program. Assume the base voltage is 230 kV, the base power is 100 MVA, the frequency is 50 Hz, the relative voltage drop is 8%, the power factor is 0.85, and the reference busbar is Gen.1. The network data are given in Tables (1) and (2).
[pu] Gen [pu]
[pu] [pu] [pu] Load
1.0 0.26 4.00 2.65 Gen.1
1.0 0.56 4.00 1.95 Gen.2
1.0 -1.80 -0.20 -1.60 Load.1
1.0 -1.00 -0.00 -1.00 Load.2
1.0 -2.10 -0.10 -2.00 Load.3
1.0 -1.00 -0.15 -0.99 Load.4 Table 2: Data lines
Sth [pu] Impedance
[pu] Bus to Bus
3.0515 j 0.1300 Gen.1 to Load.3
3.0515 j 0.0500 Gen.1 to Load.4
3.0515 j 0.0100 Gen.2 to Load.1
3.0515 j 0.0400 Gen.2 to Load.3
3.0515 j 0.0800 Gen.2 to Load.4
3.0515 j 0.0300 Load.1 to Load.2
3.0515 j 0.0325 Load.2 to Load.3
1. Finding matrices and some factors:
Using the program, the matrix B is calculated, then the matrix X, and the factors that are sensitive to generation change and line interruption, to obtain tables (3), (4), (5) and (6) shown consecutively. Table 3: Matrix B
2. Power flow studying:
Assuming that the operating parameters of the studied network were economic and a new change occurred in generation or load, the study of power flow shows that the transmission line (Gen.1 to Load.3) has become overloaded by 5.8996% above the static stability limit, as It is shown in Table (7), and therefore the previous economic operation does not meet the working conditions of the electric power system. Table 7: Power flow
By choosing the order of finding the optimal solution by changing the generation only, we obtain the results shown in Table (8), with a penalty equal to Cost = 30.9709 units. Where we conclude that by decreasing the generation on the busbar (Gen.1) by 14.4855 MVA and increasing the generation value on the busbar (Gen.2) by the same amount, we get power flow according to the required conditions, which is the least expensive solution, where the power flow on the line ( Gen.1 to Load.3) at its maximum. Table 8: The optimal solution is to change the generation only for the 6-Busbar system
in necessity case, some loads can be separated according to specific priorities by choosing the order of finding the optimal solution by changing the generation and decreasing the loads, to obtain the results shown in Table (9), with a penalty equal to Cost = 24.8381 unit, where it can be concluded that by reducing the generation on the busbar ( Gen.1) by 12.4190 MVA and decreasing the loads on the busbar (Load.3) by the same amount, we obtain a power flow according to the required conditions, and at a lower cost than in the case of changing the generation only, so the space of searching the solution in the case of changing the generation only, is part of the space of searching in the case of changing generation and decreasing loads.
3. Line interruption studying:
Table (10) shows the effect of line interruption on the power system, where we find that line interruption (Gen.1 to Load.4) leads to the highest load in the network, as its interruption causes an overload on the line (Gen.1 to Load.3) by 126.8453% in excess of the allowable limit. Also, the interruption of any line causes an overload on the network, except for the line (Gen.1 to Load.3), which does not cause any overload. Also interruption line (Gen.2 to Load.3) causes overload on two lines.
By simulating the interruption of all lines individually, we find that the program always gives an optimal solution for this network in case of changing generation and decreasing load. This is shown in Figure (4) for the case of line interruption (Gen.2 to Load.3), for example.
4. Power factor studying:
Using the program, it is possible to study the effect of changing the power factor on the possibility of finding the optimal solution by changing the generation, or by changing the generation and decreasing the loads. Figure (5) shows the relationship between the penalty of finding the optimal solution by changing the generation with the power factor change, as we notice the high penalty when the power factor is small. The penalty decreases as the power factor increases dramatically. When the power factor is (0.87), the cost becomes zero because there is no overload in the network. As for Figure (6), it shows the relationship between the penalty of finding the optimal solution by changing the generation and decreasing the loads with the change of the power factor, as we notice the high penalty when the power factor is small. The penalty decreases as the power factor increases dramatically. Of course, lower power factor values can be achieved in this case, but with a relatively large increase in penalty.
The research begins with an introduction that explains the concept and importance of electrical power system security, followed by a mathematical model that was built based on linear load flow and sensitivity factors to the most important events that the power system is exposed to, such as a line or generation interrupted. The potential event algorithm is designed to assess the safety of any electrical power system in terms of actual power flow. Based on this algorithm, a visual software system was designed using the MATLAB environment that allows the user to have easy dialogue with the computer during operation. It was found through simulation that the program is highly efficient and suitable for estimating network security accurately and quickly. The following are the conclusions we reached during this research:
1. Through the implemented program, it is possible to perform many calculations on the electrical network, such as finding the B matrix, the X matrix, the sensitivity matrix for generation variation, the sensitivity matrix for line interruption, and finding the power flow in all network lines, with the load ratio, and the exhausted lines. 2. The program automatically represents the possible events for all lines and generating stations, so that it deduces the overloaded lines with showing the percentage increasing overload, which gives the operator in the coordination center a prior picture of the network situation in case of faults before they occur. 3. The program proposes corrective actions for the generation change algorithm, with the aim of mitigating as much as possible cases of overloading of lines. 4. The program proposes corrective measures for the generation change algorithm and load decreasing, with the aim of mitigating as much as possible cases of overloading of lines. 5. The penalty of finding the optimal solution by changing the generation increases when the power factor is small, while it decreases significantly with the increase in the power factor. As for using the algorithm to find the optimal solution by changing the generation and decreasing the loads with the change of the power factor, we noticed that it is possible to find the optimal solution for the values of the power factor less than in the case of using the algorithm to find the optimal solution by changing the generation only.