rte-france / grid2op-milp-agent

Mozilla Public License 2.0
7 stars 1 forks source link

Mixed Integer Linear Programming (MILP) agent

The MILP agent controller is a power grid monitoring developed to manage over-thermal lines using topological actions. The MLIP agent takes a snapshot of the grid state (environment), then under linear constraints based on the DC approximation, this agent seeks to minimize the overthermal lines by using topological actions (line switching, bus reconfiguration). Currently, the MILP agent is adapted with pandapower backend powerflow solver.

Installation

Requirements

This agent uses the following python libraries, which will be installed when you install milp_agent:

The MILP agent will used by the way the following libraries:

They will be installed if you install the MILP agent from source.

You can install them using pip: pip install -U grid2op pandapower ortools numpy pandas

Install the package

You can directly install the milp agent from pip too:

# first you need to clone the repository
git clone THEGITHUBLINK
cd milp_agent
pip install -e .

And you can now use it as any python library.

How to use MILP_agent ?

After install the MIP_Agent, the following example shows how use the MLIP agent.

import grid2op 
from grid2op.Agent import DoNothingAgent
from grid2op.PlotGrid import PlotMatplot
from grid2op.Action import DontAct
from grid2op.Chronics import GridStateFromFileWithForecastsWithoutMaintenance
import numpy as np
import milp_agent
from milp_agent.agent import MILPAgent

env_name = "rte_case5_example"
env = grid2op.make(env_name, test=True)
obs = env.get_obs()
margins = 0.95*np.ones(obs.n_line)
obs = env.get_obs()
Agent_type = milp_agent.GLOBAL_SWITCH 
Solver_type = milp_agent.MIP_CBC
agent = MILPAgent(env, Agent_type, margins, solver_name=Solver_type)
# and now you can use it as any grid2op compatible agent, for example:
action = agent.act(obs, reward=0.0, done=False)
new_state, reward, done, info = env.step(action)

Note that this library takes the environment from grid2op library. The MILP agent is tested on L2RPN data.

Additional information

The process of execution

In order to use the MILP agent for topological agent controller, you follow these steps:

You could use the usecase method to run the MILP agent automatically to solve the over thermal lines in complete episode until the end of the episode or gameover due to the violation of one of grid2op rules. Using this method, the result will be saved in output and log_agent folders.

MILP agent types

The MILP agent is implemented in different ways:

MILP Solver

The MILP agent uses Or-tools to set the constraint equations, define the cost function and solve the optimization problem. Or-tools is an open source software shaped for handling integer, linear and constraint programming. Or-tools allow us to implement the modelization of any problems in the programming language of your choice. Or-tools is adapted to many open-source solvers like Scip,GLPK, GloP or CBC, or commercial solvers like Xpress or CPLEX. In out work, we adapt our MILP agent to run under CBC, SCIP, GLOP or Xpress solver.

Grid2op environment

The environment that the MLIP agent relies on to observe the state of the grid, set actions and check the correctness of the action are encapsulated under Grid2op. This platform constructed to simulate the power grid control, allows the MILP agent to get a snapshot of the grid and perform the action that minimize the over-thremal lines on the grid.

Agent characteristics

Each type of the MILP agents needs to specify the following parameters:

The uses of the complimentary double agent need to specify:

The other iteration manages the complimentary grid structures.

The utility of complimentary double and multi-zone agent need additionally to specify:

The agents could be customized by:

License information

copyright 2020-2021 RTE France

RTE: http://www.rte-france.com

This Source Code is subject to the terms of the Mozilla Public Licence (MPL) v2 also avaible here

Contributing

We welcome contribution from everyone. They can take the form of pull requests. In case of a major change, please open an issue first to discuss what you would like to change.

Code in the contribution should pass all the tests, have some dedicated tests for the new feature and documentation.