to enhance the operation of a microgrid , a two level intelligent power management system ( ipms ) is disclosed . a general structure of primary and secondary power managements in iplms is shown in fig1 a and detailed below . this hierarchical approach makes it easy to prioritize different tasks of the management system based on their importance . overall , homer provides a powerful tool for economical design and making decision about types and ratings of different assets to be utilized in a microgrid . once the design and sizing stages are complete , iplms can result in a more cost - effective control and operation of a microgrid in real time . in order to find the proper time to discharge a battery in a microgrid , it is necessary to calculate the cost of energy from battery ( ceb ) and compare it with costs of other available sources of energy . for this purpose , in this study , a novel cost model based on equivalent uniform annual cost ( euac ) for the battery is presented . equivalent uniform annual cost ( euac ) is a well - known decision making tool to compare different investment projects . it can be used to specify the annual cost of operating a generator asset over its useful lifetime as shown in ( 1 )-( 4 ). for a battery , number of replacements and the replacement years in ( 2 ) are determined by a battery life estimator unit which is explained in the next section . battery usage cost ( buc ) in terms of $/ kwh is then calculated from euac as follows : if the battery is charged by renewable generation , ceb is equal to buc because power from renewable sources is almost free after the installation . in the case of charging the battery by other generator assets such as a diesel generator or the grid , ceb can be written as : ceb can be used to compare cost of generating electric energy by discharging a battery with cost of buying power from other sources of energy such as the grid or a diesel generator at each time instants . parameters such as useful lifetime of the project , inflation and interest rates , and capital and replacement costs are time - independent and only needed once at the initialization stage of cost calculation . however , over the time , the output of ble block varies depending on the updated historical discharge profile of the battery . whenever the estimated life of the battery becomes less than the useful lifetime of the project , a replacement cost component is added to euac which makes cost of energy from battery more expensive . in this way , ceb changes dynamically to reflect the most recent estimated life of the battery in a microgrid . since the number of battery replacements is always an integer number greater or equal to zero , ceb changes in discrete steps depending on the number of replacements within the useful lifetime of the project . a necessary step in design of the intelligent management system is to estimate the remaining life of a battery and its level of degradation at each instant . the main three parameters contributing to a battery aging process are dod , rate of discharge ( discharge current ), and the temperature . in one embodiment , the effects of the first two parameters on the battery aging are considered . assuming the presence of environmental controls , temperature - based battery aging can be ignored . the life estimation method is based on the concept of effective ampere - hours for a battery cell . the required data to implement this ble is generally available for public from the battery datasheets or it can be obtained by a limited set of experiments on the battery by the user . this makes this approach easy to implement and universal for all different types of batteries . in order to calculate the effective ampere - hours of a particular discharge event for a battery , it is necessary to multiply the measured ampere - hour during the discharge event by two weighting factors related to dod and the relative magnitude of discharge current . these two factors can be written as follows : where parameters u 0 and u 1 can be calculated by applying a curve fitting procedure to cycle life versus dod data available from the battery datasheet . similarly , c a can be obtained by applying a 1 - d cubic spline interpolation on finite pairs of data for battery capacities versus discharge currents . different methods can be used to perform curve fitting . two different methods have been used in this study including particle swarm optimization ( pso ) and non - linear least square ( nlls ) method from matlab curve fitting toolbox . pso , as a heuristic optimization technique , is able to achieve optimal solution in a small fraction of a second and is a curve fitting tool compatible with nonlinear battery characteristics . also , nlls is a popular regression method which has been used . the results of curve fitting by pso and nlls for a sample battery are shown in simulation results . the battery end of life ( eol ) reaches when the cumulative effective ampere - hours for all discharge events on the battery equals the rated charge life of the battery which is defined as : based on the above discussion , life of a battery under a specified usage pattern can be estimated as follows : to derive ( 13 ) it is assumed the same series of discharge events ( 1 , . . . , n ) will be repeated for the remaining life of the battery under study . curve fitting on the data is required to determine the coefficients of the function in ( 10 ). the root mean square error ( rmse ) of the curve fitting is 0 . 124 and 3 . 509 for pso and nlls methods , respectively . this error is defined as follows : where x n is the error between data sample n and the value obtained by fitted curve . the results from pso are far better than the results from nlls method . as a result of using pso , battery lifetime estimation will be more accurate which results in a more accurate calculation for the cost of battery . fig1 a shows an exemplary block diagram of the power management unit in the controller . the primary management scheme detects any unbalance in the supply and demand based on the measured dg outputs and load demand . if dg generation is more than the demand and the storage unit is not fully charged the excess generation is used to charge the storage . if dg generation is less than the load demand , secondary management scheme is activated to cover the power shortage either by discharging the battery or by buying power from the grid . the system of fig1 a uses a real - time power and load management controller . the controller collects information about different dg generation power , storage state of charge , and the end - user demand . this will determine discharge pattern of the storage at the time of management which is used to estimate the battery lifetime and consequently calculating the cost of energy from the battery based on a levelized cost model . the cost of energy from the battery is then compared to the grid price signal . in this way the end - user can determine whether it is more cost - effective to use its own storage unit or to buy the power from the grid to balance the electric supply and demand . in case that the purchase of power from the grid is recommended , the end - user can decide to cut its load during high grid prices to reduce its utility bill . the management framework will be updated every minute . in the first level , primary power management , general status of power flow in a microgrid is evaluated . real - time data about the generation level and demand are collected and analyzed to calculate the mismatch power in the microgrid as follows : if excess generation is available in the microgrid ( mismatch power is positive ), it will be used to charge the battery . if sellback is allowed and the battery is fully charged , excess generation can also be exported to the grid . in case of any shortage in the local generation ( negative mismatch power ), primary management triggers the secondary power management unit to remedy the shortage either by importing power from the grid or discharging the battery ( or both ). input parameters to the primary power management unit include dg output powers , load demand , battery state of charge ( soc ), and scheduled imported power from the grid ( if any ). this scheduled power is considered as a fixed source of generation ( typically only changing on an hourly basis ) which is planned in advance based on a unit commitment analysis or other methods . any imported power from the grid decided by the secondary management unit will be added to the scheduled power from the grid . primary power management flowchart is depicted in fig1 b . primary power management unit checks the status of microgrid every minute to achieve a reliable and efficient real - time control of the system . if necessary , secondary power management is then triggered to decide on how to remove the power shortage in a microgrid . fig2 depicts the levelized cost model which is used to calculate the cost of energy from the battery . the storage life estimator decides if any replacement of storage will become necessary during the project life - time depending on the current discharge requirement . based on the output of the life estimator and economic parameters such as inflation and interest rates , the net present cost of storage is divided over the project life - time to calculate the cost of energy from the battery . finally the cost of energy from the battery is compared with the grid price to make a decision on using the grid or discharging the battery . in one embodiment , the system of fig2 uses the following input parameters and steps to calculate cost of energy from a battery in the secondary management unit . this unit first estimates corresponding discharge current and dod of the battery if it is going to be used to meet the power shortage . these parameters can be calculated as follows : these parameters are then used in the ble unit to update the estimated life of the battery based on ( 13 ) as shown in step 1 in fig1 a . the output of ble unit determines the battery replacement cost during the useful lifetime of the microgrid . battery replacement cost along with other necessary parameters such as battery capital cost , battery o & amp ; m cost , nominal interest rate and inflation rate and useful project lifetime are passed to the euac calculator block ( step ) which calculates the annualized cost of battery from ( 1 ). battery usage cost is then calculated from the output of euac calculator block by using ( 8 ) ( step 3 ). finally cost of energy from battery ( ceb ) is calculated based on ( 9 ) by adding the charging cost of battery to the battery usage cost ( step 4 ). by comparing ceb with the grid price , the cheaper source of energy either from the battery or from the grid is detected and will be used to supply the power shortage in a microgrid . decision making process in the secondary power management unit is visually presented in fig3 a . secondary power management flowchart is depicted in fig3 b . fig3 a shows the load management unit in the controller which decides when the demand response can be applicable in order to reduce the utility bill . if the power management unit decides to discharge the battery no demand response is necessary . on the other hand , if the power management unit decides to buy the power shortage from the grid then the end - user can dynamically decide to cut its load if the grid price is high . the demand response algorithm can be carried out without the user interaction by specifying the percentage of the load shedding based on the grid price in advance . the proposed demand response algorithm is new and different from the state of the art . ever increasing installation of microgrids in residential , commercial , and industrial buildings requires demand response ( dr ) programs which take into account customer side electric energy generation and storage capabilities . conventional dr programs in the distribution level only focus on the interaction between the utility and the end - users based on the grid price signal or incentives offered by the utility . previous studies in this area neglected the effects of having distributed generations and energy storage units on the energy consumer decision to participate in a demand response program . a real - time load management controller can be used in conjunction with the power management units described above . the power management units determine whether it is more cost - effective to use on - site storage unit or to buy the power from the grid to balance the electric supply and demand in case of any power shortage . when the purchase of power from the grid is recommended , the load management controller can decide to drop part of the load during peak grid prices to reduce the utility bill . the main differentiation of the proposed load management technique compared to previous methods is that it decides in real - time if a demand response execution ( load shedding ) can result in any saving in terms of the utility bill . fig4 shows the load management flowchart . it can be carried out without the user interaction by specifying the percentage of the load shedding based on the grid price in advance . this solution will provide a guideline for energy consumers to assess the benefits and an automated mechanism to participate in a dr program . it can be used to ensure the end - users that their storage unit will be fully utilized during the desired time span already specified . also , it detects in real - time when it is necessary to buy the power from the grid and how much saving can be achieved by cutting the load . real - time control takes into account any unexpected changes in the distributed generation , demand , and the grid price signal . the whole algorithm presents relatively small complexity and very fast solution so that it can be easily implemented in real - time . overall , it characterizes demand as a virtual resource . the foregoing presents an intelligent power and load management system for cost - effective real - time operation and control of distributed energy resources ( microgrids ) including distributed generations , batteries and controllable loads . special attention is paid to the battery cost model since batteries are the most expensive components of a microgrid . the model to derive the cost of energy from battery ( ceb ) is based on the number of necessary battery replacements over the micro grid useful lifetime . this cost model is later used for electric power sharing between the battery and the grid as the two controllable sources of electric energy in a microgrid . the new cost model dynamically adjusts the number of battery replacements in a way to keep the cost of energy from the battery comparable to the grid price . this battery cost model is compared with homer energy modeling software cost model to show its superior performance . the load management technique is also presented which complements the power management technique in order to maximize the operational cost saving for the microgrid owner . the load management technique is activated when the power management system decides to import power from the grid . in this way , the overall management system tries to optimally utilize the installed battery in a microgrid before applying load shedding in the system . this new load management system considers impacts of both on - site storage capacity and grid price signal while current demand response programs are only based on the grid price or other signals from the utility . case studies based on real data for a commercial building with on - site pv and wind generations and a lithium - ion battery show the effectiveness of the proposed power and load management system for the operation of a microgrid . by using the intelligent management system up to 60 % saving in terms of the operational cost for the mismatch power in a microgrid compared to a no - battery scenario can be achieved . sensitivity studies are also carried out to show the impacts of possible future changes in parameters of the microgrid on the performance of the intelligent management system . an alternative power management system based on a fixed battery lifetime scheme is also taught . this approach is useful when the desired battery lifetime is already determined in advance and the management system is responsible for making sure the battery capacity is fully utilized within the specified time period . results obtained based on the fixed lifetime approach are compared with ipms for the same case study . rapid growth in the installation of microgrid systems requires intelligent and cost effective solutions to control charge and discharge of the battery and other controllable assets in the system . current providers of storage systems for residential and commercial buildings do not provide smart management techniques to minimize the cost of electricity for the customer . the iplms can be used to monitor and control a microgrid system with the minimal interaction from the end user . it can also be made flexible enough to work with different electricity tariffs , renewable energy to load ratios , and battery technologies . the management system can be further improved by defining a cost function to be used as a reference for charging the battery . currently , the charging strategy is based on heuristic rules which must be defined based on specifics of each application . a charge cost function eases the way to develop a universal charging strategy for batteries in microgrids . also , the current version of iplms only switches between the battery and the grid . a mechanism to share the mismatch power between these two sources of energy can be used to enhance iplms performance . other applications of the storage in distribution networks such as peak shaving and load following can also be realized by modifying the cost function accordingly in the iplms . in particular , to implement a peak shaving scenario grid price signal should include an extra component related to demand charges . the invention may be implemented in hardware , firmware or software , or a combination of the three . preferably the invention is implemented in a computer program executed on a programmable computer having a processor , a data storage system , volatile and non - volatile memory and / or storage elements , at least one input device and at least one output device . by way of example , a block diagram of a computer to support the system is discussed next . the computer preferably includes a processor , random access memory ( ram ), a program memory ( preferably a writable read - only memory ( rom ) such as a flash rom ) and an input / output ( i / o ) controller coupled by a cpu bus . the computer may optionally include a hard drive controller which is coupled to a hard disk and cpu bus . hard disk may be used for storing application programs , such as the present invention , and data . alternatively , application programs may be stored in ram or rom . i / o controller is coupled by means of an i / o bus to an i / o interface . i / o interface receives and transmits data in analog or digital form over communication links such as a serial link , local area network , wireless link , and parallel link . optionally , a display , a keyboard and a pointing device ( mouse ) may also be connected to i / o bus . alternatively , separate connections ( separate buses ) may be used for i / o interface , display , keyboard and pointing device . programmable processing system may be preprogrammed or it may be programmed ( and reprogrammed ) by downloading a program from another source ( e . g ., a floppy disk , cd - rom , or another computer ). each computer program is tangibly stored in a machine - readable storage media or device ( e . g ., program memory or magnetic disk ) readable by a general or special purpose programmable computer , for configuring and controlling operation of a computer when the storage media or device is read by the computer to perform the procedures described herein . the inventive system may also be considered to be embodied in a computer - readable storage medium , configured with a computer program , where the storage medium so configured causes a computer to operate in a specific and predefined manner to perform the functions described herein . the invention has been described herein in considerable detail in order to comply with the patent statutes and to provide those skilled in the art with the information needed to apply the novel principles and to construct and use such specialized components as are required . however , it is to be understood that the invention can be carried out by specifically different equipment and devices , and that various modifications , both as to the equipment details and operating procedures , can be accomplished without departing from the scope of the invention itself . c a actual capacity of a battery for a discharge event ( ah ) c r rated ampere - hours capacity of a battery at rated discharge current ( ah ) i discharge battery discharge current φ r rated charge life l r rated cycle life lf batt estimated battery life t time period of system operation for series of discharge events 1 to n d act measured ampere - hours for a discharge event ( ah ) d eff effective ampere - hours for a discharge event ( ah ) buc battery usage cost ($/ kwh ) ceb cost of energy from battery ($/ kwh ) c charge cost of charging the battery ($/ kwh ) euac equivalent uniform annual cost ($) rbc rated battery capacity ( kw ) cc capital cost ($/ kw ) rc replacement cost ($/ kw ) sff sinking fund factor crf capital recovery factor o & amp ; mc annual operation and maintenance cost , $/ kah / year f inflation rate , % i act actual interest rate , % i nom nominal interest rate , % no , rep number of replacements of the battery y rep replacement year y proj useful lifetime of a project ( years ) i * discharge estimated battery discharge current ( a ) dod * estimated depth of discharge p mismatch mismatch power ( w ) v battery battery voltage ( v ) p dg total dgs output power ( w ) p scheduled - grid scheduled power from the grid ( w ) p load demand ( load ) ( w ) c g grid price ($/ kwh ) p battery battery power ( w ) q lifetime battery lifetime throughput ( kwh ) f i battery cycle life c bw battery wear cost ($/ kwh ) μ rt battery roundtrip efficiency ceb homer cost of energy from battery based on homer model ($/ kwh ) t discharge discharge time for a particular discharge event ( hour )