Simple overview of use/purpose.
Install python dependancies:
python -m pip install numpy scipy sklearn matplotlib
Clone and Unzip Repo:
git clone https://github.com/zepp14/NumLibDistroPub.git
cd NumLibDistroPub
unzip SDMI_Base_Folder_V2.zip
cd SDMI_Base_Folder
Build and Install:
python setup.py build
sudo python setup.py install
Test:
import sdmiFuncLib as sfl
sfl.generalParaEq(0.2, [1, 3], [0,0], 4, 0, 0)
Expected Output: (1.909796863652831, 3.1844249545367442)
plotSDMI_w_Order_Example.py
This python example implements the plot trial function for predefined capture order https://github.com/zepp14/NumLibDistroPub/blob/main/Examples/plotSDMI_w_Order_Example.py
plot_SDMI_AdaptiveMethod_Order_Example.py
Example showing demo of adaptive method https://github.com/zepp14/NumLibDistroPub/blob/main/Examples/plot_SDMI_AdaptiveMethod_Order_Example.py
plot_SDMI_Enumeration_Order_Example.py
Example showing demo of Enumeration method https://github.com/zepp14/NumLibDistroPub/blob/main/Examples/plot_SDMI_Enumeration_Order_Example.py
Description: This function generates a single X,Y coordinate point on the boundry of the dominant region based on the parametric angular coordinate theta.
Parameters:
- theta: scalar, parametric angular coordinate of point on dominant region boundry
- Invader: [X,Y], position of invader
- Defender: [X,Y], position of defender
- alpha: scalar, ratio of speeds, V_defender / V_invader
- r: scalar, capture range of defender
- T: scalar, Time offset before defender takes optimal pursuit, used for SDMI cases
Output:
- [X,Y]: coordinate point on the boundry of the dominant region based on the parametric angular coordinate
Description: This function generates an array of (#)num points on dominant region boundry, evenly distributed between bounds placed on the parametric angular coordinate.
Parameters:
- Invader: [X,Y], position of invader
- Defender: [X,Y], position of defender
- alpha: scalar, ratio of speeds, V_defender / V_invader
- r: scalar, capture range of defender
- T: scalar, Time offset before defender takes optimal pursuit, used for SDMI cases
- bounds [optional]: [LowerBound, Upperbound ], default = [-pi, pi]
- num [optional]: number of points generated, default = 314
Output:
- [[X, Y],.. [Xn, Yn]]: Array Size [num,2]
Description: Convex Target Region function f(p) >= 0 is out of region and f(p) < 0 inside region.
Parameters:
- Pos: [X,Y], Any 2-D point on game field
- Invader: [X,Y], position of invader
- Defender: [X,Y], position of defender
- alpha: scalar, ratio of speeds, V_defender / V_invader
- r: scalar, capture range of defender
- T: scalar, Time offset before defender takes optimal pursuit, used for SDMI cases
- G_circ: [X_c, Y_c, R], Circular Function Parameters, [X_c, Y_c] = Center of target region, R = Radius of dominant region
Output:
- g: Value of convex target region evaluated at point Pos
Description: Takes in 2D array of Invader location, [[X, Y],.. [Xn, Yn]], creates python dictionary object with invader data.
Parameters:
- I_array: [[X, Y],.. [Xn, Yn]], positions of invader
Output:
- I_dict: Dictionary Object with invader location
- I_list: List of Invader names
plotTrial(Defender, I_dict, Capt_Order, G_circ, alpha, r, axisSz=[-10,10,-5,10], plotFlag=1, T = 0, effMethod = 0, plt=plt)
Description: This function plays out an SDMI game from initial condition with a predefined capture order defined by the order of Capt_Order It can plot out the trial, and returns some key stats about the trial
Parameters:
- Defender: [X,Y], position of defender
- I_dict: Dictionary Object with invader location
- Capt_Order: ex. ['I1', 'I3', 'I2'] Ordered List of Invaders (Capture Order)
- G_circ: [X_c, Y_c, R], Circular Function Parameters, [X_c, Y_c] = Center of target region, R = Radius of dominant region
- alpha: scalar, ratio of speeds, V_defender / V_invader
- r: scalar, capture range of defender
- axisSz [optional]: size of gamefield plotted
- plotFlag [optional]: set to 1(default) to plot to 0 to suppress
- T: scalar, Time offset before defender takes optimal pursuit, used for SDMI cases
- effMethod: scalar, effeciency calculation method, 2 = Distance Traveled, 1 = Distance from Target region, 0 = hybrid effeciency method [Han Fu, 2020]
Output:
- TotEff: Total efficency of Capture order plan
- P_star: 2D array of optimal capture points
- T: Time duration of game
Description: Load trial from dataset (.npz) file and retrieve key info on trial results
Parameters:
- filename: str, name of npz file
- trialNo: scalar, Number ID of trial in question
Output:
- BestOrder: Total efficency of Capture order plan
- BestScore: 2D array of optimal capture points
- Iarr: Time duration of game
- NumCount: Number of SDSI sub-problems solved
- meanVect: Mean of the aggregated performance of dataset
- StdData: Standard deviation of aggregated perfromance of the dataset
Description: Computes a 'fliability' score of the flight path based on how sharp turns in the flight path are.
Parameters:
- P_star: 2D array of optimal capture points
- Defender: [X,Y], position of defender
Output:
- Score: score of capture order plan
Description: Calculates how many invaders have made it past the defences
Parameters:
- P_star: 2D array of optimal capture points
- G_circ: [X_c, Y_c, R], Circular Function Parameters, [X_c, Y_c] = Center of target region, R = Radius of dominant region
- Capt_Order: ex. ['I1', 'I3', 'I2'] Ordered List of Invaders (Capture Order)
- I_dict: Dictionary Object with invader location
Output:
- Score: Number of invaders that have reached the target region
Description: Computes the best capture order through brute force enumeration
Parameters:
- I_array: [[X, Y],.. [Xn, Yn]], 2D array of Invader Locations
- r: scalar, capture range of defender
- alpha: scalar, ratio of speeds, V_defender / V_invader
- Defender: [X,Y], position of defender
- G_circ: [X_c, Y_c, R], Circular Function Parameters, [X_c, Y_c] = Center of target region, R = Radius of dominant region
- dist: scalar, Time offset before defender takes optimal pursuit, used for SDMI cases
- eMethod: scalar, effeciency calculation method, 2 = Distance Traveled, 1 = Distance from Target region, 0 = hybrid effeciency method [Han Fu, 2020]
Output:
- Best Order: Str Array, Best Capture Order
- P_star: 2D array of optimal capture points
- meanVect: Mean of the aggregated performance of dataset
- StdData: Standard deviation of aggregated perfromance of the dataset
- T: scalar, Time offset before defender takes optimal pursuit, used for SDMI cases
Description: This function computes stats on the total set of feasible solution, used for research purposes
Parameters:
- I_array: [[X, Y],.. [Xn, Yn]], 2D array of Invader Locations
- r: scalar, capture range of defender
- alpha: scalar, ratio of speeds, V_defender / V_invader
- Defender: [X,Y], position of defender
- G_circ: [X_c, Y_c, R], Circular Function Parameters, [X_c, Y_c] = Center of target region, R = Radius of dominant region
- dist: scalar, Time offset before defender takes optimal pursuit, used for SDMI cases
- eMethod: scalar, effeciency calculation method, 2 = Distance Traveled, 1 = Distance from Target region, 0 = hybrid effeciency method [Han Fu, 2020]
- plt: plot figure ID
Output:
- Best Order: Str Array, Best Capture Order
- P_star: 2D array of optimal capture points
- meanVect: Mean of the aggregated performance of dataset
- StdData: Standard deviation of aggregated perfromance of the dataset
Description: Facilitates The virtual invader approximation and picks the best cluster to visit first
Parameters:
- r: scalar, capture range of defender
- alpha: scalar, ratio of speeds, V_defender / V_invader
- Defender: [X,Y], position of defender
- G_circ: [X_c, Y_c, R], Circular Function Parameters, [X_c, Y_c] = Center of target region, R = Radius of dominant region
- C1: [X,Y], Centroid of invader cluster 1
- C2: [X,Y], Centroid of invader cluster 2
- dist: scalar, Time offset before defender takes optimal pursuit, used for SDMI cases
- effMethod: scalar, effeciency calculation method, 2 = Distance Traveled, 1 = Distance from Target region, 0 = hybrid effeciency method [Han Fu, 2020]
Output:
- BestIdx: Best Option between C1 and C2
Description: Facilitates KMeans Clustering of the Invaders and outputs Invader Clusters
Parameters:
- I_dict: Dictionary Object with invader location
- I_list: List of Invader names
- r: scalar, capture range of defender
- alpha: scalar, ratio of speeds, V_defender / V_invader
- Defender: [X,Y], position of defender
- G_circ: [X_c, Y_c, R], Circular Function Parameters, [X_c, Y_c] = Center of target region, R = Radius of dominant region
- dist: scalar, Time offset before defender takes optimal pursuit, used for SDMI cases
- eMethod: scalar, effeciency calculation method, 2 = Distance Traveled, 1 = Distance from Target region, 0 = hybrid effeciency method [Han Fu, 2020]
Output:
- invInClust0: Str Array, Cluster of Invaders1
- invInClust1: Str Array Cluster of Invaders2
- ClusterLabel: Labels of Clusters
adaptiveClusteringOrder (I_array, Defender, G_circ, alpha, r, typeEff=0, InitMode=True, reInit = False)
Description: This function implements the adaptive clustering approach to find a good capture.
Parameters:
- I_array: [[X, Y],.. [Xn, Yn]], 2D array of Invader Locations
- Defender: [X,Y], position of defender
- G_circ: [X_c, Y_c, R], Circular Function Parameters, [X_c, Y_c] = Center of target region, R = Radius of dominant region
- alpha: scalar, ratio of speeds, V_defender / V_invader
- r: scalar, capture range of defender
- typeEff: scalar, effeciency calculation method, 2 = Distance Traveled, 1 = Distance from Target region, 0 = hybrid effeciency method [Han Fu, 2020]
- InitMode [optional]: Initialization Flag (Keep True for standard use)
- reInit [optional]: Allow Reinitialization Flag (Default=False: If true, it can be less effecient but the results are more reliable)
Output:
- predictedOrder: Str Array, Approximated Optimal Capture Order