PyDiffGame
is a Python package that allows to solve equations arising in models that involve the use of differential
games for finding optimal controllers of a multi-objective system with multiple controlled objects.
To clone Git repository locally run this from the command prompt:
git clone https://github.com/krichelj/PyDiffGame.git
The package contains a file named PyDiffGame.py
and a class of the same name.
An object of the class represents an instance of differential game. Once the object is created,
the method that calls for the game to begin is play_the_game
.
All the constants are defined in the Mathematical Description section.
The input parameters to instantiate a PyDiffGame
object are:
The system dynamics matrix
System input matrices for each control agenda
Cost function state weights for each control agenda
Cost function input weights for each control agenda
cl
: boolean
Indicates whether to render the closed (True) or open (False) loop behaviour
T_f
: positive float, optional, default = 5
System dynamics horizon. Should be given in the case of finite horizon
Initial state vector
P_f
: list of numpy 2-d arrays, of shape(), optional, default = solution of scipy'ssolve_continuous_are
Final condition for the Riccati equation matrix. Should be given in the case of finite horizon
data_points
: positive int, optional, default = 1000
Number of data points to evaluate the Riccati equation matrix. Should be given in the case of finite horizon
Let us consider the following input parameters for the instantiation of a PyDiffGame
object and
corresponding call for play_the_game
:
import numpy as np
from PyDiffGame import PyDiffGame
A = np.array([[-2, 1],
[1, 4]])
B = [np.array([[1, 0],
[0, 1]]),
np.array([[0],
[1]]),
np.array([[1],
[0]])]
Q = [np.array([[1, 0],
[0, 1]]),
np.array([[1, 0],
[0, 10]]),
np.array([[10, 0],
[0, 1]])
]
R = [np.array([[100, 0],
[0, 200]]),
np.array([[5]]),
np.array([[7]])]
cl = False
X0 = np.array([10, 20])
T_f = 5
P_f = [np.array([[10, 0],
[0, 20]]),
np.array([[30, 0],
[0, 40]]),
np.array([[50, 0],
[0, 60]])]
data_points = 1000
show_legend = True
P = PyDiffGame(A=A, B=B, Q=Q, R=R, cl=cl, X0=X0, P_f =P_f, T_f=T_f, data_points=data_points,
show_legend=show_legend).play_the_game() # the function returns P
This will result in the following plot for the Riccati equation solution:
and the following state space simulation: