Economic Dispatch and Demand Response of Microgrids MATLAB Code

 Hi, brother. We now will explain the code for economic dispatch and demand response using particle swarm optimization in MATLAB. This code Contain five files. Each file makes some functions. The first thing we will load the input data, the input data file contain the solar profile and wind profiles for the case one.

 

And after that, we decide the number of decision variables. The decision variables, contains three generations, and the power from the network and the power demand response from the customer, three customers for generation, from 1 to 3 and the network power and the customer from 1 to 3. And after that, we define the minimum, a minimum for each and decision variables or for each generation and maximum for each generation and customers after define maximum and minimum regions.

 

Also, we define the ramping upper ramp and down ramp for each generation and the maximum iteration number of iteration 600 and the population size or swarm three hundreds. After that we initialize some parameters of PSO optimizations.

 Here, and after that we also define some velocity limits for PSO optimization and initialization. The position particle's cost a velocitys best cost, best position for optimization PSO and after that defined also global best cost and particle best cost.

 

After that we now define the initialize position, initialize position for 24 hours for particles, each position and this is uniform round of the position. After initialize the position we make or apply the load function. The load function. The main object of the load function here is to,

 the main object. For the load function here is to apply to constrain the first constraint.




 

Is the load equal generation plus wind and PV power minus demand response customers and another object for this function for apply the constraint of upper ramping and down ramping. If you will see here in the load the code that is first thing table 2 contain two things. The first thing is the load in each hour and the second thing is the cost of energy in each hour from the network or if you customer curtail and after that table three is contained wind profile and solar profile and here defines upper bound of the generation and customers and lower down, upper and lower bound of each generation and customer and also defined

 

upper rates ramp rate and down ramp rates. After that we applied the constraint for that the load the load should equal the should equal the load should equal generation plus wind and solar profile minus demands response. And this is also applied for the upper and lower demand, lower ramp rates.

 After that we finish that load profile, we get a new position.

 After initialize the position here and go to the as mentioned before, go to the load and the output from the load function a new position that achieved the constraint of the load equal generation and the lower and upper ramp rates.

 

After initialize that of the position, we initialize the velocity of each particles by zeros. And after that evaluation the object function object function economic dispatch anddemand response. As you see here, this function contained the first the table 1 is load and cost of energy in each hours and also load and wind profile each hours and after that initial parameters for the generation and customers for the demand response and after initialize the parameters we applied, the total load should be equal to generations minus demand response.

 

After that, apply this function, we calculate the cost of conventional power here. This cost for generation conventional power plan and this is for cost of the networks C2 and after that calculate the cost incentives and the cost of customers and applied in the fitness function with weight factor point 5 after calculate the economic dispatch and demand response here.

 

Now we calculate we get some cost of particles and the cost of incentives, the cost of customers, the cost of generation and the cost of networks. And after that we calculate the cost of customers and the cost of network for 24 hours after finished 24 hours, we applied the constraint that constraint talk about the incentive scores should be less than 500 and also calculate that a customer energy that should that should be less then the upper or lower limits after calculate after applied this constraint, we update the global best.

 

The global best is the best cost we calculated ever in each or all particles and update the position of the global best costs and the global best cost also and the customer cost in this position that get the minimum costs. And after that we start the main loop for pso and start from the 1 to 600 iteration and repeated that this loop is contained the first thing after calculate the best positions.

 

We update the new velocity for each particles and then after I updated the velocity we applied the limits of the velocity should be less than a point minus point 25 for velocity maximums and velocity minimums. And after that, after applied the velocity limit, we update the new position after update the new position, we applied also the position of limits that should be less than

 

the maximum for each variables and the minimum and after apply the limits on the position. Applied the load function to achieve the load, load equal generation constraint and then the upper and lower demand ramp rates. After applied this load against the new position that achieved the upper and down ramp rates and the load generation constraint, we evaluation a new object function or fitness and by applied on new position in economic dispatch and demand response functions and get the cost, the new costs for each position and the the cost of incentive, the cost of customer cost of generation.

 

and cost of networks and after that after calculate for 24 hours we applied the constraint for the incentive of customers less than five hundreds and the energy from the customer should be less than the maximum energy should be curtailt. And after that, we have two things. First thing update the personal best for each customers. We compare the best position in each partticles with the new costs for the position.

 

If the cost of new position is best then the cost of the particles of the best cost particles. We will update the new position for the best for the particles and the new best costs. And as a personal best costs for each particles and for each particle. And after that, we also update if some particles.

 

less than the global best costs and we should updated the best global best positions and the global best costs and the cost and and save the cost of customers and generation costs and network cost at the global best cost and then and display the best cost in each iteration. And after that we repeated this function to a 600 a time and after that, after the finished the maximum iteration, we memorize the global best position in this solution and display the result.

 

display the generation one and generation 2 and generation 3and the network power and the curtailed energy from x1 x2 x3. Customer one, Customer two and customer 3 and and the load or generation from wind and solar in each 24 hours. And after that we make some plots for the best cost with the iteration and power curtailed from the customer one and customer two and customer three and the power from generation units one and unit two and three and the power from the network and wind and solar with the time.

 

And after that we display the total conventional power costs and the total transfered power transaction cost and the total the customer incentive and total customer energy curtailed and total in conventional energy curtailed generated and total transferred Energy Kilowatt. Thank you for your listening.

 

Hi brother now we need to explain the deragonfly algorithms code for demand response and economic dispatch and the same things that is here, the maximum iteration and the input data the input data contain that wind profile and the solar profile and after that initialize the upper and lower limits for each customer and generations.

 

And the number of search agent also initialized here and also in variable size. And after that we initialize some variables for DA algorithms here for food fitness and enemy fitness and enemy pos after that initialize that position for each search agents and also initiate lies the another position for each search agents and put it to the fitness zero for each agents.

 

After that we start that the loop here from one to maximum iterations and define some variables for DA optimization. And after that we initialize start from the agents and then initialize the customer energy customer costs to a total generation cost, total network cost. After that we apply the load. As I mentioned before, the load is a function to apply the that load generation constraints and the ramp rates constraints.

 

 

And after applied this load function we get a new position that achieved the two constraints. After that we calculate the demand in economic dispatch and demand response as mentioned as explained before, and the output of this function, the costs, fitness function and the customer incentive cost of customers generation cost and network cost.

 

And this is applied for 24 hours After a finished 24 hours we applied constraint of incentive cost less than 500, and that energy from the customer should be less than the upper or the maximum curtailed energy can be achieved after calculate the demand responses, economic dispatch and demand response, we update the fitness. The food fitness.

 

If the food fitness is less than the fitness and now we update the food fitness. This is the best position mean food fitness. It's the best position and update the value of food fitness and the value of the position and the value of the cost. Customer and generation cost and network cost memorized and save it. And also the enemy is the opposite of our food fitness.

 

After that, we now compare between the new position for the search agent and the previous position, and if the sum limits for that to applied on it and after that after applied this algorithms of the enemies and calculate the new positions by using this function, this function to calculate the new position of the next iteration after and the new position of the delta X after that after finish that we put in the best we put the best score equal food fitness and best position equal food be assumed after finished that iteration or loop, we display the result as I mentioned before.

 

Hi, and now we want to explain the case 2 the case 2 for economic dispatch and demand response. It is the same case one, but that the data is different or that an initial parameter is different. Now we the first thing is the load, the input data and input data. As mentioned before, it's contained the

 

wind profile and solar profiles and then put it, the number of decision variables is 18. We have ten generators and one network connection and seven customers. And here we mentioned P1, p2, p3 to be ten. This is for general conventional generation and Pr are for the network. And this is x1x2x7 for the customers.

 

And this is that a minimum and maximum bound upper maximum bound for each variables. And also we define the upper and down, up and down ramp rates for each generation, for ten generations. And after initialize that and put it the maximum iteration 100 and the number of population size 600 because there is a lot of variables and decision variables.

 

So we need more iterations to get the best solution. And after that we defined the PSO parameters and velocities and initialize and particle cost and global cost. And after that we initialize the position by randomly and uniform randomly. And after that applied that load. for load the function, the load function as I mentioned before, is then to apply 2 constrain.

 

The first one is the load should be equal, the generation minus the demand response plus wind and solar profiles. And another thing to apply the up and down ramp rates after applied the load function, we each achieved a new or we get a new position that achieved 2 constraints and initialize the new initialize the velocity equal zero for each particles and after that we calculate the demand response and the economics dispatch functions.

 

Object functions as before. Here the function and we calculate the cost of And we here initialized parameters for each generator, for each customers. And after that we calculated the cost from the conventional powers and the from the networks. And after that, from at the customers incentive customers and the course of customers and after that put it in the fitness function with weights.

 

This is the weight point five for each customers, for each function. And after calculating this function, we get it. The best costs and the energy from each customers for 24 hours, and that costs of the customer for 24 hours. After that, we after finished the 24 hours, we apply the cost incentive, the customers incentive cost customers should be less than 150,000 US dollar and apply that that each customer should be less than the maximum energy can be curtailed.

 

And after applied 2 constraint this 2 constrain, we updated the global best costs by compare with the global best cost with the best cost for each particle. If the best cost for each particle is less than global, the global best cost we updated the global best position and global best cost and save the customer cost. And after updating the global best costs now we go to the main loop for the PSO from one to maximum iteration 1000 and make repeated all this functions 1 thousand.

 

We initialize the generation from the generation from each customers. The best position cost. The customer costs its total generation cost this is initial for each cost and after that updated the velocity depend on the global best cost position and applied the velocity limits on the new velocities and updated the new positions by the old position plus new velocity for each particles and applied After that the best applied The position limits should be less than the maximum for each generation or customers, and after that after updated the new position and applied, the limits we applied the load function to achieve 2 constrain for the generation equal load,

 

and the up and down ramp rates. And after applied that load we get the new position that achieved to constrain that mentioned. And then after that we calculate the fitness function for economic dispatch demand response and get the position cost, the cost of incentive, the cost of customer cost of generation and cost of networks.

 

And after that we calculate it for 24 hours. And after finished from the 24 hours we applied the limit for total customer incentive costs for each days. And 150,000 U.S. dollar. And after that we applied also the total energy from each customer during the day and after applied 2 constrain, we updated two things. The first thing is the personal best position for each particles.

 

For each particle. We we compared with the best cost reached from each particles with the new cost of the particles. If the new costs is less than the best costs of each position, we updated the new particle position particle's best position particles, and best position cost for each particle individually. And after that we also updated the global the global best costs for all the position by comparing with the global the previous global ones.

 

Best cost with the best new best cost. If the new best cost is better than or minimum, the less than the global best cost we apply. We updated the new position for the global best cost and the global best costs also updated and after that saved the customer cost. Total generation cost and total network costs. And then displayed the best, the new best cost for that iteration.

 

After finished from the loop and repeated this procedure, we put the best solution. We put the global best costs position in the best solution, and after that we displayed the results. The result is contain ten generations, the network, the customers in each car, the customers and the PV and wind or solar profile. And after that we also plot the best cost with the iteration the customer, power curtailed from each customer, with the time and the generation power with the time and the network wind solar power with the time.

 

And after that we display the total conventional power costs total transferred power transaction costs and total customer incentive additional that to the total customer energy curtailed and total in conventional energy generated and total transferred energy. Thank you for your listening. I hope we defined all the cases and the DA case to the same thing should be understand?

 

I hope I explain. You will. If you have any question, you can can connect with us.

Comments

Popular posts from this blog

Grid New 33 Bus PV Wind - STATCOM MATLAB Simulation

UniRouter Airdrop: Bridging Bitcoin and EVM Assets

Unit Commitment and Economic Dispatch - UC & ED by Salp Swarm Algorithm (SSA) MATLAB Code