agd.ExportedCode.Notebooks_FMM.DubinsState
1# Code automatically exported from notebook DubinsState.ipynb in directory Notebooks_FMM 2# Do not modify 3import numpy as np; xp = np 4from matplotlib import pyplot as plt 5 6def control_source(activeNeighs,ncontrols,control_default=np.nan,source_default=np.nan): 7 """ 8 Returns the optimal control, or the source of the optimal jump, at each point reached 9 by the front. 10 Input : 11 - activeNeighs : produced by the eikonal solver, with option 'exportActiveNeighs':True 12 - ncontrols : number of controls of the model (needed in case of several states) 13 - control default : when no control is used (jump to another state, or stationnary point) 14 - jump default : when no jump is done (following a control vector, or stationnary point) 15 Output : 16 - control : the index of the control used 17 - source (only if several states) : the index of the source state of the jump 18 """ 19 nstates = activeNeighs.shape[-1] 20 ndim = activeNeighs.ndim 21 decompdim = (ndim*(ndim-1))//2 22 active = activeNeighs%(2**decompdim) 23 stationnary = (active==0) # No control used. Seeds and non reachable points (e.g. inside walls) 24 control = np.where(stationnary,control_default,activeNeighs//(2**decompdim)) 25 assert np.all(control[~stationnary]<ncontrols+(nstates>1)) 26 if nstates==1: return control # Model with a single state 27 jump = (~stationnary) & (control==ncontrols) # Points where the optimal option is to jump to a different state 28 source = np.log2(active).round().astype(int) # source of the jump 29 source = np.where(jump,source + (source>=xp.arange(nstates)), source_default) 30 return np.where(control==ncontrols,control_default,control),source
def
control_source(activeNeighs, ncontrols, control_default=nan, source_default=nan):
7def control_source(activeNeighs,ncontrols,control_default=np.nan,source_default=np.nan): 8 """ 9 Returns the optimal control, or the source of the optimal jump, at each point reached 10 by the front. 11 Input : 12 - activeNeighs : produced by the eikonal solver, with option 'exportActiveNeighs':True 13 - ncontrols : number of controls of the model (needed in case of several states) 14 - control default : when no control is used (jump to another state, or stationnary point) 15 - jump default : when no jump is done (following a control vector, or stationnary point) 16 Output : 17 - control : the index of the control used 18 - source (only if several states) : the index of the source state of the jump 19 """ 20 nstates = activeNeighs.shape[-1] 21 ndim = activeNeighs.ndim 22 decompdim = (ndim*(ndim-1))//2 23 active = activeNeighs%(2**decompdim) 24 stationnary = (active==0) # No control used. Seeds and non reachable points (e.g. inside walls) 25 control = np.where(stationnary,control_default,activeNeighs//(2**decompdim)) 26 assert np.all(control[~stationnary]<ncontrols+(nstates>1)) 27 if nstates==1: return control # Model with a single state 28 jump = (~stationnary) & (control==ncontrols) # Points where the optimal option is to jump to a different state 29 source = np.log2(active).round().astype(int) # source of the jump 30 source = np.where(jump,source + (source>=xp.arange(nstates)), source_default) 31 return np.where(control==ncontrols,control_default,control),source
Returns the optimal control, or the source of the optimal jump, at each point reached by the front. Input :
- activeNeighs : produced by the eikonal solver, with option 'exportActiveNeighs':True
- ncontrols : number of controls of the model (needed in case of several states)
- control default : when no control is used (jump to another state, or stationnary point)
- jump default : when no jump is done (following a control vector, or stationnary point) Output :
- control : the index of the control used
- source (only if several states) : the index of the source state of the jump