Optimization for Power Outage Restoration Using Python

Published: Sep 10, 2024 Duration: 00:17:37 Category: People & Blogs

Trending searches: power outage
all right everyone in today's teaching lesson we're going to switch back to optimization and we're going to focus specifically on power outage restoration and we're going to use python as always and Jupiter notebook okay um I'm going to use I love optimization uh put together a couple videos I talk about um the benefits of optimization how it works how you can leverage it to uh save money to um increase your profits right so there's um all kinds of applications for optimization I'm going to focus specifically on uh power outage restoration including um Transformers that have been blown out um trees fall down over power lines and the power needs to be restored um a lightning hits a tree and that falls and takes out a bunch of power lines and and um the power has to be brought back on and they have to clean up the um the tree mess and put it in the wood chipper and things like this because I used to work at a company where they did exactly this and they did not have any kind of optimization in place and I I took a look at it one day I thought wow this is a pretty easy win we can put together a script or I can put together a script for these guys that's going to save them a lot of money and you're talking about pretty big numbers here so even um probably a 1% Improvement in the process or in terms of um optimization of the overall um business management can save probably a million dollars right so 1% Improvement can translate to a million dollars in savings so you're talking about some some pretty big numbers here right 10% can save 10 million dollar per year so it's really worth it to understand the concept here and to try to um figure out how you can use this to solve problems as your own company that's where the rubber meets are ug right when you start saving millions of dollars you're going to get notice by some pretty high up people so in this specific example we are going to uh try to find which utility trucks we can send to the power outage site to restore the power okay I'm try going to try to highlight a couple things here in my notes we're going to make sure that the um trucks have the proper skills and the training on board so if there's somebody on the truck that does know how to restore some kind of Transformer or restore the power in in some way then we're not going to send that truck we're only get to send the people that have the skills we're going to send the closest truck to the site where I worked before I'm not going to name any names but they would just send a random truck now you didn't know if that truck was 5 miles away 50 miles away it could be 200 miles away and the drivers in the truck really didn't care because they're going to paid sometimes they're getting paid overtime to drive to the site um but the company cared right because it was a big expense for them if you have to drive two hours to get to the site before you even start working that's kind of a waste right if you can send a closer truck and they can literally restore the power now um you've just saved yourself two hours worth of driving time they used to call it windshield time okay and also we're going to be um aware of how many hours these people have on the shift already if they're at close to seven or eight hours and we don't want to pay overtime and we have another truck that's just as close we can send another truck because we don't have to pay these guys overtime right maybe they just started working one or two hours ago we don't have to send the guys that have been working for eight hours they're about to roll off um we can save a lot of money in overtime too okay so that's how I the problem here I don't have the data because that is all confidential data at this company I used to work at I don't work there anymore but I put together a very realistic example so we have truck coordinates um this is going to be latitude longitude coordinates so we can see how close a truck is to a power outage site or how not close it is right um we're going to have the outage coordinates so we're going to match those two we are going to be looking at the labor skills on the truck okay and the worker skills as well okay and we're going to look work sorry we're going to look at the number of hours that have been worked already and again if it's getting close to seven or eight we don't want to pay these guys overtime because that's going to be a big expense um at the end of the year if you're paying overtime all year long you're paying a lot of money if you can save yourself that overtime you're going save a lot of corporate expenses and it's going to um go go straight to the bottom line right it's going to help your bottom line so we're going to create a distance Matrix so we know how close um Each truck is to the power outage we created these distance Matrix matrices and a couple other videos I did exactly the same thing so we can look at every possible combination of um coordinates for L lud longitude and see how close or how far away something is right so um we have the Baseline assignment this is a list we can tell from the square brackets and we have the assigned trucks over here too so I'm going to go ahead and run h a small Loop to get the number of outages right here um number of outages comes from uh where is it outages oh 10 okay we're going to say we have 10 outages and we have to pick the truck that's the closest so I'm going to go ahead hit control enter run this I'm going to share all this code with you when I post a video so you don't have to worry about all the details or take a lot of notes here or whatever I'm going to give you this code when I load the video okay so you can copy and paste this in your own jupyter notebook environment and run it in and take the take the code apart uh disassemble it reassemble it you can see how everything works here so um we have the distance Matrix we're looking at the number of hours worked if it's less than 8 we are going to consider sending these guys again we have to find the closest truck to the the site where the outage has occurred and if it's greater than eight we're just going to skip this truck and S tell these guys to go home okay take a break you've been working eight hours um we're we're going to pick another truck okay so this is the this is the setup here let me go ahead I just U refreshed the sell and ran it and we can see the Baseline scenario so this is a typical uh thing that you would see at this company that I worked out before truck 4 has mechanical electrical and mechanical these are skill sets it's 11 miles away from the site okay the power outage is 11 miles away and they've worked four hours we can send that truck this truck right here is uh 30 9.9 we can say that's basically 40 miles away if already work 6 hours I'm not going to send that truck it makes no sense this guy is pretty close three miles away so we might send that truck but they've already Works seven hours I might not need those guys I might go with the first truck it's a little bit further away but they have four hours to go on their 8 hour shift the next one is uh basically 35 miles away then the 66 miles away and seven hours worked ready that's not going to happen and all these other trucks are further away okay so um none of these are are really um desirable uh scenarios over here but if we go ahead and optimize it okay we get 11 miles away that's not too bad four hours worked that's doable this um this guy is probably not going to get called he's 40 miles away three miles seven hours worked um maybe it's very close if you can finish the job in 1 hour I would send that we'd have to understand like how long it's going to take to restore the power it's probably more than 1 hour right and this down here looks uh looks possible 16 miles away and then the other two of 36 and 44 that's pretty far but overall when we've optimized this scenario right here we're saving 20% 20.4% overall savings so that's pretty huge if you're talking about a big budget and some of these companies certainly where I used to work 1% savings translated to about a million dollar in in savings over the course of the calendar year so there's 20 million dollars we can save the company right there okay for doing not a whole lot of work that's what I love about these optimization problems you're not investing in new software you're not buying new systems you're not um creating new architecture or infrastructure not hiring dozens of new people you're not opening opening new branches or new warehouses it's just a little software that we have to write we have to understand how the business works and understand how to optimize that business and we're saving $20 million so for not a lot of upfront cost basically zero all we have to do is understand how the business operates and then make that business streamlined efficient we can save $20 million so that's a pretty huge one this is this is Nob brainer we're definitely going to employe this kind of system and some type of um Cloud environment so a lot of people have access to it certainly the operations people the management people um a couple people in the data team should have access to this Tye type of solution right we'll deploy it in a in a shared environment where a lot of people have access to it anybody can run the scenario anytime they want in real time it takes a few seconds and then you know which truck to send to which power outage right so that's pretty cool now let's look at this um we have a model called um grobi this is in the python world there's a few models there's a couple different type of solvers this is a groby solver and it is great at making uh lots of decisions and then optimizing the decisions so like we saw before we have a distance Matrix it'll look at all the possible combination that distance Matrix and then pick the the um distance that's closest to us or shortest distance to travel or the least time to taken to do something and use use that as a final solution so that's what we're going to do we're use groy it's a pretty popular tool for doing a bunch of different things we can do linear programming mix integer programming quadratic programming we can do quadratically constraint programming okay that's when you add constraints to your problem um in the real world usually there's some kind of limitations to something or other that's called a constraint and it also does Mex integer quadratically constrained programming I'll be honest with you I don't even to know what that is I would have to Google that but apparently groy is good at that good in those types of scenarios I use it for the first four and it performs uh fantastic so we'll see an example of that in just a minute um again it's great for supply chain optimization scheduling problems portfolio optimization Transportation finding the the shortest path between two distances say things like that so that's what we're going to do in this in this example the last the last example I showed you was a Brute Force solution so this is a more elegant um gry solver optimized solution so again we have the trucks outages the coordinates we are creating a distance Matrix so we know every possible combination of every distance every truck and every power outage okay and we are going to go ahead and use grobi GP right here as grobi Pi and we are going to go ahead and set the model this g p right there uh we have a distance Matrix I and J these are conventions it could be AB uh Y and Z IJ are pretty pretty commonly used in the uh software development area um it's just a way of of creating two variables and then tracking two variables I don't know the whole history of inj but I've been using this basically forever and it works pretty well so you have the this distance Matrix you have every possible combination okay and we are going to go ahead and run this groy solver and optimize it and see what the outcome is so I'm going to hit control enter to run this thing okay it finishes in about a second not too bad we have um some outputs from groby it says Matrix range object objective range the bounds so the constraints on the problem okay and if we go down here uh solution optimal solution and it found a solution okay now sometimes it cannot find the solution if the constraints are too strict or the problem is too complex for whatever reason usually it has to do with the constraints not being met you'll have an invasible solution and then the solver just can't solve it it's just an impossible problem so you'll have to play around the constraints and loosen those U probably the constraints are too tight that's usually what that means um but you have to get a solution right if you don't you'll have an infusible solution and you'll have to you'll have to um I guess like adjust the conditions or uh play around with your your um logic a little bit to get this thing to run right um so let me go ahead and run this we are going to refresh to Nexel we found an optimized Solution that's great okay and here are the trucks that it's going to or here's the recommendation so power rage 1 through 10 we have assigned truck four the distance is 11 miles Truck 2 39 I'm assuming that's the closest truck right with the skills on board and we're meeting the the constraint of not uh not making people work more than eight hours so we don't have to pay overtime and so on and so forth okay this truck down here truck number seven is 25 miles I like the the truck that's three miles that's closer but it is what it is right this truck is the closest one it has the skills on board and they have the U requirement under eight hours under 8 hours work so here the savings is 15.7% in the last case the savings was a little bit better as 20% but we still save 15% the translation to dollars is probably going to be around $50 million of the course of the calendar year so pretty good stuff right let's look at another example here okay um this is haven't looked at this in a little while so give me a chance to skim through this and see what's going on here uh okay I want to see what it is okay so here is another scenario where we're a little bit clueless we are not optimizing the problem we don't really understand what's going on um we just don't understand the the business logic here right this is before the optimizer if we just had an arbitrary scenario this is random we're just sending random trucks to the site this is what it's going to cost us uh to operate the for one day for one day $35,000 uh 4 423 35k $423 that's what's going to cost right with the optimized solution let's rerun that okay the first one is just um optimize everything now we're comparing an arbitrary random scenar scenario to an to an optimized scenario so it's going to cost $35,000 for one day to handle all these power outages now let's optimize the solution go down here uh I just create the model okay I'm assign the model that's the next step you can certainly do this all in one cell I broke it out into a couple different cells I think it's a little bit easier to read if you're doing this in a production setting you would probably do your development and different cells and once all the codes is developed and refined and and debugged and everything you would probably push it to production one single cell you wouldn't really run this in multiple sales um but just to break it out and to make it easier to read that's how that's how I'm doing in this case Okay so control enter to refresh it okay we're optimizing the problem now and it costs $30,000 per day for these trucks to go to these sites if we divide 35k by 30k subtract one to get a percentage uh you'd have 17.26% increase in savings okay so again pretty decent savings not a lot of upfront work we're not investing software we're not hiring new people we're not investing in new trucks or new warehouses or Staffing um upgrades or anything it's just a simple optimization problem takes very little time uh very little effort to set up but the payoff is huge right so why would you not do this you would you would absolutely do this right so let's look at another scenario here I think this is probably the last one and go down and see what grobi is telling me okay and it says it's going ahead and solving it and found a solution okay so it's model is infusible with four trucks uh we can't send four trucks but we could instead of just sending one we could decide between one or two or no actually we can send two trucks that's what it is we could send two trucks and restore the pet faster so rather than just sending one we can actually send two trucks and the power would be stored even restored even faster right and um electricity is brought up back online and the customers are happy right when your power goes out you're not too happy about that so customer satisfaction is boosted and the job is done even quicker now so we can't send four trucks that's not a feasible solution but we can send two and finish the job even faster that's the takeway here so um good stuff overall it's a it's a little bit to chew on this is a little bit convoluted the first time you see it but it's not impossible to learn this I would encourage you to um do some Googling read up about this understand grobi do some research figure out what's going on and yeah that's pretty much it guys hopefully you learned a couple new things here thanks for your time today and have a wonderful day bye

Share your thoughts